🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

fix(bitbucket): don't parse an existing pull request body when spec.body is set - #11386

Merged
olblak merged 2 commits into
updatecli:mainfrom
roulettedares:fix/bitbucket-pr-custom-body-merge
Nov 25, 2026
Merged

olblak merged 2 commits into
updatecli:mainfrom
roulettedares:fix/bitbucket-pr-custom-body-merge

Conversation

@roulettedares

@roulettedares roulettedares commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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.
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

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.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix

Suggested reviewers: mcwarman, olblak

Merge Risk: Minimal · previous review be707

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed 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.

Share

Recent review info

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: 8cafc15b-060a-420c-9a86-44121a9b100b
Commits

Reviewing files that changed from the base of the PR and between 172f5d2 and be707dc.

Files selected for processing: 3

  • pkg/core/reports/actions.go
  • pkg/core/reports/actions_test.go
  • pkg/plugins/resources/bitbucket/pullrequest/create.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@olblak olblak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix

@olblak
olblak merged commit e2aff87 into updatecli:main Nov 25, 2026
8 checks passed
@olblak olblak added the bug Something isn't working label Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants