Skip to content

Commit a96fac1

Browse files
authored
misc: auto notify when issue is fixed (#152)
* add comment-resolved-issues action * feedback * feedback * comment * fix * feedback * cleanup * feedback * found issue in changelog, add pr link
1 parent 29552a9 commit a96fac1

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: 'Comment on Resolved Issues'
2+
description: 'Comments on issues referenced in PRs merged since last release'
3+
4+
inputs:
5+
token:
6+
description: >
7+
Personal access token (PAT) used to fetch the repository. The PAT is configured
8+
with the local git config, which enables your scripts to run authenticated git
9+
commands. The post-job step removes the PAT.
10+
default: ${{ github.token }}
11+
required: false
12+
13+
runs:
14+
using: composite
15+
steps:
16+
- name: Comment on issues
17+
shell: bash
18+
env:
19+
GH_TOKEN: ${{ inputs.token }}
20+
run: |
21+
# Get the previous tag
22+
PREVIOUS_TAG=$(git tag --sort=-version:refname | sed -n '2p')
23+
CURRENT_TAG=$(git tag --sort=-version:refname | sed -n '1p')
24+
25+
# Convert tag date to GitHub search format
26+
TAG_DATE=$(git log -1 --format="%ci" "$PREVIOUS_TAG" | sed 's/ /T/' | sed 's/ +0000/Z/')
27+
echo "Using tag date: $TAG_DATE"
28+
29+
# Find all PRs merged from the last release tag date
30+
ALL_PRS=$(gh pr list \
31+
--state merged \
32+
--json number,body,mergedAt \
33+
--jq '[.[] | select(.mergedAt > "'$TAG_DATE'") | .number]'
34+
)
35+
36+
# Find all issue number from PRs merged into release branch
37+
ISSUE_NUMBERS=""
38+
FAILURES=""
39+
40+
for pr_number in $(echo "$ALL_PRS" | jq -r '.[]'); do
41+
42+
# Get the merge commit SHA for this PR
43+
MERGE_COMMIT=$(gh pr view "$pr_number" --json mergeCommit --jq '.mergeCommit.oid')
44+
45+
# Check if this commit exists in the release branch
46+
if git merge-base --is-ancestor "$MERGE_COMMIT" origin/release 2>/dev/null; then
47+
echo "PR $pr_number is in release branch"
48+
49+
# Get issue numbers from changelog entries in this PR
50+
PR_ISSUES=$(gh pr view "$pr_number" --json files --jq '.files[].path' | \
51+
grep '\.changes/.*\.json$' | \
52+
xargs -I {} cat {} 2>/dev/null | \
53+
jq -r '.issues[]?' 2>/dev/null | \
54+
sed 's/.*#//')
55+
echo " Found issues: $PR_ISSUES"
56+
57+
# Comment on each issue
58+
for issue in $PR_ISSUES; do
59+
if [ -n "$issue" ]; then
60+
echo "Commenting on issue #$issue"
61+
if ! gh issue comment "$issue" --body "A [change](https://github.com/${{ github.repository }}/pull/$pr_number) related to this issue was included in [**$CURRENT_TAG**](https://github.com/${{ github.repository }}/releases/tag/$CURRENT_TAG)."; then
62+
echo "::error::Failed to comment on issue #$issue"
63+
FAILURES="$FAILURES #$issue"
64+
fi
65+
fi
66+
done
67+
fi
68+
done
69+
70+
if [ -n "$FAILURES" ]; then
71+
echo "::error::Failed to update the following issue(s):$FAILURES"
72+
exit 1
73+
fi

0 commit comments

Comments
 (0)