Skip to content

Commit 1cf0b56

Browse files
🩹 [Patch]: Use ConvertFrom-IssueForm in GitHub module (#6)
## Description This pull request includes several changes aimed at improving script execution and simplifying the codebase. The most important changes include adding output visibility to scripts, updating markdown formatting in the README, and removing redundant filters in the PowerShell script. Enhancements to script execution: * [`.github/workflows/Action-Test.yml`](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4R32): Added `ShowOutput: true` to display script output during the `GetIssueFileContent` job. * [`action.yml`](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6R28): Added `ShowOutput: true` to display script output during the custom `runs` job. Documentation improvements: * [`README.md`](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L98-R101): Corrected the markdown formatting for the list of alternative parsers. Codebase simplification: * [`scripts/main.ps1`](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011R1-R17): Removed the `Remove-MarkdownComments`, `Parse-IssueBody`, and `Process-IssueBody` filters and replaced them with a call to `ConvertFrom-IssueForm` for processing issue bodies. * [`scripts/main.ps1`](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011R1-R17): Added a `SuppressMessageAttribute` to suppress warnings about unused parameters in the `IssueBody` variable. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 0e929c7 commit 1cf0b56

File tree

4 files changed

+12
-121
lines changed

4 files changed

+12
-121
lines changed

.github/workflows/Action-Test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
id: GetIssueFileContent
3030
uses: PSModule/GitHub-Script@v1
3131
with:
32+
ShowOutput: true
3233
Script: . '.\tests\Get-IssueFileContent.ps1'
3334

3435
- name: Action-Test

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
9696
## Alternatives
9797
98-
[github/issue-parser](https://github.com/github/issue-parser)
99-
[issue-ops/parser](https://github.com/issue-ops/parser)
100-
[peter-murray/issue-forms-body-parser](https://github.com/peter-murray/issue-forms-body-parser)
101-
[peter-murray/issue-body-parser-action](https://github.com/peter-murray/issue-body-parser-action)
98+
- [github/issue-parser](https://github.com/github/issue-parser)
99+
- [issue-ops/parser](https://github.com/issue-ops/parser)
100+
- [peter-murray/issue-forms-body-parser](https://github.com/peter-murray/issue-forms-body-parser)
101+
- [peter-murray/issue-body-parser-action](https://github.com/peter-murray/issue-body-parser-action)

action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ runs:
2525
env:
2626
GITHUB_ACTION_INPUT_IssueBody: ${{ inputs.IssueBody }}
2727
with:
28+
ShowOutput: true
2829
Script: . (Join-Path -Path '${{ github.action_path }}' -ChildPath 'scripts\main.ps1')

scripts/main.ps1

Lines changed: 6 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,19 @@
1+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
2+
'PSReviewUnusedParameter', 'IssueBody',
3+
Justification = 'Variable is used in LogGroup blocks.'
4+
)]
15
[CmdletBinding()]
26
param(
37
[Parameter()]
48
[string] $IssueBody = $env:GITHUB_ACTION_INPUT_IssueBody
59
)
610

7-
filter Remove-MarkdownComments {
8-
[OutputType([string])]
9-
[CmdletBinding()]
10-
param(
11-
[Parameter(
12-
Mandatory,
13-
ValueFromPipeline
14-
)]
15-
[string] $Markdown
16-
)
17-
$commentPattern = '<!--[\s\S]*?-->'
18-
$content = $Markdown
19-
$content = $Markdown -replace $commentPattern
20-
$content
21-
}
22-
23-
filter Parse-IssueBody {
24-
[OutputType([PSCustomObject[]])]
25-
[CmdletBinding()]
26-
param(
27-
[Parameter(
28-
Mandatory,
29-
ValueFromPipeline
30-
)]
31-
[string] $IssueBody
32-
)
33-
$content = $IssueBody | Remove-MarkdownComments
34-
$content = $content.Split([Environment]::NewLine).Trim() | Where-Object { $_ -ne '' }
35-
36-
$results = @()
37-
$currentHeader = ''
38-
$currentParagraph = @()
39-
40-
foreach ($line in $content) {
41-
Write-Verbose "Processing line: [$line]"
42-
43-
if ($line -match '^### (.+)$') {
44-
# If a new header is found, store the current header and paragraph in the results
45-
if ($currentHeader -ne '') {
46-
$results += [PSCustomObject]@{
47-
Header = $currentHeader
48-
Paragraph = $currentParagraph.Trim()
49-
}
50-
}
51-
52-
# Update the newly detected header and reset the paragraph
53-
$currentHeader = $matches[1]
54-
$currentParagraph = @()
55-
} else {
56-
# Append the line to the current paragraph
57-
$currentParagraph += $line
58-
}
59-
}
60-
61-
# Add the last header and paragraph to the results
62-
if ($currentHeader -ne '') {
63-
$results += [PSCustomObject]@{
64-
Header = $currentHeader
65-
Paragraph = $currentParagraph.Trim()
66-
}
67-
}
68-
$results | ConvertTo-Json
69-
}
70-
71-
filter Process-IssueBody {
72-
[OutputType([hashtable])]
73-
[CmdletBinding()]
74-
param(
75-
[Parameter(
76-
Mandatory,
77-
ValueFromPipeline
78-
)]
79-
[string] $IssueBody
80-
)
81-
82-
$content = $IssueBody | ConvertFrom-Json
83-
84-
# Initialize hashtable
85-
$data = @{}
86-
87-
# Process each entry in the JSON
88-
foreach ($entry in $content) {
89-
$header = $entry.Header
90-
$paragraph = $entry.Paragraph
91-
92-
if ($paragraph -is [string]) {
93-
# Assign string value directly
94-
$data[$header] = $paragraph
95-
} elseif ($paragraph -is [array]) {
96-
# Check if it's a multi-line string or checkbox list
97-
if ($paragraph -match '^\s*- \[.\]\s') {
98-
# It's a checkbox list, process as key-value pairs
99-
$checkboxHashTable = @{}
100-
foreach ($line in $paragraph) {
101-
if ($line -match '^\s*- \[(x| )\]\s*(.+)$') {
102-
$checked = $matches[1] -eq 'x'
103-
$item = $matches[2]
104-
$checkboxHashTable[$item] = $checked
105-
}
106-
}
107-
$data[$header] = $checkboxHashTable
108-
} else {
109-
# It's a multi-line string
110-
$data[$header] = $paragraph -join [System.Environment]::NewLine
111-
}
112-
}
113-
}
114-
$data
115-
}
116-
11711
LogGroup 'Issue Body - Raw' {
11812
Write-Output $IssueBody
11913
}
12014

12115
LogGroup 'Issue Body - Object' {
122-
$data = $IssueBody | Parse-IssueBody | Process-IssueBody
123-
$data | Format-Table -AutoSize
124-
}
125-
126-
LogGroup 'Issue Body - JSON' {
127-
$data = $data | ConvertTo-Json -Compress
128-
Write-Output $data
16+
$data = $IssueBody | ConvertFrom-IssueForm
17+
$data | Format-List
12918
Set-GitHubOutput -Name 'data' -Value $data
13019
}

0 commit comments

Comments
 (0)