Skip to content

Commit

Permalink
Merge pull request #9 from issue-ops/format
Browse files Browse the repository at this point in the history
Update output format
  • Loading branch information
ncalteen authored Sep 21, 2023
2 parents f85f731 + 6f77674 commit ebdacd7
Show file tree
Hide file tree
Showing 44 changed files with 9,842 additions and 418 deletions.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ node_modules/
*.scss
dist/
coverage/
fixtures/
fixtures/**/*.md
188 changes: 141 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ steps:
## Inputs
| Input | Description |
| ------------- | ----------------------------------------------------------- |
| `body` | The issue body to parse (`${{ github.event.issue.body }}`) |
| `csv_to_list` | Convert single-line responses with commas to lists (`true`) |
| Input | Description |
| --------------------- | ----------------------------------------- |
| `body` | The issue body to parse |
| | Default: `${{ github.event.issue.body }}` |
| `issue-form-template` | The issue form template file |
| | e.g. `example.yml` |
| `workspace` | The checkout path on the runner |
| | Default: `${{ github.workspace }}` |

## Outputs

Expand All @@ -56,43 +60,100 @@ steps:

## Example

Given the following issue body:
Given an [example issue template](./__tests__/fixtures/example/template.yml) and
the following issue submitted with that template:

```markdown
### Your contact details
### The Name of the Thing
[email protected]
this-thing
### What happened?
### The Nickname of the Thing
A bug happened!
thing
### Version
### The Color of the Thing
1.0.0
blue
### What browsers are you seeing the problem on?
### The Shape of the Thing
Chrome, Safari
square
### What else?
### The Sounds of the Thing
- [x] Never give up
- [ ] Hot Dog is a Sandwich
re, mi
### The Topics About the Thing
_No response_
### The Description of the Thing
This is a description.
It has lines.
### The Notes About the Thing
- Note
- Another note
- Lots of notes
### The Code of the Thing
const thing = new Thing()
thing.doThing()
### The String Method of the Code of the Thing
thing.toString()
### Is the Thing a Thing?
- [x] Yes
- [x] No
### Is the Thing Useful?
- [ ] Yes
- [x] Sometimes
- [ ] No
### Read Team
IssueOps-Demo-Readers
### Write Team
IssueOps-Demo-Writers-NotATeam
```

The output of this action would be:

```json
{
"your_contact_details": "[email protected]",
"what_happened": "A bug happened!",
"version": "1.0.0",
"what_browsers_are_you_seeing_the_problem_on": ["Chrome", "Safari"],
"code_of_conduct": {
"selected": ["Never give up"],
"unselected": ["Hot Dog is a Sandwich"]
}
"the_name_of_the_thing": "this-thing",
"the_nickname_of_the_thing": "thing",
"the_color_of_the_thing": ["blue"],
"the_shape_of_the_thing": ["square"],
"the_sounds_of_the_thing": ["re", "mi"],
"the_topics_about_the_thing": [],
"the_description_of_the_thing": "This is a description.\n\nIt has lines.",
"the_notes_about_the_thing": "- Note\n- Another note\n- Lots of notes",
"the_code_of_the_thing": "const thing = new Thing()\n\nthing.doThing()",
"the_string_method_of_the_code_of_the_thing": "thing.toString()",
"is_the_thing_a_thing": {
"selected": ["Yes"],
"unselected": ["No"]
},
"is_the_thing_useful": {
"selected": ["Sometimes"],
"unselected": ["Yes", "No"]
},
"read_team": "IssueOps-Demo-Readers",
"write_team": "IssueOps-Demo-Writers"
}
```

Expand All @@ -104,75 +165,81 @@ The following transformations will take place for each heading:

<!--markdownlint-disable-->

| Transformation | Before | After |
| ------------------ | --------------------------- | ---------------------- |
| Trim | `### This is a title! :) ` | `This is a title! :)` |
| Lowercase | `This is a title! :)` | `this is a title! :)` |
| Replace Spaces | `this is a title! :)` | `this_is__a_title!_:)` |
| Remove Symbols | `this_is_a_title!_:)` | `this_is__a_title_` |
| Dedupe Underscores | `this_is__a_title_` | `this_is_a_title` |
| Transformation | Before | After |
| ---------------- | --------------------------- | ---------------------- |
| Trim | `### This is a title! :) ` | `This is a title! :)` |
| Lowercase | `This is a title! :)` | `this is a title! :)` |
| Replace Spaces | `this is a title! :)` | `this_is__a_title!_:)` |
| Remove Symbols | `this_is_a_title!_:)` | `this_is__a_title_` |
| Trim Underscores | `this_is__a_title_` | `this_is_a_title` |

<!--markdownlint-enable-->

### Values

The following transformations will take place for responses, depending on the
type/format.
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).

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

Before:

```plain
This is a response
```

After:
After (no change):

```plain
This is a response
```

#### Single Line with Commas
### Multiline

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

> [!NOTE]
>
> This can be disable by setting the `csv_to_list` parameter to `'false'`.
> Empty lines are preserved in multiline responses.

Before:

```plain
These, are, options
First line :D
Third line!
```

After:

```json
["These", "are", "options"]
```plain
First line :D\n\nThird line!
```

### Multiline
### Dropdown Selections

> [!NOTE]
>
> Empty lines are preserved in multiline responses.
[Type: `dropdown`](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema#dropdown)

Before:

```plain
First line :D
Third line!
red, blue, green
```

After:

```plain
First line :D\n\nThird line!
```json
["red", "blue", "green"]
```

### Checkboxes

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

Before:

```plain
Expand Down Expand Up @@ -202,3 +269,30 @@ In the following situations, an input will be omitted from the output JSON:
| | `<empty>` |
| | `### This is another` |
| | `This is a value` |

If a form is submitted with empty field(s), they will be included in the issue
body as one of the following:

```markdown
### Field A
_No response_
### Field B
None
### Field C
<empty>
```

These will be converted to one of the following, based on the type of input
specified in the issue form template:

| Type | Output |
| ------------ | -------------------------------------------------------- |
| `input` | Empty string (`""`) |
| `textarea` | Empty string (`""`) |
| `dropdown` | Empty list (`[]`) |
| `checkboxes` | Empty checkboxes (`{ "selected": [], "unselected": []}`) |
1 change: 0 additions & 1 deletion __tests__/fixtures/blank/expected.json

This file was deleted.

1 change: 1 addition & 0 deletions __tests__/fixtures/blank/parsed-issue.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions __tests__/fixtures/blank/parsed-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"the_name_of_the_thing": { "type": "input", "required": true }
}
13 changes: 13 additions & 0 deletions __tests__/fixtures/blank/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Example Request
description: Submit an example request
title: '[Request] Example'

body:
- type: input
id: name
attributes:
label: The Name of the Thing
description: The name of the thing you want to create.
placeholder: this-is-the-thing
validations:
required: true
13 changes: 0 additions & 13 deletions __tests__/fixtures/bug-report/expected.json

This file was deleted.

20 changes: 0 additions & 20 deletions __tests__/fixtures/bug-report/issue.md

This file was deleted.

Loading

0 comments on commit ebdacd7

Please sign in to comment.