From 45c8c827c53f8f8325b4b01c82995ce8bd0580bc Mon Sep 17 00:00:00 2001 From: Kynan Ware <47394200+BagToad@users.noreply.github.com> Date: Mon, 30 Jun 2025 10:51:54 -0600 Subject: [PATCH] Add `workflow_dispatch` support to PR Help Wanted check (#11179) * Add workflow_dispatch support to PR Help Wanted check This update allows the PR Help Wanted workflow to be triggered manually via workflow_dispatch with a specified PR URL. It adds logic to fetch PR details using the GitHub CLI for manual runs and unifies variable handling for both event types. * Update workflow to use PR number instead of URL Changed the workflow_dispatch input from 'pr_url' to 'pr_number' and updated the script to construct the PR URL from the number. * Move help-wanted check for draft PRs into script * Don't prefix URL with `#` * Invert draft checking logic Inverting this logic because anything other than "false" means we should skip it. * Move PR draft status check to shell script The logic for checking if a pull request is a draft has been moved from the GitHub Actions workflow YAML to the check-help-wanted.sh script. This simplifies the workflow file and centralizes the draft status check within the script. --- .github/workflows/pr-help-wanted.yml | 24 +++++++++++++++++-- .../workflows/scripts/check-help-wanted.sh | 8 ++++++- 2 files changed, 29 insertions(+), 3 deletions(-) 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