Skip to content

Commit ef76948

Browse files
authored
added release notes file option for create-release v6 (#309)
1 parent c7b3239 commit ef76948

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Logger } from "@octopusdeploy/api-client";
22
import { createCommandFromInputs } from "./inputCommandBuilder";
33
import { MockTaskWrapper } from "../../Utils/MockTaskWrapper";
4+
import * as path from "path";
5+
import fs from "fs";
6+
import os from "os";
47

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

49+
test("release notes file", async () => {
50+
const tempOutDir = await fs.mkdtempSync(path.join(os.tmpdir(), "octopus_"));
51+
const notesPath = path.join(tempOutDir, "notes.txt");
52+
53+
task.addVariableString("Space", "Default");
54+
task.addVariableString("Project", "Awesome project");
55+
task.addVariableString("ReleaseNotesFile", notesPath);
56+
57+
fs.writeFileSync(notesPath, "this is a release note");
58+
const command = createCommandFromInputs(logger, task);
59+
expect(command.ReleaseNotes).toBe("this is a release note");
60+
});
61+
62+
test("specifying both release notes and release notes file causes error", async () => {
63+
const tempOutDir = await fs.mkdtempSync(path.join(os.tmpdir(), "octopus_"));
64+
const notesPath = path.join(tempOutDir, "notes.txt");
65+
66+
task.addVariableString("Space", "Default");
67+
task.addVariableString("Project", "Awesome project");
68+
task.addVariableString("ReleaseNotes", "inline release notes");
69+
task.addVariableString("ReleaseNotesFile", notesPath);
70+
71+
fs.writeFileSync(notesPath, "this is a release note");
72+
expect(() => createCommandFromInputs(logger, task)).toThrowError("cannot specify ReleaseNotes and ReleaseNotesFile");
73+
});
74+
4675
test("duplicate variable name, variables field takes precedence", () => {
4776
task.addVariableString("Space", "Default");
4877
task.addVariableString("Project", "Awesome project");

source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.ts

+17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import shlex from "shlex";
33
import { getLineSeparatedItems } from "../../Utils/inputs";
44
import { CreateReleaseCommandV1, Logger } from "@octopusdeploy/api-client";
55
import { TaskWrapper } from "tasks/Utils/taskInput";
6+
import { isNullOrWhitespace } from "../../../tasksLegacy/Utils/inputs";
7+
import fs from "fs";
68

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

69+
const releaseNotesFilePath = task.getInput("ReleaseNotesFile");
70+
71+
if (command.ReleaseNotes && releaseNotesFilePath) {
72+
const message = "cannot specify ReleaseNotes and ReleaseNotesFile";
73+
task.setFailure(message);
74+
throw new Error(message);
75+
}
76+
77+
if (releaseNotesFilePath) {
78+
const releaseNotesFile = releaseNotesFilePath;
79+
if (!isNullOrWhitespace(releaseNotesFile) && fs.existsSync(releaseNotesFile) && fs.lstatSync(releaseNotesFile).isFile()) {
80+
command.ReleaseNotes = fs.readFileSync(releaseNotesFile).toString();
81+
}
82+
}
83+
6784
logger.debug?.(JSON.stringify(command));
6885

6986
return command;

source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/task.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,15 @@
9292
"label": "Release Notes",
9393
"defaultValue": "",
9494
"required": false,
95-
"helpMarkDown": "Octopus Release notes. This field supports markdown. To include newlines, you can use HTML linebreaks."
95+
"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."
96+
},
97+
{
98+
"name": "ReleaseNotesFile",
99+
"type": "string",
100+
"label": "Release Notes File",
101+
"defaultValue": "",
102+
"required": false,
103+
"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."
96104
},
97105
{
98106
"name": "GitRef",

0 commit comments

Comments
 (0)