Skip to content

Commit

Permalink
Default to template field ID for parsed issue body key
Browse files Browse the repository at this point in the history
By default, when an issue body is parsed, the action will now attempt to match the header in the issue body markdown with the label field of the issue template. If found, it will check if an ID is present for that field. If present, the ID will be used for the property key. Otherwise, the action reverts to the original behavior (slugifying the field label).

E.g. If the field looks like this in the template:

```yaml
  - 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
```

Then the parsed issue body will loo like this:

```json
{
  "name": "Whatever the user-provided value is"
}
```

Otherwise, if the field looks like this in the template

```yaml
  - type: input
    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
```

Then the parsed issue body JSON will look like:

```json
{
  "the_name_of_the_thing": "Whatever the user-provided value is"
}
```
  • Loading branch information
ncalteen committed Aug 29, 2024
1 parent dec1804 commit 602b9f7
Show file tree
Hide file tree
Showing 29 changed files with 643 additions and 202 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
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

Convert issue form responses to JSON

> [!IMPORTANT]
>
> As of version `v2.0.0`, this action has been converted to ESM.
## About

This action is designed to be used in conjunction with
Expand Down
6 changes: 5 additions & 1 deletion __fixtures__/blank/parsed-template.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"the_name_of_the_thing": { "type": "input", "required": true }
"name": {
"label": "The Name of the Thing",
"type": "input",
"required": true
}
}
28 changes: 14 additions & 14 deletions __fixtures__/example/parsed-issue.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"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 multiple lines.\n\nIt's pretty cool!",
"the_notes_about_the_thing": "- Note\n- Another note\n- Lots of notes",
"the_code_of_the_thing": "const thing = new Thing()\nthing.doThing()",
"the_string_method_of_the_code_of_the_thing": "thing.toString()",
"is_the_thing_a_thing": {
"name": "this-thing",
"nickname": "thing",
"color": ["blue"],
"shape": ["square"],
"sounds": ["re", "mi"],
"topics": [],
"description": "This is a description.\n\nIt has multiple lines.\n\nIt's pretty cool!",
"notes": "- Note\n- Another note\n- Lots of notes",
"code": "const thing = new Thing()\nthing.doThing()",
"code-string": "thing.toString()",
"is-thing": {
"selected": ["Yes"],
"unselected": ["No"]
},
"is_the_thing_useful": {
"is-thing-useful": {
"selected": ["Sometimes"],
"unselected": ["Yes", "No"]
},
"read_team": "IssueOps-Demo-Readers",
"write_team": "IssueOps-Demo-Writers"
"read-team": "IssueOps-Demo-Readers",
"write-team": "IssueOps-Demo-Writers"
}
55 changes: 41 additions & 14 deletions __fixtures__/example/parsed-template.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
{
"the_name_of_the_thing": { "type": "input", "required": true },
"the_nickname_of_the_thing": { "type": "input", "required": false },
"the_color_of_the_thing": {
"name": {
"label": "The Name of the Thing",
"type": "input",
"required": true
},
"nickname": {
"label": "The Nickname of the Thing",
"type": "input",
"required": false
},
"color": {
"label": "The Color of the Thing",
"type": "dropdown",
"required": true,
"multiple": false,
Expand All @@ -16,40 +25,58 @@
"yellow"
]
},
"the_shape_of_the_thing": {
"shape": {
"label": "The Shape of the Thing",
"type": "dropdown",
"required": false,
"multiple": false,
"options": ["circle", "square", "triangle"]
},
"the_sounds_of_the_thing": {
"sounds": {
"label": "The Sounds of the Thing",
"type": "dropdown",
"required": true,
"multiple": true,
"options": ["do", "re", "mi", "fa", "so", "la", "ti"]
},
"the_topics_about_the_thing": {
"topics": {
"label": "The Topics About the Thing",
"type": "dropdown",
"required": false,
"multiple": true,
"options": ["cool", "fun", "interesting", "neat"]
},
"the_description_of_the_thing": { "type": "textarea", "required": true },
"the_notes_about_the_thing": { "type": "textarea", "required": false },
"the_code_of_the_thing": { "type": "textarea", "required": true },
"the_string_method_of_the_code_of_the_thing": {
"description": {
"label": "The Description of the Thing",
"type": "textarea",
"required": true
},
"notes": {
"label": "The Notes About the Thing",
"type": "textarea",
"required": false
},
"code": {
"label": "The Code of the Thing",
"type": "textarea",
"required": true
},
"code-string": {
"label": "The String Method of the Code of the Thing",
"type": "textarea",
"required": false
},
"is_the_thing_a_thing": {
"is-thing": {
"label": "Is the Thing a Thing?",
"type": "checkboxes",
"required": false,
"options": [
{ "label": "Yes", "required": true },
{ "label": "No", "required": false }
]
},
"is_the_thing_useful": {
"is-thing-useful": {
"label": "Is the Thing Useful?",
"type": "checkboxes",
"required": false,
"options": [
Expand All @@ -58,6 +85,6 @@
{ "label": "No", "required": false }
]
},
"read_team": { "type": "input", "required": true },
"write_team": { "type": "input", "required": true }
"read-team": { "label": "Read Team", "type": "input", "required": true },
"write-team": { "label": "Write Team", "type": "input", "required": true }
}
4 changes: 2 additions & 2 deletions __fixtures__/extra/parsed-issue.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"model_description": "who's molecule is this? (we don't know)",
"ersilia_id": [],
"description": "who's molecule is this? (we don't know)",
"id": [],
"code": []
}
15 changes: 11 additions & 4 deletions __fixtures__/extra/parsed-template.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
{
"model_name": { "type": "input", "required": true },
"model_description": { "type": "input", "required": false },
"ersilia_id": {
"name": { "label": "Model Name", "type": "input", "required": true },
"description": {
"label": "Model Description",
"type": "input",
"required": false
},
"id": {
"label": "Ersilia ID",
"type": "dropdown",
"required": true,
"multiple": false,
"options": ["abc123", "def456"]
},
"publication": {
"label": "Publication",
"type": "textarea",
"required": false
},
"code": {
"label": "Code",
"type": "dropdown",
"required": true,
"multiple": false,
"options": ["123abc", "456def"]
},
"license": { "type": "input", "required": true }
"license": { "label": "License", "type": "input", "required": true }
}
6 changes: 5 additions & 1 deletion __fixtures__/header/parsed-template.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"the_name_of_the_thing": { "type": "input", "required": true }
"name": {
"label": "The Name of the Thing",
"type": "input",
"required": true
}
}
8 changes: 6 additions & 2 deletions __fixtures__/invalid/parsed-template.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"this_isnt_a_good_issue": { "type": "input", "required": true },
"empty_header": { "type": "input", "required": false }
"bad": {
"label": "This isn't a good issue",
"type": "input",
"required": true
},
"empty": { "label": "Empty header", "type": "input", "required": false }
}
4 changes: 2 additions & 2 deletions __fixtures__/missing/parsed-issue.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"model_description": "who's molecule is this? (we don't know)",
"ersilia_id": [],
"description": "who's molecule is this? (we don't know)",
"id": [],
"publication": "The following link is just an example:\n\n`www.example.com`",
"code": []
}
15 changes: 11 additions & 4 deletions __fixtures__/missing/parsed-template.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
{
"model_name": { "type": "input", "required": true },
"model_description": { "type": "input", "required": false },
"ersilia_id": {
"name": { "label": "Model Name", "type": "input", "required": true },
"description": {
"label": "Model Description",
"type": "input",
"required": false
},
"id": {
"label": "Ersilia ID",
"type": "dropdown",
"required": true,
"multiple": false,
"options": ["abc123", "def456"]
},
"publication": {
"label": "Publication",
"type": "textarea",
"required": false
},
"code": {
"label": "Code",
"type": "dropdown",
"required": true,
"multiple": false,
"options": ["123abc", "456def"]
},
"license": { "type": "input", "required": true }
"license": { "label": "License", "type": "input", "required": true }
}
65 changes: 65 additions & 0 deletions __fixtures__/no-ids/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
### 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

_No response_

### The Description of the Thing

This is a description.

It has multiple lines.

It's pretty cool!

### 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
- [ ] No

### Is the Thing Useful?

- [ ] Yes
- [x] Sometimes
- [ ] No

### Read Team

IssueOps-Demo-Readers

### Write Team

IssueOps-Demo-Writers
22 changes: 22 additions & 0 deletions __fixtures__/no-ids/parsed-issue.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"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 multiple lines.\n\nIt's pretty cool!",
"the_notes_about_the_thing": "- Note\n- Another note\n- Lots of notes",
"the_code_of_the_thing": "const thing = new Thing()\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"
}
Loading

0 comments on commit 602b9f7

Please sign in to comment.