@leitwerk-dev/gitlab-repo-change 0.3.1 → 0.4.0

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.
package/README.md CHANGED
@@ -1,19 +1,25 @@
1
1
  # GitLab repository change
2
2
 
3
- `@leitwerk-dev/gitlab-repo-change` plans, implements, reviews, and publishes a
4
- repository change as a new GitLab merge request. Load `gitlab`, `coding`, and this
5
- extension on the server and worker. The extension is opt-in.
3
+ `@leitwerk-dev/gitlab-repo-change` plans, implements, simplifies, and publishes a
4
+ repository change as a new GitLab merge request. Load `gitlab`, `git-ssh`, `coding`,
5
+ and this extension on the server and worker. The extension is opt-in.
6
6
 
7
7
  The UI launcher selects a GitLab profile, a visible project, and a requested change.
8
- It checks project visibility and HTTPS Git read/write admission, pins the bot Git
9
- identity, and targets the default branch. Replaying a UI launch generates a new
10
- work branch. Planning and implementation require operator approval.
8
+ It selects a matching Git SSH profile, checks project visibility and SSH read/write
9
+ admission, pins the bot Git identity, and targets the default branch. Replaying a UI
10
+ launch generates a new work branch. Plan approval starts implementation and MR
11
+ publication automatically. The launcher offers unchecked **Skip plan approval**
12
+ and **Skip simplification** options and preserves both on relaunch. Skipping
13
+ approval still generates and retains a plan.
14
+
15
+ [Generated process graph](process.mmd). Dashed edges are external triggers; terminal
16
+ outcomes are separate from the ten registered turns.
11
17
 
12
18
  ## Configuration
13
19
 
14
- Use the same [GitLab profile](../gitlab/README.md) for API and HTTPS repository
15
- access. No separate Git SSH profile is required. Configure issue discovery on the
16
- process:
20
+ Use a server-side [GitLab profile](../gitlab/README.md) for API access and a matching
21
+ [Git SSH profile](../git-ssh/README.md) for cloning and pushing. Configure issue
22
+ discovery on the process:
17
23
 
18
24
  ```yaml
19
25
  process_configs:
@@ -22,6 +28,7 @@ process_configs:
22
28
  use_leitwerk:
23
29
  enabled: true
24
30
  profile: team
31
+ git_ssh_profile: team
25
32
  poll_interval: 30s
26
33
  projects:
27
34
  include: [team/service]
@@ -49,14 +56,15 @@ starts with `{ profile, projectId }`; the server pins the MR `iid` after creatio
49
56
  A lost creation response or a restart before binding recovers the same request.
50
57
  Existing MR-bound integration tools still require the pinned IID.
51
58
 
52
- Human discussion feedback settles for two minutes. Delivery acknowledges it with
53
- an eyes reaction, revises in a fresh turn, and reconciles discussion replies. CI
54
- repair reads failed jobs and bounded traces for the current MR pipeline. Synthetic
55
- merge pipelines must contain the tracked source revision; newer pending pipelines
56
- supersede older terminal results. After three automatic CI cycles the operator
57
- chooses retry, resume waiting, or abort. Successful or absent CI continues waiting.
58
- Confirmed merge conflicts use the shared rebase implementation and original-head
59
- push lease. Unknown mergeability does not trigger a repair.
59
+ The process uses [shared GitLab MR maintenance](../gitlab/README.md#shared-mr-maintenance)
60
+ for feedback, CI observations, ownership labels, fencing, and recovery. Deliver runs
61
+ only for initial publication and changed adjustments; maintenance adds no business
62
+ turns. Removing `leitwerk-active` aborts this single-MR process and leaves the MR open.
63
+
64
+ After three automatic CI repair cycles the operator chooses retry, resume waiting,
65
+ or abort. CI repair uses failed jobs and bounded traces from the current MR pipeline;
66
+ see [pipeline selection](../gitlab/README.md#public-interface). Confirmed conflicts
67
+ use the shared rebase implementation and original-head push lease.
60
68
 
61
69
  Merge completes delivery. Unmerged closure aborts it. A source issue loses its
62
70
  trigger, gains the done label, receives a comment, and closes after merge. Unmerged
@@ -68,6 +76,26 @@ precedence. UI-origin processes never require a source issue.
68
76
 
69
77
  The default extension requires Docker. Trusted local compositions can use
70
78
  `createGitLabRepoChange({ docker: false })`; load exactly one variant. Both retain
71
- `gitlab_repo_change_process`. Credentials remain in the owning integration except
72
- for the existing repository-scoped worker Git credential delivery. Automatic
73
- merging, existing-MR adoption, fork publication, and release delivery are not provided.
79
+ `gitlab_repo_change_process`. GitLab API tokens remain server-side. Git SSH
80
+ credential delivery is repository-scoped. Automatic merging, existing-MR adoption,
81
+ fork publication, and release delivery are not provided.
82
+
83
+ ## Shared workflow
84
+
85
+ This process uses the [ten-turn workflow](../jira-gitlab-change/README.md#workflow)
86
+ from `coding`. Plan decisions offer approval or revisions with human comments.
87
+ Implementation, simplification analysis, simplification application, commit-message
88
+ generation, and publication then proceed automatically. The simplification analysis
89
+ covers staged, unstaged, and untracked changes and hands durable findings to the
90
+ separate application turn. Both turns run once before first publication.
91
+
92
+ For issue launches, `leitwerk-skip-simplification` is read immediately after
93
+ implementation. UI launches use the checkbox. A failed source lookup pauses for
94
+ retry; recovery reuses completed routing decisions. Later labels do not interrupt
95
+ simplification that already started. GitLab source issues do not use the Jira
96
+ plan-bypass label. Neither skip label replaces the watcher launch trigger.
97
+
98
+ Before deployment, finish or abort active instances using the removed plan-review,
99
+ implementation-review, implementation-approval, or simplification-approval turns.
100
+ Their history must be retained. GitHub and Forgejo use the same workflow and
101
+ upgrade boundary; provider-specific publication and CI semantics remain separate.
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ export declare const manifest: {
6
6
  /** @public */
7
7
  readonly version: "0.1.9";
8
8
  /** @public */
9
- readonly requires: readonly ["gitlab", "coding"];
9
+ readonly requires: readonly ["gitlab", "coding", "git-ssh"];
10
10
  };
11
11
  /** @public */
12
12
  /** @public */
@@ -21,10 +21,12 @@ export declare function createGitLabRepoChange(options: {
21
21
  /** @public */
22
22
  launcher: {
23
23
  /** @public */
24
- configure: (value: import("@leitwerk-dev/gitlab").GitLabIntegration | null) => void;
24
+ configure: (value: import("@leitwerk-dev/gitlab").GitLabIntegration | null, sshIntegration?: import("@leitwerk-dev/git-ssh").GitSshIntegration | null) => void;
25
25
  /** @public */
26
26
  launcher: import("@leitwerk-dev/process-sdk").ProcessLauncherDefinition<import("./params.js").GitLabRepoChangeParams>;
27
27
  /** @public */
28
+ workflow: import("@leitwerk-dev/coding/repository-change-launch").RepositoryChangeWorkflow<import("./params.js").GitLabRepoChangeParams>;
29
+ /** @public */
28
30
  preparationChecks: (_input: unknown, { params }: import("@leitwerk-dev/process-sdk").ProcessLaunchConfig<import("./params.js").GitLabRepoChangeParams>) => readonly import("@leitwerk-dev/process-sdk").LaunchPreparationCheck<import("./params.js").GitLabRepoChangeParams>[];
29
31
  /** @public */
30
32
  fromIssue(event: import("@leitwerk-dev/gitlab").GitLabIssueWatcherEvent): Promise<import("@leitwerk-dev/process-sdk").ProcessLaunchConfig<import("./params.js").GitLabRepoChangeParams>>;
@@ -33,10 +35,12 @@ export declare function createGitLabRepoChange(options: {
33
35
  /** @public */
34
36
  export declare const defaultExtension: LeitwerkExtensionModule, gitlabRepoChangeProcess: import("@leitwerk-dev/process-sdk").ExtensionProcessDefinition<import("./params.js").GitLabRepoChangeParams, import("@leitwerk-dev/coding/repository-change-state").RepositoryChangeState>, defaultGitLabRepoChangeLauncher: {
35
37
  /** @public */
36
- configure: (value: import("@leitwerk-dev/gitlab").GitLabIntegration | null) => void;
38
+ configure: (value: import("@leitwerk-dev/gitlab").GitLabIntegration | null, sshIntegration?: import("@leitwerk-dev/git-ssh").GitSshIntegration | null) => void;
37
39
  /** @public */
38
40
  launcher: import("@leitwerk-dev/process-sdk").ProcessLauncherDefinition<import("./params.js").GitLabRepoChangeParams>;
39
41
  /** @public */
42
+ workflow: import("@leitwerk-dev/coding/repository-change-launch").RepositoryChangeWorkflow<import("./params.js").GitLabRepoChangeParams>;
43
+ /** @public */
40
44
  preparationChecks: (_input: unknown, { params }: import("@leitwerk-dev/process-sdk").ProcessLaunchConfig<import("./params.js").GitLabRepoChangeParams>) => readonly import("@leitwerk-dev/process-sdk").LaunchPreparationCheck<import("./params.js").GitLabRepoChangeParams>[];
41
45
  /** @public */
42
46
  fromIssue(event: import("@leitwerk-dev/gitlab").GitLabIssueWatcherEvent): Promise<import("@leitwerk-dev/process-sdk").ProcessLaunchConfig<import("./params.js").GitLabRepoChangeParams>>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAGzE,cAAc;AACd,eAAO,MAAM,QAAQ;IACpB,cAAc;;IAEd,cAAc;;IAEd,cAAc;;CAEL,CAAC;AACX,cAAc;AACd,cAAc;AACd,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC/C,cAAc;IACd,MAAM,EAAE,OAAO,CAAC;CAChB;IAmBC,cAAc;;IAEd,cAAc;;IAEd,cAAc;;;;;;;;;;;EAGf;AACD,cAAc;AACd,eAAO,MACK,gBAAgB,2BAClB,uBAAuB,8LACtB,+BAA+B;;;;;;;;;CACE,CAAC;AAC7C,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAIzE,cAAc;AACd,eAAO,MAAM,QAAQ;IACpB,cAAc;;IAGd,cAAc;;IAGd,cAAc;;CAEL,CAAC;AAEX,cAAc;AACd,cAAc;AACd,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC/C,cAAc;IACd,MAAM,EAAE,OAAO,CAAC;CAChB;IAuBC,cAAc;;IAGd,cAAc;;IAGd,cAAc;;;;;;;;;;;;;EAGf;AAED,cAAc;AACd,eAAO,MACK,gBAAgB,2BAClB,uBAAuB,8LACtB,+BAA+B;;;;;;;;;;;CACE,CAAC;AAC7C,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,eAAe,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,14 @@
1
1
  // src/index.ts
2
+ import { gitSshIntegration } from "@leitwerk-dev/git-ssh";
2
3
  import { gitlabIntegration } from "@leitwerk-dev/gitlab";
3
4
 
4
5
  // src/launcher.ts
5
6
  import { buildAutoWorkBranchFromSeed } from "@leitwerk-dev/coding/auto-work-branch";
7
+ import {
8
+ repositoryChangeOptionFields,
9
+ repositoryChangeOptions,
10
+ repositoryChangeWorkflow
11
+ } from "@leitwerk-dev/coding/repository-change-launch";
6
12
 
7
13
  // ../../node_modules/valibot/dist/index.mjs
8
14
  var store$4;
@@ -398,41 +404,44 @@ function isUnknownRecord(value) {
398
404
  }
399
405
 
400
406
  // src/launcher.ts
407
+ import { createGitSshPreparationCheck } from "@leitwerk-dev/git-ssh";
401
408
  import {
402
- gitlabIssueExternalId
409
+ gitlabIssueExternalId,
410
+ resolveGitLabLaunchProject
403
411
  } from "@leitwerk-dev/gitlab";
404
412
  import {
405
413
  SafeLaunchPreparationError
406
414
  } from "@leitwerk-dev/process-sdk";
407
415
  function createGitLabRepoChangeLauncher() {
408
416
  let integration = null;
417
+ let ssh = null;
409
418
  const requireIntegration = () => {
410
419
  if (!integration) throw new Error("GitLab repository launcher is not configured");
411
420
  return integration;
412
421
  };
413
- const configure = (value) => {
422
+ const configure = (value, sshIntegration = null) => {
414
423
  integration = value;
424
+ ssh = sshIntegration;
415
425
  };
416
- async function launch(repository, profile, prompt, issue) {
426
+ async function launch(repository, profile, prompt, issue, options = {}) {
417
427
  const service = requireIntegration();
418
428
  if (!service.profiles().includes(profile)) throw new Error("GitLab profile is unavailable");
419
429
  const client = service.client(profile);
420
- const split = repository.path_with_namespace.lastIndexOf("/");
421
- if (split < 1) throw new Error("Invalid GitLab project path");
422
- const common = {
423
- gitlabProfile: profile,
424
- gitlabOrigin: client.baseUrl,
425
- projectId: repository.id,
426
- owner: repository.path_with_namespace.slice(0, split),
427
- repo: repository.path_with_namespace.slice(split + 1),
428
- repoLocator: repository.http_url_to_repo,
429
- baseBranch: repository.default_branch,
430
- workBranch: issue ? `leitwerk/issue-${issue.issue.iid}` : buildAutoWorkBranchFromSeed(
430
+ const gitSshProfile = options.gitSshProfile ?? issue?.gitSshProfile ?? (ssh?.profiles().length === 1 ? ssh.profiles()[0] : "");
431
+ if (!gitSshProfile || !ssh?.profiles().includes(gitSshProfile))
432
+ throw new Error("Select a matching Git SSH profile");
433
+ const { params: binding, project } = await resolveGitLabLaunchProject(
434
+ client,
435
+ profile,
436
+ repository,
437
+ issue ? `leitwerk/issue-${issue.issue.iid}` : buildAutoWorkBranchFromSeed(
431
438
  prompt,
432
439
  `${repository.http_url_to_repo}:${repository.default_branch}`
433
- ),
434
- prompt
435
- };
440
+ )
441
+ );
442
+ project.settingsRepository.origin = new URL(repository.web_url).origin;
443
+ if (issue) Object.assign(project.metadata.gitlab, { issueIid: issue.issue.iid });
444
+ const common = { ...binding, gitSshProfile, ...repositoryChangeOptions(options), prompt };
436
445
  const params = issue ? {
437
446
  ...common,
438
447
  origin: "issue",
@@ -448,7 +457,6 @@ function createGitLabRepoChangeLauncher() {
448
457
  triggerLabel: null,
449
458
  doneLabel: null
450
459
  };
451
- const identity = await client.resolveGitIdentity();
452
460
  return {
453
461
  processId: "gitlab_repo_change_process",
454
462
  title: issue?.issue.title ?? prompt,
@@ -458,50 +466,31 @@ function createGitLabRepoChangeLauncher() {
458
466
  externalId: gitlabIssueExternalId(client.baseUrl, repository.id, issue.issue.iid),
459
467
  externalUrl: issue.issue.web_url
460
468
  } : {},
461
- projects: [
462
- {
463
- key: "repo",
464
- repoLocator: params.repoLocator,
465
- baseBranch: params.baseBranch,
466
- workBranch: params.workBranch,
467
- metadata: {
468
- gitlab: {
469
- profile,
470
- projectId: repository.id,
471
- ...issue ? { issueIid: issue.issue.iid } : {}
472
- },
473
- "leitwerk.gitIdentity": {
474
- provider: "gitlab",
475
- profile,
476
- login: identity.username,
477
- name: identity.name,
478
- email: identity.email
479
- }
480
- }
481
- }
482
- ]
469
+ projects: [project]
483
470
  };
484
471
  }
485
472
  const preparationChecks = (_input, { params }) => [
486
473
  {
487
474
  id: "gitlab_repository_access",
488
- label: "Verify GitLab repository and HTTPS read/write access",
475
+ label: "Verify GitLab repository access",
489
476
  async run({ signal }) {
490
477
  const client = requireIntegration().client(params.gitlabProfile);
491
478
  const repository = await client.getProject(params.projectId, signal);
492
- if (repository.archived || repository.http_url_to_repo !== params.repoLocator || repository.default_branch !== params.baseBranch)
479
+ if (repository.archived || repository.ssh_url_to_repo !== params.repoLocator || repository.default_branch !== params.baseBranch)
493
480
  throw new SafeLaunchPreparationError(
494
481
  "Repository changed or is archived",
495
482
  "Select an active GitLab project and launch again."
496
483
  );
497
- await client.preflightRepository(
498
- params.projectId,
499
- params.baseBranch,
500
- params.workBranch,
501
- signal
502
- );
503
484
  }
504
- }
485
+ },
486
+ createGitSshPreparationCheck(
487
+ "write",
488
+ { ...params, sshCredentialRef: params.gitSshProfile ?? "" },
489
+ () => {
490
+ if (!params.gitSshProfile || !ssh) throw new Error("Git SSH profile is unavailable");
491
+ return ssh;
492
+ }
493
+ )
505
494
  ];
506
495
  const launcher = {
507
496
  id: "gitlab_repo_change_process.ui_launcher",
@@ -519,7 +508,15 @@ function createGitLabRepoChangeLauncher() {
519
508
  fields: [
520
509
  { id: "gitlabProfile", label: "GitLab profile", kind: "select", required: true },
521
510
  { id: "repository", label: "Project", kind: "select", required: true },
522
- { id: "prompt", label: "Requested change", kind: "textarea", required: true }
511
+ {
512
+ id: "gitSshProfile",
513
+ label: "Git SSH profile",
514
+ kind: "select",
515
+ required: true,
516
+ options: []
517
+ },
518
+ { id: "prompt", label: "Requested change", kind: "textarea", required: true },
519
+ ...repositoryChangeOptionFields
523
520
  ],
524
521
  submitLabel: "Start change"
525
522
  },
@@ -527,13 +524,16 @@ function createGitLabRepoChangeLauncher() {
527
524
  return {
528
525
  gitlabProfile: requireIntegration().profiles()[0] ?? "",
529
526
  repository: "",
530
- prompt: ""
527
+ gitSshProfile: ssh?.profiles()[0] ?? "",
528
+ prompt: "",
529
+ ...repositoryChangeOptions({})
531
530
  };
532
531
  },
533
532
  async resolveOptions(input) {
534
533
  const i = requireIntegration();
535
534
  const profile = trimString(input.gitlabProfile);
536
535
  return {
536
+ gitSshProfile: (ssh?.profiles() ?? []).map((value) => ({ value, label: value })),
537
537
  gitlabProfile: i.profiles().map((value) => ({ value, label: value })),
538
538
  repository: (i.profiles().includes(profile) ? await i.client(profile).listProjects() : []).filter((p) => !p.archived && p.default_branch).map((p) => ({
539
539
  value: String(p.id),
@@ -547,7 +547,9 @@ function createGitLabRepoChangeLauncher() {
547
547
  return {
548
548
  gitlabProfile: trimString(input.gitlabProfile),
549
549
  repository: trimString(input.repository),
550
- prompt: trimString(input.prompt)
550
+ prompt: trimString(input.prompt),
551
+ gitSshProfile: trimString(input.gitSshProfile),
552
+ ...repositoryChangeOptions(input)
551
553
  };
552
554
  },
553
555
  async resolveLaunchConfig(input) {
@@ -555,6 +557,12 @@ function createGitLabRepoChangeLauncher() {
555
557
  const projectId = Number(input.repository);
556
558
  const prompt = trimString(input.prompt);
557
559
  const errors = [];
560
+ if (!ssh?.profiles().includes(trimString(input.gitSshProfile)))
561
+ errors.push({
562
+ fieldId: "gitSshProfile",
563
+ message: "Select an available Git SSH profile",
564
+ code: "custom_rule"
565
+ });
558
566
  if (!requireIntegration().profiles().includes(profile))
559
567
  errors.push({
560
568
  fieldId: "gitlabProfile",
@@ -586,7 +594,13 @@ function createGitLabRepoChangeLauncher() {
586
594
  }
587
595
  ]
588
596
  };
589
- return { ok: true, launchConfig: await launch(repository, profile, prompt) };
597
+ return {
598
+ ok: true,
599
+ launchConfig: await launch(repository, profile, prompt, void 0, {
600
+ gitSshProfile: trimString(input.gitSshProfile),
601
+ ...repositoryChangeOptions(input)
602
+ })
603
+ };
590
604
  }
591
605
  }
592
606
  };
@@ -595,6 +609,14 @@ function createGitLabRepoChangeLauncher() {
595
609
  configure,
596
610
  /** @public */
597
611
  launcher,
612
+ /** Server-side routing policies. @public */
613
+ workflow: repositoryChangeWorkflow(async (params) => {
614
+ if (params.origin !== "issue") throw new Error("Missing GitLab source issue");
615
+ const client = requireIntegration().client(params.gitlabProfile);
616
+ if (client.baseUrl !== params.gitlabOrigin)
617
+ throw new Error("GitLab profile installation changed from the source issue");
618
+ return (await client.getIssue(params.projectId, params.issueNumber)).labels;
619
+ }),
598
620
  /** @public */
599
621
  preparationChecks,
600
622
  /** @public */
@@ -615,13 +637,13 @@ ${event.issue.description}` : ""}`,
615
637
  import { createRepositoryChangeProcess } from "@leitwerk-dev/coding";
616
638
  import {
617
639
  createRepositoryChangePublication,
618
- publicationObject as object2,
619
640
  readPublicationState
620
641
  } from "@leitwerk-dev/coding/repository-change-publication";
621
642
  import {
643
+ createGitLabPublicationAdapter,
622
644
  gitlabExternal,
623
645
  gitlabIssueWatcherSource,
624
- gitlabRepositoryCredentials
646
+ gitlabPublicationEvidenceForRequest
625
647
  } from "@leitwerk-dev/gitlab";
626
648
 
627
649
  // src/params.ts
@@ -643,6 +665,7 @@ var gitlabRepoChangeParamsCodec = createRepositoryChangeParamsCodec({
643
665
  const common = {
644
666
  ...normalizeRepositoryChangeParamsInput(value, "GitLab Repo Change"),
645
667
  gitlabProfile: text("gitlabProfile"),
668
+ gitSshProfile: trimString(r.gitSshProfile),
646
669
  gitlabOrigin: text("gitlabOrigin"),
647
670
  projectId: r.projectId,
648
671
  owner: text("owner"),
@@ -672,13 +695,10 @@ var gitlabRepoChangeParamsCodec = createRepositoryChangeParamsCodec({
672
695
 
673
696
  // src/process.ts
674
697
  var remote = (state) => readPublicationState(state, "gitlabRepoChange");
675
- var request = (mr) => ({
676
- number: mr.iid,
677
- html_url: mr.web_url,
678
- merged: mr.state === "merged",
679
- merge_commit_sha: mr.merge_commit_sha
680
- });
681
- var callFor = (ctx) => (name, args = {}) => ctx.callIntegrationTool(name, { projectKey: "repo", ...args });
698
+ var maintenanceAdapters = /* @__PURE__ */ new WeakMap();
699
+ function registerGitLabRepoChangeMaintenance(api, process) {
700
+ maintenanceAdapters.get(process)?.maintenance?.register(api, process);
701
+ }
682
702
  function requireRequest(state) {
683
703
  const current = remote(state);
684
704
  if (!current.prNumber || !current.headSha)
@@ -686,65 +706,20 @@ function requireRequest(state) {
686
706
  return { ...current, prNumber: current.prNumber, headSha: current.headSha };
687
707
  }
688
708
  function gitlabPublicationEvidence(state, event) {
689
- const current = requireRequest(state);
690
- const key = { observationKey: event.observationKey };
691
- if (event.mr.iid !== current.prNumber) throw new Error("Stale GitLab merge request evidence");
692
- if (event.mr.state === "merged" || event.mr.state === "closed")
693
- return { kind: "terminal", request: request(event.mr), ...key };
694
- if (event.mr.sha !== current.headSha) return { kind: "observed", ...key };
695
- if (event.conflict) return { kind: "conflict", conflict: event.conflict, ...key };
696
- if (event.feedback?.length)
697
- return {
698
- kind: "feedback",
699
- feedbackIds: event.feedback.map((n) => ({
700
- kind: "inline",
701
- id: n.id,
702
- discussionId: n.discussionId
703
- })),
704
- conversationCursor: Math.max(current.conversationCursor, ...event.feedback.map((n) => n.id)),
705
- reviewCursor: 0,
706
- inlineCursor: 0
707
- };
708
- if (event.pipeline && ["failed", "canceled"].includes(event.pipeline.status))
709
- return { kind: "failure", pipeline: { ...event.pipeline, number: event.pipeline.id }, ...key };
710
- return { kind: "observed", ...key };
709
+ return gitlabPublicationEvidenceForRequest(remote(state), event);
711
710
  }
712
711
  function createGitLabRepoChangeProcess(launcher, docker) {
713
712
  const sources = [
714
- {
715
- id: "gitlab_merge_request",
716
- kind: "observation",
717
- label: "GitLab merge request evidence",
718
- source: gitlabExternal.mergeRequest(({ params, state }) => {
719
- const c = requireRequest(state);
720
- return {
721
- profile: params.gitlabProfile,
722
- projectId: params.projectId,
723
- iid: c.prNumber,
724
- pollInterval: "30s",
725
- afterKey: c.observationKey,
726
- feedback: { afterId: c.conversationCursor, quietPeriodMs: 12e4 },
727
- delivery: {
728
- headSha: c.headSha,
729
- owner: params.owner,
730
- repo: params.repo,
731
- headBranch: params.workBranch,
732
- baseBranch: params.baseBranch,
733
- lastConflictKey: c.lastConflictKey
734
- }
735
- };
736
- }),
737
- read: ({ state, event }) => gitlabPublicationEvidence(state, event)
738
- },
739
713
  {
740
714
  id: "source_cancelled",
741
715
  kind: "cancelled",
742
716
  label: "GitLab source issue cancelled",
743
- enabled: (p) => p.origin === "issue",
717
+ enabled: (params, state) => params.origin === "issue" && !!remote(state).prNumber && !!remote(state).headSha,
744
718
  source: gitlabExternal.issueCancelled(({ params, state }) => {
745
719
  if (params.origin !== "issue") throw new Error("Missing GitLab source issue");
746
720
  return {
747
721
  profile: params.gitlabProfile,
722
+ origin: params.gitlabOrigin,
748
723
  projectId: params.projectId,
749
724
  issueIid: params.issueNumber,
750
725
  iid: requireRequest(state).prNumber,
@@ -755,103 +730,8 @@ function createGitLabRepoChangeProcess(launcher, docker) {
755
730
  read: () => ({ kind: "cancelled" })
756
731
  }
757
732
  ];
758
- const publication = createRepositoryChangePublication({
759
- namespace: "gitlabRepoChange",
760
- label: "GitLab MR",
761
- ids: {
762
- deliver: "deliver_change",
763
- feedback: "revise_from_merge_request_feedback",
764
- ciRepair: "repair_gitlab_pipeline",
765
- operator: "ci_operator_action"
766
- },
767
- sources,
768
- tools: {
769
- delivery: [
770
- "gitlab_ensure_merge_request",
771
- "gitlab_observe_merge_request",
772
- "gitlab_comment",
773
- "gitlab_reply",
774
- "gitlab_get_identity",
775
- "gitlab_acknowledge_feedback",
776
- "gitlab_add_issue_comment",
777
- "gitlab_finalize_source_issue"
778
- ],
779
- feedback: [
780
- "gitlab_observe_merge_request",
781
- "gitlab_get_changes",
782
- "gitlab_list_merge_request_feedback"
783
- ],
784
- ci: ["gitlab_observe_merge_request", "gitlab_list_failed_jobs", "gitlab_get_job_trace"]
785
- },
786
- async identity(ctx) {
787
- const pinned = object2(
788
- ctx.projects.find((p) => p.key === "repo")?.metadata?.["leitwerk.gitIdentity"]
789
- );
790
- if (pinned.provider !== "gitlab" || pinned.profile !== ctx.params.gitlabProfile || typeof pinned.name !== "string" || typeof pinned.email !== "string")
791
- throw new Error("Pinned GitLab Git identity is unavailable");
792
- return { name: pinned.name, email: pinned.email };
793
- },
794
- async ensureRequest(ctx) {
795
- const mr = await callFor(ctx)("gitlab_ensure_merge_request", {
796
- title: ctx.process.title ?? "Leitwerk change",
797
- body: `${ctx.params.origin === "issue" ? `Implements ${ctx.params.issueUrl}
798
-
799
- ` : ""}Leitwerk process: ${ctx.process.id}`
800
- });
801
- return request(mr);
802
- },
803
- async reconcileTerminal(ctx, _current, pr) {
804
- if (ctx.params.origin !== "issue") return;
805
- const call = callFor(ctx);
806
- await call("gitlab_finalize_source_issue", {
807
- issueNumber: ctx.params.issueNumber,
808
- merged: pr.merged,
809
- triggerLabel: ctx.params.triggerLabel,
810
- doneLabel: ctx.params.doneLabel,
811
- writeKey: `gitlab:${ctx.process.id}:${pr.merged ? "complete-source-issue" : "remove-source-trigger"}`
812
- });
813
- await call("gitlab_add_issue_comment", {
814
- issueNumber: ctx.params.issueNumber,
815
- body: pr.merged ? `Merged ${pr.html_url}${pr.merge_commit_sha ? ` at ${pr.merge_commit_sha}` : ""}.` : `Leitwerk stopped because ${pr.html_url} was closed without merge.`,
816
- writeKey: `gitlab:${ctx.process.id}:${pr.merged ? "merged" : "closed"}-mr-comment`
817
- });
818
- },
819
- async linkIssue(ctx, current) {
820
- if (ctx.params.origin === "issue")
821
- await callFor(ctx)("gitlab_add_issue_comment", {
822
- issueNumber: ctx.params.issueNumber,
823
- body: `Leitwerk opened merge request ${current.prUrl}.`,
824
- writeKey: `gitlab:${ctx.process.id}:source-mr-link:${current.prNumber}`
825
- });
826
- },
827
- async acknowledge(ctx, current) {
828
- for (const feedback of current.feedbackIds)
829
- await callFor(ctx)("gitlab_acknowledge_feedback", { noteId: feedback.id });
830
- },
831
- async reply(ctx, current) {
832
- for (const feedback of current.feedbackIds) {
833
- if (!feedback.discussionId) throw new Error("GitLab feedback discussion is missing");
834
- await callFor(ctx)("gitlab_reply", {
835
- discussionId: feedback.discussionId,
836
- body: `Addressed in ${current.headSha?.slice(0, 8) ?? "the current revision"}.`,
837
- writeKey: `gitlab:${ctx.process.id}:feedback-reply:${feedback.id}:${current.headSha}`
838
- });
839
- }
840
- },
841
- async head(ctx) {
842
- return (await callFor(ctx)("gitlab_observe_merge_request")).mr.sha;
843
- },
844
- async afterRebase(ctx, current) {
845
- await callFor(ctx)("gitlab_comment", {
846
- body: `Merge conflict repair completed at ${current.headSha}; base ${current.conflict?.baseSha}.`,
847
- writeKey: `rebase:${ctx.process.id}:${current.lastConflictKey}:${current.headSha}`
848
- });
849
- },
850
- commitMessage: (kind) => kind === "feedback" ? "fix: address GitLab review feedback" : "fix: repair GitLab pipeline",
851
- prompt(kind, current) {
852
- return kind === "feedback" ? `Address the unseen GitLab feedback for MR !${current.prNumber}: ${JSON.stringify(current.feedbackIds)}. Read the full discussions with gitlab_list_merge_request_feedback, inspect the checkout, and make only justified changes. Call changes_ready when ready to publish, no_changes with an explicit diagnosis when no change is needed, or cannot_repair for operator action.` : `Diagnose GitLab pipeline ${current.pipeline?.number} for head ${current.headSha}. Read gitlab_list_failed_jobs with pipelineId and bounded gitlab_get_job_trace before making repository repairs. Call changes_ready to publish, no_changes with a justified diagnosis, or cannot_repair when operator action is needed.`;
853
- }
854
- });
733
+ const adapter = createGitLabPublicationAdapter(sources);
734
+ const publication = createRepositoryChangePublication(adapter);
855
735
  publication.fragment.watcher({
856
736
  id: "use_leitwerk",
857
737
  label: "GitLab use-leitwerk issues",
@@ -865,17 +745,19 @@ function createGitLabRepoChangeProcess(launcher, docker) {
865
745
  displayName: "GitLab Repo Change",
866
746
  paramsCodec: gitlabRepoChangeParamsCodec,
867
747
  launcher: launcher.launcher,
868
- finalizeLabel: "Publish merge request",
869
- finalizeForm: {
870
- id: "gitlab_publish",
871
- title: "Publish merge request",
872
- fields: [],
873
- submitLabel: "Publish"
874
- },
875
- repositoryCredentials: ({ params, projects }) => gitlabRepositoryCredentials(params.gitlabProfile, projects),
748
+ workflow: launcher.workflow,
749
+ repositoryCredentials: ({ params, projects }) => projects.map((project) => {
750
+ if (!params.gitSshProfile) throw new Error("Missing Git SSH profile");
751
+ return {
752
+ projectKey: project.key,
753
+ kind: "git_ssh",
754
+ credentialRef: params.gitSshProfile
755
+ };
756
+ }),
876
757
  publication
877
758
  });
878
759
  definition.process.runtime = { ...definition.process.runtime, docker };
760
+ maintenanceAdapters.set(definition.process, adapter);
879
761
  return definition.process;
880
762
  }
881
763
 
@@ -886,7 +768,7 @@ var manifest = {
886
768
  /** @public */
887
769
  version: "0.1.9",
888
770
  /** @public */
889
- requires: ["gitlab", "coding"]
771
+ requires: ["gitlab", "coding", "git-ssh"]
890
772
  };
891
773
  function createGitLabRepoChange(options) {
892
774
  if (typeof options.docker !== "boolean") throw new Error("docker must be a boolean");
@@ -898,9 +780,12 @@ function createGitLabRepoChange(options) {
898
780
  api.registerProcess(process);
899
781
  },
900
782
  setupServer(api) {
783
+ registerGitLabRepoChangeMaintenance(api, process);
901
784
  const integration = api.require(gitlabIntegration);
902
785
  if (Array.isArray(integration)) throw new Error("GitLab integration must be singular");
903
- launcher.configure(integration);
786
+ const ssh = api.require(gitSshIntegration);
787
+ if (Array.isArray(ssh)) throw new Error("Git SSH integration must be singular");
788
+ launcher.configure(integration, ssh);
904
789
  api.onStop(() => launcher.configure(null));
905
790
  }
906
791
  };
@@ -929,6 +814,7 @@ export {
929
814
  gitlabPublicationEvidence,
930
815
  gitlabRepoChangeParamsCodec,
931
816
  gitlabRepoChangeProcess,
932
- manifest
817
+ manifest,
818
+ registerGitLabRepoChangeMaintenance
933
819
  };
934
820
  //# sourceMappingURL=index.js.map