|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +PR_URL="$1" |
| 6 | + |
| 7 | +if [ -z "$PR_URL" ]; then |
| 8 | + echo "Usage: $0 <PR_URL>" |
| 9 | + echo "" |
| 10 | + echo "Check if the PR references any non-help-wanted issues and, if so, comment" |
| 11 | + echo "on it explaining why the team might close/dismiss it." |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | + |
| 15 | +# Skip if PR is from a bot or org member |
| 16 | +if [ "$PR_AUTHOR_TYPE" = "Bot" ] || [ "$PR_AUTHOR_ASSOCIATION" = "MEMBER" ] || [ "$PR_AUTHOR_ASSOCIATION" = "OWNER" ]; then |
| 17 | + 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)" |
| 18 | + exit 0 |
| 19 | +fi |
| 20 | + |
| 21 | +# Extract PR number from URL for logging |
| 22 | +PR_NUM="$(basename "$PR_URL")" |
| 23 | + |
| 24 | +# Extract cli/cli closing issues references from PR |
| 25 | +CLOSING_ISSUES="$(gh pr view "$PR_URL" --json closingIssuesReferences --jq '.closingIssuesReferences[] | select(.repository.name == "cli" and .repository.owner.login == "cli") | .number')" |
| 26 | + |
| 27 | +if [ -z "$CLOSING_ISSUES" ]; then |
| 28 | + echo "No closing issues found for PR #$PR_NUM" |
| 29 | + exit 0 |
| 30 | +fi |
| 31 | + |
| 32 | +# Check each closing issue for 'help-wanted' label |
| 33 | +ISSUES_WITHOUT_HELP_WANTED=() |
| 34 | + |
| 35 | +for issue_num in $CLOSING_ISSUES; do |
| 36 | + echo "Checking issue #$issue_num for 'help wanted' label..." |
| 37 | + |
| 38 | + # Get issue labels |
| 39 | + LABELS=$(gh issue view "$issue_num" --json labels --jq '.labels[].name') |
| 40 | + |
| 41 | + # Skip if the issue has the gh-attestion or gh-codespace label |
| 42 | + # This is because the codeowners for these commands may not be public |
| 43 | + # cli org members, and so unless we authenticate with a PAT, we can't |
| 44 | + # know who is an external contributor or not. |
| 45 | + # So we skip these issues to avoid falsely writing a comment |
| 46 | + # on each PR opened by these codeowners. |
| 47 | + if echo "$LABELS" | grep -q -e "gh-attestation" -e "gh-codespace"; then |
| 48 | + echo "Issue #$issue_num is skipped due to labels" |
| 49 | + continue |
| 50 | + fi |
| 51 | + |
| 52 | + # Check if 'help wanted' label exists |
| 53 | + if ! echo "$LABELS" | grep -q "help wanted"; then |
| 54 | + ISSUES_WITHOUT_HELP_WANTED+=("$issue_num") |
| 55 | + echo "Issue #$issue_num does not have 'help wanted' label" |
| 56 | + else |
| 57 | + echo "Issue #$issue_num has 'help wanted' label" |
| 58 | + fi |
| 59 | +done |
| 60 | + |
| 61 | +# If we found issues without 'help wanted' label, post a comment |
| 62 | +if [ ${#ISSUES_WITHOUT_HELP_WANTED[@]} -gt 0 ]; then |
| 63 | + echo "Found ${#ISSUES_WITHOUT_HELP_WANTED[@]} issues without 'help wanted' label" |
| 64 | + |
| 65 | + # Build issue list for comment |
| 66 | + ISSUE_LIST="" |
| 67 | + for issue_num in "${ISSUES_WITHOUT_HELP_WANTED[@]}"; do |
| 68 | + ISSUE_LIST="$ISSUE_LIST- #$issue_num"$'\n' |
| 69 | + done |
| 70 | + |
| 71 | + # Create comment message |
| 72 | + gh pr comment "$PR_URL" --body-file - <<EOF |
| 73 | +Thank you for your pull request! 🎉 |
| 74 | +
|
| 75 | +This PR appears to fix the following issues that are not labeled with \`help wanted\`: |
| 76 | +
|
| 77 | +$ISSUE_LIST |
| 78 | +As outlined in our [Contributing Guidelines](https://github.com/cli/cli/blob/trunk/.github/CONTRIBUTING.md), we expect that PRs are only created for issues that have been labeled \`help wanted\`. |
| 79 | +
|
| 80 | +While we appreciate your initiative, please note that: |
| 81 | +
|
| 82 | +- **PRs for non-\`help wanted\` issues may not be reviewed immediately** as they might not align with our current priorities |
| 83 | +- **The issue might already be assigned** to a team member or planned for a specific release |
| 84 | +- **We may need to close this PR**. For example, if it conflicts with ongoing work or architectural decisions |
| 85 | +
|
| 86 | +**What happens next:** |
| 87 | +- Our team will review this PR and the associated issues |
| 88 | +- We may add the \`help wanted\` label to the issues, if appropriate, and review this pull request |
| 89 | +- In some cases, we may need to close the PR. For example, if it doesn't fit our current roadmap |
| 90 | +
|
| 91 | +Thank you for your understanding and contribution to the project! 🙏 |
| 92 | +
|
| 93 | +*This comment was automatically generated by cliAutomation.* |
| 94 | +EOF |
| 95 | + |
| 96 | + echo "Posted comment on PR #$PR_NUM" |
| 97 | +else |
| 98 | + echo "All closing issues have 'help wanted' label - no action needed" |
| 99 | +fi |
0 commit comments