Skip to content

Commit cf55537

Browse files
Ansuelgr2m
andauthored
fix: improve body parsing logic (#72)
Current body parsing logic with trim() + split("###") is too fragile and pose problems with some body that contains case with ### in the middle of the line or case with codeblock ``` section. These case will cause the script to parse these as separate section and produce wrong outputs and in some case even prints error assuming things are checkbox and errors out on the concat function. To make the parsing logic more solid, implement a dedicated function and parse with this logic: - We split the body for "\n" - We ignore codeblock ``` section - We check "###" only at the start of the line - We check for "### " (with the space included) as that is the correct section Github issue template expects. With the following change case like: ``` root@OpenWrt:~# cat /boot/config.txt ``` Are correctly parsed as all part of a single section instead of being wrongly treated as different empty sections. --------- Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
1 parent 0d9ce93 commit cf55537

14 files changed

Lines changed: 226 additions & 3 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"textarea-one": "Textarea input text 1 ####"
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
body:
2+
- type: textarea
3+
id: textarea-one
4+
attributes:
5+
label: My textarea input
6+
- type: textarea
7+
id: textarea-two
8+
attributes:
9+
label: Another textarea input
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### My textarea input
2+
3+
Textarea input text 1 ####
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { readFileSync } from "node:fs";
2+
import { resolve } from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
5+
const __dirname = fileURLToPath(new URL(".", import.meta.url));
6+
const issueBodyPath = resolve(__dirname, "issue-body.md");
7+
8+
export default readFileSync(issueBodyPath, "utf-8");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"textarea-one": "Textarea input text 1\n\n```\n### To be ignored tag\n```"
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
body:
2+
- type: textarea
3+
id: textarea-one
4+
attributes:
5+
label: My textarea input
6+
- type: textarea
7+
id: textarea-two
8+
attributes:
9+
label: Another textarea input
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### My textarea input
2+
3+
Textarea input text 1
4+
5+
```
6+
### To be ignored tag
7+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { readFileSync } from "node:fs";
2+
import { resolve } from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
5+
const __dirname = fileURLToPath(new URL(".", import.meta.url));
6+
const issueBodyPath = resolve(__dirname, "issue-body.md");
7+
8+
export default readFileSync(issueBodyPath, "utf-8");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"textarea-one": "Textarea input text 1\n\n```sh\n### To be ignored tag\n```"
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
body:
2+
- type: textarea
3+
id: textarea-one
4+
attributes:
5+
label: My textarea input
6+
- type: textarea
7+
id: textarea-two
8+
attributes:
9+
label: Another textarea input

0 commit comments

Comments
 (0)