fix(gitlab): merge request details report their head commit (#18608)

Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Scott NortemanandClaude Opus 5.5 authored and GitHub committed 2026-10-12 18:20:50 -05:00
1 parent 511d20c6f2
commit a3c4e9e936
2 files changed
+20

No files matched your search

@@ -181,6 +181,20 @@ describe("decodeMergeRequestDetailJson", () => {
expect(detail.changedFiles).toBe(0);
});
it("reads the head commit, and says nothing where GitLab omitted it", () => {
const headSha = (entry: Record<string, unknown>) =>
expectSuccess(decodeMergeRequestDetailJson(detailJson(entry))).headSha;
const sha = "afce4da4d5fe7d2fd0647b5b864526ea0a2827cb";
expect(headSha({ sha })).toBe(sha);
// A new merge request can report its head before GitLab has computed `diff_refs`.
expect(headSha({ sha, diff_refs: null })).toBe(sha);
expect(headSha({ sha, merge_commit_sha: "0".repeat(40) })).toBe(sha);
expect(headSha({})).toBeUndefined();
expect(headSha({ sha: null })).toBeUndefined();
expect(headSha({ sha: " " })).toBeUndefined();
});
it("reads either auto-merge field, and says nothing where GitLab named neither", () => {
const armed = (entry: Record<string, unknown>) =>
expectSuccess(decodeMergeRequestDetailJson(detailJson(entry))).autoMergeEnabled;
@@ -51,6 +51,8 @@ const RawMergeRequestSchema = Schema.Struct({
author: Schema.optional(Schema.NullOr(RawUserSchema)),
source_branch: Schema.String,
target_branch: Schema.String,
/** The source branch's head commit. */
sha: Schema.optional(Schema.NullOr(Schema.String)),
state: Schema.optional(Schema.NullOr(Schema.String)),
draft: Schema.optional(Schema.Boolean),
work_in_progress: Schema.optional(Schema.Boolean),
@@ -240,6 +242,8 @@ export interface GitLabMergeRequestDetail extends GitLabMergeRequestListItem {
* it: an install too old to answer must not be read as saying the branch is current.
*/
readonly divergedCommits?: number;
/** Absent where GitLab did not report the head commit. */
readonly headSha?: string;
}
function trimmed(value: string | null | undefined): string | null {
@@ -365,6 +369,7 @@ function toListItem(
function toDetail(raw: Schema.Schema.Type<typeof RawMergeRequestSchema>): GitLabMergeRequestDetail {
const listItem = toListItem(raw);
const headSha = trimmed(raw.sha);
const autoMerge =
raw.merge_when_pipeline_succeeds == null && raw.auto_merge_enabled == null
? undefined
@@ -390,6 +395,7 @@ function toDetail(raw: Schema.Schema.Type<typeof RawMergeRequestSchema>): GitLab
? { autoMergeMethod: "squash" as const }
: {}),
...(raw.diverged_commits_count == null ? {} : { divergedCommits: raw.diverged_commits_count }),
...(headSha === null ? {} : { headSha }),
};
}