@@ -399,6 +399,129 @@ jobs:
399399 fi
400400 git push origin --delete test/e2e-pr-project-${{ github.run_id }} 2>/dev/null || true
401401
402+ pull-request-with-created-labels :
403+ name : Pull request with created labels
404+ needs : [preflight]
405+ runs-on : ubuntu-24.04-arm
406+ env :
407+ TEST_ID : ${{ github.run_id }}-${{ github.run_attempt }}
408+ TEST_LABEL : zzz-e2e/action-pull-request-${{ github.run_id }}-${{ github.run_attempt }}
409+ steps :
410+ - name : Checkout repository
411+ uses : actions/checkout@v7
412+ with :
413+ fetch-depth : 0
414+
415+ - name : Create test branch with a commit
416+ run : |
417+ git config user.name "github-actions[bot]"
418+ git config user.email "github-actions[bot]@users.noreply.github.com"
419+ git checkout -b "test/e2e-pr-labels-${TEST_ID}"
420+ echo "E2E PR label creation test $(date -u)" > e2e-pr-label-test.txt
421+ git add -f e2e-pr-label-test.txt
422+ git commit -m "test(pull-request): label creation PR test"
423+ git push origin "test/e2e-pr-labels-${TEST_ID}"
424+
425+ - name : Checkout action under test
426+ if : ${{ inputs.mode == 'ref' }}
427+ uses : actions/checkout@v7
428+ with :
429+ repository : devops-infra/action-pull-request
430+ ref : ${{ inputs.action_ref }}
431+ path : .tmp/action-pull-request
432+
433+ - name : Create pull request with created labels
434+ if : ${{ inputs.mode == 'ref' }}
435+ id : pr
436+ uses : ./.tmp/action-pull-request
437+ with :
438+ github_token : ${{ secrets.GITHUB_TOKEN }}
439+ title : " test(pull-request): label creation test - safe to close"
440+ body : " Automated end-to-end test for missing label creation."
441+ target_branch : master
442+ label : ${{ env.TEST_LABEL }}
443+ create_missing_labels : " true"
444+
445+ - name : Create pull request via docker image
446+ if : ${{ inputs.mode == 'image' }}
447+ env :
448+ ACTION_IMAGE : devopsinfra/action-pull-request:${{ inputs.image_tag }}
449+ run : |
450+ if [ -z "${{ inputs.image_tag }}" ]; then
451+ echo "image_tag is required when mode=image"
452+ exit 1
453+ fi
454+ mkdir -p .tmp
455+ : > .tmp/e2e-pr-labels.outputs
456+ docker pull "${ACTION_IMAGE}"
457+ docker run --rm \
458+ -e GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
459+ -e GITHUB_REPOSITORY="${{ github.repository }}" \
460+ -e GITHUB_WORKSPACE=/github/workspace \
461+ -e GITHUB_ACTOR="${{ github.actor }}" \
462+ -e GITHUB_OUTPUT=/github/workspace/.tmp/e2e-pr-labels.outputs \
463+ -e INPUT_GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
464+ -e INPUT_SOURCE_BRANCH="test/e2e-pr-labels-${TEST_ID}" \
465+ -e INPUT_TITLE="test(pull-request): label creation test - safe to close" \
466+ -e INPUT_BODY="Automated end-to-end test for missing label creation." \
467+ -e INPUT_TARGET_BRANCH=master \
468+ -e INPUT_LABEL="${TEST_LABEL}" \
469+ -e INPUT_CREATE_MISSING_LABELS=true \
470+ -v "$PWD:/github/workspace" \
471+ -w /github/workspace \
472+ "${ACTION_IMAGE}"
473+
474+ - name : Verify outputs
475+ if : ${{ inputs.mode == 'ref' }}
476+ run : |
477+ echo "url=${{ steps.pr.outputs.url }}"
478+ echo "pr_number=${{ steps.pr.outputs.pr_number }}"
479+ test -n "${{ steps.pr.outputs.url }}"
480+ test -n "${{ steps.pr.outputs.pr_number }}"
481+
482+ - name : Verify outputs from docker image
483+ if : ${{ inputs.mode == 'image' }}
484+ run : |
485+ URL="$(sed -n 's/^url=//p' .tmp/e2e-pr-labels.outputs | tail -1)"
486+ PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-labels.outputs | tail -1)"
487+ echo "url=${URL}"
488+ echo "pr_number=${PR_NUMBER}"
489+ test -n "${URL}"
490+ test -n "${PR_NUMBER}"
491+
492+ - name : Verify label assignment
493+ env :
494+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
495+ run : |
496+ PR_NUMBER="${{ steps.pr.outputs.pr_number }}"
497+ if [ -z "$PR_NUMBER" ] && [ -f .tmp/e2e-pr-labels.outputs ]; then
498+ PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-labels.outputs | tail -1)"
499+ fi
500+ test -n "${PR_NUMBER}"
501+
502+ LABEL_FOUND="$(
503+ gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" --json labels \
504+ | jq -r --arg label "${TEST_LABEL}" 'any(.labels[]?; .name == $label)'
505+ )"
506+
507+ test "${LABEL_FOUND}" = "true"
508+
509+ - name : Cleanup - close PR, delete label, and delete test branch
510+ if : ${{ always() }}
511+ env :
512+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
513+ run : |
514+ PR_NUMBER="${{ steps.pr.outputs.pr_number }}"
515+ if [ -z "$PR_NUMBER" ] && [ -f .tmp/e2e-pr-labels.outputs ]; then
516+ PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-labels.outputs | tail -1)"
517+ fi
518+ if [ -n "$PR_NUMBER" ]; then
519+ gh pr close "$PR_NUMBER" --repo "${{ github.repository }}" 2>/dev/null || true
520+ fi
521+ ENCODED_LABEL="$(python3 -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1], safe=""))' "${TEST_LABEL}")"
522+ gh api --method DELETE "repos/${{ github.repository }}/labels/${ENCODED_LABEL}" 2>/dev/null || true
523+ git push origin --delete "test/e2e-pr-labels-${TEST_ID}" 2>/dev/null || true
524+
402525 pull-request-with-repository-path :
403526 name : Pull request using custom checkout path and explicit repository
404527 needs : [preflight]
0 commit comments