diff --git a/scripts/update-changelog.ts b/scripts/update-changelog.ts index 874af8f..fe7b2ba 100644 --- a/scripts/update-changelog.ts +++ b/scripts/update-changelog.ts @@ -250,12 +250,8 @@ function subjectsOnlyOn (ref: string): Set { } /** Committer date of the commit a tag points at, as an ISO 8601 string. */ -function tagDate (ref: string): string | null { - try { - return execFileSync('git', ['log', '-1', '--format=%cI', ref], { encoding: 'utf8', maxBuffer: MAX_BUFFER }).trim() || null - } catch { - return null - } +function tagDate (ref: string): string { + return execFileSync('git', ['log', '-1', '--format=%cI', ref], { encoding: 'utf8', maxBuffer: MAX_BUFFER }).trim() } function getCommitsSince (tag: Tag | null): Commit[] { diff --git a/test/pack.test.ts b/test/pack.test.ts index 3091a1e..00b211b 100644 --- a/test/pack.test.ts +++ b/test/pack.test.ts @@ -1,4 +1,4 @@ -import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs' +import { mkdirSync, mkdtempSync, readFileSync, realpathSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { resolve } from 'node:path' import process from 'node:process' @@ -35,7 +35,7 @@ beforeEach(() => { env = { ...process.env } cwd = process.cwd() for (const key of PACK_ENV) delete process.env[key] - root = mkdtempSync(resolve(tmpdir(), 'uppt-pack-')) + root = realpathSync(mkdtempSync(resolve(tmpdir(), 'uppt-pack-'))) outDir = resolve(root, 'out') process.env.PACK_OUT_DIR = outDir process.env.GITHUB_REF = 'refs/tags/v1.2.3' diff --git a/test/update-changelog-main.test.ts b/test/update-changelog-main.test.ts index 01e20ea..ec0933d 100644 --- a/test/update-changelog-main.test.ts +++ b/test/update-changelog-main.test.ts @@ -52,6 +52,7 @@ const git = { commits: [] as FakeCommit[], revList: [] as string[], divergedSubjects: [] as string[], + failDivergedSubjects: false, remote: 'git@github.com:owner/repo.git', branch: 'main', } @@ -86,7 +87,10 @@ function stubGit () { if (sub === 'rev-parse') return args.includes('--abbrev-ref') ? git.branch : HEAD_SHA if (sub === 'rev-list') return git.revList.join('\n') if (sub === 'log' && args[1] === '-1') return '2024-01-01T00:00:00Z' - if (sub === 'log' && args.includes('--pretty=format:%s')) return git.divergedSubjects.join('\n') + if (sub === 'log' && args.includes('--pretty=format:%s')) { + if (git.failDivergedSubjects) throw new Error('bad revision') + return git.divergedSubjects.join('\n') + } if (sub === 'log') return record(...git.commits) throw new Error(`unexpected git call: ${args.join(' ')}`) }) @@ -216,6 +220,7 @@ beforeEach(() => { git.commits = [FEAT] git.revList = [FEAT.hash] git.divergedSubjects = [] + git.failDivergedSubjects = false git.remote = 'git@github.com:owner/repo.git' git.branch = 'main' @@ -269,6 +274,17 @@ describe('lockstep main', () => { expect(prBody()).not.toContain('cherry-picked') }) + it('keeps every commit when the diverged-subject lookup fails', async () => { + const other: FakeCommit = { hash: 'b'.repeat(40), short: 'bbbbbbb', name: 'Bo', email: 'bo@example.com', subject: 'fix: cherry-picked (#8)' } + git.commits = [FEAT, other] + git.revList = [FEAT.hash, other.hash] + api.logins = new Map([['aaaaaaa', 'ada'], ['bbbbbbb', 'bo']]) + git.divergedSubjects = [other.subject] + git.failDivergedSubjects = true + await main() + expect(prBody()).toContain('cherry-picked') + }) + it('cuts the commit range at the date of the previous tag', async () => { await main() const calls = execFileSync.mock.calls as Array<[string, string[]]> diff --git a/test/update-changelog.test.ts b/test/update-changelog.test.ts index 931d358..b81e8aa 100644 --- a/test/update-changelog.test.ts +++ b/test/update-changelog.test.ts @@ -551,6 +551,12 @@ describe('truncateBody', () => { expect(result).toMatch(/_Changelog truncated: it exceeded GitHub's 65536 character limit\._$/) expect(result.split('\n').at(-3)).toBe('- line 13') }) + + it('cuts mid-line when there is no line boundary to trim on', () => { + const result = truncateBody('x'.repeat(200), 100) + expect(result.length).toBeLessThanOrEqual(100) + expect(result).toMatch(/^x+\n\n_Changelog truncated: it exceeded GitHub's 65536 character limit\._$/) + }) }) describe('independent release PR', () => {