You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(bitbucket): don't parse an existing pull request body when spec.body is set - #11386
When a Bitbucket pull request already exists, CreateAction calls reports.MergeFromMarkdown on its description before checking spec.body, then discards the merged result when spec.body is set. If that description isn't an Updatecli report, markdownToActions indexes actions.Actions[-1] and the run panics:
panic: runtime error: index out of range [-1]
github.com/updatecli/updatecli/pkg/core/reports.markdownToActions(...)
github.com/updatecli/updatecli/pkg/core/reports.MergeFromMarkdown(...)
github.com/updatecli/updatecli/pkg/core/pipeline.(*Pipeline).RunActions(...)
We hit this with a custom body that opens with a level-2 heading (## Update …): the first run opens the pull request fine, and every later run against the still-open pull request panics. A person editing an Updatecli-generated description the same way would trigger it too.
This pull request:
uses spec.body before touching the existing description in the Bitbucket action, matching what the Azure DevOps action's pullRequestBody already does
makes markdownToActions skip a level-2/3 heading, Pipeline ID:, Pipeline URL: or Target ID: line that appears before its parent, instead of indexing with -1
Test
cd pkg/core/reports
go test -run 'TestMarkdownToActionsUnexpectedStructure|TestMergeFromMarkdown' ./...
TestMarkdownToActionsUnexpectedStructure panics with index out of range [-1] without the markdownToActions change. pkg/plugins/resources/bitbucket/pullrequest has no tests; it builds and passes go vet.
Additional Information
Checklist
I have updated the documentation via pull request in website repository. (Not applicable: no behaviour change for valid reports.)
I have tested this pull request manually with a custom Updatecli build and it works as expected.
Tradeoff
Unexpected structure is skipped silently rather than returned as an error, so a hand-edited description degrades to "nothing to merge" instead of failing the run.
Potential improvement
None.
Summary by CodeRabbit
Bug Fixes
Pull request descriptions with unexpected Markdown heading structures are now handled without causing errors.
When updating a pull request, a configured custom description is preserved as written. If no custom description is provided, the report is still merged with the existing description.
…ody is set
When a pull request already existed, CreateAction merged the existing description into the new report before checking spec.body, then discarded the result. A custom body that isn't an Updatecli report (for example one opening with a level-2 heading) made markdownToActions index Actions[-1] and panic, failing the whole run.
Use spec.body first, as the Azure DevOps action already does, and make markdownToActions skip headings and ID lines that appear before their parent instead of panicking.
Review was skipped as selected files did not have any reviewable changes.
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 3a2b4b35-65d2-4832-bb98-d3937b49e586
Commits
Reviewing files that changed from the base of the PR and between be707dc and 586f5f6.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
The report Markdown parser now skips headings and metadata that appear before their expected parent headings. For existing Bitbucket pull requests, a configured custom body is used directly; otherwise, the existing description is merged with the report.
Changes: Report Markdown handling
Layer / File(s)
Summary
Guard report parsing against unexpected structure pkg/core/reports/actions.go, pkg/core/reports/actions_test.go
The parser skips target and changelog headings and pipeline or target metadata when the required parent heading has not been processed. Tests cover unexpected heading structures and merging a custom old body.
Select the existing pull request body pkg/plugins/resources/bitbucket/pullrequest/create.go
For an existing pull request, a non-empty custom body bypasses report merging. Otherwise, the existing description is merged with the report, and merge errors are returned.
This change prevents a panic when an existing Bitbucket pull request description does not follow the expected report structure. No actionable merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the Bitbucket pull request action and the core behavior change: the existing pull request body is no longer parsed when spec.body is set. It also uses the fix prefix. The title matches…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description explains the problem clearly: CreateAction merges the existing Bitbucket PR description before checking spec.body, and a non-Updatecli description makes markdownToActions index Actions…
Full details: Title check
Explanation
The title names the Bitbucket pull request action and the core behavior change: the existing pull request body is no longer parsed when spec.body is set. It also uses the fix prefix. The title matches the main change in the changeset. The parser hardening in markdownToActions is not named, but the title does not need to cover every detail.
Full details: Description check
Explanation
The description explains the problem clearly: CreateAction merges the existing Bitbucket PR description before checking spec.body, and a non-Updatecli description makes markdownToActions index Actions[-1] and panic. It gives the panic trace, a reproduction case (custom body starting with a level-2 heading), and the two code changes. It includes a runnable test command and reports that the new test panics without the parser fix. The template sections (Fix reference, Test, Checklist, Tradeoff, Potential improvement) are all present. The Fix #XXX line is missing an issue number, and the documentation checkbox is left unchecked with a note that it does not apply. These gaps are minor.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a Bitbucket pull request already exists,
CreateActioncallsreports.MergeFromMarkdownon its description before checkingspec.body, then discards the merged result whenspec.bodyis set. If that description isn't an Updatecli report,markdownToActionsindexesactions.Actions[-1]and the run panics:We hit this with a custom
bodythat opens with a level-2 heading (## Update …): the first run opens the pull request fine, and every later run against the still-open pull request panics. A person editing an Updatecli-generated description the same way would trigger it too.This pull request:
spec.bodybefore touching the existing description in the Bitbucket action, matching what the Azure DevOps action'spullRequestBodyalready doesmarkdownToActionsskip a level-2/3 heading,Pipeline ID:,Pipeline URL:orTarget ID:line that appears before its parent, instead of indexing with -1Test
TestMarkdownToActionsUnexpectedStructurepanics withindex out of range [-1]without themarkdownToActionschange.pkg/plugins/resources/bitbucket/pullrequesthas no tests; it builds and passesgo vet.Additional Information
Checklist
Tradeoff
Unexpected structure is skipped silently rather than returned as an error, so a hand-edited description degrades to "nothing to merge" instead of failing the run.
Potential improvement
None.
Summary by CodeRabbit