Skip to content

Commit 76d5aa0

Browse files
authored
Merge pull request #128 from issue-ops/ncalteen/outputs
Enhance output handling in main action: add detailed parsed outputs
2 parents eba68dc + 8d13905 commit 76d5aa0

7 files changed

Lines changed: 99 additions & 17 deletions

File tree

‎.markdown-lint.yml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
MD003: false
22
MD004:
33
style: dash
4-
MD013:
5-
tables: false
4+
MD013: false
65
MD026: false
76
MD029:
87
style: one

‎README.md‎

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
![Continuous Delivery](https://github.com/issue-ops/parser/actions/workflows/continuous-delivery.yml/badge.svg)
88
![Linter](https://github.com/issue-ops/parser/actions/workflows/linter.yml/badge.svg)
99

10-
Convert issue form responses to JSON
10+
Convert issue form responses to JSON!
1111

1212
## About
1313

@@ -54,9 +54,10 @@ steps:
5454

5555
## Outputs
5656

57-
| Output | Description |
58-
| ------ | --------------------------------- |
59-
| `json` | The parsed issue as a JSON string |
57+
| Output | Description |
58+
| -------------- | --------------------------------- |
59+
| `json` | The parsed issue as a JSON string |
60+
| `parsed_<key>` | The parsed value for `<key>` |
6061

6162
## Example
6263

@@ -131,9 +132,7 @@ IssueOps-Demo-Readers
131132
IssueOps-Demo-Writers-NotATeam
132133
```
133134

134-
The output of this action would be:
135-
136-
<!-- markdownlint-disable -->
135+
The `json` output of this action would be:
137136

138137
```json
139138
{
@@ -160,7 +159,24 @@ The output of this action would be:
160159
}
161160
```
162161

163-
<!-- markdownlint-enable -->
162+
Additionally, the following outputs would be available:
163+
164+
| Output | Value |
165+
| ------------------------ | ----------------------------------------------------------------------- |
166+
| `parsed_name` | `this-thing` |
167+
| `parsed_nickname` | `thing` |
168+
| `parsed_color` | `["blue"]` |
169+
| `parsed_shape` | `["square"]` |
170+
| `parsed_sounds` | `["re", "mi"]` |
171+
| `parsed_topics` | `[]` |
172+
| `parsed_description` | `This is a description.\n\nIt has multiple lines.\n\nIt's pretty cool!` |
173+
| `parsed_notes` | `- Note\n- Another note\n- Lots of notes` |
174+
| `parsed_code` | `const thing = new Thing()\nthing.doThing()` |
175+
| `parsed_code-string` | `thing.toString()` |
176+
| `parsed_is-thing` | `{ "selected": ["Yes"], "unselected": ["No"] }` |
177+
| `parsed_is-thing-useful` | `{ "selected": ["Sometimes"], "unselected": ["Yes", "No"] }` |
178+
| `parsed_read-team` | `IssueOps-Demo-Readers` |
179+
| `parsed_write-team` | `IssueOps-Demo-Writers` |
164180

165181
### No Template Provided
166182

@@ -169,9 +185,7 @@ still parse the issue body, however the output will be a flat JSON object. The
169185
object keys will be slugified versions of the headers, and the values will be
170186
the contents of the headers.
171187

172-
Using the same example as above, the output would instead be:
173-
174-
<!-- markdownlint-disable -->
188+
Using the same example as above, the `json` output would instead be:
175189

176190
```json
177191
{
@@ -192,7 +206,24 @@ Using the same example as above, the output would instead be:
192206
}
193207
```
194208

195-
<!-- markdownlint-enable -->
209+
Additionally, the following outputs would be available:
210+
211+
| Output | Value |
212+
| --------------------------------------------------- | ----------------------------------------------------------------------- |
213+
| `parsed_the_name_of_the_thing` | `this-thing` |
214+
| `parsed_the_nickname_of_the_thing` | `thing` |
215+
| `parsed_the_color_of_the_thing` | `["blue"]` |
216+
| `parsed_the_shape_of_the_thing` | `["square"]` |
217+
| `parsed_the_sounds_of_the_thing` | `["re", "mi"]` |
218+
| `parsed_the_topics_about_the_thing` | `[]` |
219+
| `parsed_the_description_of_the_thing` | `This is a description.\n\nIt has multiple lines.\n\nIt's pretty cool!` |
220+
| `parsed_the_notes_about_the_thing` | `- Note\n- Another note\n- Lots of notes` |
221+
| `parsed_the_code_of_the_thing` | `const thing = new Thing()\nthing.doThing()` |
222+
| `parsed_the_string_method_of_the_code_of_the_thing` | `thing.toString()` |
223+
| `parsed_is_the_thing_a_thing` | `{ "selected": ["Yes"], "unselected": ["No"] }` |
224+
| `parsed_is_the_thing_useful` | `{ "selected": ["Sometimes"], "unselected": ["Yes", "No"] }` |
225+
| `parsed_read_team` | `IssueOps-Demo-Readers` |
226+
| `parsed_write_team` | `IssueOps-Demo-Writers` |
196227

197228
## Transformations
198229

@@ -219,6 +250,12 @@ input type. The type is inferred from the issue form template. For information
219250
on each specific type, see
220251
[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).
221252

253+
> [!NOTE]
254+
>
255+
> If the issue form template is not provided, the action will assume all inputs
256+
> are of type `input`. This means that all values will be treated as strings (no
257+
> transformations will be applied).
258+
222259
#### Single Line
223260

224261
[Type: `input`](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema#input)

‎__tests__/main.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ describe('main', () => {
4545
JSON.stringify(parsedIssueWithTemplate)
4646
)
4747

48+
for (const [key, value] of Object.entries(parsedIssueWithTemplate))
49+
expect(core.setOutput).toHaveBeenCalledWith(
50+
`parsed_${key}`,
51+
value === undefined
52+
? ''
53+
: typeof value === 'string'
54+
? value
55+
: JSON.stringify(value)
56+
)
57+
4858
// Does not fail
4959
expect(core.setFailed).not.toHaveBeenCalled()
5060
})
@@ -71,6 +81,16 @@ describe('main', () => {
7181
JSON.stringify(parsedIssueNoTemplate)
7282
)
7383

84+
for (const [key, value] of Object.entries(parsedIssueNoTemplate))
85+
expect(core.setOutput).toHaveBeenCalledWith(
86+
`parsed_${key}`,
87+
value === undefined
88+
? ''
89+
: typeof value === 'string'
90+
? value
91+
: JSON.stringify(value)
92+
)
93+
7494
// Does not fail
7595
expect(core.setFailed).not.toHaveBeenCalled()
7696
})

‎dist/index.js‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "parser",
33
"description": "Convert issue form responses to JSON",
4-
"version": "4.1.0",
4+
"version": "4.2.0",
55
"author": "Nick Alteen <ncalteen@github.com>",
66
"type": "module",
77
"homepage": "https://github.com/issue-ops/parser#readme",

‎src/main.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,19 @@ export async function run(): Promise<void> {
3333

3434
core.info(`Parsed issue: ${JSON.stringify(parsedIssue, null, 2)}`)
3535
core.setOutput('json', JSON.stringify(parsedIssue))
36+
37+
for (const [key, value] of Object.entries(parsedIssue)) {
38+
core.setOutput(
39+
`parsed_${key}`,
40+
value === undefined
41+
? /* istanbul ignore next */
42+
// Output an empty string
43+
''
44+
: typeof value === 'string'
45+
? // If the value is a string, output it as is
46+
value
47+
: // Otherwise, stringify the object
48+
JSON.stringify(value)
49+
)
50+
}
3651
}

0 commit comments

Comments
 (0)