-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add workflow to comment on PRs when released #1772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
maxisbey
merged 5 commits into
modelcontextprotocol:main
from
yugannkt:feat/pr-release-notification-workflow
Dec 19, 2025
+149
−0
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2a021eb
Add workflow to comment on PRs when released
yugannkt 1c601d1
fix: Apply prettier formatting
yugannkt 37410a1
refacored
yugannkt 632e6fb
Removed whitespaces
yugannkt 0195cd8
Merge branch 'main' into feat/pr-release-notification-workflow
yugannkt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,126 @@ | ||
| name: Comment on PRs in Release | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
| comment-on-prs: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Get previous release tag | ||
| id: previous_tag | ||
| run: | | ||
| # Get all tags sorted by version | ||
| CURRENT_TAG="${{ github.event.release.tag_name }}" | ||
| PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -A 1 "^${CURRENT_TAG}$" | tail -n 1) | ||
yugannkt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # If there's no previous tag, use the first commit | ||
| if [ -z "$PREVIOUS_TAG" ] || [ "$PREVIOUS_TAG" = "$CURRENT_TAG" ]; then | ||
| PREVIOUS_TAG=$(git rev-list --max-parents=0 HEAD) | ||
| fi | ||
yugannkt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| echo "previous_tag=${PREVIOUS_TAG}" >> $GITHUB_OUTPUT | ||
| echo "Found previous tag/commit: ${PREVIOUS_TAG}" | ||
|
|
||
| - name: Get merged PRs between releases | ||
| id: get_prs | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const currentTag = '${{ github.event.release.tag_name }}'; | ||
| const previousTag = '${{ steps.previous_tag.outputs.previous_tag }}'; | ||
|
|
||
| console.log(`Finding PRs between ${previousTag} and ${currentTag}`); | ||
|
|
||
| // Get commits between previous and current release | ||
| const comparison = await github.rest.repos.compareCommits({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| base: previousTag, | ||
| head: currentTag | ||
| }); | ||
|
|
||
| const commits = comparison.data.commits; | ||
| console.log(`Found ${commits.length} commits`); | ||
|
|
||
| // Extract PR numbers from commit messages | ||
| const prNumbers = new Set(); | ||
| const prPattern = /#(\d+)/g; | ||
|
|
||
| for (const commit of commits) { | ||
| const message = commit.commit.message; | ||
| const matches = message.matchAll(prPattern); | ||
felixweinberger marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| for (const match of matches) { | ||
| const prNumber = parseInt(match[1]); | ||
| prNumbers.add(prNumber); | ||
| } | ||
|
|
||
| // Also check if the commit is associated with a PR | ||
| if (commit.commit.message.includes('Merge pull request #')) { | ||
| const match = commit.commit.message.match(/Merge pull request #(\d+)/); | ||
| if (match) { | ||
| prNumbers.add(parseInt(match[1])); | ||
| } | ||
| } | ||
| } | ||
|
|
||
yugannkt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Verify these are actually PRs (not issues) | ||
| const validPRs = []; | ||
|
|
||
| for (const prNumber of prNumbers) { | ||
| try { | ||
| const { data: pr } = await github.rest.pulls.get({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: prNumber | ||
| }); | ||
|
|
||
| // Only include merged PRs | ||
| if (pr.merged_at) { | ||
| validPRs.push(prNumber); | ||
| console.log(`Found valid merged PR: #${prNumber}`); | ||
| } | ||
| } catch (error) { | ||
| console.log(`#${prNumber} is not a valid PR or was not found`); | ||
| } | ||
| } | ||
|
|
||
| console.log(`Found ${validPRs.length} valid merged PRs`); | ||
| return validPRs; | ||
|
|
||
| - name: Comment on PRs | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const prNumbers = ${{ steps.get_prs.outputs.result }}; | ||
| const releaseTag = '${{ github.event.release.tag_name }}'; | ||
| const releaseUrl = '${{ github.event.release.html_url }}'; | ||
|
|
||
| const comment = `🎉 This pull request is included in [${releaseTag}](${releaseUrl})!`; | ||
felixweinberger marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| for (const prNumber of prNumbers) { | ||
| try { | ||
| await github.rest.issues.createComment({ | ||
yugannkt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| body: comment | ||
| }); | ||
| console.log(`Successfully commented on PR #${prNumber}`); | ||
| } catch (error) { | ||
| console.error(`Failed to comment on PR #${prNumber}:`, error.message); | ||
| } | ||
| } | ||
|
|
||
| console.log(`Commented on ${prNumbers.length} PRs`); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this anymore given we're now using the API only?