Skip to content

Commit 6ccffab

Browse files
committed
Close issues on merge workflow
1 parent 2522eae commit 6ccffab

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
2+
3+
name: Close issues from merged PRs
4+
5+
on:
6+
pull_request:
7+
branches:
8+
- "2.1.x"
9+
types:
10+
- closed
11+
12+
jobs:
13+
close-issues:
14+
name: Close linked issues
15+
if: github.repository_owner == 'phpstan' && github.event.pull_request.merged == true
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: "Find and close linked issues"
19+
env:
20+
GH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }}
21+
run: |
22+
# Query GraphQL for closing issues references
23+
ISSUES=$(gh api graphql -f query='
24+
query ($owner:String!, $repo:String!, $pr:Int!) {
25+
repository(owner:$owner, name:$repo) {
26+
pullRequest(number:$pr) {
27+
closingIssuesReferences(first:100) {
28+
nodes { number url repository { nameWithOwner } }
29+
}
30+
}
31+
}
32+
}
33+
' -f owner="${{ github.repository_owner }}" -f repo="${{ github.event.repository.name }}" -F pr=${{ github.event.pull_request.number }} --jq '.data.repository.pullRequest.closingIssuesReferences.nodes[]')
34+
35+
if [ -z "$ISSUES" ]; then
36+
echo "No linked issues found"
37+
exit 0
38+
fi
39+
40+
echo "$ISSUES" | jq -c '.' | while read -r issue; do
41+
REPO=$(echo "$issue" | jq -r '.repository.nameWithOwner')
42+
NUMBER=$(echo "$issue" | jq -r '.number')
43+
URL=$(echo "$issue" | jq -r '.url')
44+
45+
echo "Closing $URL"
46+
gh issue close "$NUMBER" --repo "$REPO" --comment "Closed via merging ${{ github.event.pull_request.html_url }}"
47+
done

0 commit comments

Comments
 (0)