Skip to content

Commit 7da1c3a

Browse files
jamackustefanbuckgr2m
authored
fix: Handle correctly issues with an empty body (#34)
* fix: Handle correctly issues with an empty body Fixes: #33 * Update fixtures/blank/issue.js Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com> Co-authored-by: Stefan Buck <github@stefanbuck.com> Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
1 parent f7e22bd commit 7da1c3a

5 files changed

Lines changed: 66 additions & 1 deletion

File tree

fixtures/blank/expected.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

fixtures/blank/form.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
body:
2+
- type: textarea
3+
id: textarea-one
4+
attributes:
5+
label: My textarea input
6+
- type: textarea
7+
id: textarea-two
8+
attributes:
9+
label: Another textarea input

fixtures/blank/issue.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
issue: {
3+
body: null,
4+
},
5+
};

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async function run(env, eventPayload, fs, core) {
3939
}
4040

4141
let result;
42-
const body = eventPayload.issue.body;
42+
const body = eventPayload.issue.body || '';
4343
const idMapping = getIDsFromIssueTemplate(form);
4444

4545
function toKey(str) {

test.spec.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,53 @@ it("multiple paragraphs", () => {
106106

107107
run(env, eventPayload, fs, core);
108108
});
109+
110+
it("blank", () => {
111+
const expectedOutput = require("./fixtures/blank/expected.json");
112+
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);
113+
114+
// mock ENV
115+
const env = {
116+
HOME: "<home path>",
117+
};
118+
119+
// mock event payload
120+
const eventPayload = require("./fixtures/blank/issue");
121+
122+
// mock fs
123+
const fs = {
124+
readFileSync(path, encoding) {
125+
expect(path).toBe("<template-path>");
126+
expect(encoding).toBe("utf8");
127+
return readFileSync("fixtures/blank/form.yml", "utf-8");
128+
},
129+
writeFileSync(path, content) {
130+
expect(path).toBe("<home path>/issue-parser-result.json");
131+
expect(content).toBe(expectedOutputJson);
132+
},
133+
};
134+
135+
// mock core
136+
const core = {
137+
getInput(inputName) {
138+
expect(inputName).toBe("template-path");
139+
return "<template-path>";
140+
},
141+
setOutput(outputName, outputValue) {
142+
if (outputName === "jsonString") {
143+
expect(outputValue).toBe(expectedOutputJson);
144+
return;
145+
}
146+
147+
if (outputName.startsWith("issueparser_")) {
148+
const key = outputName.substr("issueparser_".length);
149+
expect(Object.keys(expectedOutput)).toContain(key);
150+
151+
expect(outputValue).toBe(expectedOutput[key]);
152+
return;
153+
}
154+
},
155+
};
156+
157+
run(env, eventPayload, fs, core);
158+
});

0 commit comments

Comments
 (0)