fix: format and lint#78
Conversation
Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>
|
Warning Rate limit exceeded
To continue reviewing without waiting, purchase usage credits in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (10)
WalkthroughRename event variables to ChangesEvent, Cmdlets, Helpers, Actions, and Logging
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>
Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>
Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/Helpers.psm1 (1)
48-54: ⚡ Quick winConsider suppressing the lint rule instead of guarding pure helpers with
ShouldProcess.
New-Array,New-DetailsCommentString, andNew-CheckListItemare pure, in-memory factory helpers — they don't mutate any external state. Wiring them throughSupportsShouldProcessonly to silencePSUseShouldProcessForStateChangingFunctionsintroduces a real footgun: under-WhatIf(or a non-default$WhatIfPreference), each helper returns$null, which breaks callers like$responses = New-Array; Add-IntoArray $responses …in src/Action/PR.psm1 and src/Action/Issue/Extraction.psm1.Either suppress the rule on these specific functions, or pick a non-state-changing verb. Example for
New-Array:♻️ Suggested alternative
function New-Array { <# .SYNOPSIS Create new Array list. More suitable for usage as it provides better operations. #> - [CmdletBinding(SupportsShouldProcess)] - param() - - if ($PSCmdlet.ShouldProcess('In-memory', 'Create New Array')) { - return New-Object System.Collections.ArrayList - } + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseShouldProcessForStateChangingFunctions', '', + Justification = 'In-memory factory; no external state is changed.')] + param() + + return New-Object System.Collections.ArrayList }The same idea applies to
New-DetailsCommentStringandNew-CheckListItem.Also applies to: 153-203
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/Helpers.psm1` around lines 48 - 54, The helper functions New-Array, New-DetailsCommentString, and New-CheckListItem are pure in-memory factories and must not be gated by SupportsShouldProcess/ShouldProcess (which makes them return $null under -WhatIf); remove the CmdletBinding/ShouldProcess guard from these functions so they always return their value, and instead suppress the PSUseShouldProcessForStateChangingFunctions rule for each helper (add the appropriate PSScriptAnalyzer suppression comment for PSUseShouldProcessForStateChangingFunctions above each function) or rename to a non-state-changing verb if you prefer; ensure callers like Add-IntoArray continue to receive a non-null ArrayList from New-Array.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/Github.psm1`:
- Around line 199-204: The DELETE request URL in the loop uses the wrong
variable ($label) which stringifies the whole $Label array; update the
interpolated path in the Invoke-GithubRequest call inside the foreach ($lab in
$Label) loop to use $lab instead of $label so each individual label is deleted;
ensure this change is applied where Add-IntoArray calls Invoke-GithubRequest
(the delete branch) and that the surrounding variables ($issueLabels, $lab,
Add-IntoArray, Invoke-GithubRequest) remain unchanged.
---
Nitpick comments:
In `@src/Helpers.psm1`:
- Around line 48-54: The helper functions New-Array, New-DetailsCommentString,
and New-CheckListItem are pure in-memory factories and must not be gated by
SupportsShouldProcess/ShouldProcess (which makes them return $null under
-WhatIf); remove the CmdletBinding/ShouldProcess guard from these functions so
they always return their value, and instead suppress the
PSUseShouldProcessForStateChangingFunctions rule for each helper (add the
appropriate PSScriptAnalyzer suppression comment for
PSUseShouldProcessForStateChangingFunctions above each function) or rename to a
non-state-changing verb if you prefer; ensure callers like Add-IntoArray
continue to receive a non-null ArrayList from New-Array.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8d5264b2-9556-4951-9d7a-034328378f03
📒 Files selected for processing (8)
action.ps1src/Action/Issue.psm1src/Action/Issue/Extraction.psm1src/Action/PR.psm1src/ActionWrapper.psm1src/Github.psm1src/Helpers.psm1src/Variables.psm1
✅ Files skipped from review due to trivial changes (2)
- src/ActionWrapper.psm1
- action.ps1
🚧 Files skipped from review as they are similar to previous changes (1)
- src/Action/Issue/Extraction.psm1
| foreach ($lab in $Label) { | ||
| if ($issueLabels -contains $lab) { | ||
| # https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue | ||
| Add-IntoArray $responses (Invoke-GithubRequest -Query "repos/$REPOSITORY/issues/$ID/labels/$label" -Method Delete) | ||
| } | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Confirm the typo is present in the file under review and check if any caller
# currently passes a multi-element label array to Remove-Label.
rg -nP -C3 '\b(Remove-Label)\b'
rg -nP -C2 '"\s*repos/\$REPOSITORY/issues/\$ID/labels/\$label\s*"'Repository: ScoopInstaller/GithubActions
Length of output: 3753
🌐 Web query:
PowerShell variable name case sensitivity rules
💡 Result:
PowerShell variable names are case-insensitive. This means $myVar, $MyVar, and $MYVAR all refer to the same variable.[1][2] PowerShell is designed to be case-insensitive wherever possible while preserving the case used in the original reference.[1] Official Microsoft documentation explicitly lists variable names as case-insensitive on all systems.[1] Variable names can include alphanumeric characters, underscores, spaces, and special characters (with curly braces for those), but best practices recommend alphanumeric and underscores only.[2] This behavior holds across scopes, as scope modifiers and variable resolution follow the same case-insensitive rules.[1][3]
Citations:
- 1: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_case-sensitivity?view=powershell-7.6
- 2: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_variables?view=powershell-7.6
- 3: https://learn.microsoft.com/en-us/powershell/scripting/lang-spec/chapter-03?view=powershell-7.4
Fix critical bug: Variable name should be $lab not $label in DELETE request URL (line 202).
PowerShell variable names are case-insensitive, so $label in the interpolated URL resolves to the parameter $Label (an array). When an array is stringified in a URL, it uses the default $OFS separator (space), producing a malformed request. For example, Remove-Label -Label 'verify','hash-fix-needed' becomes:
DELETE repos/<owner>/<repo>/issues/<id>/labels/verify hash-fix-needed
This prevents actual label deletion. The loop iterates over individual labels with variable $lab, so that is the correct reference.
Proposed fix
foreach ($lab in $Label) {
if ($issueLabels -contains $lab) {
# https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue
- Add-IntoArray $responses (Invoke-GithubRequest -Query "repos/$REPOSITORY/issues/$ID/labels/$label" -Method Delete)
+ Add-IntoArray $responses (Invoke-GithubRequest -Query "repos/$REPOSITORY/issues/$ID/labels/$lab" -Method Delete)
}
}At least one caller (src/Action/PR.psm1:114) passes a variable that may contain multiple labels, making this a functional defect.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| foreach ($lab in $Label) { | |
| if ($issueLabels -contains $lab) { | |
| # https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue | |
| Add-IntoArray $responses (Invoke-GithubRequest -Query "repos/$REPOSITORY/issues/$ID/labels/$label" -Method Delete) | |
| } | |
| } | |
| foreach ($lab in $Label) { | |
| if ($issueLabels -contains $lab) { | |
| # https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue | |
| Add-IntoArray $responses (Invoke-GithubRequest -Query "repos/$REPOSITORY/issues/$ID/labels/$lab" -Method Delete) | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/Github.psm1` around lines 199 - 204, The DELETE request URL in the loop
uses the wrong variable ($label) which stringifies the whole $Label array;
update the interpolated path in the Invoke-GithubRequest call inside the foreach
($lab in $Label) loop to use $lab instead of $label so each individual label is
deleted; ensure this change is applied where Add-IntoArray calls
Invoke-GithubRequest (the delete branch) and that the surrounding variables
($issueLabels, $lab, Add-IntoArray, Invoke-GithubRequest) remain unchanged.
There was a problem hiding this comment.
This pull request only concerns format and lint. I'll open another PR to resolve this and other pre-existing bugs.
There was a problem hiding this comment.
@chawyehsu, understood — thanks for the clarification! That's a reasonable scope boundary for this PR.
Would you like me to open a GitHub issue to track the $label → $lab variable bug (and any other pre-existing bugs you have in mind) so nothing gets lost before the follow-up PR?
Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>
Relate to #77
Summary by CodeRabbit
New Features
Bug Fixes
Chores