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.
This commit is contained in:
Kynan Ware 2025-06-30 10:51:54 -06:00 committed by GitHub
parent e5913fe02f
commit 45c8c827c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 3 deletions

View file

@ -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}"

View file

@ -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