Skip to content

Commit

Permalink
ci: update changelog with github tags/handles of users
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jan 30, 2024
1 parent f1fe97f commit 60ab5de
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
23 changes: 23 additions & 0 deletions scripts/_utils.ts
@@ -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'
Expand Down Expand Up @@ -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
}
10 changes: 8 additions & 2 deletions scripts/update-changelog.ts
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 60ab5de

Please sign in to comment.