Skip to content

Commit

Permalink
Fix release link (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty287 authored Apr 15, 2024
1 parent b69989d commit b2d11a3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/cmd/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export async function prepare(cmdCtx: CommandContext) {
nextVersion,
pullRequestBranch,
shouldBeRC,
useVersionPrefixV,
} = cmdCtx;

console.log(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down
10 changes: 6 additions & 4 deletions src/cmd/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/__snapshots__/change.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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! ❤️
Expand Down
2 changes: 2 additions & 0 deletions src/utils/change.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ describe("change", () => {
const forge = new GithubForge("", "");
const changelog = getChangeLogSection(
"1.0.0",
"v1.0.0",
config,
changes,
forge,
Expand Down Expand Up @@ -204,6 +205,7 @@ describe("change", () => {

const forge = new GithubForge("", "");
const newSection = getChangeLogSection(
nextVersion,
nextVersion,
config,
changes,
Expand Down
11 changes: 7 additions & 4 deletions src/utils/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export function getNextVersionFromLabels(

export function getChangeLogSection(
nextVersion: string,
tag: string,
config: Config,
changes: Change[],
forge: Forge,
Expand Down Expand Up @@ -112,21 +113,23 @@ export function getChangeLogSection(
const releaseLink = forge.getReleaseUrl(
config.ci.repoOwner!,
config.ci.repoName!,
nextVersion
tag
);

const releaseDate = new Date().toISOString().split("T")[0];

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}`;
Expand Down

0 comments on commit b2d11a3

Please sign in to comment.