fix: refine hash fixing workflow#75
Conversation
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ 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 (1)
WalkthroughThe Test-Hash flow was refactored to use a new git wrapper (Invoke-Git), try a direct commit-and-push to the default branch first, and on push failure create a random branch, push it, and open a PR; failures during push or PR creation trigger cleanup and append-log comment behavior. ChangesDirect Commit/Push with Branch Fallback
Sequence DiagramsequenceDiagram
participant TestHash as Test-Hash
participant Git as Git (Invoke-Git)
participant GitHub as GitHub API
TestHash->>Git: git status --porcelain
TestHash->>Git: git add <manifest>
TestHash->>Git: git commit -m "Title (Closes `#IssueID`)"
TestHash->>Git: git push origin <default>
alt Push succeeds
Git-->>TestHash: push OK
else Push fails
Git-->>TestHash: push rejected
TestHash->>TestHash: gen random branch name
TestHash->>Git: git checkout -B <rand>
TestHash->>Git: git commit --amend -m "Title"
TestHash->>Git: git push origin <rand>
alt Branch push succeeds
Git-->>TestHash: branch pushed
TestHash->>GitHub: Create PR (head=<rand>, base=<default>)
alt PR created
GitHub-->>TestHash: PR URL/response
else PR creation fails
GitHub-->>TestHash: error response
TestHash->>Git: git push origin --delete <rand> (attempt)
Git-->>TestHash: delete result
TestHash->>TestHash: post append-log comment and return
end
else Branch push fails
Git-->>TestHash: push error
TestHash->>TestHash: post append-log comment and return
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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. Review rate limit: 0/1 reviews remaining, refill in 42 minutes and 23 seconds.Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/Action/Issue.psm1`:
- Around line 112-135: The catch blocks that handle branch and PR creation
errors currently log and return without updating the GitHub issue, so failures
are not surfaced and the issue can wrongly be marked verified; update the catch
handlers in Issue.psm1 (the blocks around the branch creation try/catch and the
Invoke-GithubRequest POST to "repos/$REPOSITORY/pulls") to post a comment or add
a label on the related issue before returning (use Invoke-GithubRequest to POST
to "repos/$REPOSITORY/issues/$IssueID/comments" or PATCH to the issue to add a
label), and ensure the secondary cleanup catch (the git push delete failure)
also posts a warning comment if it fails so automation failures are visible on
the issue.
- Around line 94-135: Native git commands (git add/commit/push and later git
push origin --delete) won't throw in PowerShell so the catch block and PR
fallback never run and the early returns prevent the final Add-Comment
notification; fix by making native failures throw and avoid early return: either
set $PSNativeCommandUseErrorActionPreference = $true and $ErrorActionPreference
= 'Stop' at the top of this logical operation (or for broader compatibility,
implement a small helper like Ensure-CommandSuccess/Run-Git that runs a git
command, checks $LASTEXITCODE and throws on non-zero) and replace direct calls
to git add/commit/push, git push origin $branch, and git push origin --delete
$branch with that helper; also remove or replace the early return statements
inside the inner catch blocks so they set a failure flag or throw (so
Add-Comment still executes), ensuring Invoke-GithubRequest and Write-Log usage
remains the same but now executes only after command failures are properly
surfaced.
🪄 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: 4111ed15-3d0e-4866-9491-56e61b06ffcc
📒 Files selected for processing (1)
src/Action/Issue.psm1
99612ca to
1e3cf3c
Compare
ScoopInstaller/GithubActions#75 Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>
|
After multiple rounds of testing and confirmation that it works, I'm going to merge this. tests:
|
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
1e3cf3c to
de59f19
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (1)
src/Action/Issue.psm1 (1)
106-107:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUnprotected
git add/git commitleave the issue labeled but silent on failure.
Add-Label 'verified', 'hash-fix-needed'fires at Line 81 before reaching here. If eitherInvoke-Gitcall throws (e.g., a path or git-config problem), the exception escapesTest-Hashunhandled, skippingAdd-Commentat Line 160. The issue ends up labeled without any comment.🐛 Proposed fix
- Invoke-Git -GitArgs @('add', $gci.FullName) - Invoke-Git -GitArgs @('commit', '-m', "$titleToBePosted (Closes #$IssueID)") + try { + Invoke-Git -GitArgs @('add', $gci.FullName) + Invoke-Git -GitArgs @('commit', '-m', "$titleToBePosted (Closes #$IssueID)") + } catch { + Write-Log 'Staging or committing the fix failed.' + Add-Comment -ID $IssueID -AppendLogLink -Message @( + 'Hash mismatch confirmed, but the bot could not commit the fix currently.' + ) + return + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/Action/Issue.psm1` around lines 106 - 107, The git add/commit calls inside Test-Hash (Invoke-Git -GitArgs @('add', $gci.FullName) and Invoke-Git -GitArgs @('commit', '-m', "$titleToBePosted (Closes #$IssueID)")) are unprotected and can throw, leaving Add-Label executed but skipping Add-Comment; wrap both Invoke-Git calls in a try/catch so exceptions are caught, log the error, and ensure Add-Comment is still invoked in the catch (or finally) to post a failure comment referencing $IssueID and the failing path ($gci.FullName); keep the label behavior (Add-Label 'verified','hash-fix-needed') but make the commit failures non-fatal to Test-Hash so the issue never ends up labeled without a comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/Action/Issue.psm1`:
- Around line 103-104: The Write-Log call is using an unassigned $gitStatus so
it always logs $null; in Test-Hash, capture the output of Invoke-Git into
$gitStatus before logging (e.g. assign the result of Invoke-Git -GitArgs
@('status','--porcelain') to $gitStatus, normalise it to a string if needed),
then call Write-Log 'Git Status:' $gitStatus; alternatively move the Write-Log
to after the Invoke-Git invocation and reference the captured $gitStatus
variable so the diagnostic shows the real git output.
- Around line 119-121: The outer catch currently rethrows if Invoke-Git calls
for checkout (Invoke-Git -GitArgs @('checkout', '-B', $branch)) or commit
amendment (Invoke-Git -GitArgs @('commit', '--amend', '-m', "$titleToBePosted"))
throw, so Add-Comment is never invoked; wrap these Invoke-Git calls in their own
try/catch (or extend the existing try) to catch any exceptions from checkout and
commit --amend and ensure Add-Comment is called in the catch/finally path;
reference the Invoke-Git invocation sites and the Add-Comment call so the new
catch block logs the error and then calls Add-Comment before rethrowing or
exiting as appropriate.
---
Duplicate comments:
In `@src/Action/Issue.psm1`:
- Around line 106-107: The git add/commit calls inside Test-Hash (Invoke-Git
-GitArgs @('add', $gci.FullName) and Invoke-Git -GitArgs @('commit', '-m',
"$titleToBePosted (Closes #$IssueID)")) are unprotected and can throw, leaving
Add-Label executed but skipping Add-Comment; wrap both Invoke-Git calls in a
try/catch so exceptions are caught, log the error, and ensure Add-Comment is
still invoked in the catch (or finally) to post a failure comment referencing
$IssueID and the failing path ($gci.FullName); keep the label behavior
(Add-Label 'verified','hash-fix-needed') but make the commit failures non-fatal
to Test-Hash so the issue never ends up labeled without a comment.
🪄 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: fecdeedb-b1ad-4a12-aacf-33832fe28acf
📒 Files selected for processing (1)
src/Action/Issue.psm1
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>
de59f19 to
c822ae0
Compare
rework of #74
Summary by CodeRabbit