Skip to content

fix(shared): handle empty Bitbucket commit list in get_ancestors_tree - #2242

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/bitbucket-empty-commits
Open

fix(shared): handle empty Bitbucket commit list in get_ancestors_tree#2242
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/bitbucket-empty-commits

Conversation

@sentry

@sentry sentry Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

This PR addresses WORKER-JAB, an IndexError: list index out of range occurring in libs/shared/shared/torngit/bitbucket.py:get_ancestors_tree.

Root Cause:
Bitbucket's /repositories/{slug}/commits?include=<commitid> API endpoint returns an HTTP 200 OK response with an empty "values": [] list when a requested commit ID is not resolvable (e.g., if it's on a deleted branch). The get_ancestors_tree method then attempts to access res["values"][0]["hash"] without checking if the values list is empty, leading to an IndexError.

Unlike GitHub and GitLab adapters, which typically receive a 404 for unresolvable objects and raise TorngitObjectNotFoundError, the Bitbucket adapter was not handling this specific 200-with-empty-list scenario. This caused the IndexError to propagate unhandled, crashing the Upload task.

Fix:
Added a check in get_ancestors_tree to verify if res["values"] is empty. If it is, a TorngitObjectNotFoundError is now explicitly raised. This aligns the Bitbucket adapter's behavior with other providers and ensures that callers (like possibly_update_commit_from_provider_info and sync_pull) can gracefully handle unresolvable commits, as they already catch TorngitObjectNotFoundError or its parent TorngitClientError.

Legal Boilerplate

Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.

Fixes WORKER-JAB

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@thomasrockhu-codecov

thomasrockhu-codecov commented Sep 11, 2026

Copy link
Copy Markdown
Contributor
✨ Harness AI Code Review View in Harness →

Risk: LOW

This PR fixes WORKER-JAB — an IndexError in the Bitbucket get_ancestors_tree adapter when the /commits?include=<commitid> endpoint returns HTTP 200 with an empty "values": [] list for an unresolvable commit. It adds a guard that raises TorngitObjectNotFoundError before dereferencing res["values"][0], aligning Bitbucket with the GitHub/GitLab adapters.

The change is minimal and correct: TorngitObjectNotFoundError is already imported, the raise matches the file's established pattern, and callers (possibly_update_commit_from_provider_info, sync_pull) already catch TorngitObjectNotFoundError / TorngitClientError, so the new exception is handled gracefully.

No issues found above the confidence threshold.

@codspeed-hq

codspeed-hq Bot commented Sep 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing seer/fix/bitbucket-empty-commits (3303cda) with main (17e0f08)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (1c2ed4e) during the generation of this report, so 17e0f08 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@codecov-notifications

codecov-notifications Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
libs/shared/shared/torngit/bitbucket.py 0.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sentry

sentry Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

⚠️ Seer needs additional GitHub permissions

Seer wants to keep iterating on this pull request to get CI passing, but the Sentry GitHub App installation is missing permissions it needs to read the failing checks and push a fix.

Review and accept the updated permissions to let Seer continue: https://github.com/organizations/codecov/settings/installations/86101127/permissions/update

@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.62%. Comparing base (17e0f08) to head (3303cda).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
libs/shared/shared/torngit/bitbucket.py 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2242      +/-   ##
==========================================
- Coverage   91.63%   91.62%   -0.01%     
==========================================
  Files        1337     1337              
  Lines       53262    53264       +2     
  Branches     1647     1648       +1     
==========================================
  Hits        48805    48805              
- Misses       4136     4137       +1     
- Partials      321      322       +1     
Flag Coverage Δ
apiunit 93.98% <ø> (ø)
sharedintegration 36.74% <0.00%> (-0.01%) ⬇️
sharedunit 84.87% <0.00%> (-0.02%) ⬇️
workerintegration 58.49% <ø> (ø)
workerunit 90.55% <ø> (ø)

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.

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.

1 participant