Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/actions/setup-node-4
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m authored Apr 29, 2024
2 parents 4162947 + a87a2d9 commit ae04b7d
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'

- run: npm ci

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "lts/*"
node-version: '20'
- run: npm ci
- run: npm run build
- run: rm .gitignore # dist/ folder is ignored by default
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ outputs:
jsonString:
description: 'JSON string'
runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'
9 changes: 9 additions & 0 deletions fixtures/mismatched-parsing/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"your_contact_details": "[email protected]",
"what_happened": "A bug happened!",
"version": "1.0.0",
"what_browsers_are_you_seeing_the_problem_on": "Chrome, Safari",
"what_else": ["Never give up"],
"and_with_that": ["Hot Dog is a Sandwich", "Another item"],
"checkbox_without_an_id": []
}
16 changes: 16 additions & 0 deletions fixtures/mismatched-parsing/form.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
body:
- type: input
id: favorite_dish
attributes:
label: What's your favorite dish?
validations:
required: true

- type: checkboxes
id: favorite_color
attributes:
label: What's your preferred color?
options:
- label: Red
- label: Green
- label: Blue
31 changes: 31 additions & 0 deletions fixtures/mismatched-parsing/issue-body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
### Your contact details

[email protected]

### What happened?

A bug happened!

### Version

1.0.0

### What browsers are you seeing the problem on?

Chrome, Safari

### What else?

- [x] Never give up
- [ ] Hot Dog is a Sandwich

### And with that?

- [] Never give up
- [X] Hot Dog is a Sandwich
- [x] Another item

### Checkbox without an id?

- [ ] IDs are great
- [ ] IDs are bad
6 changes: 6 additions & 0 deletions fixtures/mismatched-parsing/issue.js
Original file line number Diff line number Diff line change
@@ -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");
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async function run(env, body, fs, core) {
if (key in result) {
const content = result[key];

if (value !== undefined) {
if (content !== undefined && value !== undefined) {
result[key] = content.concat(value);
}
return;
Expand Down Expand Up @@ -127,6 +127,9 @@ async function run(env, body, fs, core) {
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
// even when issue-form template is not provided or wrong template is provided
idTypes[toKey(key)] = "checkboxes";
if (check.toUpperCase().startsWith("- [X] ")) {
return [key, field];
}
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"js-yaml": "^4.0.0"
},
"devDependencies": {
"@vercel/ncc": "^0.38.0",
"@vercel/ncc": "^0.38.1",
"jest": "^29.7.0"
},
"release": {
Expand Down
44 changes: 44 additions & 0 deletions test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,50 @@ it("full example", () => {
expect(core.setOutput.mock.calls.length).toBe(8)
});

it("mismatched parsing", () => {
const expectedOutput = require("./fixtures/mismatched-parsing/expected.json");
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);

// mock ENV
const env = {
HOME: "<home path>",
};

// mock event payload
const eventPayload = require("./fixtures/mismatched-parsing/issue");

// mock fs
const fs = {
readFileSync(path, encoding) {
expect(path).toBe("<template-path>");
expect(encoding).toBe("utf8");
return readFileSync("fixtures/mismatched-parsing/form.yml", "utf-8");
},
writeFileSync(path, content) {
expect(path).toBe("<home path>/issue-parser-result.json");
expect(content).toBe(expectedOutputJson);
},
};

// mock core
const core = {
getInput: jest.fn(() => '<template-path>'),
setOutput: jest.fn(),
};

run(env, eventPayload, fs, core);
expect(core.getInput).toHaveBeenCalledWith('template-path')
expect(core.setOutput).toHaveBeenCalledWith('jsonString', JSON.stringify(expectedOutput, null, 2))
expect(core.setOutput).toHaveBeenCalledWith('issueparser_your_contact_details', '[email protected]')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_what_happened', 'A bug happened!')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_version', '1.0.0')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_what_browsers_are_you_seeing_the_problem_on', 'Chrome, Safari')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_what_else', 'Never give up')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_and_with_that', 'Hot Dog is a Sandwich,Another item')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_checkbox_without_an_id', '')
expect(core.setOutput.mock.calls.length).toBe(8)
});

it("multiple paragraphs", () => {
const expectedOutput = require("./fixtures/multiple-paragraphs/expected.json");
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);
Expand Down

0 comments on commit ae04b7d

Please sign in to comment.