Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .markdown-lint.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
MD003: false
MD004:
style: dash
MD013:
tables: false
MD013: false
MD026: false
MD029:
style: one
Expand Down
61 changes: 49 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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_<key>` | The parsed value for `<key>` |

## Example

Expand Down Expand Up @@ -131,9 +132,7 @@ IssueOps-Demo-Readers
IssueOps-Demo-Writers-NotATeam
```

The output of this action would be:

<!-- markdownlint-disable -->
The `json` output of this action would be:

```json
{
Expand All @@ -160,7 +159,24 @@ The output of this action would be:
}
```

<!-- markdownlint-enable -->
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

Expand All @@ -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:

<!-- markdownlint-disable -->
Using the same example as above, the `json` output would instead be:

```json
{
Expand All @@ -192,7 +206,24 @@ Using the same example as above, the output would instead be:
}
```

<!-- markdownlint-enable -->
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

Expand All @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand All @@ -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()
})
Expand Down
11 changes: 11 additions & 0 deletions dist/index.js

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

4 changes: 2 additions & 2 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
@@ -1,7 +1,7 @@
{
"name": "parser",
"description": "Convert issue form responses to JSON",
"version": "4.1.0",
"version": "4.2.0",
"author": "Nick Alteen <[email protected]>",
"type": "module",
"homepage": "https://github.com/issue-ops/parser#readme",
Expand Down
15 changes: 15 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,19 @@ export async function run(): Promise<void> {

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)
)
}
}