diff --git a/.github/workflows/pr-help-wanted.yml b/.github/workflows/pr-help-wanted.yml index 3482ecd08..0052f58db 100644 --- a/.github/workflows/pr-help-wanted.yml +++ b/.github/workflows/pr-help-wanted.yml @@ -2,6 +2,12 @@ name: PR Help Wanted Check on: pull_request_target: types: [opened] + workflow_dispatch: + inputs: + pr_number: + description: "Pull Request number to check" + required: true + type: string permissions: contents: none @@ -15,13 +21,27 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 + - name: Set PR variables for workflow_dispatch event + id: pr-vars-dispatch + if: github.event_name == 'workflow_dispatch' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.inputs.pr_number }} + run: | + # We only need to construct the PR URL from the dispatch event input. + echo "pr_url=https://github.com/cli/cli/pull/${PR_NUMBER}" >> $GITHUB_OUTPUT + - name: Check for issues without help-wanted label env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # These variables are optionally used in the check-help-wanted.sh + # script for additional checks; but they are not strictly necessary + # for the script to run. This is why we are okay with them being + # empty when the event is workflow_dispatch. PR_AUTHOR: ${{ github.event.pull_request.user.login }} PR_AUTHOR_TYPE: ${{ github.event.pull_request.user.type }} PR_AUTHOR_ASSOCIATION: ${{ github.event.pull_request.author_association }} - if: "!github.event.pull_request.draft" + PR_URL: ${{ github.event.pull_request.html_url || steps.pr-vars-dispatch.outputs.pr_url }} run: | # Run the script to check for issues without help-wanted label - bash .github/workflows/scripts/check-help-wanted.sh ${{ github.event.pull_request.html_url }} + bash .github/workflows/scripts/check-help-wanted.sh "${PR_URL}" diff --git a/.github/workflows/scripts/check-help-wanted.sh b/.github/workflows/scripts/check-help-wanted.sh index d316e8bde..75462ddb9 100755 --- a/.github/workflows/scripts/check-help-wanted.sh +++ b/.github/workflows/scripts/check-help-wanted.sh @@ -14,7 +14,13 @@ fi # Skip if PR is from a bot or org member if [ "$PR_AUTHOR_TYPE" = "Bot" ] || [ "$PR_AUTHOR_ASSOCIATION" = "MEMBER" ] || [ "$PR_AUTHOR_ASSOCIATION" = "OWNER" ]; then - echo "Skipping check for PR #$PR_URL as it is from a bot ($PR_AUTHOR_TYPE) or an org member ($PR_AUTHOR_ASSOCIATION: MEMBER/OWNER)" + echo "Skipping check for PR $PR_URL as it is from a bot ($PR_AUTHOR_TYPE) or an org member ($PR_AUTHOR_ASSOCIATION: MEMBER/OWNER)" + exit 0 +fi + +# Skip if PR is a draft +if [ "$(gh pr view "${PR_URL}" --json isDraft --jq '.isDraft')" != "false" ]; then + echo "Skipping check for PR $PR_URL as it is a draft" exit 0 fi