Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.
TypeScript albumsexif-extractiongeocodinglive-photomotion-photophoto-galleryphoto-sharingwebgl-viewer
feat(ci): add contributor credits to release changelog
Timothy Yind34e35459d54
diff --git a/.github/workflows/publish-images.yml b/.github/workflows/publish-images.ymlindex 30f599e7..0e6fc44e 100644--- a/.github/workflows/publish-images.yml+++ b/.github/workflows/publish-images.yml@@ -42,6 +42,8 @@ jobs:- name: 📝 Generate changelogid: changelog+ env:+ GITHUB_TOKEN: ${{ github.token }}run: |echo "Generating changelog..."@@ -58,13 +60,17 @@ jobs:if [ -n "$PREVIOUS_TAG" ]; thenecho "Generating changelog from $PREVIOUS_TAG to current"- changelog=$(npx @uniiem/changelogen@latest --from=$PREVIOUS_TAG --no-output --noMerges)+ changelog=$(npx @uniiem/[email protected] --from="$PREVIOUS_TAG" --no-output --noMerges --noAuthors)+ contributors=$(node scripts/changelog-contributors.mjs "$PREVIOUS_TAG..HEAD")elseecho "No previous tag found, generating full changelog"- changelog=$(npx @uniiem/changelogen@latest --no-output --noMerges)+ changelog=$(npx @uniiem/[email protected] --no-output --noMerges --noAuthors)+ contributors=$(node scripts/changelog-contributors.mjs HEAD)fichangelog=$(echo "$changelog" | sed 's/^\[log\][[:space:]]*//')+ changelog="$changelog+ $contributors"echo "changelog<<EOF" >> $GITHUB_OUTPUTecho "$changelog" >> $GITHUB_OUTPUTdiff --git a/scripts/changelog-contributors.mjs b/scripts/changelog-contributors.mjsnew file mode 100644index 00000000..5060b97d--- /dev/null+++ b/scripts/changelog-contributors.mjs@@ -0,0 +1,85 @@+import { execFileSync } from 'node:child_process'+import { pathToFileURL } from 'node:url'++export async function generateContributors(commits, getCommit, warn) {+ const authors = new Map()+ for (const commit of commits) {+ if (!commit.name || commit.name.includes('[bot]')) continue+ const key = commit.email.toLowerCase()+ const author = authors.get(key) || { name: commit.name, commits: [] }+ author.commits.push(commit.sha)+ authors.set(key, author)+ }++ const contributors = new Map()+ for (const [email, author] of authors) {+ let login+ // GitHub noreply addresses contain the account name even for unlinked commits.+ const noreply = email.match(+ /^(?:\d+\+)?([^@]+)@users\.noreply\.github\.com$/,+ )+ if (noreply) login = noreply[1]+ for (const sha of author.commits) {+ if (login) break+ const commit = await getCommit(sha)+ // The committer can be GitHub's merge bot or a different developer.+ login = commit.author?.login+ }+ if (login?.endsWith('[bot]')) continue+ if (!login) warn(`No GitHub account linked to commits by ${author.name}`)+ const key = login ? `github:${login.toLowerCase()}` : `email:${email}`+ if (!contributors.has(key)) {+ contributors.set(key, `- ${author.name}${login ? ` (@${login})` : ''}`)+ }+ }+ return contributors.size+ ? `\n\n### ❤️ Contributors\n\n${[...contributors.values()].join('\n')}\n`+ : ''+}++async function main() {+ const token = process.env.GITHUB_TOKEN+ const repo = process.env.GITHUB_REPOSITORY+ if (!token || !repo)+ throw new Error('GITHUB_TOKEN and GITHUB_REPOSITORY are required')+ const range = process.argv[2] || 'HEAD'+ const log = execFileSync(+ 'git',+ ['log', '--no-merges', '--format=%H%x00%an%x00%ae', range],+ { encoding: 'utf8' },+ ).trim()+ const commits = log+ ? log.split('\n').map((line) => {+ const [sha, name, email] = line.trim().split('\0')+ return { sha, name, email }+ })+ : []+ const markdown = await generateContributors(+ commits,+ async (sha) => {+ const response = await fetch(+ `${process.env.GITHUB_API_URL || 'https://api.github.com'}/repos/${repo}/commits/${sha}`,+ {+ headers: {+ Authorization: `Bearer ${token}`,+ Accept: 'application/vnd.github+json',+ },+ },+ )+ if (!response.ok)+ throw new Error(+ `GitHub commit lookup failed (${response.status}) for ${sha}`,+ )+ return response.json()+ },+ (message) => console.error(message),+ )+ process.stdout.write(markdown)+}++if (+ process.argv[1] &&+ import.meta.url === pathToFileURL(process.argv[1]).href+) {+ await main()+}diff --git a/scripts/changelog-contributors.test.mjs b/scripts/changelog-contributors.test.mjsnew file mode 100644index 00000000..5a44c0f3--- /dev/null+++ b/scripts/changelog-contributors.test.mjs@@ -0,0 +1,61 @@+import assert from 'node:assert/strict'+import { test } from 'node:test'+import { generateContributors } from './changelog-contributors.mjs'++test('resolves commit authors, retries unlinked commits, and deduplicates accounts', async () => {+ const commits = [+ { sha: '1', name: 'Developer', email: '[email protected]' },+ { sha: '2', name: 'Developer', email: '[email protected]' },+ { sha: '3', name: 'Other name', email: '[email protected]' },+ ]+ const calls = []+ const output = await generateContributors(+ commits,+ async (sha) => {+ calls.push(sha)+ return {+ author: sha === '1' ? null : { login: 'developer' },+ committer: { login: 'web-flow' },+ }+ },+ assert.fail,+ )+ assert.deepEqual(calls, ['1', '2', '3'])+ assert.equal(output, '\n\n### ❤️ Contributors\n\n- Developer (@developer)\n')+})++test('handles noreply addresses, bots, and unlinked authors without exposing emails', async () => {+ const warnings = []+ const output = await generateContributors(+ [+ { sha: '1', name: 'Alice', email: '[email protected]' },+ { sha: '2', name: 'Bob', email: '[email protected]' },+ { sha: '3', name: 'Unknown', email: '[email protected]' },+ { sha: '4', name: 'dependabot[bot]', email: '[email protected]' },+ ],+ async (sha) => {+ assert.equal(sha, '3')+ return { author: null, committer: { login: 'someone-else' } }+ },+ (message) => warnings.push(message),+ )+ assert.match(output, /Alice \(@alice\)/)+ assert.match(output, /Bob \(@bob\)/)+ assert.match(output, /- Unknown\n/)+ assert.doesNotMatch(output, /private@example|someone-else|dependabot/)+ assert.equal(warnings.length, 1)+})++test('fails visibly on API errors instead of silently losing mentions', async () => {+ await assert.rejects(+ generateContributors(+ [{ sha: '1', name: 'Alice', email: '[email protected]' }],+ async () => {+ throw new Error('rate limit')+ },+ assert.fail,+ ),+ /rate limit/,+ )+ assert.equal(await generateContributors([], assert.fail, assert.fail), '')+})