MCPcopy Create free account
hub / github.com/backnotprop/plannotator / gitlabRuntime

Function gitlabRuntime

packages/shared/pr-gitlab.test.ts:108–141  ·  view source on GitHub ↗
(opts: {
  rawDiffs: { stdout?: string; stderr?: string; exitCode: number };
  diffs?: { stdout?: string; stderr?: string; exitCode: number };
})

Source from the content-addressed store, hash-verified

106]);
107
108function gitlabRuntime(opts: {
109 rawDiffs: { stdout?: string; stderr?: string; exitCode: number };
110 diffs?: { stdout?: string; stderr?: string; exitCode: number };
111}): { runtime: PRRuntime; calls: string[] } {
112 const calls: string[] = [];
113 const metadata = JSON.stringify({
114 title: "T",
115 author: { username: "u" },
116 source_branch: "feature",
117 target_branch: "main",
118 diff_refs: { base_sha: "a".repeat(40), head_sha: "b".repeat(40), start_sha: "a".repeat(40) },
119 web_url: "https://gitlab.com/g/p/-/merge_requests/1",
120 });
121 const runtime: PRRuntime = {
122 async runCommand(command, args) {
123 calls.push([command, ...args].join(" "));
124 const endpoint = args[1] ?? "";
125 if (endpoint.endsWith("/raw_diffs")) {
126 return { stdout: opts.rawDiffs.stdout ?? "", stderr: opts.rawDiffs.stderr ?? "", exitCode: opts.rawDiffs.exitCode };
127 }
128 if (endpoint.includes("/diffs?per_page=100")) {
129 return { stdout: opts.diffs?.stdout ?? "", stderr: opts.diffs?.stderr ?? "", exitCode: opts.diffs?.exitCode ?? 1 };
130 }
131 if (/merge_requests\/\d+$/.test(endpoint)) {
132 return { stdout: metadata, stderr: "", exitCode: 0 };
133 }
134 if (/^projects\/[^/]+$/.test(endpoint)) {
135 return { stdout: JSON.stringify({ default_branch: "main" }), stderr: "", exitCode: 0 };
136 }
137 return { stdout: "", stderr: `unexpected endpoint: ${endpoint}`, exitCode: 1 };
138 },
139 };
140 return { runtime, calls };
141}
142
143describe("fetchGlMR raw_diffs fallback", () => {
144 test("falls back to the JSON diffs API when raw_diffs is unavailable (older GitLab)", async () => {

Callers 1

pr-gitlab.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected