@leitwerk-dev/gitlab-repo-change 0.0.0-bootstrap.0 → 0.3.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 +73 -1
- package/dist/LICENSE +13 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +934 -0
- package/dist/index.js.map +1 -0
- package/dist/launcher.d.ts +15 -0
- package/dist/launcher.d.ts.map +1 -0
- package/dist/params.d.ts +17 -0
- package/dist/params.d.ts.map +1 -0
- package/dist/process.d.ts +10 -0
- package/dist/process.d.ts.map +1 -0
- package/package.json +49 -14
- package/src/index.ts +55 -0
- package/src/launcher.ts +240 -0
- package/src/params.ts +70 -0
- package/src/process.ts +249 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type GitLabIntegration, type GitLabIssueWatcherEvent } from "@leitwerk-dev/gitlab";
|
|
2
|
+
import { type LaunchPreparationCheck, type ProcessLaunchConfig, type ProcessLauncherDefinition } from "@leitwerk-dev/process-sdk";
|
|
3
|
+
import type { GitLabRepoChangeParams } from "./params.js";
|
|
4
|
+
/** @public */
|
|
5
|
+
export declare function createGitLabRepoChangeLauncher(): {
|
|
6
|
+
/** @public */
|
|
7
|
+
configure: (value: GitLabIntegration | null) => void;
|
|
8
|
+
/** @public */
|
|
9
|
+
launcher: ProcessLauncherDefinition<GitLabRepoChangeParams>;
|
|
10
|
+
/** @public */
|
|
11
|
+
preparationChecks: (_input: unknown, { params }: ProcessLaunchConfig<GitLabRepoChangeParams>) => readonly LaunchPreparationCheck<GitLabRepoChangeParams>[];
|
|
12
|
+
/** @public */
|
|
13
|
+
fromIssue(event: GitLabIssueWatcherEvent): Promise<ProcessLaunchConfig<GitLabRepoChangeParams>>;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=launcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launcher.d.ts","sourceRoot":"","sources":["../src/launcher.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAG5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAE9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC1D,cAAc;AACd,wBAAgB,8BAA8B;IA+M5C,cAAc;uBAzMW,iBAAiB,GAAG,IAAI;IA2MjD,cAAc;;IAEd,cAAc;gCAzHN,OAAO,cACH,mBAAmB,CAAC,sBAAsB,CAAC,KACrD,SAAS,sBAAsB,CAAC,sBAAsB,CAAC,EAAE;IAyH3D,cAAc;qBACS,uBAAuB;EAS/C"}
|
package/dist/params.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type RepositoryChangeLaunchParams, type RepositoryIssueOriginParams, type RepositoryUiOriginParams } from "@leitwerk-dev/coding/repository-change-launch";
|
|
2
|
+
/** @public */
|
|
3
|
+
export type GitLabRepoChangeParams = RepositoryChangeLaunchParams<{
|
|
4
|
+
/** @public */
|
|
5
|
+
gitlabProfile: string;
|
|
6
|
+
/** @public */
|
|
7
|
+
gitlabOrigin: string;
|
|
8
|
+
/** @public */
|
|
9
|
+
projectId: number;
|
|
10
|
+
/** @public */
|
|
11
|
+
owner: string;
|
|
12
|
+
/** @public */
|
|
13
|
+
repo: string;
|
|
14
|
+
} & (RepositoryUiOriginParams | RepositoryIssueOriginParams)>;
|
|
15
|
+
/** @public */
|
|
16
|
+
export declare const gitlabRepoChangeParamsCodec: import("@leitwerk-dev/process-sdk").Codec<GitLabRepoChangeParams>;
|
|
17
|
+
//# sourceMappingURL=params.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../src/params.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,4BAA4B,EACjC,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,EAE7B,MAAM,+CAA+C,CAAC;AAEvD,cAAc;AACd,MAAM,MAAM,sBAAsB,GAAG,4BAA4B,CAChE;IACC,cAAc;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc;IACd,KAAK,EAAE,MAAM,CAAC;IACd,cAAc;IACd,IAAI,EAAE,MAAM,CAAC;CACb,GAAG,CAAC,wBAAwB,GAAG,2BAA2B,CAAC,CAC5D,CAAC;AACF,cAAc;AACd,eAAO,MAAM,2BAA2B,mEA4CrC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type PublicationEvidence } from "@leitwerk-dev/coding/repository-change-publication";
|
|
2
|
+
import type { RepositoryChangeState } from "@leitwerk-dev/coding/repository-change-state";
|
|
3
|
+
import { type GitLabDeliveryObservation } from "@leitwerk-dev/gitlab";
|
|
4
|
+
import type { createGitLabRepoChangeLauncher } from "./launcher.js";
|
|
5
|
+
import { type GitLabRepoChangeParams } from "./params.js";
|
|
6
|
+
/** @public */
|
|
7
|
+
export declare function gitlabPublicationEvidence(state: RepositoryChangeState, event: GitLabDeliveryObservation): PublicationEvidence;
|
|
8
|
+
/** @public */
|
|
9
|
+
export declare function createGitLabRepoChangeProcess(launcher: ReturnType<typeof createGitLabRepoChangeLauncher>, docker: boolean): import("@leitwerk-dev/process-sdk").ExtensionProcessDefinition<GitLabRepoChangeParams, RepositoryChangeState>;
|
|
10
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../src/process.ts"],"names":[],"mappings":"AACA,OAAO,EAIN,KAAK,mBAAmB,EAIxB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAC1F,OAAO,EACN,KAAK,yBAAyB,EAK9B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,KAAK,sBAAsB,EAA+B,MAAM,aAAa,CAAC;AAmBvF,cAAc;AACd,wBAAgB,yBAAyB,CACxC,KAAK,EAAE,qBAAqB,EAC5B,KAAK,EAAE,yBAAyB,GAC9B,mBAAmB,CAuBrB;AACD,cAAc;AACd,wBAAgB,6BAA6B,CAC5C,QAAQ,EAAE,UAAU,CAAC,OAAO,8BAA8B,CAAC,EAC3D,MAAM,EAAE,OAAO,iHAmLf"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,51 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
"name": "@leitwerk-dev/gitlab-repo-change",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"leitwerk": {
|
|
6
|
+
"extension": {
|
|
7
|
+
"source": "./src/index.ts",
|
|
8
|
+
"import": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"discover": false
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"source": "./src/index.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup && tsc -p tsconfig.tsup.json --emitDeclarationOnly"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@leitwerk-dev/coding": "0.3.1",
|
|
24
|
+
"@leitwerk-dev/external-writes": "0.3.1",
|
|
25
|
+
"@leitwerk-dev/process-sdk": "0.3.1",
|
|
26
|
+
"@leitwerk-dev/gitlab": "0.3.1"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"tsup": "^8.5.1"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/leitwerk-dev/leitwerk.git",
|
|
34
|
+
"directory": "extensions/gitlab-repo-change"
|
|
35
|
+
},
|
|
36
|
+
"license": "Apache-2.0",
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=26 <27"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist/**",
|
|
45
|
+
"src/**",
|
|
46
|
+
"!dist/**/*.test.*",
|
|
47
|
+
"!src/**/*.test.ts",
|
|
48
|
+
"!src/testing/**",
|
|
49
|
+
"!dist/testing/**"
|
|
50
|
+
]
|
|
16
51
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { gitlabIntegration } from "@leitwerk-dev/gitlab";
|
|
2
|
+
import type { LeitwerkExtensionModule } from "@leitwerk-dev/process-sdk";
|
|
3
|
+
import { createGitLabRepoChangeLauncher } from "./launcher.js";
|
|
4
|
+
import { createGitLabRepoChangeProcess } from "./process.js";
|
|
5
|
+
/** @public */
|
|
6
|
+
export const manifest = {
|
|
7
|
+
/** @public */
|
|
8
|
+
id: "gitlab-repo-change",
|
|
9
|
+
/** @public */
|
|
10
|
+
version: "0.1.9",
|
|
11
|
+
/** @public */
|
|
12
|
+
requires: ["gitlab", "coding"],
|
|
13
|
+
} as const;
|
|
14
|
+
/** @public */
|
|
15
|
+
/** @public */
|
|
16
|
+
export function createGitLabRepoChange(options: {
|
|
17
|
+
/** @public */
|
|
18
|
+
docker: boolean;
|
|
19
|
+
}) {
|
|
20
|
+
if (typeof options.docker !== "boolean") throw new Error("docker must be a boolean");
|
|
21
|
+
const launcher = createGitLabRepoChangeLauncher();
|
|
22
|
+
const process = createGitLabRepoChangeProcess(launcher, options.docker);
|
|
23
|
+
const extension: LeitwerkExtensionModule = {
|
|
24
|
+
manifest,
|
|
25
|
+
setupCatalog(api) {
|
|
26
|
+
api.registerProcess(process);
|
|
27
|
+
},
|
|
28
|
+
setupServer(api) {
|
|
29
|
+
const integration = api.require(gitlabIntegration);
|
|
30
|
+
if (Array.isArray(integration)) throw new Error("GitLab integration must be singular");
|
|
31
|
+
launcher.configure(integration);
|
|
32
|
+
api.onStop(() => launcher.configure(null));
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
/** @public */
|
|
36
|
+
/** @public */
|
|
37
|
+
return {
|
|
38
|
+
/** @public */
|
|
39
|
+
extension,
|
|
40
|
+
/** @public */
|
|
41
|
+
process,
|
|
42
|
+
/** @public */
|
|
43
|
+
launcher,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** @public */
|
|
47
|
+
export const {
|
|
48
|
+
extension: defaultExtension,
|
|
49
|
+
process: gitlabRepoChangeProcess,
|
|
50
|
+
launcher: defaultGitLabRepoChangeLauncher,
|
|
51
|
+
} = createGitLabRepoChange({ docker: true });
|
|
52
|
+
export * from "./launcher.js";
|
|
53
|
+
export * from "./params.js";
|
|
54
|
+
export * from "./process.js";
|
|
55
|
+
export default defaultExtension;
|
package/src/launcher.ts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { buildAutoWorkBranchFromSeed } from "@leitwerk-dev/coding/auto-work-branch";
|
|
2
|
+
import { trimString } from "@leitwerk-dev/domain";
|
|
3
|
+
import {
|
|
4
|
+
type GitLabIntegration,
|
|
5
|
+
type GitLabIssueWatcherEvent,
|
|
6
|
+
type GitLabProject,
|
|
7
|
+
gitlabIssueExternalId,
|
|
8
|
+
} from "@leitwerk-dev/gitlab";
|
|
9
|
+
import {
|
|
10
|
+
type LaunchPreparationCheck,
|
|
11
|
+
type ProcessLaunchConfig,
|
|
12
|
+
type ProcessLauncherDefinition,
|
|
13
|
+
SafeLaunchPreparationError,
|
|
14
|
+
} from "@leitwerk-dev/process-sdk";
|
|
15
|
+
import type { GitLabRepoChangeParams } from "./params.js";
|
|
16
|
+
/** @public */
|
|
17
|
+
export function createGitLabRepoChangeLauncher() {
|
|
18
|
+
let integration: GitLabIntegration | null = null;
|
|
19
|
+
const requireIntegration = () => {
|
|
20
|
+
if (!integration) throw new Error("GitLab repository launcher is not configured");
|
|
21
|
+
return integration;
|
|
22
|
+
};
|
|
23
|
+
const configure = (value: GitLabIntegration | null) => {
|
|
24
|
+
integration = value;
|
|
25
|
+
};
|
|
26
|
+
async function launch(
|
|
27
|
+
repository: GitLabProject,
|
|
28
|
+
profile: string,
|
|
29
|
+
prompt: string,
|
|
30
|
+
issue?: GitLabIssueWatcherEvent,
|
|
31
|
+
): Promise<ProcessLaunchConfig<GitLabRepoChangeParams>> {
|
|
32
|
+
const service = requireIntegration();
|
|
33
|
+
if (!service.profiles().includes(profile)) throw new Error("GitLab profile is unavailable");
|
|
34
|
+
const client = service.client(profile);
|
|
35
|
+
const split = repository.path_with_namespace.lastIndexOf("/");
|
|
36
|
+
if (split < 1) throw new Error("Invalid GitLab project path");
|
|
37
|
+
const common = {
|
|
38
|
+
gitlabProfile: profile,
|
|
39
|
+
gitlabOrigin: client.baseUrl,
|
|
40
|
+
projectId: repository.id,
|
|
41
|
+
owner: repository.path_with_namespace.slice(0, split),
|
|
42
|
+
repo: repository.path_with_namespace.slice(split + 1),
|
|
43
|
+
repoLocator: repository.http_url_to_repo,
|
|
44
|
+
baseBranch: repository.default_branch,
|
|
45
|
+
workBranch: issue
|
|
46
|
+
? `leitwerk/issue-${issue.issue.iid}`
|
|
47
|
+
: buildAutoWorkBranchFromSeed(
|
|
48
|
+
prompt,
|
|
49
|
+
`${repository.http_url_to_repo}:${repository.default_branch}`,
|
|
50
|
+
),
|
|
51
|
+
prompt,
|
|
52
|
+
};
|
|
53
|
+
const params: GitLabRepoChangeParams = issue
|
|
54
|
+
? {
|
|
55
|
+
...common,
|
|
56
|
+
origin: "issue",
|
|
57
|
+
issueNumber: issue.issue.iid,
|
|
58
|
+
issueUrl: issue.issue.web_url,
|
|
59
|
+
triggerLabel: issue.labels.trigger,
|
|
60
|
+
doneLabel: issue.labels.done,
|
|
61
|
+
}
|
|
62
|
+
: {
|
|
63
|
+
...common,
|
|
64
|
+
origin: "ui",
|
|
65
|
+
issueNumber: null,
|
|
66
|
+
issueUrl: null,
|
|
67
|
+
triggerLabel: null,
|
|
68
|
+
doneLabel: null,
|
|
69
|
+
};
|
|
70
|
+
const identity = await client.resolveGitIdentity();
|
|
71
|
+
return {
|
|
72
|
+
processId: "gitlab_repo_change_process",
|
|
73
|
+
title: issue?.issue.title ?? prompt,
|
|
74
|
+
params,
|
|
75
|
+
startTurnId: "generate_plan",
|
|
76
|
+
...(issue
|
|
77
|
+
? {
|
|
78
|
+
externalId: gitlabIssueExternalId(client.baseUrl, repository.id, issue.issue.iid),
|
|
79
|
+
externalUrl: issue.issue.web_url,
|
|
80
|
+
}
|
|
81
|
+
: {}),
|
|
82
|
+
projects: [
|
|
83
|
+
{
|
|
84
|
+
key: "repo",
|
|
85
|
+
repoLocator: params.repoLocator,
|
|
86
|
+
baseBranch: params.baseBranch,
|
|
87
|
+
workBranch: params.workBranch,
|
|
88
|
+
metadata: {
|
|
89
|
+
gitlab: {
|
|
90
|
+
profile,
|
|
91
|
+
projectId: repository.id,
|
|
92
|
+
...(issue ? { issueIid: issue.issue.iid } : {}),
|
|
93
|
+
},
|
|
94
|
+
"leitwerk.gitIdentity": {
|
|
95
|
+
provider: "gitlab",
|
|
96
|
+
profile,
|
|
97
|
+
login: identity.username,
|
|
98
|
+
name: identity.name,
|
|
99
|
+
email: identity.email,
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const preparationChecks = (
|
|
107
|
+
_input: unknown,
|
|
108
|
+
{ params }: ProcessLaunchConfig<GitLabRepoChangeParams>,
|
|
109
|
+
): readonly LaunchPreparationCheck<GitLabRepoChangeParams>[] => [
|
|
110
|
+
{
|
|
111
|
+
id: "gitlab_repository_access",
|
|
112
|
+
label: "Verify GitLab repository and HTTPS read/write access",
|
|
113
|
+
async run({ signal }) {
|
|
114
|
+
const client = requireIntegration().client(params.gitlabProfile);
|
|
115
|
+
const repository = await client.getProject(params.projectId, signal);
|
|
116
|
+
if (
|
|
117
|
+
repository.archived ||
|
|
118
|
+
repository.http_url_to_repo !== params.repoLocator ||
|
|
119
|
+
repository.default_branch !== params.baseBranch
|
|
120
|
+
)
|
|
121
|
+
throw new SafeLaunchPreparationError(
|
|
122
|
+
"Repository changed or is archived",
|
|
123
|
+
"Select an active GitLab project and launch again.",
|
|
124
|
+
);
|
|
125
|
+
await client.preflightRepository(
|
|
126
|
+
params.projectId,
|
|
127
|
+
params.baseBranch,
|
|
128
|
+
params.workBranch,
|
|
129
|
+
signal,
|
|
130
|
+
);
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
];
|
|
134
|
+
const launcher: ProcessLauncherDefinition<GitLabRepoChangeParams> = {
|
|
135
|
+
id: "gitlab_repo_change_process.ui_launcher",
|
|
136
|
+
label: "GitLab Repo Change",
|
|
137
|
+
description: "Plan, implement, review, and publish a GitLab merge request",
|
|
138
|
+
visibility: "ui",
|
|
139
|
+
ui: {
|
|
140
|
+
card: {
|
|
141
|
+
title: "GitLab Repo Change",
|
|
142
|
+
description: "Start a repository change and publish a merge request.",
|
|
143
|
+
},
|
|
144
|
+
launchConfigSchema: {
|
|
145
|
+
id: "gitlab_repo_change_form",
|
|
146
|
+
title: "GitLab Repo Change",
|
|
147
|
+
fields: [
|
|
148
|
+
{ id: "gitlabProfile", label: "GitLab profile", kind: "select", required: true },
|
|
149
|
+
{ id: "repository", label: "Project", kind: "select", required: true },
|
|
150
|
+
{ id: "prompt", label: "Requested change", kind: "textarea", required: true },
|
|
151
|
+
],
|
|
152
|
+
submitLabel: "Start change",
|
|
153
|
+
},
|
|
154
|
+
resolveDefaults() {
|
|
155
|
+
return {
|
|
156
|
+
gitlabProfile: requireIntegration().profiles()[0] ?? "",
|
|
157
|
+
repository: "",
|
|
158
|
+
prompt: "",
|
|
159
|
+
};
|
|
160
|
+
},
|
|
161
|
+
async resolveOptions(input) {
|
|
162
|
+
const i = requireIntegration();
|
|
163
|
+
const profile = trimString(input.gitlabProfile);
|
|
164
|
+
return {
|
|
165
|
+
gitlabProfile: i.profiles().map((value) => ({ value, label: value })),
|
|
166
|
+
repository: (i.profiles().includes(profile) ? await i.client(profile).listProjects() : [])
|
|
167
|
+
.filter((p) => !p.archived && p.default_branch)
|
|
168
|
+
.map((p) => ({
|
|
169
|
+
value: String(p.id),
|
|
170
|
+
label: p.path_with_namespace,
|
|
171
|
+
description: p.web_url,
|
|
172
|
+
})),
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
preparationChecks,
|
|
176
|
+
resolveRelaunchInput(input) {
|
|
177
|
+
return {
|
|
178
|
+
gitlabProfile: trimString(input.gitlabProfile),
|
|
179
|
+
repository: trimString(input.repository),
|
|
180
|
+
prompt: trimString(input.prompt),
|
|
181
|
+
};
|
|
182
|
+
},
|
|
183
|
+
async resolveLaunchConfig(input) {
|
|
184
|
+
const profile = trimString(input.gitlabProfile);
|
|
185
|
+
const projectId = Number(input.repository);
|
|
186
|
+
const prompt = trimString(input.prompt);
|
|
187
|
+
const errors = [];
|
|
188
|
+
if (!requireIntegration().profiles().includes(profile))
|
|
189
|
+
errors.push({
|
|
190
|
+
fieldId: "gitlabProfile",
|
|
191
|
+
message: "Select an available GitLab profile",
|
|
192
|
+
code: "custom_rule" as const,
|
|
193
|
+
});
|
|
194
|
+
if (!Number.isSafeInteger(projectId) || projectId <= 0)
|
|
195
|
+
errors.push({
|
|
196
|
+
fieldId: "repository",
|
|
197
|
+
message: "Select a project",
|
|
198
|
+
code: "required" as const,
|
|
199
|
+
});
|
|
200
|
+
if (!prompt)
|
|
201
|
+
errors.push({
|
|
202
|
+
fieldId: "prompt",
|
|
203
|
+
message: "Describe the requested change",
|
|
204
|
+
code: "required" as const,
|
|
205
|
+
});
|
|
206
|
+
if (errors.length) return { ok: false, errors };
|
|
207
|
+
const repository = await requireIntegration().client(profile).getProject(projectId);
|
|
208
|
+
if (repository.archived || !repository.default_branch)
|
|
209
|
+
return {
|
|
210
|
+
ok: false,
|
|
211
|
+
errors: [
|
|
212
|
+
{
|
|
213
|
+
fieldId: "repository",
|
|
214
|
+
message: "Project is archived or has no default branch",
|
|
215
|
+
code: "custom_rule",
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
};
|
|
219
|
+
return { ok: true, launchConfig: await launch(repository, profile, prompt) };
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
return {
|
|
224
|
+
/** @public */
|
|
225
|
+
configure,
|
|
226
|
+
/** @public */
|
|
227
|
+
launcher,
|
|
228
|
+
/** @public */
|
|
229
|
+
preparationChecks,
|
|
230
|
+
/** @public */
|
|
231
|
+
async fromIssue(event: GitLabIssueWatcherEvent) {
|
|
232
|
+
return launch(
|
|
233
|
+
event.repository,
|
|
234
|
+
event.profile,
|
|
235
|
+
`${event.issue.title}${event.issue.description ? `\n\n${event.issue.description}` : ""}`,
|
|
236
|
+
event,
|
|
237
|
+
);
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
package/src/params.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createRepositoryChangeParamsCodec,
|
|
3
|
+
normalizeRepositoryChangeParamsInput,
|
|
4
|
+
type RepositoryChangeLaunchParams,
|
|
5
|
+
type RepositoryIssueOriginParams,
|
|
6
|
+
type RepositoryUiOriginParams,
|
|
7
|
+
repositoryChangeParamsRecord,
|
|
8
|
+
} from "@leitwerk-dev/coding/repository-change-launch";
|
|
9
|
+
import { trimString } from "@leitwerk-dev/domain";
|
|
10
|
+
/** @public */
|
|
11
|
+
export type GitLabRepoChangeParams = RepositoryChangeLaunchParams<
|
|
12
|
+
{
|
|
13
|
+
/** @public */
|
|
14
|
+
gitlabProfile: string;
|
|
15
|
+
/** @public */
|
|
16
|
+
gitlabOrigin: string;
|
|
17
|
+
/** @public */
|
|
18
|
+
projectId: number;
|
|
19
|
+
/** @public */
|
|
20
|
+
owner: string;
|
|
21
|
+
/** @public */
|
|
22
|
+
repo: string;
|
|
23
|
+
} & (RepositoryUiOriginParams | RepositoryIssueOriginParams)
|
|
24
|
+
>;
|
|
25
|
+
/** @public */
|
|
26
|
+
export const gitlabRepoChangeParamsCodec =
|
|
27
|
+
createRepositoryChangeParamsCodec<GitLabRepoChangeParams>({
|
|
28
|
+
normalize(value) {
|
|
29
|
+
const r = repositoryChangeParamsRecord(value, "GitLab Repo Change");
|
|
30
|
+
const text = (key: string) => {
|
|
31
|
+
const v = trimString(r[key]);
|
|
32
|
+
if (!v) throw new Error(`GitLab Repo Change requires ${key}`);
|
|
33
|
+
return v;
|
|
34
|
+
};
|
|
35
|
+
if (typeof r.projectId !== "number" || !Number.isSafeInteger(r.projectId) || r.projectId <= 0)
|
|
36
|
+
throw new Error("GitLab Repo Change requires projectId");
|
|
37
|
+
const common = {
|
|
38
|
+
...normalizeRepositoryChangeParamsInput(value, "GitLab Repo Change"),
|
|
39
|
+
gitlabProfile: text("gitlabProfile"),
|
|
40
|
+
gitlabOrigin: text("gitlabOrigin"),
|
|
41
|
+
projectId: r.projectId,
|
|
42
|
+
owner: text("owner"),
|
|
43
|
+
repo: text("repo"),
|
|
44
|
+
};
|
|
45
|
+
if (r.origin === "ui")
|
|
46
|
+
return {
|
|
47
|
+
...common,
|
|
48
|
+
origin: "ui",
|
|
49
|
+
issueNumber: null,
|
|
50
|
+
issueUrl: null,
|
|
51
|
+
triggerLabel: null,
|
|
52
|
+
doneLabel: null,
|
|
53
|
+
};
|
|
54
|
+
if (
|
|
55
|
+
r.origin !== "issue" ||
|
|
56
|
+
typeof r.issueNumber !== "number" ||
|
|
57
|
+
!Number.isSafeInteger(r.issueNumber) ||
|
|
58
|
+
r.issueNumber <= 0
|
|
59
|
+
)
|
|
60
|
+
throw new Error("GitLab Repo Change requires a valid origin and issueNumber");
|
|
61
|
+
return {
|
|
62
|
+
...common,
|
|
63
|
+
origin: "issue",
|
|
64
|
+
issueNumber: r.issueNumber,
|
|
65
|
+
issueUrl: text("issueUrl"),
|
|
66
|
+
triggerLabel: text("triggerLabel"),
|
|
67
|
+
doneLabel: text("doneLabel"),
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
});
|