-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workflow to close issue linked to PR that target a release branches
This is a workaround the limitation that github only close linked issues when the PR target the main branch.
- Loading branch information
1 parent
d93eee7
commit 834beda
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: When a PR is closed | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
branches: | ||
- releases/* | ||
|
||
jobs: | ||
close-linked-issue-when-merged: | ||
name: Close linked issue when merged | ||
# Only run the job if the PR is merged. | ||
if: github.event.pull_request.merged | ||
permissions: | ||
# Need write permissions to close issues. | ||
issues: write | ||
pull-requests: read | ||
runs-on: ubuntu-24.04 | ||
env: | ||
PR_INFO: ${{ runner.temp }}/pr-info.json | ||
steps: | ||
# Github REST Api does not provide access to linked issues for a PR. | ||
# But we can access that data by using the graphql object `PullRequest.closingIssuesReferences`. | ||
# | ||
# Links: | ||
# | ||
# - [`PullRequest`](https://docs.github.com/en/graphql/reference/objects#pullrequest) | ||
# - [`IssueConnection`](https://docs.github.com/en/graphql/reference/objects#issueconnection) | ||
# - [`Issue`](https://docs.github.com/en/graphql/reference/objects#issue) | ||
- name: Get information about linked issues | ||
shell: bash -e -o pipefail {0} | ||
run: | | ||
gh api graphql \ | ||
-f id='${{ github.event.pull_request.node_id }}' \ | ||
-f query=' | ||
query($id: ID!) { | ||
node(id: $id) { | ||
... on PullRequest { | ||
title | ||
number | ||
closingIssuesReferences(first: 100) { | ||
nodes { | ||
number | ||
} | ||
} | ||
} | ||
} | ||
} | ||
' \ | ||
| jq .data.node \ | ||
| tee "${{ env.PR_INFO }}" | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
|
||
- name: Close linked issues | ||
run: | | ||
PR_TITLE="$(jq .title "${{ env.PR_INFO }}")" | ||
PR_NUMBER="$(jq .number "${{ env.PR_INFO }}")" | ||
echo "Closing linked issue to PR-${PR_NUMBER} called '${PR_TITLE}'" | ||
for issue in $(jq '.closingIssuesReferences.nodes[].number' "${{ env.PR_INFO }}"); do | ||
echo "Closing issue #${issue}" | ||
gh issue close "${issue}" --reason complete --comment "Fixed by #${PR_NUMBER}" | ||
done | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
|
||
|