@leitwerk-dev/gitlab 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +174 -1
  2. package/dist/capability.d.ts +3 -0
  3. package/dist/capability.d.ts.map +1 -1
  4. package/dist/chunk-23NUGZ3Q.js +2429 -0
  5. package/dist/chunk-23NUGZ3Q.js.map +1 -0
  6. package/dist/client.d.ts +116 -2
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/external.d.ts +23 -1
  9. package/dist/external.d.ts.map +1 -1
  10. package/dist/index.d.ts +8 -3
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +519 -10
  13. package/dist/index.js.map +1 -1
  14. package/dist/issue-watcher.d.ts +2 -0
  15. package/dist/issue-watcher.d.ts.map +1 -1
  16. package/dist/launch.d.ts +40 -0
  17. package/dist/launch.d.ts.map +1 -0
  18. package/dist/maintenance-labels.d.ts +30 -0
  19. package/dist/maintenance-labels.d.ts.map +1 -0
  20. package/dist/maintenance.d.ts +122 -0
  21. package/dist/maintenance.d.ts.map +1 -0
  22. package/dist/publication-maintenance.d.ts +7 -0
  23. package/dist/publication-maintenance.d.ts.map +1 -0
  24. package/dist/publication.d.ts +39 -0
  25. package/dist/publication.d.ts.map +1 -0
  26. package/dist/repository-catalog.d.ts +16 -0
  27. package/dist/repository-catalog.d.ts.map +1 -0
  28. package/dist/setup.d.ts +8 -2
  29. package/dist/setup.d.ts.map +1 -1
  30. package/dist/testing.d.ts +14 -1
  31. package/dist/testing.d.ts.map +1 -1
  32. package/dist/testing.js +158 -5
  33. package/dist/testing.js.map +1 -1
  34. package/dist/ticket-creation.d.ts +5 -0
  35. package/dist/ticket-creation.d.ts.map +1 -0
  36. package/dist/tools.d.ts +144 -3
  37. package/dist/tools.d.ts.map +1 -1
  38. package/package.json +7 -7
  39. package/src/capability.ts +3 -0
  40. package/src/client.ts +321 -7
  41. package/src/delivery-tools.ts +4 -4
  42. package/src/external.ts +90 -19
  43. package/src/index.ts +57 -10
  44. package/src/issue-watcher.ts +10 -1
  45. package/src/launch.ts +63 -0
  46. package/src/maintenance-labels.ts +129 -0
  47. package/src/maintenance.ts +721 -0
  48. package/src/publication-maintenance.ts +290 -0
  49. package/src/publication.ts +254 -0
  50. package/src/repository-catalog.ts +94 -0
  51. package/src/setup.ts +115 -6
  52. package/src/testing.ts +178 -4
  53. package/src/ticket-creation.ts +145 -0
  54. package/src/tools.ts +508 -23
  55. package/dist/chunk-TQIZKDAM.js +0 -1160
  56. package/dist/chunk-TQIZKDAM.js.map +0 -1
package/src/capability.ts CHANGED
@@ -4,12 +4,15 @@ import {
4
4
  type RepositoryCredentialRequirement,
5
5
  } from "@leitwerk-dev/process-sdk";
6
6
  import type { GitLabClientLike } from "./client.js";
7
+ import type { GitLabRepositoryCatalog } from "./repository-catalog.js";
7
8
  /** @public */
8
9
  export interface GitLabIntegration {
9
10
  /** @public */
10
11
  profiles(): readonly string[];
11
12
  /** @public */
12
13
  client(profile: string): GitLabClientLike;
14
+ /** Cached repository metadata for Settings, supplied by server setup. @public */
15
+ readonly repositoryCatalog?: GitLabRepositoryCatalog;
13
16
  }
14
17
  /** @public */
15
18
  export const gitlabIntegration = createCapabilityToken<GitLabIntegration>(
package/src/client.ts CHANGED
@@ -9,6 +9,8 @@ export interface GitLabProfile {
9
9
  /** @internal */
10
10
  token: string;
11
11
  /** @internal */
12
+ ignoredCommentUsers?: readonly string[];
13
+ /** @internal */
12
14
  gitIdentity?: {
13
15
  /** @internal */
14
16
  name: string;
@@ -24,6 +26,8 @@ export interface GitLabProject {
24
26
  path_with_namespace: string;
25
27
  /** @public */
26
28
  http_url_to_repo: string;
29
+ /** SSH clone URL supplied by GitLab. @public */
30
+ ssh_url_to_repo?: string;
27
31
  /** @public */
28
32
  web_url: string;
29
33
  /** @internal */
@@ -31,6 +35,10 @@ export interface GitLabProject {
31
35
  /** @public */
32
36
  archived?: boolean;
33
37
  /** @internal */
38
+ issues_enabled?: boolean;
39
+ /** @internal */
40
+ issues_access_level?: string;
41
+ /** @internal */
34
42
  permissions?: {
35
43
  /** @internal */
36
44
  project_access?: {
@@ -249,6 +257,25 @@ export interface GitLabDiscussion {
249
257
  };
250
258
  })[];
251
259
  }
260
+ /** @internal */
261
+ export interface GitLabDiscussionPosition {
262
+ /** @internal */
263
+ position_type: "text";
264
+ /** @internal */
265
+ base_sha: string;
266
+ /** @internal */
267
+ start_sha: string;
268
+ /** @internal */
269
+ head_sha: string;
270
+ /** @internal */
271
+ old_path: string;
272
+ /** @internal */
273
+ new_path: string;
274
+ /** @internal */
275
+ old_line?: number;
276
+ /** @internal */
277
+ new_line?: number;
278
+ }
252
279
  /** @public */
253
280
  export interface GitLabIdentity {
254
281
  /** @public */
@@ -264,6 +291,8 @@ export interface GitLabObservation {
264
291
  mr: GitLabMergeRequest;
265
292
  /** @public */
266
293
  pipeline: GitLabPipeline | null;
294
+ /** Source head verified against pipeline/merge-result ancestry. @internal */
295
+ pipelineSourceHead?: string;
267
296
  /** @public */
268
297
  targetHead?: string;
269
298
  }
@@ -324,6 +353,7 @@ export function parseGitLabProfiles(raw: unknown): Map<string, GitLabProfile> {
324
353
  profiles.set(name, {
325
354
  baseUrl,
326
355
  token,
356
+ ignoredCommentUsers: parseIgnoredCommentUsers(item.ignored_comment_users),
327
357
  ...(identity
328
358
  ? { gitIdentity: { name: String(identity.name), email: String(identity.email) } }
329
359
  : {}),
@@ -331,15 +361,32 @@ export function parseGitLabProfiles(raw: unknown): Map<string, GitLabProfile> {
331
361
  }
332
362
  return profiles;
333
363
  }
364
+
365
+ function parseIgnoredCommentUsers(raw: unknown): string[] {
366
+ if (raw === undefined) return [];
367
+ if (!Array.isArray(raw) || raw.some((user) => typeof user !== "string"))
368
+ throw new Error("GitLab ignored_comment_users must be a list of usernames");
369
+ const users = raw.map((user: string) => user.trim().replace(/^@/, "").toLowerCase());
370
+ if (users.some((user) => !/^[a-z0-9_.-]+$/.test(user)))
371
+ throw new Error("GitLab ignored_comment_users requires nonempty GitLab usernames");
372
+ return [...new Set(users)];
373
+ }
334
374
  const projectPath = (id: number | string) => `/projects/${encodeURIComponent(id)}`;
335
375
  const mrPath = (id: number, iid: number) => `${projectPath(id)}/merge_requests/${iid}`;
336
376
 
377
+ function nextGitLabPage(response: Response, page: number, count: number, perPage = 100) {
378
+ const next = response.headers.get("x-next-page");
379
+ if (next === "" || (next === null && count < perPage)) return null;
380
+ return next === null ? page + 1 : Number(next);
381
+ }
382
+
337
383
  /** GitLab v4 API. Errors deliberately omit response bodies, headers and tokens. */
338
384
  /** @public */
339
385
  export class GitLabClient {
340
386
  /** @public */
341
387
  readonly baseUrl: string;
342
388
  readonly #profile: GitLabProfile;
389
+ readonly #ignoredCommentUsers: ReadonlySet<string>;
343
390
  readonly #fetch: typeof fetch;
344
391
  readonly #sleep: (ms: number) => Promise<unknown>;
345
392
  /** @internal */
@@ -358,6 +405,7 @@ export class GitLabClient {
358
405
  if (!profile.token || /[\r\n\0]/.test(profile.token))
359
406
  throw new Error("GitLab requires a valid token");
360
407
  this.#profile = profile;
408
+ this.#ignoredCommentUsers = new Set(parseIgnoredCommentUsers(profile.ignoredCommentUsers));
361
409
  this.baseUrl = profile.baseUrl;
362
410
  this.#fetch = options.fetch ?? fetch;
363
411
  this.#sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
@@ -426,9 +474,8 @@ export class GitLabClient {
426
474
  const batch = await this.json<T[]>(response);
427
475
  if (!Array.isArray(batch)) throw new Error("Invalid GitLab list response");
428
476
  rows.push(...batch);
429
- const next = response.headers.get("x-next-page");
430
- if (next === "" || (next === null && batch.length < 100)) return rows;
431
- const nextPage = next === null ? page + 1 : Number(next);
477
+ const nextPage = nextGitLabPage(response, page, batch.length);
478
+ if (nextPage === null) return rows;
432
479
  if (!Number.isInteger(nextPage) || nextPage <= page)
433
480
  throw new Error("Invalid GitLab pagination");
434
481
  page = nextPage;
@@ -436,8 +483,24 @@ export class GitLabClient {
436
483
  throw new Error("GitLab pagination limit exceeded; discovery incomplete");
437
484
  }
438
485
  /** @public */
439
- listIssues(id: number, signal?: AbortSignal): Promise<GitLabIssue[]> {
440
- return this.pages(`${projectPath(id)}/issues?state=opened&scope=all`, signal);
486
+ listIssues(
487
+ id: number,
488
+ signal?: AbortSignal,
489
+ state: "opened" | "all" = "opened",
490
+ ): Promise<GitLabIssue[]> {
491
+ return this.pages(`${projectPath(id)}/issues?state=${state}&scope=all`, signal);
492
+ }
493
+ /** @internal */
494
+ createIssue(
495
+ id: number,
496
+ input: {
497
+ /** @internal */ title: string;
498
+ /** @internal */ description: string;
499
+ /** @internal */ labels: string;
500
+ },
501
+ signal?: AbortSignal,
502
+ ): Promise<GitLabIssue> {
503
+ return this.request(`${projectPath(id)}/issues`, signal, input);
441
504
  }
442
505
  /** @public */
443
506
  getIssue(id: number, iid: number, signal?: AbortSignal): Promise<GitLabIssue> {
@@ -546,6 +609,120 @@ export class GitLabClient {
546
609
  listProjects(signal?: AbortSignal): Promise<GitLabProject[]> {
547
610
  return this.pages("/projects?archived=false", signal);
548
611
  }
612
+ /** Read at most one page of matching repositories. @internal */
613
+ searchProjects(search: string, signal?: AbortSignal): Promise<GitLabProject[]> {
614
+ const query = new URLSearchParams({
615
+ archived: "false",
616
+ search,
617
+ search_namespaces: "true",
618
+ per_page: "100",
619
+ page: "1",
620
+ order_by: "path",
621
+ sort: "asc",
622
+ });
623
+ return this.request(`/projects?${query}`, signal);
624
+ }
625
+ /** @internal */
626
+ listRepositoryTree(
627
+ id: number,
628
+ ref: string,
629
+ path = "",
630
+ signal?: AbortSignal,
631
+ ): Promise<
632
+ {
633
+ /** @internal */
634
+ path: string;
635
+ /** @internal */
636
+ type: string;
637
+ /** @internal */
638
+ id: string;
639
+ }[]
640
+ > {
641
+ return this.pages(
642
+ `${projectPath(id)}/repository/tree?ref=${encodeURIComponent(ref)}&path=${encodeURIComponent(path)}`,
643
+ signal,
644
+ );
645
+ }
646
+ /** @internal */
647
+ getRepositoryFile(
648
+ id: number,
649
+ ref: string,
650
+ path: string,
651
+ signal?: AbortSignal,
652
+ ): Promise<{
653
+ /** @internal */
654
+ file_path: string;
655
+ /** @internal */
656
+ content: string;
657
+ /** @internal */
658
+ encoding: string;
659
+ /** @internal */
660
+ last_commit_id: string;
661
+ }> {
662
+ return this.request(
663
+ `${projectPath(id)}/repository/files/${encodeURIComponent(path)}?ref=${encodeURIComponent(ref)}`,
664
+ signal,
665
+ );
666
+ }
667
+ /** Project-scoped basic blob search at a full commit, one page per request. @internal */
668
+ async searchRepositoryCode(
669
+ id: number,
670
+ ref: string,
671
+ search: string,
672
+ page = 1,
673
+ perPage = 20,
674
+ signal?: AbortSignal,
675
+ ): Promise<{
676
+ /** @internal */ revision: string;
677
+ /** @internal */ results: {
678
+ /** @internal */ path: string;
679
+ /** @internal */ snippet: string;
680
+ /** @internal */ startLine: number;
681
+ }[];
682
+ /** @internal */ page: number;
683
+ /** @internal */ nextPage: number | null;
684
+ }> {
685
+ if (!/^[a-f0-9]{40,64}$/i.test(ref)) throw new Error("Code search requires a full commit ID");
686
+ if (!search.trim()) throw new Error("Code search requires a search term");
687
+ if (
688
+ !Number.isSafeInteger(page) ||
689
+ page < 1 ||
690
+ !Number.isSafeInteger(perPage) ||
691
+ perPage < 1 ||
692
+ perPage > 100
693
+ )
694
+ throw new Error("Invalid GitLab search pagination");
695
+ const query = new URLSearchParams({
696
+ scope: "blobs",
697
+ search_type: "basic",
698
+ ref,
699
+ search,
700
+ page: String(page),
701
+ per_page: String(perPage),
702
+ });
703
+ const response = await this.response(`${projectPath(id)}/search?${query}`, signal);
704
+ const rows = await this.json<{ path: string; data: string; startline: number }[]>(response);
705
+ if (
706
+ !Array.isArray(rows) ||
707
+ rows.some(
708
+ (row) =>
709
+ !row ||
710
+ typeof row.path !== "string" ||
711
+ typeof row.data !== "string" ||
712
+ !Number.isSafeInteger(row.startline),
713
+ )
714
+ )
715
+ throw new Error("Invalid GitLab code search response");
716
+ const nextPage = nextGitLabPage(response, page, rows.length, perPage);
717
+ if (nextPage !== null && (!Number.isSafeInteger(nextPage) || nextPage <= page))
718
+ throw new Error("Invalid GitLab pagination");
719
+ return {
720
+ revision: ref,
721
+ results: rows.map((row) => ({ path: row.path, snippet: row.data, startLine: row.startline })),
722
+ page,
723
+ nextPage,
724
+ };
725
+ }
549
726
  /** @internal */
550
727
  getGroup(id: number | string, signal?: AbortSignal): Promise<GitLabGroup> {
551
728
  return this.request(`/groups/${encodeURIComponent(id)}`, signal);
@@ -572,6 +749,60 @@ export class GitLabClient {
572
749
  getMergeRequest(id: number, iid: number, signal?: AbortSignal): Promise<GitLabMergeRequest> {
573
750
  return this.request(mrPath(id, iid), signal);
574
751
  }
752
+ /** @internal */
753
+ getMergeRequestApprovals(
754
+ id: number,
755
+ iid: number,
756
+ signal?: AbortSignal,
757
+ ): Promise<{
758
+ /** @internal */
759
+ user_has_approved: boolean;
760
+ }> {
761
+ return this.request(`${mrPath(id, iid)}/approvals`, signal);
762
+ }
763
+ /** @internal */
764
+ approveMergeRequest(
765
+ id: number,
766
+ iid: number,
767
+ sha: string,
768
+ signal?: AbortSignal,
769
+ ): Promise<{
770
+ /** @internal */
771
+ sha: string;
772
+ }> {
773
+ return this.request(`${mrPath(id, iid)}/approve`, signal, { sha });
774
+ }
775
+ /** @internal */
776
+ unapproveMergeRequest(
777
+ id: number,
778
+ iid: number,
779
+ signal?: AbortSignal,
780
+ ): Promise<{
781
+ /** @internal */
782
+ sha: string;
783
+ }> {
784
+ return this.request(`${mrPath(id, iid)}/unapprove`, signal, {});
785
+ }
786
+ /** Read every label transition, including changes between watcher polls. @public */
787
+ listMergeRequestLabelEvents(
788
+ id: number,
789
+ iid: number,
790
+ signal?: AbortSignal,
791
+ ): Promise<GitLabLabelEvent[]> {
792
+ return this.pages(`${mrPath(id, iid)}/resource_label_events`, signal);
793
+ }
794
+ /** Apply label deltas without replacing unrelated labels. @public */
795
+ updateMergeRequestLabels(
796
+ id: number,
797
+ iid: number,
798
+ patch: {
799
+ /** @public */ add_labels?: string;
800
+ /** @public */ remove_labels?: string;
801
+ },
802
+ signal?: AbortSignal,
803
+ ): Promise<GitLabMergeRequest> {
804
+ return this.request(mrPath(id, iid), signal, patch, "PUT");
805
+ }
575
806
  /** @public */
576
807
  getChanges(id: number, iid: number, signal?: AbortSignal): Promise<GitLabDiff[]> {
577
808
  return this.pages(`${mrPath(id, iid)}/diffs`, signal);
@@ -587,6 +818,12 @@ export class GitLabClient {
587
818
  getCommit(id: number, sha: string, signal?: AbortSignal): Promise<GitLabCommit> {
588
819
  return this.request(`${projectPath(id)}/repository/commits/${encodeURIComponent(sha)}`, signal);
589
820
  }
821
+ /** Find shared ancestry without cloning a repository. @public */
822
+ getMergeBase(id: number, refs: readonly string[], signal?: AbortSignal): Promise<GitLabCommit> {
823
+ const query = new URLSearchParams();
824
+ for (const ref of refs) query.append("refs[]", ref);
825
+ return this.request(`${projectPath(id)}/repository/merge_base?${query}`, signal);
826
+ }
590
827
  /** @internal */
591
828
  listMergeRequestPipelines(
592
829
  id: number,
@@ -635,6 +872,20 @@ export class GitLabClient {
635
872
  );
636
873
  }
637
874
  /** @internal */
875
+ listDiscussions(id: number, iid: number, signal?: AbortSignal): Promise<GitLabDiscussion[]> {
876
+ return this.pages(`${mrPath(id, iid)}/discussions`, signal);
877
+ }
878
+ /** @internal */
879
+ addDiscussion(
880
+ id: number,
881
+ iid: number,
882
+ body: string,
883
+ position: GitLabDiscussionPosition,
884
+ signal?: AbortSignal,
885
+ ): Promise<GitLabDiscussion> {
886
+ return this.request(`${mrPath(id, iid)}/discussions`, signal, { body, position });
887
+ }
888
+ /** @internal */
638
889
  replyToDiscussion(
639
890
  id: number,
640
891
  iid: number,
@@ -649,6 +900,21 @@ export class GitLabClient {
649
900
  );
650
901
  }
651
902
  /** @internal */
903
+ resolveDiscussion(
904
+ id: number,
905
+ iid: number,
906
+ discussionId: string,
907
+ resolved: boolean,
908
+ signal?: AbortSignal,
909
+ ): Promise<GitLabDiscussion> {
910
+ return this.request(
911
+ `${mrPath(id, iid)}/discussions/${encodeURIComponent(discussionId)}`,
912
+ signal,
913
+ { resolved },
914
+ "PUT",
915
+ );
916
+ }
917
+ /** @internal */
652
918
  listNoteReactions(
653
919
  id: number,
654
920
  iid: number,
@@ -684,6 +950,7 @@ export class GitLabClient {
684
950
  note.system ||
685
951
  note.resolved ||
686
952
  note.author.bot ||
953
+ this.#ignoredCommentUsers.has(note.author.username.toLowerCase()) ||
687
954
  /<!-- leitwerk:gitlab:[a-f0-9]{64} -->/.test(note.body) ||
688
955
  !note.body.trim() ||
689
956
  !Number.isFinite(Date.parse(note.created_at))
@@ -711,6 +978,16 @@ export class GitLabClient {
711
978
  addNote(id: number, iid: number, body: string, signal?: AbortSignal): Promise<GitLabNote> {
712
979
  return this.request(`${mrPath(id, iid)}/notes`, signal, { body });
713
980
  }
981
+ /** @internal */
982
+ updateNote(
983
+ id: number,
984
+ iid: number,
985
+ noteId: number,
986
+ body: string,
987
+ signal?: AbortSignal,
988
+ ): Promise<GitLabNote> {
989
+ return this.request(`${mrPath(id, iid)}/notes/${noteId}`, signal, { body }, "PUT");
990
+ }
714
991
  /** @public */
715
992
  async resolveGitIdentity(signal?: AbortSignal): Promise<GitLabIdentity> {
716
993
  const user = await this.request<{
@@ -766,9 +1043,24 @@ export class GitLabClient {
766
1043
  }
767
1044
  }
768
1045
  /** @public */
1046
+ export interface GitLabLabelEvent {
1047
+ /** Monotonically increasing GitLab resource-label event identity. @public */
1048
+ id: number;
1049
+ /** @public */
1050
+ action: "add" | "remove";
1051
+ /** @public */
1052
+ created_at: string;
1053
+ /** Deleted labels may have no name. @public */
1054
+ label: {
1055
+ /** @public */
1056
+ name: string;
1057
+ } | null;
1058
+ }
1059
+ /** @public */
769
1060
  export type GitLabClientLike = Pick<
770
1061
  GitLabClient,
771
1062
  | "listIssues"
1063
+ | "createIssue"
772
1064
  | "getIssue"
773
1065
  | "updateIssue"
774
1066
  | "listIssueNotes"
@@ -780,6 +1072,8 @@ export type GitLabClientLike = Pick<
780
1072
  | "preflightRepository"
781
1073
  | "addNote"
782
1074
  | "addNoteReaction"
1075
+ | "addDiscussion"
1076
+ | "updateNote"
783
1077
  | "baseUrl"
784
1078
  | "getBranch"
785
1079
  | "getChanges"
@@ -788,20 +1082,34 @@ export type GitLabClientLike = Pick<
788
1082
  | "getGroup"
789
1083
  | "getJobTrace"
790
1084
  | "getMergeRequest"
1085
+ | "getMergeRequestApprovals"
1086
+ | "approveMergeRequest"
1087
+ | "unapproveMergeRequest"
1088
+ | "listMergeRequestLabelEvents"
1089
+ | "updateMergeRequestLabels"
791
1090
  | "getPipeline"
792
1091
  | "getProject"
793
1092
  | "listBranchPipelines"
794
1093
  | "listFailedJobs"
795
1094
  | "listGroupProjects"
796
1095
  | "listMergeRequestFeedback"
1096
+ | "listDiscussions"
797
1097
  | "listMergeRequestPipelines"
798
1098
  | "listMergeRequests"
799
1099
  | "listNoteReactions"
800
1100
  | "listNotes"
801
1101
  | "listProjects"
1102
+ | "searchProjects"
802
1103
  | "replyToDiscussion"
1104
+ | "resolveDiscussion"
803
1105
  | "resolveGitIdentity"
804
- >;
1106
+ > &
1107
+ Partial<
1108
+ Pick<
1109
+ GitLabClient,
1110
+ "listRepositoryTree" | "getRepositoryFile" | "getMergeBase" | "searchRepositoryCode"
1111
+ >
1112
+ >;
805
1113
 
806
1114
  /** A pending current pipeline supersedes every older result. Synthetic merges must contain this source head. */
807
1115
  /** @public */
@@ -830,7 +1138,12 @@ export async function observeMergeRequest(
830
1138
  matches = commit.parent_ids.includes(mr.sha);
831
1139
  }
832
1140
  if (matches)
833
- return { mr, targetHead, pipeline: await client.getPipeline(id, candidate.id, signal) };
1141
+ return {
1142
+ mr,
1143
+ targetHead,
1144
+ pipeline: await client.getPipeline(id, candidate.id, signal),
1145
+ pipelineSourceHead: mr.sha,
1146
+ };
834
1147
  }
835
1148
  const candidates = await client.listBranchPipelines(
836
1149
  mr.source_project_id,
@@ -845,5 +1158,6 @@ export async function observeMergeRequest(
845
1158
  mr,
846
1159
  targetHead,
847
1160
  pipeline: latest ? await client.getPipeline(mr.source_project_id, latest.id, signal) : null,
1161
+ ...(latest ? { pipelineSourceHead: mr.sha } : {}),
848
1162
  };
849
1163
  }
@@ -26,7 +26,7 @@ export function registerGitLabDeliveryTools(
26
26
  "body",
27
27
  ]),
28
28
  async execute(ctx, args) {
29
- const binding = resolveGitLabRepositoryBinding(ctx);
29
+ const binding = resolveGitLabRepositoryBinding(ctx, integration);
30
30
  const client = integration.client(binding.profile);
31
31
  const project = projects.getByInstanceAndKey(ctx.process.id, ctx.project?.key ?? "");
32
32
  if (!project?.workBranch || project.workBranch === project.baseBranch)
@@ -92,7 +92,7 @@ export function registerGitLabDeliveryTools(
92
92
  description: "Read human discussion feedback on the bound merge request",
93
93
  parameters: projectParameters(),
94
94
  async execute(ctx) {
95
- const b = resolveGitLabBinding(ctx);
95
+ const b = resolveGitLabBinding(ctx, integration);
96
96
  return integration.client(b.profile).listMergeRequestFeedback(b.projectId, b.iid, ctx.signal);
97
97
  },
98
98
  });
@@ -101,7 +101,7 @@ export function registerGitLabDeliveryTools(
101
101
  description: "Reconcile the bot's seen reaction on bound merge request feedback",
102
102
  parameters: projectParameters({ noteId: { type: "integer" } }, ["noteId"]),
103
103
  async execute(ctx, args) {
104
- const b = resolveGitLabBinding(ctx);
104
+ const b = resolveGitLabBinding(ctx, integration);
105
105
  const client = integration.client(b.profile);
106
106
  const noteId = numberArg(args, "noteId");
107
107
  if (
@@ -142,7 +142,7 @@ export function registerGitLabDeliveryTools(
142
142
  ["issueNumber"],
143
143
  ),
144
144
  async execute(ctx, args) {
145
- const b = resolveGitLabRepositoryBinding(ctx);
145
+ const b = resolveGitLabRepositoryBinding(ctx, integration);
146
146
  const client = integration.client(b.profile);
147
147
  const iid = numberArg(args, "issueNumber");
148
148
  const bound = (ctx.project?.metadata?.gitlab as { issueIid?: number })?.issueIid;