diff --git a/.markdown-lint.yml b/.markdown-lint.yml index f177033..1ff5857 100644 --- a/.markdown-lint.yml +++ b/.markdown-lint.yml @@ -1,8 +1,7 @@ MD003: false MD004: style: dash -MD013: - tables: false +MD013: false MD026: false MD029: style: one diff --git a/README.md b/README.md index 430c41e..8e3135a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ![Continuous Delivery](https://github.com/issue-ops/parser/actions/workflows/continuous-delivery.yml/badge.svg) ![Linter](https://github.com/issue-ops/parser/actions/workflows/linter.yml/badge.svg) -Convert issue form responses to JSON +Convert issue form responses to JSON! ## About @@ -54,9 +54,10 @@ steps: ## Outputs -| Output | Description | -| ------ | --------------------------------- | -| `json` | The parsed issue as a JSON string | +| Output | Description | +| -------------- | --------------------------------- | +| `json` | The parsed issue as a JSON string | +| `parsed_` | The parsed value for `` | ## Example @@ -131,9 +132,7 @@ IssueOps-Demo-Readers IssueOps-Demo-Writers-NotATeam ``` -The output of this action would be: - - +The `json` output of this action would be: ```json { @@ -160,7 +159,24 @@ The output of this action would be: } ``` - +Additionally, the following outputs would be available: + +| Output | Value | +| ------------------------ | ----------------------------------------------------------------------- | +| `parsed_name` | `this-thing` | +| `parsed_nickname` | `thing` | +| `parsed_color` | `["blue"]` | +| `parsed_shape` | `["square"]` | +| `parsed_sounds` | `["re", "mi"]` | +| `parsed_topics` | `[]` | +| `parsed_description` | `This is a description.\n\nIt has multiple lines.\n\nIt's pretty cool!` | +| `parsed_notes` | `- Note\n- Another note\n- Lots of notes` | +| `parsed_code` | `const thing = new Thing()\nthing.doThing()` | +| `parsed_code-string` | `thing.toString()` | +| `parsed_is-thing` | `{ "selected": ["Yes"], "unselected": ["No"] }` | +| `parsed_is-thing-useful` | `{ "selected": ["Sometimes"], "unselected": ["Yes", "No"] }` | +| `parsed_read-team` | `IssueOps-Demo-Readers` | +| `parsed_write-team` | `IssueOps-Demo-Writers` | ### No Template Provided @@ -169,9 +185,7 @@ still parse the issue body, however the output will be a flat JSON object. The object keys will be slugified versions of the headers, and the values will be the contents of the headers. -Using the same example as above, the output would instead be: - - +Using the same example as above, the `json` output would instead be: ```json { @@ -192,7 +206,24 @@ Using the same example as above, the output would instead be: } ``` - +Additionally, the following outputs would be available: + +| Output | Value | +| --------------------------------------------------- | ----------------------------------------------------------------------- | +| `parsed_the_name_of_the_thing` | `this-thing` | +| `parsed_the_nickname_of_the_thing` | `thing` | +| `parsed_the_color_of_the_thing` | `["blue"]` | +| `parsed_the_shape_of_the_thing` | `["square"]` | +| `parsed_the_sounds_of_the_thing` | `["re", "mi"]` | +| `parsed_the_topics_about_the_thing` | `[]` | +| `parsed_the_description_of_the_thing` | `This is a description.\n\nIt has multiple lines.\n\nIt's pretty cool!` | +| `parsed_the_notes_about_the_thing` | `- Note\n- Another note\n- Lots of notes` | +| `parsed_the_code_of_the_thing` | `const thing = new Thing()\nthing.doThing()` | +| `parsed_the_string_method_of_the_code_of_the_thing` | `thing.toString()` | +| `parsed_is_the_thing_a_thing` | `{ "selected": ["Yes"], "unselected": ["No"] }` | +| `parsed_is_the_thing_useful` | `{ "selected": ["Sometimes"], "unselected": ["Yes", "No"] }` | +| `parsed_read_team` | `IssueOps-Demo-Readers` | +| `parsed_write_team` | `IssueOps-Demo-Writers` | ## Transformations @@ -219,6 +250,12 @@ input type. The type is inferred from the issue form template. For information on each specific type, see [Syntax for GitHub's form schema](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema). +> [!NOTE] +> +> If the issue form template is not provided, the action will assume all inputs +> are of type `input`. This means that all values will be treated as strings (no +> transformations will be applied). + #### Single Line [Type: `input`](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema#input) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 7a729a3..dc9be44 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -45,6 +45,16 @@ describe('main', () => { JSON.stringify(parsedIssueWithTemplate) ) + for (const [key, value] of Object.entries(parsedIssueWithTemplate)) + expect(core.setOutput).toHaveBeenCalledWith( + `parsed_${key}`, + value === undefined + ? '' + : typeof value === 'string' + ? value + : JSON.stringify(value) + ) + // Does not fail expect(core.setFailed).not.toHaveBeenCalled() }) @@ -71,6 +81,16 @@ describe('main', () => { JSON.stringify(parsedIssueNoTemplate) ) + for (const [key, value] of Object.entries(parsedIssueNoTemplate)) + expect(core.setOutput).toHaveBeenCalledWith( + `parsed_${key}`, + value === undefined + ? '' + : typeof value === 'string' + ? value + : JSON.stringify(value) + ) + // Does not fail expect(core.setFailed).not.toHaveBeenCalled() }) diff --git a/dist/index.js b/dist/index.js index 0900611..902c121 100644 --- a/dist/index.js +++ b/dist/index.js @@ -34921,6 +34921,17 @@ async function run() { parsedIssue = parseIssue(body, undefined, { slugify: true }); coreExports.info(`Parsed issue: ${JSON.stringify(parsedIssue, null, 2)}`); coreExports.setOutput('json', JSON.stringify(parsedIssue)); + for (const [key, value] of Object.entries(parsedIssue)) { + coreExports.setOutput(`parsed_${key}`, value === undefined + ? /* istanbul ignore next */ + // Output an empty string + '' + : typeof value === 'string' + ? // If the value is a string, output it as is + value + : // Otherwise, stringify the object + JSON.stringify(value)); + } } /* istanbul ignore next */ diff --git a/package-lock.json b/package-lock.json index 2cfa8ed..deae180 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "parser", - "version": "4.1.0", + "version": "4.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "parser", - "version": "4.1.0", + "version": "4.2.0", "license": "MIT", "dependencies": { "@actions/core": "^1.11.1", diff --git a/package.json b/package.json index cdf680d..898a835 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "parser", "description": "Convert issue form responses to JSON", - "version": "4.1.0", + "version": "4.2.0", "author": "Nick Alteen ", "type": "module", "homepage": "https://github.com/issue-ops/parser#readme", diff --git a/src/main.ts b/src/main.ts index 2914537..b59b26a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -33,4 +33,19 @@ export async function run(): Promise { core.info(`Parsed issue: ${JSON.stringify(parsedIssue, null, 2)}`) core.setOutput('json', JSON.stringify(parsedIssue)) + + for (const [key, value] of Object.entries(parsedIssue)) { + core.setOutput( + `parsed_${key}`, + value === undefined + ? /* istanbul ignore next */ + // Output an empty string + '' + : typeof value === 'string' + ? // If the value is a string, output it as is + value + : // Otherwise, stringify the object + JSON.stringify(value) + ) + } }