Skip to content

Commit

Permalink
chore: refactor around how the prbody is written for changelogs
Browse files Browse the repository at this point in the history
  • Loading branch information
benjdlambert committed Apr 16, 2024
1 parent 2a79ca0 commit b063c64
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ type VersionOptions = {
commitMessage?: string;
hasPublishScript?: boolean;
customVersionBranch?: string;
skipRootChangelogUpdate?: boolean;
skipRootChangelogUpdate: boolean;
};

type RunVersionResult = {
Expand Down Expand Up @@ -244,7 +244,11 @@ export async function runVersion({
};
})
);
let changelogBody = `

let prBody: string;

if (!skipRootChangelogUpdate) {
let changelogBody = `
# Release v${releaseVersion}
Upgrade Helper: [https://backstage.github.io/upgrade-helper/?to=${releaseVersion}](https://backstage.github.io/upgrade-helper/?to=${releaseVersion})
Expand All @@ -255,21 +259,26 @@ ${changelogEntries
.map((x) => x.content)
.join("\n")}
`;

const changelogPath = `docs/releases/v${releaseVersion}-changelog.md`;

try {
const prettier = require(resolveFrom(cwd, "prettier"));
const prettierConfig = await prettier.resolveConfig(cwd);
changelogBody = prettier.format(changelogBody, {
...prettierConfig,
parser: "markdown",
});
} catch {}

await fs.writeFile(changelogPath, changelogBody);

const prBody = `See [${changelogPath}](https://github.com/backstage/backstage/blob/master/${changelogPath}) for more information.`;
const changelogPath = `docs/releases/v${releaseVersion}-changelog.md`;

try {
const prettier = require(resolveFrom(cwd, "prettier"));
const prettierConfig = await prettier.resolveConfig(cwd);
changelogBody = prettier.format(changelogBody, {
...prettierConfig,
parser: "markdown",
});
} catch {}
await fs.writeFile(changelogPath, changelogBody);

prBody = `See [${changelogPath}](https://github.com/backstage/backstage/blob/master/${changelogPath}) for more information.`;
} else {
prBody = `# Releases\n ${changelogEntries
.filter((x) => x)
.sort(sortTheThings)
.map((x) => x.content)
.join("\n")}}`;
}

const finalPrTitle = `${prTitle}${!!preState ? ` (${preState.tag})` : ""}`;

Expand Down

0 comments on commit b063c64

Please sign in to comment.