Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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 }),
};
}

Expand Down
Loading