Skip to content

Instantly share code, notes, and snippets.

@iamazeem
Created May 26, 2023 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamazeem/6411ffddcdb4f2d4717c9ddfb463d57c to your computer and use it in GitHub Desktop.
Save iamazeem/6411ffddcdb4f2d4717c9ddfb463d57c to your computer and use it in GitHub Desktop.
GitHub - close PRs with no linked issues (Bash script)
#!/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