Skip to content

Commit

Permalink
chore: mention contributors in release changelog/notes
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 5, 2024
1 parent a1ab2d7 commit 977d55f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
24 changes: 24 additions & 0 deletions scripts/_utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { promises as fsp } from 'node:fs'
import { execSync } from 'node:child_process'
import { $fetch } from 'ofetch'
import { resolve } from 'pathe'
import { globby } from 'globby'
import { execaSync } from 'execa'
Expand Down Expand Up @@ -112,3 +114,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/bridge/commits/${commit.shortHash}`, {
headers: {
'User-Agent': 'nuxt/bridge',
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
Original file line number Diff line number Diff line change
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/bridge/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 977d55f

Please sign in to comment.