Skip to content

Commit 60ab5de

Browse files
committedJan 30, 2024
ci: update changelog with github tags/handles of users
1 parent f1fe97f commit 60ab5de

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed
 

Diff for: ‎scripts/_utils.ts

+23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { execSync } from 'node:child_process'
12
import { promises as fsp } from 'node:fs'
23
import { resolve } from 'pathe'
34
import { globby } from 'globby'
@@ -112,3 +113,25 @@ export async function getLatestCommits () {
112113

113114
return parseCommits(await getGitDiff(latestTag), config)
114115
}
116+
117+
export async function getContributors () {
118+
const contributors = [] as Array<{ name: string, username: string }>
119+
const emails = new Set<string>()
120+
const latestTag = execSync('git describe --tags --abbrev=0').toString().trim()
121+
const rawCommits = await getGitDiff(latestTag)
122+
for (const commit of rawCommits) {
123+
if (emails.has(commit.author.email) || commit.author.name === 'renovate[bot]') { continue }
124+
const { author } = await $fetch<{ author: { login: string, email: string }}>(`https://api.github.com/repos/nuxt/nuxt/commits/${commit.shortHash}`, {
125+
headers: {
126+
'User-Agent': 'nuxt/nuxt',
127+
Accept: 'application/vnd.github.v3+json',
128+
Authorization: `token ${process.env.GITHUB_TOKEN}`
129+
}
130+
})
131+
if (!contributors.some(c => c.username === author.login)) {
132+
contributors.push({ name: commit.author.name, username: author.login })
133+
}
134+
emails.add(author.email)
135+
}
136+
return contributors
137+
}

Diff for: ‎scripts/update-changelog.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { $fetch } from 'ofetch'
33
import { inc } from 'semver'
44
import { generateMarkDown, getCurrentGitBranch, loadChangelogConfig } from 'changelogen'
55
import { consola } from 'consola'
6-
import { determineBumpType, getLatestCommits, loadWorkspace } from './_utils'
6+
import { determineBumpType, getContributors, getLatestCommits, loadWorkspace } from './_utils'
77

88
async function main () {
99
const releaseBranch = await getCurrentGitBranch()
@@ -36,11 +36,17 @@ async function main () {
3636

3737
// Get the current PR for this release, if it exists
3838
const [currentPR] = await $fetch(`https://api.github.com/repos/nuxt/nuxt/pulls?head=nuxt:v${newVersion}`)
39+
const contributors = await getContributors()
3940

4041
const releaseNotes = [
4142
currentPR?.body.replace(/## 👉 Changelog[\s\S]*$/, '') || `> ${newVersion} is the next ${bumpType} release.\n>\n> **Timetable**: to be announced.`,
4243
'## 👉 Changelog',
43-
changelog.replace(/^## v.*?\n/, '').replace(`...${releaseBranch}`, `...v${newVersion}`)
44+
changelog
45+
.replace(/^## v.*?\n/, '')
46+
.replace(`...${releaseBranch}`, `...v${newVersion}`)
47+
.replace(/### Contributors[\s\S]*$/, ''),
48+
`### ❤️ Contributors`,
49+
contributors.map(c => `- ${c.name} (@${c.username})`).join('\n')
4450
].join('\n')
4551

4652
// Create a PR with release notes if none exists

0 commit comments

Comments
 (0)
Please sign in to comment.