Skip to content
Open
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/actions/comment-resolved-issues/action.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than checking the PR body for GitHub issue links, I was hoping we could be more intentional with these comments by using changelog entries. I think the current implementation will be much noisier than it needs to be

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: 'Comment on Resolved Issues'
description: 'Comments on issues referenced in PRs merged since last release'

inputs:
token:
description: >
Personal access token (PAT) used to fetch the repository. The PAT is configured
with the local git config, which enables your scripts to run authenticated git
commands. The post-job step removes the PAT.
default: ${{ github.token }}
required: false

runs:
using: composite
steps:
- name: Comment on issues
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
run: |
# Get the previous tag
PREVIOUS_TAG=$(git tag --sort=-version:refname | sed -n '2p')
CURRENT_TAG=$(git tag --sort=-version:refname | sed -n '1p')

# Convert tag date to GitHub search format
TAG_DATE=$(git log -1 --format="%ci" "$PREVIOUS_TAG" | sed 's/ /T/' | sed 's/ +0000/Z/')
echo "Using tag date: $TAG_DATE"

# Find all PRs merged from the last release tag date
ALL_PRS=$(gh pr list \
--state merged \
--json number,body,mergedAt \
--jq '[.[] | select(.mergedAt > "'$TAG_DATE'") | .number]'
)

# Find all issue number from PRs merged into release branch
ISSUE_NUMBERS=""
for pr_number in $(echo "$ALL_PRS" | jq -r '.[]'); do

# Get the merge commit SHA for this PR
MERGE_COMMIT=$(gh pr view "$pr_number" --json mergeCommit --jq '.mergeCommit.oid')

# Check if this commit exists in the release branch
if git merge-base --is-ancestor "$MERGE_COMMIT" origin/release 2>/dev/null; then
echo "PR $pr_number is in release branch"

# Get issue numbers from this PR
PR_ISSUES=$(gh pr view "$pr_number" --json body --jq '.body' | \
grep -o 'issues/[0-9]*' | \
sed 's/issues\///')
echo " Found issues: $PR_ISSUES"

ISSUE_NUMBERS="$ISSUE_NUMBERS $PR_ISSUES"
fi
done

# Comment on each issue found
echo "$ISSUE_NUMBERS" | tr ' ' '\n' | while read -r issue_number; do
if [ -n "$issue_number" ]; then
echo "Commenting on issue #$issue_number"
if ! gh issue comment "$issue_number" --body "A change related to this issue was included in release: $CURRENT_TAG"; then
echo "::error::Failed to comment on issue #$issue_number"
exit 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Does Markdown work in the --body argument? If so, it'd be nice to link readers to the release itself:

gh issue comment "$issue_number" --body "A change related to this issue was included in [release **$CURRENT_TAG**](https://github.com/${{ github.repository }}/releases/tag/$CURRENT_TAG)."

fi
done
Loading