@leitwerk-dev/forgejo-repo-change 0.0.0-bootstrap.0 → 0.2.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.
@@ -0,0 +1,48 @@
1
+ import type { ForgejoGitIdentity, ForgejoIntegration, ForgejoRepository } from "@leitwerk-dev/forgejo";
2
+ import type { GitSshIntegration } from "@leitwerk-dev/git-ssh";
3
+ import { type LaunchPreparationCheck, type ProcessLaunchConfig, type ProcessLauncherDefinition } from "@leitwerk-dev/process-sdk";
4
+ import type { WoodpeckerIntegration } from "@leitwerk-dev/woodpecker";
5
+ import { type ForgejoRepoChangeParams } from "./params.js";
6
+ import { type ProfileBindings } from "./profile-bindings.js";
7
+ /** @internal */
8
+ export declare const forgejoRepoChangeUiLauncherId: "forgejo_repo_change_process.ui_launcher";
9
+ /** @internal */
10
+ export declare function forgejoRepoChangeParams(repository: ForgejoRepository, input: {
11
+ /** @internal */
12
+ profile: string;
13
+ /** @internal */
14
+ woodpeckerProfile: string;
15
+ /** @internal */
16
+ sshCredentialRef: string;
17
+ /** @internal */
18
+ prompt: string;
19
+ /** @internal */
20
+ workBranch: string;
21
+ }): ForgejoRepoChangeParams;
22
+ /** @internal */
23
+ export declare function forgejoRepoChangeLaunchConfig(params: ForgejoRepoChangeParams, title: string, gitIdentity: ForgejoGitIdentity): ProcessLaunchConfig<ForgejoRepoChangeParams>;
24
+ /** @internal */
25
+ export interface LauncherDependencies {
26
+ /** @internal */
27
+ forgejo: ForgejoIntegration;
28
+ /** @internal */
29
+ gitSsh: GitSshIntegration;
30
+ /** @internal */
31
+ woodpecker: WoodpeckerIntegration;
32
+ /** @internal */
33
+ profileBindings?: ProfileBindings;
34
+ }
35
+ /** @internal */
36
+ export declare function createForgejoRepoChangeLauncher(): {
37
+ /** @internal */
38
+ configure: (value: LauncherDependencies | null) => void;
39
+ /** @internal */
40
+ preparationChecks: (_input: unknown, { params }: ProcessLaunchConfig<ForgejoRepoChangeParams>) => readonly LaunchPreparationCheck<ForgejoRepoChangeParams>[];
41
+ /** @internal */
42
+ resolveProfiles: (profile: string) => import("./profile-bindings.js").ProfileBinding;
43
+ /** @internal */
44
+ resolveGitIdentity: (profile: string) => Promise<ForgejoGitIdentity>;
45
+ /** @internal */
46
+ launcher: ProcessLauncherDefinition<ForgejoRepoChangeParams>;
47
+ };
48
+ //# sourceMappingURL=launcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launcher.d.ts","sourceRoot":"","sources":["../src/launcher.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAEN,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAE9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,KAAK,uBAAuB,EAAiB,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,KAAK,eAAe,EAAyB,MAAM,uBAAuB,CAAC;AAEpF,gBAAgB;AAChB,eAAO,MAAM,6BAA6B,EAAG,yCAAkD,CAAC;AAEhG,gBAAgB;AAChB,wBAAgB,uBAAuB,CACtC,UAAU,EAAE,iBAAiB,EAC7B,KAAK,EAAE;IACN,gBAAgB;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB;IAChB,UAAU,EAAE,MAAM,CAAC;CACnB,GACC,uBAAuB,CAkBzB;AAED,gBAAgB;AAChB,wBAAgB,6BAA6B,CAC5C,MAAM,EAAE,uBAAuB,EAC/B,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,kBAAkB,GAC7B,mBAAmB,CAAC,uBAAuB,CAAC,CA6B9C;AAED,gBAAgB;AAChB,MAAM,WAAW,oBAAoB;IACpC,gBAAgB;IAChB,OAAO,EAAE,kBAAkB,CAAC;IAC5B,gBAAgB;IAChB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,gBAAgB;IAChB,UAAU,EAAE,qBAAqB,CAAC;IAClC,gBAAgB;IAChB,eAAe,CAAC,EAAE,eAAe,CAAC;CAClC;AAED,gBAAgB;AAChB,wBAAgB,+BAA+B;IAgO7C,gBAAgB;uBA5NkC,oBAAoB,GAAG,IAAI,KAAG,IAAI;IA8NpF,gBAAgB;gCAxLR,OAAO,cACH,mBAAmB,CAAC,uBAAuB,CAAC,KACtD,SAAS,sBAAsB,CAAC,uBAAuB,CAAC,EAAE;IAwL5D,gBAAgB;+BAtJiB,MAAM;IAwJvC,gBAAgB;kCAzIiC,MAAM,KAAG,OAAO,CAAC,kBAAkB,CAAC;IA2IrF,gBAAgB;;EAGjB"}
@@ -0,0 +1,48 @@
1
+ import { type RepositoryChangeLaunchParams } from "@leitwerk-dev/coding/repository-change-launch";
2
+ /** @public */
3
+ interface ForgejoRepoChangeCommonParams {
4
+ /** @internal */
5
+ forgejoProfile: string;
6
+ /** @internal */
7
+ woodpeckerProfile: string;
8
+ /** @internal */
9
+ sshCredentialRef: string;
10
+ /** @internal */
11
+ owner: string;
12
+ /** @internal */
13
+ repo: string;
14
+ }
15
+ /** @public */
16
+ export interface ForgejoIssueOriginParams {
17
+ /** @internal */
18
+ origin: "issue";
19
+ /** @internal */
20
+ issueNumber: number;
21
+ /** @internal */
22
+ issueUrl: string;
23
+ /** @internal */
24
+ triggerLabel: string;
25
+ /** @internal */
26
+ doneLabel: string;
27
+ }
28
+ /** @public */
29
+ export interface ForgejoUiOriginParams {
30
+ /** @internal */
31
+ origin: "ui";
32
+ /** @internal */
33
+ issueNumber: null;
34
+ /** @internal */
35
+ issueUrl: null;
36
+ /** @internal */
37
+ triggerLabel: null;
38
+ /** @internal */
39
+ doneLabel: null;
40
+ }
41
+ /** @public */
42
+ export type ForgejoRepoChangeParams = RepositoryChangeLaunchParams<ForgejoRepoChangeCommonParams & (ForgejoIssueOriginParams | ForgejoUiOriginParams)>;
43
+ /** @internal */
44
+ export declare function isIssueOrigin(params: ForgejoRepoChangeParams): params is ForgejoRepoChangeParams & ForgejoIssueOriginParams;
45
+ /** @internal */
46
+ export declare const forgejoRepoChangeParamsCodec: import("@leitwerk-dev/process-sdk").Codec<ForgejoRepoChangeParams>;
47
+ export {};
48
+ //# 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,EAEjC,MAAM,+CAA+C,CAAC;AAGvD,cAAc;AACd,UAAU,6BAA6B;IACtC,gBAAgB;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB;IAChB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,cAAc;AACd,MAAM,WAAW,wBAAwB;IACxC,gBAAgB;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,gBAAgB;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,cAAc;AACd,MAAM,WAAW,qBAAqB;IACrC,gBAAgB;IAChB,MAAM,EAAE,IAAI,CAAC;IACb,gBAAgB;IAChB,WAAW,EAAE,IAAI,CAAC;IAClB,gBAAgB;IAChB,QAAQ,EAAE,IAAI,CAAC;IACf,gBAAgB;IAChB,YAAY,EAAE,IAAI,CAAC;IACnB,gBAAgB;IAChB,SAAS,EAAE,IAAI,CAAC;CAChB;AAED,cAAc;AACd,MAAM,MAAM,uBAAuB,GAAG,4BAA4B,CACjE,6BAA6B,GAAG,CAAC,wBAAwB,GAAG,qBAAqB,CAAC,CAClF,CAAC;AAEF,gBAAgB;AAChB,wBAAgB,aAAa,CAC5B,MAAM,EAAE,uBAAuB,GAC7B,MAAM,IAAI,uBAAuB,GAAG,wBAAwB,CAE9D;AAED,gBAAgB;AAChB,eAAO,MAAM,4BAA4B,oEAkDtC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { RepositoryChangeState } from "@leitwerk-dev/coding/repository-change-state";
2
+ import { type createForgejoRepoChangeLauncher } from "./launcher.js";
3
+ import { type ForgejoRepoChangeParams } from "./params.js";
4
+ /** @internal */
5
+ export declare function createForgejoRepoChangeProcess(launcher: ReturnType<typeof createForgejoRepoChangeLauncher>, docker: boolean): import("@leitwerk-dev/process-sdk").ExtensionProcessDefinition<ForgejoRepoChangeParams, RepositoryChangeState>;
6
+ //# sourceMappingURL=process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../src/process.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAiB1F,OAAO,EACN,KAAK,+BAA+B,EAGpC,MAAM,eAAe,CAAC;AACvB,OAAO,EAEN,KAAK,uBAAuB,EAG5B,MAAM,aAAa,CAAC;AAiNrB,gBAAgB;AAChB,wBAAgB,8BAA8B,CAC7C,QAAQ,EAAE,UAAU,CAAC,OAAO,+BAA+B,CAAC,EAC5D,MAAM,EAAE,OAAO,kHAsgBf"}
@@ -0,0 +1,14 @@
1
+ /** Server-owned, non-secret wiring for future launches. @internal */
2
+ export interface ProfileBinding {
3
+ /** @internal */
4
+ woodpeckerProfile: string;
5
+ /** @internal */
6
+ sshCredentialRef: string;
7
+ }
8
+ /** @internal */
9
+ export type ProfileBindings = Readonly<Record<string, Readonly<ProfileBinding>>>;
10
+ /** @internal */
11
+ export declare function parseProfileBindings(raw: unknown): ProfileBindings;
12
+ /** @internal */
13
+ export declare function resolveProfileBinding(bindings: ProfileBindings, profile: string): ProfileBinding;
14
+ //# sourceMappingURL=profile-bindings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile-bindings.d.ts","sourceRoot":"","sources":["../src/profile-bindings.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,MAAM,WAAW,cAAc;IAC9B,gBAAgB;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB;IAChB,gBAAgB,EAAE,MAAM,CAAC;CACzB;AACD,gBAAgB;AAChB,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;AAajF,gBAAgB;AAChB,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,CA8BlE;AACD,gBAAgB;AAChB,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc,CAIhG"}
package/package.json CHANGED
@@ -1,16 +1,54 @@
1
1
  {
2
- "name": "@leitwerk-dev/forgejo-repo-change",
3
- "version": "0.0.0-bootstrap.0",
4
- "description": "Registration placeholder only. Not a usable Leitwerk release.",
5
- "license": "Apache-2.0",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/leitwerk-dev/leitwerk.git"
9
- },
10
- "publishConfig": {
11
- "access": "public",
12
- "registry": "https://registry.npmjs.org/",
13
- "tag": "bootstrap",
14
- "provenance": false
15
- }
2
+ "name": "@leitwerk-dev/forgejo-repo-change",
3
+ "version": "0.2.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.2.1",
24
+ "@leitwerk-dev/external-writes": "0.2.1",
25
+ "@leitwerk-dev/git-ssh": "0.2.1",
26
+ "@leitwerk-dev/process-sdk": "0.2.1",
27
+ "@leitwerk-dev/forgejo": "0.2.1",
28
+ "@leitwerk-dev/woodpecker": "0.2.1",
29
+ "@leitwerk-dev/repository-rebase": "0.2.1"
30
+ },
31
+ "devDependencies": {
32
+ "tsup": "^8.5.1"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/leitwerk-dev/leitwerk.git",
37
+ "directory": "extensions/forgejo-repo-change"
38
+ },
39
+ "license": "Apache-2.0",
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "engines": {
44
+ "node": ">=26 <27"
45
+ },
46
+ "files": [
47
+ "dist/**",
48
+ "src/**",
49
+ "!dist/**/*.test.*",
50
+ "!src/**/*.test.ts",
51
+ "!src/testing/**",
52
+ "!dist/testing/**"
53
+ ]
16
54
  }
package/src/index.ts ADDED
@@ -0,0 +1,64 @@
1
+ import { forgejoIntegration } from "@leitwerk-dev/forgejo";
2
+ import { gitSshIntegration } from "@leitwerk-dev/git-ssh";
3
+ import type { LeitwerkExtensionModule } from "@leitwerk-dev/process-sdk";
4
+ import { woodpeckerIntegration } from "@leitwerk-dev/woodpecker";
5
+ import { createForgejoRepoChangeLauncher } from "./launcher.js";
6
+
7
+ export { forgejoRepoChangeLaunchConfig, forgejoRepoChangeParams } from "./launcher.js";
8
+
9
+ import { createForgejoRepoChangeProcess } from "./process.js";
10
+ import { parseProfileBindings } from "./profile-bindings.js";
11
+
12
+ /** @internal */
13
+ const manifest = {
14
+ /** @internal */
15
+ id: "forgejo-repo-change",
16
+ /** @internal */
17
+ version: "0.1.9",
18
+ /** @internal */
19
+ requires: ["forgejo", "woodpecker", "coding", "git-ssh"],
20
+ } as const;
21
+
22
+ /** Load exactly one variant per catalog. Only trusted composition code selects Docker. @public */
23
+ export function createForgejoRepoChange(options: {
24
+ /** @public */
25
+ docker: boolean;
26
+ }) {
27
+ if (typeof options.docker !== "boolean") throw new Error("docker must be a boolean");
28
+ const launcher = createForgejoRepoChangeLauncher();
29
+ const process = createForgejoRepoChangeProcess(launcher, options.docker);
30
+ const extension: LeitwerkExtensionModule = {
31
+ manifest,
32
+ setupCatalog(api) {
33
+ api.registerProcess(process);
34
+ },
35
+ setupServer(api, config) {
36
+ const forgejo = api.require(forgejoIntegration);
37
+ const gitSsh = api.require(gitSshIntegration);
38
+ const woodpecker = api.require(woodpeckerIntegration);
39
+ if (Array.isArray(forgejo) || Array.isArray(gitSsh) || Array.isArray(woodpecker))
40
+ throw new Error("Repository delivery integrations must be singular");
41
+ launcher.configure({
42
+ forgejo,
43
+ gitSsh,
44
+ woodpecker,
45
+ profileBindings: parseProfileBindings(config),
46
+ });
47
+ api.onStop(() => launcher.configure(null));
48
+ },
49
+ };
50
+ return {
51
+ /** @public */
52
+ extension,
53
+ /** @public */
54
+ process,
55
+ /** @internal */
56
+ launcher,
57
+ };
58
+ }
59
+
60
+ export type { ForgejoRepoChangeParams } from "./params.js";
61
+
62
+ /** @internal */
63
+ const { extension: defaultExtension } = createForgejoRepoChange({ docker: true });
64
+ export default defaultExtension;
@@ -0,0 +1,342 @@
1
+ import { buildAutoWorkBranchFromSeed } from "@leitwerk-dev/coding/auto-work-branch";
2
+ import { trimString } from "@leitwerk-dev/domain";
3
+ import type {
4
+ ForgejoGitIdentity,
5
+ ForgejoIntegration,
6
+ ForgejoRepository,
7
+ } from "@leitwerk-dev/forgejo";
8
+ import type { GitSshIntegration } from "@leitwerk-dev/git-ssh";
9
+ import {
10
+ type LauncherValidationError,
11
+ type LaunchPreparationCheck,
12
+ type ProcessLaunchConfig,
13
+ type ProcessLauncherDefinition,
14
+ SafeLaunchPreparationError,
15
+ } from "@leitwerk-dev/process-sdk";
16
+ import type { WoodpeckerIntegration } from "@leitwerk-dev/woodpecker";
17
+ import { type ForgejoRepoChangeParams, isIssueOrigin } from "./params.js";
18
+ import { type ProfileBindings, resolveProfileBinding } from "./profile-bindings.js";
19
+
20
+ /** @internal */
21
+ export const forgejoRepoChangeUiLauncherId = "forgejo_repo_change_process.ui_launcher" as const;
22
+
23
+ /** @internal */
24
+ export function forgejoRepoChangeParams(
25
+ repository: ForgejoRepository,
26
+ input: {
27
+ /** @internal */
28
+ profile: string;
29
+ /** @internal */
30
+ woodpeckerProfile: string;
31
+ /** @internal */
32
+ sshCredentialRef: string;
33
+ /** @internal */
34
+ prompt: string;
35
+ /** @internal */
36
+ workBranch: string;
37
+ },
38
+ ): ForgejoRepoChangeParams {
39
+ return {
40
+ launchKind: "requested_change",
41
+ repoLocator: repository.ssh_url,
42
+ baseBranch: repository.default_branch,
43
+ workBranch: input.workBranch,
44
+ prompt: input.prompt,
45
+ forgejoProfile: input.profile,
46
+ woodpeckerProfile: input.woodpeckerProfile,
47
+ sshCredentialRef: input.sshCredentialRef,
48
+ owner: repository.owner.login,
49
+ repo: repository.name,
50
+ origin: "ui",
51
+ issueNumber: null,
52
+ issueUrl: null,
53
+ triggerLabel: null,
54
+ doneLabel: null,
55
+ };
56
+ }
57
+
58
+ /** @internal */
59
+ export function forgejoRepoChangeLaunchConfig(
60
+ params: ForgejoRepoChangeParams,
61
+ title: string,
62
+ gitIdentity: ForgejoGitIdentity,
63
+ ): ProcessLaunchConfig<ForgejoRepoChangeParams> {
64
+ const { owner, repo, forgejoProfile: profile, woodpeckerProfile } = params;
65
+ const issue = isIssueOrigin(params);
66
+ return {
67
+ processId: "forgejo_repo_change_process",
68
+ params,
69
+ title,
70
+ startTurnId: "generate_plan",
71
+ ...(issue
72
+ ? {
73
+ externalId: `forgejo:${owner}/${repo}#${params.issueNumber}`,
74
+ externalUrl: params.issueUrl,
75
+ }
76
+ : {}),
77
+ projects: [
78
+ {
79
+ key: "repo",
80
+ repoLocator: params.repoLocator,
81
+ baseBranch: params.baseBranch,
82
+ workBranch: params.workBranch,
83
+ ...(issue ? { externalId: String(params.issueNumber), externalUrl: params.issueUrl } : {}),
84
+ metadata: {
85
+ forgejo: { owner, repo, profile, ...(issue ? { issueNumber: params.issueNumber } : {}) },
86
+ woodpecker: { owner, repo, profile: woodpeckerProfile },
87
+ "leitwerk.gitIdentity": gitIdentity,
88
+ },
89
+ },
90
+ ],
91
+ };
92
+ }
93
+
94
+ /** @internal */
95
+ export interface LauncherDependencies {
96
+ /** @internal */
97
+ forgejo: ForgejoIntegration;
98
+ /** @internal */
99
+ gitSsh: GitSshIntegration;
100
+ /** @internal */
101
+ woodpecker: WoodpeckerIntegration;
102
+ /** @internal */
103
+ profileBindings?: ProfileBindings;
104
+ }
105
+
106
+ /** @internal */
107
+ export function createForgejoRepoChangeLauncher() {
108
+ let dependencies: LauncherDependencies | null = null;
109
+
110
+ /** @internal */
111
+ function configureForgejoRepoChangeLauncher(value: LauncherDependencies | null): void {
112
+ dependencies = value;
113
+ }
114
+
115
+ function requireDependencies(): LauncherDependencies {
116
+ if (!dependencies) throw new Error("Forgejo repository launcher is not configured");
117
+ return dependencies;
118
+ }
119
+
120
+ function sshPreparationCheck(
121
+ access: "read" | "write",
122
+ params: ForgejoRepoChangeParams,
123
+ ): LaunchPreparationCheck<ForgejoRepoChangeParams> {
124
+ return {
125
+ id: `ssh_${access}`,
126
+ label: `Verify SSH ${access} access`,
127
+ async run({ signal, logger }) {
128
+ signal.throwIfAborted();
129
+ const result = await requireDependencies().gitSsh.preflight({
130
+ credentialRef: params.sshCredentialRef,
131
+ repoLocator: params.repoLocator,
132
+ baseBranch: params.baseBranch,
133
+ requireWrite: access === "write",
134
+ });
135
+ signal.throwIfAborted();
136
+ if (!result.ok) {
137
+ logger.warn(`Git SSH ${result.access} preflight failed: ${result.detail}`);
138
+ throw new SafeLaunchPreparationError(
139
+ `SSH ${result.access} access failed: ${result.detail}`,
140
+ `Authorize Git SSH profile '${params.sshCredentialRef}' for '${params.owner}/${params.repo}' with read/write access, then try again.`,
141
+ );
142
+ }
143
+ },
144
+ };
145
+ }
146
+
147
+ /** @internal */
148
+ function forgejoRepositoryPreparationChecks(
149
+ _input: unknown,
150
+ { params }: ProcessLaunchConfig<ForgejoRepoChangeParams>,
151
+ ): readonly LaunchPreparationCheck<ForgejoRepoChangeParams>[] {
152
+ return [
153
+ {
154
+ id: "repository_visibility",
155
+ label: "Check repository visibility",
156
+ async run({ signal }) {
157
+ signal.throwIfAborted();
158
+ const repositoryName = `${params.owner}/${params.repo}`;
159
+ const visible = (await repositories(params.forgejoProfile)).some(
160
+ (candidate) => candidate.full_name === repositoryName,
161
+ );
162
+ signal.throwIfAborted();
163
+ if (!visible) {
164
+ throw new SafeLaunchPreparationError(
165
+ "Repository is not visible",
166
+ "Grant the selected Forgejo profile access to the repository, then try again.",
167
+ );
168
+ }
169
+ },
170
+ },
171
+ sshPreparationCheck("read", params),
172
+ sshPreparationCheck("write", params),
173
+ ];
174
+ }
175
+
176
+ function validationError(
177
+ fieldId: string,
178
+ message: string,
179
+ code: LauncherValidationError["code"] = "required",
180
+ ): LauncherValidationError {
181
+ return { code, fieldId, message };
182
+ }
183
+
184
+ /** @internal */
185
+ function resolveProfiles(profile: string) {
186
+ const { forgejo, woodpecker, gitSsh, profileBindings = {} } = requireDependencies();
187
+ if (!forgejo.profiles().includes(profile)) throw new Error("Forgejo profile is not available");
188
+ const binding = resolveProfileBinding(profileBindings, profile);
189
+ try {
190
+ woodpecker.client(binding.woodpeckerProfile);
191
+ } catch {
192
+ throw new Error(`Woodpecker profile '${binding.woodpeckerProfile}' is not available`);
193
+ }
194
+ if (!gitSsh.profiles().includes(binding.sshCredentialRef))
195
+ throw new Error(`Git SSH profile '${binding.sshCredentialRef}' is not available`);
196
+ return binding;
197
+ }
198
+
199
+ /** @internal */
200
+ async function resolveForgejoGitIdentity(profile: string): Promise<ForgejoGitIdentity> {
201
+ if (!profile) throw new Error("A Forgejo profile is required to resolve Git identity");
202
+ return requireDependencies().forgejo.client(profile).resolveGitIdentity(profile);
203
+ }
204
+
205
+ async function repositories(profile: string): Promise<readonly ForgejoRepository[]> {
206
+ if (!profile) return [];
207
+ const { forgejo } = requireDependencies();
208
+ if (!forgejo.profiles().includes(profile)) return [];
209
+ return forgejo.client(profile).listRepositories();
210
+ }
211
+
212
+ const forgejoRepoChangeUiLauncher: ProcessLauncherDefinition<ForgejoRepoChangeParams> = {
213
+ id: forgejoRepoChangeUiLauncherId,
214
+ label: "Forgejo Repo Change",
215
+ description: "Plan, implement, review, and publish a Forgejo change without a source issue",
216
+ visibility: "ui",
217
+ ui: {
218
+ card: {
219
+ title: "Forgejo Repo Change",
220
+ description: "Start a repository change and publish it as a Forgejo pull request.",
221
+ },
222
+ launchConfigSchema: {
223
+ id: "forgejo_repo_change_form",
224
+ title: "Forgejo Repo Change",
225
+ fields: [
226
+ {
227
+ id: "forgejoProfile",
228
+ label: "Forgejo profile",
229
+ kind: "select",
230
+ required: true,
231
+ description: "Forgejo profile with server-configured CI and Git SSH access.",
232
+ },
233
+ {
234
+ id: "repository",
235
+ label: "Repository",
236
+ kind: "select",
237
+ required: true,
238
+ description: "Repository visible to the selected Forgejo profile.",
239
+ },
240
+ {
241
+ id: "prompt",
242
+ label: "Requested change",
243
+ kind: "textarea",
244
+ required: true,
245
+ placeholder: "Describe the change to plan, implement, review, and publish.",
246
+ },
247
+ ],
248
+ submitLabel: "Start change",
249
+ },
250
+ resolveDefaults() {
251
+ return {
252
+ forgejoProfile: requireDependencies().forgejo.profiles()[0] ?? "",
253
+ repository: "",
254
+ prompt: "",
255
+ };
256
+ },
257
+ async resolveOptions(input) {
258
+ const { forgejo } = requireDependencies();
259
+ const profile = trimString(input.forgejoProfile);
260
+ return {
261
+ forgejoProfile: forgejo.profiles().map((value) => ({ value, label: value })),
262
+ repository: (await repositories(profile)).map((repository) => ({
263
+ value: repository.full_name,
264
+ label: repository.full_name,
265
+ description: repository.html_url,
266
+ })),
267
+ };
268
+ },
269
+ preparationChecks: forgejoRepositoryPreparationChecks,
270
+ resolveRelaunchInput(previousInput) {
271
+ return {
272
+ forgejoProfile: trimString(previousInput.forgejoProfile),
273
+ repository: trimString(previousInput.repository),
274
+ prompt: trimString(previousInput.prompt),
275
+ };
276
+ },
277
+ async resolveLaunchConfig(input) {
278
+ const profile = trimString(input.forgejoProfile);
279
+ const repositoryName = trimString(input.repository);
280
+ const prompt = trimString(input.prompt);
281
+ const errors: LauncherValidationError[] = [];
282
+ const invalid = (fieldId: string, message: string) => ({
283
+ ok: false as const,
284
+ errors: [validationError(fieldId, message, "custom_rule")],
285
+ });
286
+ const { forgejo } = requireDependencies();
287
+ if (!profile) errors.push(validationError("forgejoProfile", "Forgejo profile is required"));
288
+ else if (!forgejo.profiles().includes(profile))
289
+ errors.push(
290
+ validationError("forgejoProfile", "Forgejo profile is not available", "custom_rule"),
291
+ );
292
+ if (!repositoryName) errors.push(validationError("repository", "Repository is required"));
293
+ if (!prompt) errors.push(validationError("prompt", "Requested change is required"));
294
+ if (errors.length > 0) return { ok: false, errors };
295
+
296
+ const repository = (await repositories(profile)).find(
297
+ (candidate) => candidate.full_name === repositoryName,
298
+ );
299
+ if (!repository)
300
+ return invalid(
301
+ "repository",
302
+ "Repository is not available to the selected Forgejo profile",
303
+ );
304
+
305
+ let binding: ReturnType<typeof resolveProfiles>;
306
+ try {
307
+ binding = resolveProfiles(profile);
308
+ } catch (error) {
309
+ return invalid("forgejoProfile", (error as Error).message);
310
+ }
311
+ const gitIdentity = await resolveForgejoGitIdentity(profile);
312
+ const workBranch = buildAutoWorkBranchFromSeed(
313
+ prompt,
314
+ `${repository.ssh_url}:${repository.default_branch}`,
315
+ );
316
+ const params = forgejoRepoChangeParams(repository, {
317
+ ...binding,
318
+ profile,
319
+ prompt,
320
+ workBranch,
321
+ });
322
+ return {
323
+ ok: true,
324
+ launchConfig: forgejoRepoChangeLaunchConfig(params, prompt, gitIdentity),
325
+ };
326
+ },
327
+ },
328
+ };
329
+
330
+ return {
331
+ /** @internal */
332
+ configure: configureForgejoRepoChangeLauncher,
333
+ /** @internal */
334
+ preparationChecks: forgejoRepositoryPreparationChecks,
335
+ /** @internal */
336
+ resolveProfiles,
337
+ /** @internal */
338
+ resolveGitIdentity: resolveForgejoGitIdentity,
339
+ /** @internal */
340
+ launcher: forgejoRepoChangeUiLauncher,
341
+ };
342
+ }