Skip to content

feat(bitbucket): query commit statuses for /retest - #2879

Open
theakshaypant wants to merge 2 commits into
tektoncd:mainfrom
theakshaypant:bbcloud/get-commit-status
Open

feat(bitbucket): query commit statuses for /retest#2879
theakshaypant wants to merge 2 commits into
tektoncd:mainfrom
theakshaypant:bbcloud/get-commit-status

Conversation

@theakshaypant

@theakshaypant theakshaypant commented Jul 23, 2026

Copy link
Copy Markdown
Member

📝 Description of the Change

Implement GetCommitStatuses for Bitbucket Cloud so /retest skips pipelines that already succeeded, even when PipelineRun objects have been pruned. The provider returns raw status keys; the annotation matcher uses GetBBCloudStatusKey to reverse-match truncated keys against template names.

🔗 Linked GitHub Issue

Partially fixes #2580

🧪 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

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.19298% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.04%. Comparing base (d1e7b6c) to head (fc935e9).

Files with missing lines Patch % Lines
pkg/provider/bitbucketcloud/test/bbcloudtest.go 0.00% 9 Missing ⚠️
pkg/provider/bitbucketcloud/bitbucket.go 80.95% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2879      +/-   ##
==========================================
+ Coverage   69.03%   69.04%   +0.01%     
==========================================
  Files         198      198              
  Lines       16943    16988      +45     
==========================================
+ Hits        11696    11730      +34     
- Misses       4389     4398       +9     
- Partials      858      860       +2     
Flag Coverage Δ
unit-tests 69.04% <77.19%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@pipelines-as-code

Copy link
Copy Markdown

Paco Review 🔍

This PR implements GetCommitStatuses for the Bitbucket Cloud provider (fetching and deduplicating commit statuses from the Bitbucket API) and updates pkg/matcher's filterSuccessfulTemplates to use those statuses, adding a fallback matching path that recomputes the Bitbucket-Cloud-specific truncated status key to catch cases where parseOriginalPRName can't recover the original PipelineRun name. It also adds unit tests for the new GetCommitStatuses implementation, a new test mux helper, a new Statuses type, and a build-tag-gated e2e test validating that /retest only reruns failed pipelines after PipelineRuns are pruned.

Review difficulty: 4/5 (Hard) — The change alters cross-provider PipelineRun skip/run decision logic and adds a new provider API integration, so a subtle mistake has a wide blast radius across all providers even though the diff itself is moderate in size.

2 new inline comment(s) found.

Reviewed commit: 014563c

@pipelines-as-code pipelines-as-code Bot added the paco/review-hard Paco review difficulty label Jul 23, 2026

@pipelines-as-code pipelines-as-code Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Paco inline comments -- see the Paco Review summary comment for the overview.

Comment thread pkg/matcher/annotation_matcher.go Outdated
if cs.Info.Pac != nil {
pacOpts = cs.Info.GetPacOpts()
}
successfulStatusKeys := map[string]struct{}{}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LOW] The new dedup/fallback matching logic (successfulStatusKeys, parseOriginalPRName combined with GetBBCloudStatusKey) is a meaningful behavioral change to filterSuccessfulTemplates, but the only test added in this diff is the //go:build e2e test requiring live Bitbucket credentials, which won't run in the normal unit test suite. A unit test in pkg/matcher covering the new fallback-matching and nil-Pac-guard paths would catch regressions without requiring live infrastructure.

@theakshaypant
theakshaypant force-pushed the bbcloud/get-commit-status branch 2 times, most recently from 12189c3 to 1f59efe Compare July 23, 2026 11:35
@zakisk

zakisk commented Aug 3, 2026

Copy link
Copy Markdown
Member

why [DNM]?

@theakshaypant
theakshaypant force-pushed the bbcloud/get-commit-status branch from 1f59efe to ab80c06 Compare August 3, 2026 13:23
@theakshaypant theakshaypant changed the title [DNM] feat(bitbucket): query commit statuses for /retest feat(bitbucket): query commit statuses for /retest Aug 3, 2026
@theakshaypant

Copy link
Copy Markdown
Member Author

why [DNM]?

Wanted to avoid double review effort since the implementation is similar to the one for github. I have incorporated the changes requested there.

@theakshaypant
theakshaypant force-pushed the bbcloud/get-commit-status branch from ab80c06 to 60d1bb6 Compare August 3, 2026 13:30

@theakshaypant theakshaypant Aug 3, 2026

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.

@zakisk IIRC you had implemented the GetBBCloudStatusKey logic originally; I did a couple of AI reviews and the e2e test helps but would be nice if you can have a deeper look at the changes in this file.

@theakshaypant
theakshaypant force-pushed the bbcloud/get-commit-status branch from 60d1bb6 to a25651a Compare August 4, 2026 07:16
@theakshaypant
theakshaypant marked this pull request as ready for review August 4, 2026 08:00
@theakshaypant

Copy link
Copy Markdown
Member Author

/retest

Comment on lines -3004 to +3007
assert.Equal(t, len(got), len(tt.wantStatuses))
assert.Equal(t, len(tt.wantStatuses), len(got))
for i, want := range tt.wantStatuses {
assert.Equal(t, got[i].Name, want.Name)
assert.Equal(t, got[i].Status, want.Status)
assert.Equal(t, want.Name, got[i].Name)
assert.Equal(t, want.Status, got[i].Status)

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.

why swapping 😅 aren't they same?

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.

We have a standard format mentioned here

assert.Equal(t, expected, actual)

I have been messing up the order in the last few PRs, so I was extra cautious this time :P

name: "Non BB Cloud provider skips GetBBCloudStatusKey fallback",
providerName: "github",
commitStatuses: []provider.CommitStatusInfo{
{Name: "this-is-a-long-pipelinerun-name-t-989318", Status: "successful"},

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.

this API response should also return failed one "this-is-a-long-pipelinerun-name-that-exceeds-forty-characters" as failed one otherwise it is being added because it wasn't successfulTemplate array

"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/triggertype"
"github.com/openshift-pipelines/pipelines-as-code/pkg/provider"
providerstatus "github.com/openshift-pipelines/pipelines-as-code/pkg/provider/status"

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.

Suggested change
providerstatus "github.com/openshift-pipelines/pipelines-as-code/pkg/provider/status"
providerstatus "github.com/openshift-pipelines/pipelines-as-code/pkg/provider/status"
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"

var pacOpts info.PacOpts
if cs.Info.Pac != nil {
pacOpts = cs.Info.GetPacOpts()
}

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.

Suggested change
}
if cs.Info.Pac != nil {
pacOpts = cs.Info.GetPacOpts()
} else {
pacOpts = info.NewPacOpts()
}

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.

you can also add new unit test cases for nil pacinfo with default value of ApplicationName

Comment on lines +598 to +603
if tt.noClient {
v := &Provider{}
_, err := v.GetCommitStatuses(ctx, bbcloudtest.MakeEvent(nil))
assert.Assert(t, err != nil)
return
}

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.

Suggested change
if tt.noClient {
v := &Provider{}
_, err := v.GetCommitStatuses(ctx, bbcloudtest.MakeEvent(nil))
assert.Assert(t, err != nil)
return
}
v := &Provider{}

event := bbcloudtest.MakeEvent(nil)
bbcloudtest.MuxListCommitStatuses(t, mux, event, tt.statuses)

v := &Provider{bbClient: bbclient}

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.

Suggested change
v := &Provider{bbClient: bbclient}
if !tt.noClient {
v.bbClient = bbClient
}

Implement GetCommitStatuses for Bitbucket Cloud so /retest
skips pipelines that already succeeded, even when PipelineRun
objects have been pruned. The provider returns raw status keys;
the annotation matcher uses GetBBCloudStatusKey to reverse-match
truncated keys against template names.

Signed-off-by: Akshay Pant <akpant@redhat.com>
Swap assert.Equal arguments in TestGetCommitStatuses to
follow the project convention of expected before actual.

Signed-off-by: Akshay Pant <akpant@redhat.com>
@zakisk
zakisk force-pushed the bbcloud/get-commit-status branch from a25651a to fc935e9 Compare August 6, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test paco/review-hard Paco review difficulty

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/retest falls back to re-running all pipelines when pipelineruns have been pruned

3 participants