From 7e77751e18b4103d2b823aa499a3ec275a7a1cc2 Mon Sep 17 00:00:00 2001 From: Christian Helgeson <62450112+cmhhelgeson@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:58:29 -0700 Subject: [PATCH 1/3] init branch --- fixtures/inner_values/expected.json | 15 +++++++ fixtures/inner_values/form.yml | 52 ++++++++++++++++++++++ fixtures/inner_values/issue-body.md | 18 ++++++++ fixtures/inner_values/issue.js | 6 +++ fixtures/multiple-paragraphs/expected.json | 2 +- index.js | 27 ++++++++--- test.spec.js | 2 +- 7 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 fixtures/inner_values/expected.json create mode 100644 fixtures/inner_values/form.yml create mode 100644 fixtures/inner_values/issue-body.md create mode 100644 fixtures/inner_values/issue.js diff --git a/fixtures/inner_values/expected.json b/fixtures/inner_values/expected.json new file mode 100644 index 0000000..e9e70e5 --- /dev/null +++ b/fixtures/inner_values/expected.json @@ -0,0 +1,15 @@ +{ + + "resources": { + "Related PRs": "#123456", + "Related Issues": "" + }, + "description": "Hold my Potatos", + "date": { + "Month": "April", + "Date": "14th", + "Year": "20XX" + }, + "department": "Finance" + +} \ No newline at end of file diff --git a/fixtures/inner_values/form.yml b/fixtures/inner_values/form.yml new file mode 100644 index 0000000..b9074bf --- /dev/null +++ b/fixtures/inner_values/form.yml @@ -0,0 +1,52 @@ +name: Bug Report +description: File a reproducible bug or regression. +labels: ['bug'] +body: + - type: textarea + id: graph + attributes: + label: Resources + value: | + **Related PRs**: + **Related Issues**: + - type: textarea + id: description + attributes: + label: Description + description: A clear and concise description of what the bug is. + validations: + required: true + - type: textarea + id: date + attributes: + label: Date + value: | + _Month_: + _Day_: + _Year_: + validations: + required: true + - type: textarea + id: repro + attributes: + label: Reproduction steps + description: How do you trigger this bug? Please walk us through it step by step. + value: | + 1. + 2. + 3. + validations: + required: true + - type: dropdown + id: department + attributes: + label: Department + multiple: false + options: + - IT + - HR + - Finance + - Operations + - Warehouse + - Management + - Customer \ No newline at end of file diff --git a/fixtures/inner_values/issue-body.md b/fixtures/inner_values/issue-body.md new file mode 100644 index 0000000..ab4550d --- /dev/null +++ b/fixtures/inner_values/issue-body.md @@ -0,0 +1,18 @@ +### Resources + +**Related Issues**: #123456 +**Related PRs**: + +### Description + +Hold my potatos. + +### Date + +_Month_: April +_Day_: 14th +_Year_: 202XX + +### Department + +Finance diff --git a/fixtures/inner_values/issue.js b/fixtures/inner_values/issue.js new file mode 100644 index 0000000..b83a5cfe --- /dev/null +++ b/fixtures/inner_values/issue.js @@ -0,0 +1,6 @@ +const { resolve } = require("path"); +const { readFileSync } = require("fs"); + +const issueBodyPath = resolve(__dirname, "issue-body.md"); + +module.exports = readFileSync(issueBodyPath, "utf-8"); diff --git a/fixtures/multiple-paragraphs/expected.json b/fixtures/multiple-paragraphs/expected.json index 2e971b0..9d1f0db 100644 --- a/fixtures/multiple-paragraphs/expected.json +++ b/fixtures/multiple-paragraphs/expected.json @@ -1,4 +1,4 @@ { "textarea-one": "1st paragraph\n\n2nd paragraph", - "textarea-two": "1st paragraph\n2nd paragraph" + "textarea-two": "1st paragraph\n\n2nd paragraph" } diff --git a/index.js b/index.js index 53cc884..8510c98 100644 --- a/index.js +++ b/index.js @@ -76,8 +76,8 @@ async function run(env, body, fs, core) { return input; } - const value = [input, ...extraLines].join("\n\n").trim(); - + let value = [input, ...extraLines].join("\n\n").trim(); + if (value.toLowerCase() === "_no response_") { return ""; } @@ -111,20 +111,22 @@ async function run(env, body, fs, core) { return result } + // Divide each issue into its component sections. result = body .trim() .split("###") .filter(Boolean) - .map((line) => { - return line + .map((section) => { + return section .split(/\r?\n\r?\n/) .filter(Boolean) .map((item, index, arr) => { const line = item.trim(); - + // If the relevant input is a checkbox element if (line.startsWith("- [")) { return line.split(/\r?\n/).map((check) => { const field = check.replace(/- \[[X\s]\]\s+/i, ""); + const previousIndex = index === 0 ? index : index - 1; const key = arr[previousIndex].trim(); // set the type of the field to checkboxes to ensure that values will be represented as an array @@ -135,12 +137,24 @@ async function run(env, body, fs, core) { } return [key]; }); + // Otherwise presume that input is a series of text lines and separate them. + } else { + + const splitText = line.split(/\r?\n/); + if (splitText.length === 1) { + console.log(`Returning line: ${line}`); + return line; + } + const previousIndex = index === 0 ? index : index - 1; + const key = arr[previousIndex].trim(); + console.log(`Returning splitText: ${splitText}`); + return splitText.join('\n\n') } - return line; }); }) .reduce((prev, curr) => { + // If the item is a checkbox field if (Array.isArray(curr[1])) { return [...prev, ...curr[1]]; } @@ -151,7 +165,6 @@ async function run(env, body, fs, core) { result = result.map(([key, ...lines]) => { const checkListValue = lines.find((line) => Array.isArray(line)); const value = checkListValue ? toValue(checkListValue) : toValue(...lines); - return [toKey(key), value]; }); diff --git a/test.spec.js b/test.spec.js index c3ce9bc..a856bf6 100644 --- a/test.spec.js +++ b/test.spec.js @@ -170,7 +170,7 @@ it("multiple paragraphs", () => { expect(core.getInput).toHaveBeenCalledWith('template-path') expect(core.setOutput).toHaveBeenCalledWith('jsonString', JSON.stringify(expectedOutput, null, 2)) expect(core.setOutput).toHaveBeenCalledWith('issueparser_textarea-one', '1st paragraph\n\n2nd paragraph') - expect(core.setOutput).toHaveBeenCalledWith('issueparser_textarea-two', '1st paragraph\n2nd paragraph') + expect(core.setOutput).toHaveBeenCalledWith('issueparser_textarea-two', '1st paragraph\n\n2nd paragraph') expect(core.setOutput.mock.calls.length).toBe(3) }); From 3004543de1dca9a7a70e80ab18bc93140a0ff7ce Mon Sep 17 00:00:00 2001 From: Christian Helgeson <62450112+cmhhelgeson@users.noreply.github.com> Date: Thu, 24 Oct 2024 14:32:48 -0700 Subject: [PATCH 2/3] remove comments --- index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/index.js b/index.js index 8510c98..f4cb9b9 100644 --- a/index.js +++ b/index.js @@ -137,17 +137,15 @@ async function run(env, body, fs, core) { } return [key]; }); - // Otherwise presume that input is a series of text lines and separate them. + // Otherwise presume that input is a collected chunk of text lines and separarate them. } else { const splitText = line.split(/\r?\n/); if (splitText.length === 1) { - console.log(`Returning line: ${line}`); return line; } const previousIndex = index === 0 ? index : index - 1; const key = arr[previousIndex].trim(); - console.log(`Returning splitText: ${splitText}`); return splitText.join('\n\n') } From c27c78d758aa8f45fddb87c869c1274848c60eaa Mon Sep 17 00:00:00 2001 From: Christian Helgeson <62450112+cmhhelgeson@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:00:56 -0700 Subject: [PATCH 3/3] remove unused values --- fixtures/inner_values/expected.json | 15 --------- fixtures/inner_values/form.yml | 52 ----------------------------- fixtures/inner_values/issue-body.md | 18 ---------- fixtures/inner_values/issue.js | 6 ---- index.js | 2 -- 5 files changed, 93 deletions(-) delete mode 100644 fixtures/inner_values/expected.json delete mode 100644 fixtures/inner_values/form.yml delete mode 100644 fixtures/inner_values/issue-body.md delete mode 100644 fixtures/inner_values/issue.js diff --git a/fixtures/inner_values/expected.json b/fixtures/inner_values/expected.json deleted file mode 100644 index e9e70e5..0000000 --- a/fixtures/inner_values/expected.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - - "resources": { - "Related PRs": "#123456", - "Related Issues": "" - }, - "description": "Hold my Potatos", - "date": { - "Month": "April", - "Date": "14th", - "Year": "20XX" - }, - "department": "Finance" - -} \ No newline at end of file diff --git a/fixtures/inner_values/form.yml b/fixtures/inner_values/form.yml deleted file mode 100644 index b9074bf..0000000 --- a/fixtures/inner_values/form.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Bug Report -description: File a reproducible bug or regression. -labels: ['bug'] -body: - - type: textarea - id: graph - attributes: - label: Resources - value: | - **Related PRs**: - **Related Issues**: - - type: textarea - id: description - attributes: - label: Description - description: A clear and concise description of what the bug is. - validations: - required: true - - type: textarea - id: date - attributes: - label: Date - value: | - _Month_: - _Day_: - _Year_: - validations: - required: true - - type: textarea - id: repro - attributes: - label: Reproduction steps - description: How do you trigger this bug? Please walk us through it step by step. - value: | - 1. - 2. - 3. - validations: - required: true - - type: dropdown - id: department - attributes: - label: Department - multiple: false - options: - - IT - - HR - - Finance - - Operations - - Warehouse - - Management - - Customer \ No newline at end of file diff --git a/fixtures/inner_values/issue-body.md b/fixtures/inner_values/issue-body.md deleted file mode 100644 index ab4550d..0000000 --- a/fixtures/inner_values/issue-body.md +++ /dev/null @@ -1,18 +0,0 @@ -### Resources - -**Related Issues**: #123456 -**Related PRs**: - -### Description - -Hold my potatos. - -### Date - -_Month_: April -_Day_: 14th -_Year_: 202XX - -### Department - -Finance diff --git a/fixtures/inner_values/issue.js b/fixtures/inner_values/issue.js deleted file mode 100644 index b83a5cfe..0000000 --- a/fixtures/inner_values/issue.js +++ /dev/null @@ -1,6 +0,0 @@ -const { resolve } = require("path"); -const { readFileSync } = require("fs"); - -const issueBodyPath = resolve(__dirname, "issue-body.md"); - -module.exports = readFileSync(issueBodyPath, "utf-8"); diff --git a/index.js b/index.js index f4cb9b9..9a9f706 100644 --- a/index.js +++ b/index.js @@ -144,8 +144,6 @@ async function run(env, body, fs, core) { if (splitText.length === 1) { return line; } - const previousIndex = index === 0 ? index : index - 1; - const key = arr[previousIndex].trim(); return splitText.join('\n\n') }