-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
chore: add "Thanks" section to release-please configuration #5276
Open
TG199
wants to merge
4
commits into
mochajs:main
Choose a base branch
from
TG199:release-note
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,831
−15,452
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
feat: add script to credit contributors in release notes 🎄
- Fetches contributor details for merged PRs using GitHub's API. - Enhances auto-generated release notes by tagging contributors. - Prepares for integration into the release workflow. A special holiday update to spread cheer and gratitude this Christmas season! 🎅🎁 Resolves #5272 (ho ho ho)
commit 32b9a8d9e015df9b059c51899593988fac2e5e69
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,128 @@ | ||
'use strict'; | ||
|
||
import { Octokit } from "octokit"; | ||
import fs from "node:fs"; | ||
import { date } from "zod"; | ||
import { console } from "node:inspector"; | ||
|
||
const token = process.env.GITHUB_TOKEN || ""; | ||
const owner = "mochajs"; | ||
const repo = "mocha"; | ||
|
||
const octokit = new Octokit({ auth: token}); | ||
|
||
async function getLastReleaseDate() { | ||
try { | ||
const { data: releases } = await octokit.request('GET /repos/{owner}/{repo}/releases', { | ||
owner, | ||
repo, | ||
per_page: 2 | ||
}); | ||
|
||
if (releases.length > 1) { | ||
return new Date(releases[1].published_at); | ||
} | ||
|
||
return new Date(Date.now() - (30 * 24 * 60 * 60 * 1000)); | ||
} catch (error) { | ||
console.error("Error fetching releases:", error); | ||
return new Date(Date.now() - (30 * 24 * 60 * 60 * 1000)); | ||
} | ||
} | ||
|
||
async function getContributorFullName(username) { | ||
try { | ||
const { data } = await octokit.request('GET /users/{username}', { | ||
username: username | ||
}); | ||
return data.name || username; | ||
} catch (error) { | ||
console.error(`Error fetching user info for ${username}:`, error); | ||
return username; | ||
} | ||
} | ||
|
||
async function getContributors() { | ||
try { | ||
const lastReleaseDate = await getLastReleaseDate(); | ||
const contributors = new Map(); | ||
let page = 1; | ||
const per_page = 100; | ||
|
||
while (true) { | ||
const { data } = await octokit.request('GET /repos/{owner}/{repo}/pulls', { | ||
owner, | ||
repo, | ||
state: "closed", | ||
sort: "updated", | ||
direction: "desc", | ||
per_page, | ||
page | ||
}); | ||
|
||
if (data.length === 0) break; | ||
|
||
for (const pr of data) { | ||
if (new Date(pr.merged_at) <= lastReleaseDate) { | ||
break; | ||
} | ||
|
||
if (pr.merged_at && !pr.user.login.includes('[bot]')) { | ||
if (!contributors.has(pr.user.login)) { | ||
const fullName = await getContributorFullName(pr.user.login); | ||
contributors.set(pr.user.login, fullName); | ||
} | ||
} | ||
} | ||
|
||
if (data[data.length - 1].merged_at && new Date(data[data.length - 1].merged_at) <= lastReleaseDate){ | ||
break; | ||
} | ||
page++; | ||
} | ||
return contributors; | ||
} catch (error) { | ||
console.error("Error fetching contributors:", error); | ||
return new Map(); | ||
} | ||
} | ||
|
||
async function appendThankYouSection() { | ||
try { | ||
const changelogPath = "CHANGELOG.md"; | ||
const contributors = await getContributors(); | ||
|
||
if (contributors.size === 0) { | ||
return; | ||
} | ||
let thankYouSection = "\n## ❤️ Thank You\n\n"; | ||
for (const [username, fullName] of contributors) { | ||
thankYouSection += `* ${fullName} @${username}\n`; | ||
} | ||
thankYouSection += "\n"; | ||
|
||
const existingContent = fs.readFileSync(changelogPath, "utf-8"); | ||
|
||
const lines = existingContent.split("\n"); | ||
|
||
const firstVersionIndex = lines.findIndex(line => line.startsWith("#")); | ||
if (firstVersionIndex === -1){ | ||
return; | ||
} | ||
|
||
const nextVersionIndex = lines.slice(firstVersionIndex + 1) | ||
.findIndex(line => line.startsWith("#")); | ||
|
||
const insertPosition = nextVersionIndex !== -1 | ||
? firstVersionIndex + nextVersionIndex + 1: lines.length; | ||
|
||
lines.splice(insertPosition, 0, thankYouSection); | ||
|
||
fs.writeFileSync(changelogPath, lines.join("\n"), "utf-8"); | ||
console.log("Thank you section added to changelog!") | ||
|
||
} catch (error) { | ||
console.error("Error updating CHANGELOG.md:", error); | ||
} | ||
} | ||
appendThankYouSection(); |
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.
[Change request] As a design point, I don't think taking on the burden of a full script is ideal. Assuming release-please doesn't have contribution thanks as a core feature, I think the next best thing would be a plugin. Which is a thing that can be made: https://github.com/googleapis/release-please/blob/3bae6137f939a4db2df1d32436453d1ac2a41e9f/docs/manifest-releaser.md#plugin-usage
googleapis/release-please#2221 tracks them adding more docs and also links to some information + existing plugins.
Is that an approach you think could work?
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.
Giving this a try!