Skip to content

Commit

Permalink
added release notes file option for create-release v6 (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
benPearce1 authored May 4, 2023
1 parent c7b3239 commit ef76948
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Logger } from "@octopusdeploy/api-client";
import { createCommandFromInputs } from "./inputCommandBuilder";
import { MockTaskWrapper } from "../../Utils/MockTaskWrapper";
import * as path from "path";
import fs from "fs";
import os from "os";

describe("getInputCommand", () => {
let logger: Logger;
Expand Down Expand Up @@ -43,6 +46,32 @@ describe("getInputCommand", () => {
expect(command.Packages).toStrictEqual(["Baz:2.5.0", "Step1:Foo:1.0.0", "Bar:2.0.0"]);
});

test("release notes file", async () => {
const tempOutDir = await fs.mkdtempSync(path.join(os.tmpdir(), "octopus_"));
const notesPath = path.join(tempOutDir, "notes.txt");

task.addVariableString("Space", "Default");
task.addVariableString("Project", "Awesome project");
task.addVariableString("ReleaseNotesFile", notesPath);

fs.writeFileSync(notesPath, "this is a release note");
const command = createCommandFromInputs(logger, task);
expect(command.ReleaseNotes).toBe("this is a release note");
});

test("specifying both release notes and release notes file causes error", async () => {
const tempOutDir = await fs.mkdtempSync(path.join(os.tmpdir(), "octopus_"));
const notesPath = path.join(tempOutDir, "notes.txt");

task.addVariableString("Space", "Default");
task.addVariableString("Project", "Awesome project");
task.addVariableString("ReleaseNotes", "inline release notes");
task.addVariableString("ReleaseNotesFile", notesPath);

fs.writeFileSync(notesPath, "this is a release note");
expect(() => createCommandFromInputs(logger, task)).toThrowError("cannot specify ReleaseNotes and ReleaseNotesFile");
});

test("duplicate variable name, variables field takes precedence", () => {
task.addVariableString("Space", "Default");
task.addVariableString("Project", "Awesome project");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import shlex from "shlex";
import { getLineSeparatedItems } from "../../Utils/inputs";
import { CreateReleaseCommandV1, Logger } from "@octopusdeploy/api-client";
import { TaskWrapper } from "tasks/Utils/taskInput";
import { isNullOrWhitespace } from "../../../tasksLegacy/Utils/inputs";
import fs from "fs";

export function createCommandFromInputs(logger: Logger, task: TaskWrapper): CreateReleaseCommandV1 {
const packages: string[] = [];
Expand Down Expand Up @@ -64,6 +66,21 @@ export function createCommandFromInputs(logger: Logger, task: TaskWrapper): Crea
GitCommit: task.getInput("GitCommit"),
};

const releaseNotesFilePath = task.getInput("ReleaseNotesFile");

if (command.ReleaseNotes && releaseNotesFilePath) {
const message = "cannot specify ReleaseNotes and ReleaseNotesFile";
task.setFailure(message);
throw new Error(message);
}

if (releaseNotesFilePath) {
const releaseNotesFile = releaseNotesFilePath;
if (!isNullOrWhitespace(releaseNotesFile) && fs.existsSync(releaseNotesFile) && fs.lstatSync(releaseNotesFile).isFile()) {
command.ReleaseNotes = fs.readFileSync(releaseNotesFile).toString();
}
}

logger.debug?.(JSON.stringify(command));

return command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,15 @@
"label": "Release Notes",
"defaultValue": "",
"required": false,
"helpMarkDown": "Octopus Release notes. This field supports markdown. To include newlines, you can use HTML linebreaks."
"helpMarkDown": "Octopus Release notes. This field supports markdown. To include newlines, you can use HTML linebreaks. Can only specify this if 'ReleaseNotesFile' is not supplied."
},
{
"name": "ReleaseNotesFile",
"type": "string",
"label": "Release Notes File",
"defaultValue": "",
"required": false,
"helpMarkDown": "Octopus Release notes file. Path to a file that contains the release notes. Supports markdown. Can only specify this if 'ReleaseNotes' is not supplied."
},
{
"name": "GitRef",
Expand Down

0 comments on commit ef76948

Please sign in to comment.