Skip to content

Commit 697a121

Browse files
Jonathan Muchaclaude
andcommitted
fix: use source branch SHA for commit status, log response body
CI_COMMIT_SHA may be synthetic in merged-results pipelines. Prefer CI_MERGE_REQUEST_SOURCE_BRANCH_SHA when available. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 24b8362 commit 697a121

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

socketsecurity/core/scm/gitlab.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,15 @@ def from_env(cls) -> 'GitlabConfig':
4747
# Determine which authentication pattern to use
4848
headers = cls._get_auth_headers(token)
4949

50+
# Prefer source branch SHA (real commit) over CI_COMMIT_SHA which
51+
# may be a synthetic merge-result commit in merged-results pipelines.
52+
commit_sha = (
53+
os.getenv('CI_MERGE_REQUEST_SOURCE_BRANCH_SHA') or
54+
os.getenv('CI_COMMIT_SHA', '')
55+
)
56+
5057
return cls(
51-
commit_sha=os.getenv('CI_COMMIT_SHA', ''),
58+
commit_sha=commit_sha,
5259
api_url=os.getenv('CI_API_V4_URL', ''),
5360
project_dir=os.getenv('CI_PROJECT_DIR', ''),
5461
mr_source_branch=mr_source_branch,
@@ -278,11 +285,14 @@ def set_commit_status(self, state: str, description: str, target_url: str = '')
278285
if target_url:
279286
payload["target_url"] = target_url
280287
try:
288+
log.debug(f"Posting commit status to {url}")
281289
resp = requests.post(url, json=payload, headers=self.config.headers)
282290
if resp.status_code == 401:
283291
fallback = self._get_fallback_headers(self.config.headers)
284292
if fallback:
285293
resp = requests.post(url, json=payload, headers=fallback)
294+
if resp.status_code >= 400:
295+
log.error(f"GitLab commit status API {resp.status_code}: {resp.text}")
286296
resp.raise_for_status()
287297
log.info(f"Commit status set to '{state}' on {self.config.commit_sha[:8]}")
288298
except Exception as e:

0 commit comments

Comments
 (0)