Skip to content

Fix Bitbucket PR head SHA detection - #2350

Draft
juan-fernandez wants to merge 1 commit into
masterfrom
juan-fernandez/bitbucket-pr-head-sha
Draft

juan-fernandez wants to merge 1 commit into
masterfrom
juan-fernandez/bitbucket-pr-head-sha

Conversation

@juan-fernandez

@juan-fernandez juan-fernandez commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Derive Bitbucket PR source heads from the checked-out commit graph, using local/remote branch refs only as validation evidence.
  • Use the first parent of the checked-out merge commit only when both the source branch and destination branch refs match the expected parents.
  • Reuse the shared git helper area for sync raw git execution needed by the synchronous CI tag reader.
  • Add coverage for checked-out source heads, verified synthetic merges, moved source refs, missing source validation, and missing destination validation.

Logical steps

For Bitbucket PR pipelines (BITBUCKET_PR_ID is set):

  1. Keep BITBUCKET_COMMIT as git.commit.sha, preserving the checked-out commit reported by Bitbucket.
  2. Verify local HEAD equals BITBUCKET_COMMIT. If it does not, leave git.commit.head.sha unset.
  3. Read the checked-out commit graph with git rev-list --parents -n 1 HEAD.
  4. Normalize BITBUCKET_BRANCH, then resolve the source branch ref locally first (refs/remotes/origin/<source-branch>, then refs/heads/<source-branch>), falling back to git ls-remote origin refs/heads/<source-branch>.
  5. Treat the source branch ref only as validation evidence:
    • If it matches BITBUCKET_COMMIT, the checked-out commit is already the PR source head, so set git.commit.head.sha to BITBUCKET_COMMIT.
    • If it matches the first parent of BITBUCKET_COMMIT, it may be a Bitbucket synthetic merge.
    • If it does not match either value, leave git.commit.head.sha unset. This avoids reporting a newer source branch head if the branch moved while the pipeline was running.
  6. For the synthetic merge case, require all of the following before using the first parent:
    • HEAD has exactly two parents.
    • The source branch ref matches the first parent.
    • BITBUCKET_PR_DESTINATION_BRANCH, resolved locally first and remotely only as a fallback, matches the second parent.
  7. Only after those checks pass, set git.commit.head.sha to the first parent. Otherwise, leave it unset rather than guessing.

Tests

  • yarn build
  • yarn exec eslint --cache --quiet packages/base/src/helpers/ci.ts packages/base/src/helpers/git/get-git-data.ts packages/base/src/helpers/__tests__/ci.test.ts packages/base/src/helpers/git/__tests__/get-git-data.test.ts
  • yarn test packages/base/src/helpers/__tests__/ci.test.ts packages/base/src/helpers/git/__tests__/get-git-data.test.ts

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

✨ Fix all issues with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

PR labels | Categorize PR   View in Datadog   GitHub Actions

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 7068b4e | Docs | Datadog PR Page | Give us feedback!

@juan-fernandez
juan-fernandez force-pushed the juan-fernandez/bitbucket-pr-head-sha branch from 5785080 to d77c991 Compare June 12, 2026 08:57
@juan-fernandez
juan-fernandez force-pushed the juan-fernandez/bitbucket-pr-head-sha branch from d77c991 to 7068b4e Compare June 12, 2026 09:13
@juan-fernandez juan-fernandez added the software-delivery Related to [coverage, deployment, dora, junit, measure, tag, trace] label Jun 12, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

software-delivery Related to [coverage, deployment, dora, junit, measure, tag, trace]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant