FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add workflow to comment on PRs when released by yugannkt · Pull Request #1772 · modelcontextprotocol/python-sdk · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .yml  (1) All 1 file type selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
149 changes: 149 additions & 0 deletions .github/workflows/comment-on-release.yml
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,149 @@
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
Comment on lines +17 to +18

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't think we need this anymore given we're now using the API only?


- name: Get previous release
id: previous_release
uses: actions/github-script@v7
with:
script: |
const currentTag = '${{ github.event.release.tag_name }}';

// Get all releases
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100
});

// Find current release index
const currentIndex = releases.findIndex(r => r.tag_name === currentTag);

if (currentIndex === -1) {
console.log('Current release not found in list');
return null;
}

// Get previous release (next in the list since they're sorted by date desc)
const previousRelease = releases[currentIndex + 1];

if (!previousRelease) {
console.log('No previous release found, this might be the first release');
return null;
}

console.log(`Found previous release: ${previousRelease.tag_name}`);

return previousRelease.tag_name;

- 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_release.outputs.result }};

if (!previousTag) {
console.log('No previous release found, skipping');
return [];
}

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`);

// Get PRs associated with each commit using GitHub API
const prNumbers = new Set();

for (const commit of commits) {
try {
const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: commit.sha
});

for (const pr of prs) {
if (pr.merged_at) {
prNumbers.add(pr.number);
console.log(`Found merged PR: #${pr.number}`);
}
}
} catch (error) {
console.log(`Failed to get PRs for commit ${commit.sha}: ${error.message}`);
}
}

console.log(`Found ${prNumbers.size} merged PRs`);
return Array.from(prNumbers);

- 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})`;

let commentedCount = 0;

for (const prNumber of prNumbers) {
try {
// Check if we've already commented on this PR for this release
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
per_page: 100
});

const alreadyCommented = comments.some(c =>
c.user.type === 'Bot' && c.body.includes(releaseTag)
);

if (alreadyCommented) {
console.log(`Skipping PR #${prNumber} - already commented for ${releaseTag}`);
continue;
}

await github.rest.issues.createComment({
Comment thread
yugannkt marked this conversation as resolved.
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: comment
});
commentedCount++;
console.log(`Successfully commented on PR #${prNumber}`);
} catch (error) {
console.error(`Failed to comment on PR #${prNumber}:`, error.message);
}
}

console.log(`Commented on ${commentedCount} of ${prNumbers.length} PRs`);

Back | FazBrowse Home | New Git URL