|
| 1 | +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
| 2 | + 'PSReviewUnusedParameter', 'IssueBody', |
| 3 | + Justification = 'Variable is used in LogGroup blocks.' |
| 4 | +)] |
1 | 5 | [CmdletBinding()]
|
2 | 6 | param(
|
3 | 7 | [Parameter()]
|
4 | 8 | [string] $IssueBody = $env:GITHUB_ACTION_INPUT_IssueBody
|
5 | 9 | )
|
6 | 10 |
|
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 |
| - |
117 | 11 | LogGroup 'Issue Body - Raw' {
|
118 | 12 | Write-Output $IssueBody
|
119 | 13 | }
|
120 | 14 |
|
121 | 15 | 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 |
129 | 18 | Set-GitHubOutput -Name 'data' -Value $data
|
130 | 19 | }
|
0 commit comments