#!/bin/bash set -e PR_URL="$1" if [ -z "$PR_URL" ]; then echo "Usage: $0 " 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 # 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)" 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 # 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 -qE '^help wanted$'; then ISSUES_WITHOUT_HELP_WANTED+=("$issue_num") echo "Issue #$issue_num does not have 'help wanted' label" else echo "Issue #$issue_num has 'help wanted' label" fi done # If we found issues without 'help wanted' label, post a comment if [ ${#ISSUES_WITHOUT_HELP_WANTED[@]} -gt 0 ]; then echo "Found ${#ISSUES_WITHOUT_HELP_WANTED[@]} issues without 'help wanted' label" # Build issue list for comment ISSUE_LIST="" for issue_num in "${ISSUES_WITHOUT_HELP_WANTED[@]}"; do ISSUE_LIST="$ISSUE_LIST- #$issue_num"$'\n' done # Create comment message gh pr comment "$PR_URL" --body-file - <