From b2d11a36e01e023f171e26d89fdf5b38282bcb7b Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Mon, 15 Apr 2024 08:53:25 +0200 Subject: [PATCH] Fix release link (#105) --- src/cmd/prepare.ts | 9 ++++++++- src/cmd/release.ts | 10 ++++++---- src/utils/__snapshots__/change.test.ts.snap | 2 +- src/utils/change.test.ts | 2 ++ src/utils/change.ts | 11 +++++++---- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/cmd/prepare.ts b/src/cmd/prepare.ts index 8c941d4..bf6b8cd 100644 --- a/src/cmd/prepare.ts +++ b/src/cmd/prepare.ts @@ -15,6 +15,7 @@ export async function prepare(cmdCtx: CommandContext) { nextVersion, pullRequestBranch, shouldBeRC, + useVersionPrefixV, } = cmdCtx; console.log( @@ -74,12 +75,18 @@ export async function prepare(cmdCtx: CommandContext) { } } + const tag = + useVersionPrefixV && !nextVersion.startsWith("v") + ? `v${nextVersion}` + : nextVersion; + let oldChangelog = ""; if (await fs.stat("CHANGELOG.md").catch(() => false)) { oldChangelog = await fs.readFile("CHANGELOG.md", "utf-8"); } const newChangelogSection = getChangeLogSection( nextVersion, + tag, config, changes, forge, @@ -118,7 +125,7 @@ export async function prepare(cmdCtx: CommandContext) { `- [${ shouldBeRC ? "x" : " " }] Mark this version as a release candidate\n\n` + - getChangeLogSection(nextVersion, config, changes, forge, false); + getChangeLogSection(nextVersion, tag, config, changes, forge, false); console.log("# Creating release pull-request"); const pullRequestLink = await forge.createOrUpdatePullRequest({ diff --git a/src/cmd/release.ts b/src/cmd/release.ts index 9f72e5c..3db30c9 100644 --- a/src/cmd/release.ts +++ b/src/cmd/release.ts @@ -30,8 +30,14 @@ export async function release({ throw new Error("Missing repoOwner or repoName"); } + const tag = + useVersionPrefixV && !nextVersion.startsWith("v") + ? `v${nextVersion}` + : nextVersion; + const newChangelogSection = getChangeLogSection( nextVersion, + tag, config, changes, forge, @@ -43,10 +49,6 @@ export async function release({ : newChangelogSection; console.log("# Creating release"); - const tag = - useVersionPrefixV && !nextVersion.startsWith("v") - ? `v${nextVersion}` - : nextVersion; const { releaseLink } = await forge.createRelease({ owner: config.ci.repoOwner, repo: config.ci.repoName, diff --git a/src/utils/__snapshots__/change.test.ts.snap b/src/utils/__snapshots__/change.test.ts.snap index fb3f992..28e2c0c 100644 --- a/src/utils/__snapshots__/change.test.ts.snap +++ b/src/utils/__snapshots__/change.test.ts.snap @@ -260,7 +260,7 @@ exports[`change > 'should update existing changelog section' 1`] = ` `; exports[`change > should generate a changelog 1`] = ` -"## [1.0.0](https://github.com/woodpecker-ci/woodpecker/releases/tag/1.0.0) - 2000-02-01 +"## [1.0.0](https://github.com/woodpecker-ci/woodpecker/releases/tag/v1.0.0) - 2000-02-01 ### ❤️ Thanks to all contributors! ❤️ diff --git a/src/utils/change.test.ts b/src/utils/change.test.ts index 4d95ad3..3359dd4 100644 --- a/src/utils/change.test.ts +++ b/src/utils/change.test.ts @@ -158,6 +158,7 @@ describe("change", () => { const forge = new GithubForge("", ""); const changelog = getChangeLogSection( "1.0.0", + "v1.0.0", config, changes, forge, @@ -204,6 +205,7 @@ describe("change", () => { const forge = new GithubForge("", ""); const newSection = getChangeLogSection( + nextVersion, nextVersion, config, changes, diff --git a/src/utils/change.ts b/src/utils/change.ts index 3a4b95c..43510ee 100644 --- a/src/utils/change.ts +++ b/src/utils/change.ts @@ -51,6 +51,7 @@ export function getNextVersionFromLabels( export function getChangeLogSection( nextVersion: string, + tag: string, config: Config, changes: Change[], forge: Forge, @@ -112,7 +113,7 @@ export function getChangeLogSection( const releaseLink = forge.getReleaseUrl( config.ci.repoOwner!, config.ci.repoName!, - nextVersion + tag ); const releaseDate = new Date().toISOString().split("T")[0]; @@ -120,13 +121,15 @@ export function getChangeLogSection( let section = `## [${nextVersion}](${releaseLink}) - ${releaseDate}\n\n`; if (includeContributors) { - const contributors = `### ❤️ Thanks to all contributors! ❤️\n\n${changes + const authors = changes .map((change) => `@${change.author}`) .sort() .filter((v, i, a) => a.indexOf(v) === i) .filter((c) => !c.endsWith('[bot]')) - .join(", ")}`; - section += `${contributors}\n\n`; + if (authors.length > 0) { + const contributors = `### ❤️ Thanks to all contributors! ❤️\n\n${authors.join(", ")}`; + section += `${contributors}\n\n`; + } } section += `${changeLog}`;