Created
May 26, 2023 11:38
-
-
Save iamazeem/6411ffddcdb4f2d4717c9ddfb463d57c to your computer and use it in GitHub Desktop.
GitHub - close PRs with no linked issues (Bash script)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
owner="" # owner name here | |
repo="" # repo name here | |
prs=$(gh pr list --repo "$owner/$repo" --json number --jq '.[] | join("")') | |
for pr in $prs; do | |
issue=$(gh api graphql -F owner="$owner" -F repo="$repo" -F pr="$pr" -f query=' | |
query ($owner: String!, $repo: String!, $pr: Int!) { | |
repository(owner: $owner, name: $repo) { | |
pullRequest(number: $pr) { | |
closingIssuesReferences(first: 100) { | |
nodes { | |
number | |
} | |
} | |
} | |
} | |
}' --jq '.data.repository.pullRequest.closingIssuesReferences.nodes[].number') | |
if [[ -z $issue ]]; then | |
echo "PR [$pr] linked issue not found, closing" | |
gh pr close --repo "$owner/$repo" "$pr" | |
else | |
echo "PR [$pr] linked issue found: $issue" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment