Skip to content

fix(bitbucket-datacenter): detect changes on merged PR push#2719

Open
zakisk wants to merge 1 commit into
tektoncd:mainfrom
zakisk:SRVKP-9638-fix-on-pth-change-in-bbdc-on-push
Open

fix(bitbucket-datacenter): detect changes on merged PR push#2719
zakisk wants to merge 1 commit into
tektoncd:mainfrom
zakisk:SRVKP-9638-fix-on-pth-change-in-bbdc-on-push

Conversation

@zakisk
Copy link
Copy Markdown
Member

@zakisk zakisk commented May 11, 2026

📝 Description of the Change

When a pull request is merged in Bitbucket Data Center, the resulting push event contains a merge commit that reports no file changes. This caused on-path-change and on-cel-expression filters to silently skip PipelineRuns because the changed files list was always empty.

The fix detects merge commits (commits with multiple parents) during payload parsing and uses the Bitbucket /changes API with since/until params to diff the previous HEAD against the current HEAD, retrieving the actual files modified by the merged PR.

Key changes:

  • Parse merge commits in push payloads to capture previousHeadCommit
  • Add getMergeCommitChanges using /changes API with proper pagination
  • Add DiffStats/Pagination types for the /changes API response
  • Update TearDown to skip deletion of already-merged PRs
  • Allow CreatePR to target a custom base branch for merge test scenarios
  • Add E2E test for on-path-change annotation surviving a PR merge push
  • Add unit tests for getMergeCommitChanges and merge commit GetFiles path

🔗 Linked GitHub Issue

Fixes #

JIRA

https://redhat.atlassian.net/browse/SRVKP-9638

🧪 Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests
  • Manual testing
  • Not Applicable

🤖 AI Assistance

AI assistance can be used for various tasks, such as code generation,
documentation, or testing.

Please indicate whether you have used AI assistance
for this PR and provide details if applicable.

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

Important

Slop will be simply rejected, if you are using AI assistance you need to make sure you
understand the code generated and that it meets the project's standards. you
need at least know how to run the code and deploy it (if needed). See
startpaac to make it easy
to deploy and test your code changes.

If the majority of the code in this PR was generated by an AI, please add a Co-authored-by trailer to your commit message.
For example:

Co-authored-by: Claude noreply@anthropic.com

✅ Submitter Checklist

  • 📝 My commit messages are clear, informative, and follow the project's How to write a git commit message guide. The Gitlint linter ensures in CI it's properly validated
  • ✨ I have ensured my commit message prefix (e.g., fix:, feat:) matches the "Type of Change" I selected above.
  • ♽ I have run make test and make lint locally to check for and fix any
    issues. For an efficient workflow, I have considered installing
    pre-commit and running pre-commit install to
    automate these checks.
  • 📖 I have added or updated documentation for any user-facing changes.
  • 🧪 I have added sufficient unit tests for my code changes.
  • 🎁 I have added end-to-end tests where feasible. See README for more details.
  • 🔎 I have addressed any CI test flakiness or provided a clear reason to bypass it.
  • If adding a provider feature, I have filled in the following and updated the provider documentation:
    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for accurately detecting file changes in Bitbucket Data Center push events involving merge commits. It implements a new getMergeCommitChanges method using the Bitbucket /changes API and updates the payload parsing logic to identify merge commits via parent counts. Feedback suggests improving the robustness of the API request by using url.Values for safer parameter escaping, refining the merge commit detection condition to be less restrictive, and enhancing error reporting for API failures.

Comment thread pkg/provider/bitbucketdatacenter/diff_api.go Outdated
Comment thread pkg/provider/bitbucketdatacenter/parse_payload.go
Comment thread pkg/provider/bitbucketdatacenter/diff_api.go Outdated
@zakisk zakisk requested a review from chmouel May 11, 2026 11:22
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 11, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 87.83784% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.39%. Comparing base (c615efb) to head (e20f740).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/provider/bitbucketdatacenter/diff_api.go 90.62% 4 Missing and 2 partials ⚠️
pkg/provider/bitbucketdatacenter/parse_payload.go 0.00% 2 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2719      +/-   ##
==========================================
+ Coverage   59.25%   59.39%   +0.13%     
==========================================
  Files         208      209       +1     
  Lines       20573    20663      +90     
==========================================
+ Hits        12191    12272      +81     
- Misses       7610     7616       +6     
- Partials      772      775       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zakisk zakisk force-pushed the SRVKP-9638-fix-on-pth-change-in-bbdc-on-push branch 2 times, most recently from 8622c33 to 869ff72 Compare May 11, 2026 11:39
@zakisk
Copy link
Copy Markdown
Member Author

zakisk commented May 11, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enables accurate file change detection for Bitbucket Data Center when a pull request is merged. It implements a custom API client to retrieve changes between the previous HEAD and the merge commit, addressing limitations in the underlying scm library. The implementation includes merge commit detection during payload parsing and updated E2E tests for validation. Feedback recommends using the internal client wrapper to maintain API usage metrics, refining HTTP error handling, and improving the robustness of the commit matching logic.

Comment thread pkg/provider/bitbucketdatacenter/diff_api.go Outdated
Comment thread pkg/provider/bitbucketdatacenter/diff_api.go
Comment thread pkg/provider/bitbucketdatacenter/parse_payload.go
@zakisk zakisk force-pushed the SRVKP-9638-fix-on-pth-change-in-bbdc-on-push branch from 869ff72 to 99dc953 Compare May 11, 2026 11:52
Copy link
Copy Markdown
Member

@theakshaypant theakshaypant left a comment

Choose a reason for hiding this comment

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

Minor comments on the changes

Comment thread pkg/provider/bitbucketdatacenter/types/types.go Outdated
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.

Some of these structs are duplicated in pkg/provider/bitbucketdatacenter/test/test_types.go, can we avoid this duplication?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

thanks for pointing, didn't pay attention. removed types from test_types.go

When a pull request is merged in Bitbucket Data Center, the resulting
push event contains a merge commit that reports no file changes. This
caused on-path-change and on-cel-expression filters to silently skip
PipelineRuns because the changed files list was always empty.

The fix detects merge commits (commits with multiple parents) during
payload parsing and uses the Bitbucket /changes API with since/until
params to diff the previous HEAD against the current HEAD, retrieving
the actual files modified by the merged PR.

Key changes:
- Parse merge commits in push payloads to capture previousHeadCommit
- Add getMergeCommitChanges using /changes API with proper pagination
- Add DiffStats/Pagination types for the /changes API response
- Update TearDown to skip deletion of already-merged PRs
- Allow CreatePR to target a custom base branch for merge test scenarios
- Add E2E test for on-path-change annotation surviving a PR merge push
- Add unit tests for getMergeCommitChanges and merge commit GetFiles path

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@zakisk zakisk force-pushed the SRVKP-9638-fix-on-pth-change-in-bbdc-on-push branch from 99dc953 to e20f740 Compare May 12, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants