ci: update changelog with github tags/handles of users

This commit is contained in:
Daniel Roe 2024-01-30 14:18:37 +00:00
parent f1fe97fc8a
commit 60ab5deb0f
2 changed files with 31 additions and 2 deletions

View File

@ -1,3 +1,4 @@
import { execSync } from 'node:child_process'
import { promises as fsp } from 'node:fs'
import { resolve } from 'pathe'
import { globby } from 'globby'
@ -112,3 +113,25 @@ export async function getLatestCommits () {
return parseCommits(await getGitDiff(latestTag), config)
}
export async function getContributors () {
const contributors = [] as Array<{ name: string, username: string }>
const emails = new Set<string>()
const latestTag = execSync('git describe --tags --abbrev=0').toString().trim()
const rawCommits = await getGitDiff(latestTag)
for (const commit of rawCommits) {
if (emails.has(commit.author.email) || commit.author.name === 'renovate[bot]') { continue }
const { author } = await $fetch<{ author: { login: string, email: string }}>(`https://api.github.com/repos/nuxt/nuxt/commits/${commit.shortHash}`, {
headers: {
'User-Agent': 'nuxt/nuxt',
Accept: 'application/vnd.github.v3+json',
Authorization: `token ${process.env.GITHUB_TOKEN}`
}
})
if (!contributors.some(c => c.username === author.login)) {
contributors.push({ name: commit.author.name, username: author.login })
}
emails.add(author.email)
}
return contributors
}

View File

@ -3,7 +3,7 @@ import { $fetch } from 'ofetch'
import { inc } from 'semver'
import { generateMarkDown, getCurrentGitBranch, loadChangelogConfig } from 'changelogen'
import { consola } from 'consola'
import { determineBumpType, getLatestCommits, loadWorkspace } from './_utils'
import { determineBumpType, getContributors, getLatestCommits, loadWorkspace } from './_utils'
async function main () {
const releaseBranch = await getCurrentGitBranch()
@ -36,11 +36,17 @@ async function main () {
// Get the current PR for this release, if it exists
const [currentPR] = await $fetch(`https://api.github.com/repos/nuxt/nuxt/pulls?head=nuxt:v${newVersion}`)
const contributors = await getContributors()
const releaseNotes = [
currentPR?.body.replace(/## 👉 Changelog[\s\S]*$/, '') || `> ${newVersion} is the next ${bumpType} release.\n>\n> **Timetable**: to be announced.`,
'## 👉 Changelog',
changelog.replace(/^## v.*?\n/, '').replace(`...${releaseBranch}`, `...v${newVersion}`)
changelog
.replace(/^## v.*?\n/, '')
.replace(`...${releaseBranch}`, `...v${newVersion}`)
.replace(/### ❤️ Contributors[\s\S]*$/, ''),
`### ❤️ Contributors`,
contributors.map(c => `- ${c.name} (@${c.username})`).join('\n')
].join('\n')
// Create a PR with release notes if none exists