Skip to content
Merged
Changes from 8 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
73 changes: 73 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,73 @@
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
FAILURES=""

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**](https://github.com/${{ github.repository }}/releases/tag/$CURRENT_TAG)."; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! I was taking a look at your example and I don't know how often this will be necessary; when a lot of changes are being released related to an issue, it will be hard to tell what change each comment is talking about.

Suggestion: It would be nice to include the pull request from each change

A change related to this issue was included in release.

Copy link
Member

Choose a reason for hiding this comment

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

suggestion: I don't think we need the word "release" here, just $CURRENT_TAG should be fine?

A change related to this issue was included in v1.5.64

echo "::error::Failed to comment on issue #$issue_number"
FAILURES="$FAILURES #$issue_number"
fi
fi
done < <(echo "$ISSUE_NUMBERS" | tr ' ' '\n')

if [ -n "$FAILURES" ]; then
echo "::error::Failed to update the following issue(s):$FAILURES"
exit 1
fi
Loading