@leitwerk-dev/gitlab-repo-change 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.
- package/README.md +65 -20
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +104 -218
- package/dist/index.js.map +1 -1
- package/dist/launcher.d.ts +4 -1
- package/dist/launcher.d.ts.map +1 -1
- package/dist/params.d.ts +2 -0
- package/dist/params.d.ts.map +1 -1
- package/dist/process.d.ts +4 -1
- package/dist/process.d.ts.map +1 -1
- package/package.json +10 -7
- package/process.mmd +43 -0
- package/src/index.ts +15 -3
- package/src/launcher.ts +82 -46
- package/src/params.ts +10 -0
- package/src/process.ts +33 -177
package/README.md
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
# GitLab repository change
|
|
2
2
|
|
|
3
|
-
`@leitwerk-dev/gitlab-repo-change` plans, implements,
|
|
4
|
-
repository change as a new GitLab merge request. Load `gitlab`, `coding`,
|
|
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
|
|
9
|
-
identity, and targets the default branch. Replaying a UI
|
|
10
|
-
work branch.
|
|
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
|
|
15
|
-
|
|
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,32 @@ 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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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.
|
|
68
|
+
|
|
69
|
+
Deliver executes for initial publication and adjustment verification. Preparing
|
|
70
|
+
MRs, CI, target-head and label updates refresh durable observations without worker
|
|
71
|
+
allocation or turn records. A no-change repair returns through Deliver to check
|
|
72
|
+
concurrent source updates and retained local work before acknowledging feedback.
|
|
73
|
+
Developer pushes and rebases use the
|
|
74
|
+
[shared reconciliation contract](../coding/README.md#source-branch-reconciliation).
|
|
75
|
+
The workflow retains ten business
|
|
76
|
+
turns; maintenance adds none.
|
|
77
|
+
|
|
78
|
+
Published MRs receive `leitwerk-active`, retained while CI is green and later
|
|
79
|
+
feedback is awaited. Merge replaces it with `leitwerk-done`. Removing active aborts
|
|
80
|
+
this single-MR process and leaves the MR open. Running work and operator waits are
|
|
81
|
+
monitored; publication, replies, reactions and late worker outcomes are fenced after
|
|
82
|
+
removal. A remove/re-add pair ends the old activation. Restart adopts live bindings
|
|
83
|
+
and receipts while preserving cursors, budgets and history. Label-read failures retry
|
|
84
|
+
without cancellation. Closure and stopping do not add done.
|
|
60
85
|
|
|
61
86
|
Merge completes delivery. Unmerged closure aborts it. A source issue loses its
|
|
62
87
|
trigger, gains the done label, receives a comment, and closes after merge. Unmerged
|
|
@@ -68,6 +93,26 @@ precedence. UI-origin processes never require a source issue.
|
|
|
68
93
|
|
|
69
94
|
The default extension requires Docker. Trusted local compositions can use
|
|
70
95
|
`createGitLabRepoChange({ docker: false })`; load exactly one variant. Both retain
|
|
71
|
-
`gitlab_repo_change_process`.
|
|
72
|
-
|
|
73
|
-
|
|
96
|
+
`gitlab_repo_change_process`. GitLab API tokens remain server-side. Git SSH
|
|
97
|
+
credential delivery is repository-scoped. Automatic merging, existing-MR adoption,
|
|
98
|
+
fork publication, and release delivery are not provided.
|
|
99
|
+
|
|
100
|
+
## Shared workflow
|
|
101
|
+
|
|
102
|
+
This process uses the [ten-turn workflow](../jira-gitlab-change/README.md#workflow)
|
|
103
|
+
from `coding`. Plan decisions offer approval or revisions with human comments.
|
|
104
|
+
Implementation, simplification analysis, simplification application, commit-message
|
|
105
|
+
generation, and publication then proceed automatically. The simplification analysis
|
|
106
|
+
covers staged, unstaged, and untracked changes and hands durable findings to the
|
|
107
|
+
separate application turn. Both turns run once before first publication.
|
|
108
|
+
|
|
109
|
+
For issue launches, `leitwerk-skip-simplification` is read immediately after
|
|
110
|
+
implementation. UI launches use the checkbox. A failed source lookup pauses for
|
|
111
|
+
retry; recovery reuses completed routing decisions. Later labels do not interrupt
|
|
112
|
+
simplification that already started. GitLab source issues do not use the Jira
|
|
113
|
+
plan-bypass label. Neither skip label replaces the watcher launch trigger.
|
|
114
|
+
|
|
115
|
+
Before deployment, finish or abort active instances using the removed plan-review,
|
|
116
|
+
implementation-review, implementation-approval, or simplification-approval turns.
|
|
117
|
+
Their history must be retained. GitHub and Forgejo use the same workflow and
|
|
118
|
+
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>>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
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
|
|
421
|
-
if (
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
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
|
-
|
|
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
|
|
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.
|
|
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
|
-
{
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
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
|
-
|
|
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: (
|
|
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
|
|
759
|
-
|
|
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
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
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
|
-
|
|
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
|