Skip to content

Commit

Permalink
feat: add ability to control the value to prefix the notes with
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinWilkinson committed Aug 29, 2024
1 parent 302b4b7 commit 32c3614
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions schemas/prepare-release-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
"versionJSONKeyPath": {
"type": "string",
"description": "The path to the version number in the JSON file. Only used if the file is a JSON file. (Optional)"
},
"releaseNotesFilePrefix": {
"type": "string",
"description": "The path to the version number in the JSON file. Only used if the file is a JSON file. (Optional)"
}
},
"required": ["ownerName", "repoName", "releaseTypes", "githubTokenEnvVarName"]
Expand Down
5 changes: 5 additions & 0 deletions src/prepare-release-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ export interface PrepareReleaseSettings {
* Gets the dot separated path to the JSON key that contains the version.
*/
versionJSONKeyPath?: string;

/**
* Gets the value to prefix the release notes file name with.
*/
releaseNotesFilePrefix?: string;
}
22 changes: 18 additions & 4 deletions src/release-prepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ export class ReleasePrepper {
}

// Generate the release notes
const newNotesFilePath = await this.createReleaseNotes(chosenReleaseType, chosenVersion, settings.githubTokenEnvVarName);
const newNotesFilePath = await this.createReleaseNotes(
chosenReleaseType,
chosenVersion,
settings.githubTokenEnvVarName,
settings.releaseNotesFilePrefix);

// If release notes were generated, stage and commit them.
if (newNotesFilePath !== undefined) {
Expand Down Expand Up @@ -447,16 +451,24 @@ export class ReleasePrepper {
}
}

/**
* Creates release notes based on the given {@link releaseType} and {@link chosenVersion}.
* @param releaseType The type of release.
* @param chosenVersion The version.
* @param tokenEnvVarName The name of the environment variable that contains the GitHub token.
* @param fileNamePrefix The value to prefix the notes file name with.
* @returns The release notes.
*/
private async createReleaseNotes(
releaseType: ReleaseType,
chosenVersion: string,
tokenEnvVarName: string,
fileNamePrefix?: string,
): Promise<string | undefined> {
ConsoleLogColor.gray(" ⏳Creating release notes.");

// Trim the notes dir path and replace all '\' with '/'
let notesDirPath = releaseType.releaseNotesDirPath.trim()
.replace(/\\/g, "/");
let notesDirPath = releaseType.releaseNotesDirPath.trim().replace(/\\/g, "/");

notesDirPath = notesDirPath.endsWith("/") ? notesDirPath.slice(0, -1) : notesDirPath;

Expand All @@ -475,7 +487,9 @@ export class ReleasePrepper {
Deno.mkdirSync(notesDirPath, { recursive: true });
}

const newNotesFilePath = `${notesDirPath}/Release-Notes-${chosenVersion}.md`;
const prefix = Guards.isNothing(fileNamePrefix) ? "" : fileNamePrefix;

const newNotesFilePath = `${notesDirPath}/${prefix}${chosenVersion}.md`;

Deno.writeTextFileSync(newNotesFilePath, releaseNotesFileContent, { create: true });

Expand Down

0 comments on commit 32c3614

Please sign in to comment.