Repository: cli/cli
File: .github/workflows/scripts/check-help-wanted.sh (Shell)

Code before:
#!/bin/bash

set -e

PR_URL="$1"

if [ -z "$PR_URL" ]; then
    echo "Usage: $0 <PR_URL>"
    echo ""
    echo "Check if the PR references any non-help-wanted issues and, if so, comment"
    echo "on it explaining why the team might close/dismiss it."
    exit 1
fi

# Extract PR number from URL for logging
PR_NUM="$(basename "$PR_URL")"

# Get PR details including closing issues references
PR_DATA="$(gh pr view "$PR_URL" --json closingIssuesReferences)"

# Extract closing issues references
CLOSING_ISSUES="$(echo "$PR_DATA" | jq -r '.closingIssuesReferences[]?.number // empty')"

if [ -z "$CLOSING_ISSUES" ]; then
    echo "No closing issues found for PR #$PR_NUM"
    exit 0
fi

# Check each closing issue for 'help-wanted' label
ISSUES_WITHOUT_HELP_WANTED=()

for issue_num in $CLOSING_ISSUES; do
    echo "Checking issue #$issue_num for 'help wanted' label..."

    # Get issue labels
    LABELS=$(gh issue view "$issue_num" --json labels --jq '.labels[].name')

    # Skip if the issue has the gh-attestion or gh-codespace label
    # This is because the codeowners for these commands may not be public
    # cli org members, and so unless we authenticate with a PAT, we can't
    # know who is an external contributor or not.
    # So we skip these issues to avoid falsely writing a comment
    # on each PR opened by these codeowners.
    if echo "$LABELS" | grep -q -e "gh-attestation" -e "gh-codespace"; then
        echo "Issue #$issue_num is skipped due to labels"
        continue
    fi

Review comment (refactor):
**question:** should this be limited to `cli/cli` issues only?

If so, then one approach would be:

```suggestion
# Extract cli/cli closing issues references from PR
CLOSING_ISSUES="$(gh pr view "$PR_URL" --json closingIssuesReferences --jq '.closingIssuesReferences[] | select(.repository.name == "cli" and .repository.owner.login == "cli") | .number')"
```

Demonstrating this against #11105 PR _(sorry for the chatter)_:

```shell
andyfeller@Desktop:~/workspace/cli/cli$ .github/workflows/scripts/check-help-wanted.sh https://github.com/cli/cli/pull/11105
Checking issue #11100 for 'help wanted' label...
Issue #11100 does not have 'help wanted' label
Found 1 issues without 'help wanted' label
https://github.com/cli/cli/pull/11105#issuecomment-2976697954
Posted comment on PR #11105
```

Demonstrating this against #10890:

```shell
andyfeller@Desktop:~/workspace/cli/cli$ .github/workflows/scripts/check-help-wanted.sh https://github.com/cli/cli/pull/10890
No closing issues found for PR #10890
```

Code after:
#!/bin/bash

set -e

PR_URL="$1"

if [ -z "$PR_URL" ]; then
    echo "Usage: $0 <PR_URL>"
    echo ""
    echo "Check if the PR references any non-help-wanted issues and, if so, comment"
    echo "on it explaining why the team might close/dismiss it."
    exit 1
fi

# Extract PR number from URL for logging
PR_NUM="$(basename "$PR_URL")"

# Extract cli/cli closing issues references from PR
CLOSING_ISSUES="$(gh pr view "$PR_URL" --json closingIssuesReferences --jq '.closingIssuesReferences[] | select(.repository.name == "cli" and .repository.owner.login == "cli") | .number')"

if [ -z "$CLOSING_ISSUES" ]; then
    echo "No closing issues found for PR #$PR_NUM"
    exit 0
fi

# Check each closing issue for 'help-wanted' label
ISSUES_WITHOUT_HELP_WANTED=()

for issue_num in $CLOSING_ISSUES; do
    echo "Checking issue #$issue_num for 'help wanted' label..."

    # Get issue labels
    LABELS=$(gh issue view "$issue_num" --json labels --jq '.labels[].name')

    # Skip if the issue has the gh-attestion or gh-codespace label
    # This is because the codeowners for these commands may not be public
    # cli org members, and so unless we authenticate with a PAT, we can't
    # know who is an external contributor or not.
    # So we skip these issues to avoid falsely writing a comment
    # on each PR opened by these codeowners.
    if echo "$LABELS" | grep -q -e "gh-attestation" -e "gh-codespace"; then
        echo "Issue #$issue_num is skipped due to labels"
        continue
    fi

    # Check if 'help wanted' label exists
    if ! echo "$LABELS" | grep -q "help wanted"; then