fix(ci): send real branch and PR for CI scans - #1475
Open
John-David Dalton (jdalton) wants to merge 1 commit into
Open
fix(ci): send real branch and PR for CI scans#1475John-David Dalton (jdalton) wants to merge 1 commit into
John-David Dalton (jdalton) wants to merge 1 commit into
Conversation
Backport of the SURF-634 fix from main. In a CI checkout HEAD is detached, so gitBranch fell through to a short commit SHA. A SHA can never match the repo's default branch, so those scans never showed up in the Main or PR tabs of the dashboard. Prefer the branch the workflow says it is on: GITHUB_HEAD_REF for a pull request, else GITHUB_REF_NAME when GITHUB_REF_TYPE is branch, and only then the SHA. socket ci also hardcoded pullRequest to 0, so a scan from a pull_request event could not land in the PR tab either. Derive the number from GITHUB_REF, which is refs/pull/<n>/merge on those events. main carries the branch logic in packages/cli/src/util/git/git-remote-info.mts. v1.x is the flat tree, so it lands in src/utils/git.mts as getCiBranch, and the environment is read straight from process.env because GITHUB_HEAD_REF and GITHUB_REF are not part of the constants.ENV snapshot. make_default_branch is untouched and still defaults to false.
John-David Dalton (jdalton)
enabled auto-merge (squash)
August 4, 2026 15:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LLM Description written by Claude Code:claude-opus-5
Actions needed
latestdist-tag (v1.1.152, onv1.x), so nothing changes for them until a release ships.main. Both fixes are already there with tests.What was broken
Scans from
socket ciin GitHub Actions did not show up in either the Main or the PR tab of the dashboard. Two separate causes, both already fixed onmain(SURF-634), neither onv1.x:actions/checkoutleaves HEAD detached, which is the normal state in CI.gitBranchhandled that by falling back to a short commit SHA, and a SHA can never match the repo default branch, so the scan was not a main-branch scan. On a pull request it was not a PR scan either.socket cihardcodedpullRequest: 0, so a scan from apull_requestevent could not land in the PR tab even with the branch right.The fix
getCiBranch()insrc/utils/git.mtsreads the branch the workflow says it is on before falling back to the SHA:GITHUB_HEAD_REFfirst (the pull request head branch), thenGITHUB_REF_NAMEwhenGITHUB_REF_TYPEisbranch.GITHUB_HEAD_REFhas to win, because on apull_requesteventGITHUB_REF_NAMEis<pr_number>/merge, which is not a branch name.detectCiPullRequestNumber()insrc/commands/ci/handle-ci.mtspulls the number out ofGITHUB_REF, which isrefs/pull/<n>/mergeon those events. Outside a pull request it returns 0 and the API request omitspull_requestas before.Port notes and test results
mainis a monorepo and keeps this logic inpackages/cli/src/util/git/git-remote-info.mts.v1.xis the old flat tree, so no files were copied. The branch logic went into the existingsrc/utils/git.mts, next togetBaseBranch, and the pull request logic into the existinghandle-ci.mts.mainreads the environment throughgetGithubRefName()/getGithubRefType()helpers that do not exist onv1.x. Here the values are read straight fromprocess.envwithenvAsString, because neitherGITHUB_HEAD_REFnorGITHUB_REFis part of the frozenconstants.ENVsnapshot thatgetBaseBranchuses.16 new tests, all passing, no mocks.
getCiBranchis covered directly;gitBranchis covered against a real temporary git repo that gets detached withgit checkout --detach, so the detached-HEAD path is the real thing rather than a stub. The tests clearGITHUB_HEAD_REF,GITHUB_REF_NAME,GITHUB_REF_TYPE, andGITHUB_REFfirst, otherwise they would silently read the values of the CI job they run inside.Checked that the tests are not vacuous. Disabling the branch preference in
git.mtsfails exactly the two detached-HEAD CI tests, and both report the commit SHA (expected 'b3833ac' to be 'feature/pr-branch') that is the bug customers see. MakingdetectCiPullRequestNumberalways return 0 fails exactly the tworefs/pull/<n>/...tests. Everything else stayed green in both runs, and both breaks were reverted.tsgo --noEmitand eslint are clean.Not in this PR
make_default_branchstill defaults tofalsehere, same as onmain. Flipping it would make every CI run establish the server-side default branch for every customer, which is an open product question tracked on SURF-634, so it stays as-is.Note
Low Risk
Scoped to CI metadata for scan creation; no auth or API contract changes beyond sending correct branch/PR fields that were previously wrong or omitted.
Overview
Fixes GitHub Actions
socket ciscans missing from the dashboard Main and PR tabs by labeling scans with the workflow’s real branch and PR number instead of a detached-HEAD commit SHA and hardcodedpullRequest: 0.Branch detection: Adds
getCiBranch()to readGITHUB_HEAD_REF(PR head) orGITHUB_REF_NAMEwhenGITHUB_REF_TYPEisbranch, and wiresgitBranch()to use it before falling back to a short SHA in detached HEAD (typicalactions/checkout).PR number: Adds
detectCiPullRequestNumber()to parseGITHUB_REF(refs/pull/<n>/mergeorhead) and passes that intohandleCreateNewScaninstead of always0.Adds vitest coverage for both helpers and for
gitBranchin detached HEAD with CI env vars cleared.Reviewed by Cursor Bugbot for commit fc93cb1. Configure here.