Skip to content

fix(bitbucketcloud): truncate commit status key to 40 char limit#2702

Merged
zakisk merged 1 commit into
tektoncd:mainfrom
zakisk:fix-bb-cloud-commit-status-key-len
May 6, 2026
Merged

fix(bitbucketcloud): truncate commit status key to 40 char limit#2702
zakisk merged 1 commit into
tektoncd:mainfrom
zakisk:fix-bb-cloud-commit-status-key-len

Conversation

@zakisk
Copy link
Copy Markdown
Member

@zakisk zakisk commented Apr 23, 2026

📝 Description of the Change

Bitbucket Cloud limits commit status keys to 40 characters. Move GetCheckName to the bitbucketcloud package to handle truncation locally, add unit tests, fix the e2e test to correctly decode paginated commit status responses, and add the Status type for commit status parsing.

Screenshot 2026-04-27 at 4 02 17 PM

🔗 JIRA

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

🧪 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

@zakisk zakisk requested a review from chmouel April 23, 2026 07:22

// GetCheckName returns the key for build commit status and the reason to have it
// unique for bitbucket cloud is that the key is limited to 40 characters.
// If the key is longer than 40 characters, it will be truncated to the first 40 characters.
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 is going to make a collision risk, since the random name of a PR which ensure uniqueness is a suffix, what about a numbered suffix in either when they have the same name or when it's truncated

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.

by number you mean pipelinerun sequence number?

PIpelines as Code / pipelinerun-1
PIpelines as Code / pipelinerun-2
PIpelines as Code / pipelinerun-3

like this?

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.

made them numbered in this manner, let me know what do you think about it?

Screenshot 2026-04-27 at 2 46 57 PM

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.

but this doesn't look good because there could be other kind of pipeline run e.g. on-comment that could lead to mist numbering 😕 thinking about something new

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.

now looks like this I'm using SHA-256 string 6 char appended to pipeline run name when application name and pipelinerun name combined or pipeline run name exceeds the 40 char limit

Screenshot 2026-04-27 at 4 02 17 PM

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 implements a new GetCheckName function to handle Bitbucket Cloud's 40-character limit for commit status keys, along with supporting unit and E2E tests and a new Status struct. Review feedback highlights the accidental removal of the e2e build tag in the test suite and suggests improving the truncation logic to preserve unique suffixes in PipelineRun names to prevent status key collisions.

Comment thread test/bitbucket_cloud_pullrequest_test.go
Comment thread pkg/provider/bitbucketcloud/bitbucket.go Outdated
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 23, 2026

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

Codecov Report

❌ Patch coverage is 96.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 59.24%. Comparing base (c37a213) to head (a715ee5).

Files with missing lines Patch % Lines
pkg/provider/bitbucketcloud/test/bbcloudtest.go 0.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2702      +/-   ##
==========================================
+ Coverage   59.19%   59.24%   +0.04%     
==========================================
  Files         208      208              
  Lines       20543    20566      +23     
==========================================
+ Hits        12161    12184      +23     
  Misses       7610     7610              
  Partials      772      772              

☔ 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 fix-bb-cloud-commit-status-key-len branch from b1d3544 to d00e795 Compare April 23, 2026 07:27
@zakisk
Copy link
Copy Markdown
Member Author

zakisk commented Apr 23, 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 implements a custom GetCheckName function for Bitbucket Cloud to ensure commit status keys adhere to the 40-character limit. It includes comprehensive unit tests for the truncation logic, a new Status struct for API interactions, and an E2E test to verify status reporting. Feedback was provided regarding a bug where ApplicationName was not truncated when the pipeline run name was empty, as well as a recommendation to use rune-based slicing to safely handle multi-byte characters in status keys.

Comment thread pkg/provider/bitbucketcloud/bitbucket.go Outdated
@zakisk zakisk force-pushed the fix-bb-cloud-commit-status-key-len branch from d00e795 to 1453475 Compare April 27, 2026 09:16
@zakisk
Copy link
Copy Markdown
Member Author

zakisk commented Apr 27, 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 introduces a mechanism to persist and report build statuses for Bitbucket Cloud by storing a unique status key in PipelineRun annotations. It includes the implementation of GetBBCloudStatusKey to handle Bitbucket's 40-character key limit and adds corresponding unit and E2E tests. A significant concern was raised regarding the use of a loop index for generating the status key, as this index is unstable across re-runs and could lead to incorrect status updates or collisions in Bitbucket.

Comment thread pkg/provider/provider.go Outdated
@zakisk zakisk force-pushed the fix-bb-cloud-commit-status-key-len branch 2 times, most recently from d9210ba to f695fc1 Compare April 27, 2026 11:16
@zakisk zakisk force-pushed the fix-bb-cloud-commit-status-key-len branch from f695fc1 to a820717 Compare April 28, 2026 06:26
@zakisk zakisk force-pushed the fix-bb-cloud-commit-status-key-len branch from a820717 to 70c6732 Compare April 28, 2026 06:52
Comment thread pkg/provider/provider.go
@zakisk zakisk force-pushed the fix-bb-cloud-commit-status-key-len branch 2 times, most recently from 6c97e41 to 5184ad5 Compare April 28, 2026 17:15
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.

Overall looks fine, just a comment on the added e2e test.

Comment thread test/bitbucket_cloud_pullrequest_test.go Outdated
@zakisk zakisk force-pushed the fix-bb-cloud-commit-status-key-len branch 2 times, most recently from b5c6f97 to 062a80d Compare May 5, 2026 06:14
Bitbucket Cloud limits commit status keys to 40 characters and uses
them to identify build statuses. Generated a new key on each
CreateStatus call causing duplicate statuses instead of updating
existing ones.

Fix the 40-char truncation to safely handle short names, use 1-based
indexing for status keys, and persist the generated key as a
PipelineRun annotation (pipeline-run-status-key) so subsequent calls
reuse the same key. Move GetCheckName to provider.GetBBCloudStatusKey,
add Index field to matcher.Match for stable instance counts, and add
e2e test to verify build status reporting.

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

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Zaki Shaikh <zashaikh@redhat.com>
@zakisk zakisk force-pushed the fix-bb-cloud-commit-status-key-len branch from 062a80d to a715ee5 Compare May 5, 2026 11:31
@zakisk
Copy link
Copy Markdown
Member Author

zakisk commented May 5, 2026

/retest

1 similar comment
@zakisk
Copy link
Copy Markdown
Member Author

zakisk commented May 5, 2026

/retest

@zakisk zakisk requested review from chmouel and theakshaypant May 5, 2026 14:40
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.

LGTM.
The hashing mechanism to add as a suffix when commit status key is truncated would prevent clashing if multiple pipelinerun have similar starting strings.
Handles cases when application name is to be included/excluded. Sufficient unit tests added. E2e test looks good after the update using a LONG pipelinerun name.

@zakisk zakisk merged commit eda5331 into tektoncd:main May 6, 2026
13 checks passed
@zakisk zakisk deleted the fix-bb-cloud-commit-status-key-len branch May 6, 2026 06:53
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.

5 participants