@leitwerk-dev/github-repo-change 0.0.0-bootstrap.0 → 0.3.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 +69 -1
- package/dist/LICENSE +13 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1159 -0
- package/dist/index.js.map +1 -0
- package/dist/launcher.d.ts +43 -0
- package/dist/launcher.d.ts.map +1 -0
- package/dist/params.d.ts +46 -0
- package/dist/params.d.ts.map +1 -0
- package/dist/process.d.ts +6 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/profile-bindings.d.ts +13 -0
- package/dist/profile-bindings.d.ts.map +1 -0
- package/package.json +51 -14
- package/src/index.ts +75 -0
- package/src/launcher.ts +327 -0
- package/src/params.ts +110 -0
- package/src/process.ts +391 -0
- package/src/profile-bindings.ts +53 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { GitSshIntegration } from "@leitwerk-dev/git-ssh";
|
|
2
|
+
import type { GitHubGitIdentity, GitHubIntegration, GitHubRepository } from "@leitwerk-dev/github";
|
|
3
|
+
import { type LaunchPreparationCheck, type ProcessLaunchConfig, type ProcessLauncherDefinition } from "@leitwerk-dev/process-sdk";
|
|
4
|
+
import { type GitHubRepoChangeParams } from "./params.js";
|
|
5
|
+
import { type ProfileBindings } from "./profile-bindings.js";
|
|
6
|
+
/** @public */
|
|
7
|
+
export declare const githubRepoChangeUiLauncherId: "github_repo_change_process.ui_launcher";
|
|
8
|
+
/** @public */
|
|
9
|
+
export declare function githubRepoChangeParams(repository: GitHubRepository, input: {
|
|
10
|
+
/** @public */
|
|
11
|
+
profile: string;
|
|
12
|
+
/** @public */
|
|
13
|
+
sshCredentialRef: string;
|
|
14
|
+
/** @public */
|
|
15
|
+
prompt: string;
|
|
16
|
+
/** @public */
|
|
17
|
+
workBranch: string;
|
|
18
|
+
}): GitHubRepoChangeParams;
|
|
19
|
+
/** @public */
|
|
20
|
+
export declare function githubRepoChangeLaunchConfig(params: GitHubRepoChangeParams, title: string, gitIdentity: GitHubGitIdentity): ProcessLaunchConfig<GitHubRepoChangeParams>;
|
|
21
|
+
/** @public */
|
|
22
|
+
export interface LauncherDependencies {
|
|
23
|
+
/** @public */
|
|
24
|
+
github: GitHubIntegration;
|
|
25
|
+
/** @public */
|
|
26
|
+
gitSsh: GitSshIntegration;
|
|
27
|
+
/** @public */
|
|
28
|
+
profileBindings?: ProfileBindings;
|
|
29
|
+
}
|
|
30
|
+
/** @public */
|
|
31
|
+
export declare function createGitHubRepoChangeLauncher(): {
|
|
32
|
+
/** @public */
|
|
33
|
+
configure: (value: LauncherDependencies | null) => void;
|
|
34
|
+
/** @public */
|
|
35
|
+
preparationChecks: (_input: unknown, { params }: ProcessLaunchConfig<GitHubRepoChangeParams>) => readonly LaunchPreparationCheck<GitHubRepoChangeParams>[];
|
|
36
|
+
/** @public */
|
|
37
|
+
resolveProfiles: (profile: string) => import("./profile-bindings.js").ProfileBinding;
|
|
38
|
+
/** @public */
|
|
39
|
+
resolveGitIdentity: (profile: string) => Promise<GitHubGitIdentity>;
|
|
40
|
+
/** @public */
|
|
41
|
+
launcher: ProcessLauncherDefinition<GitHubRepoChangeParams>;
|
|
42
|
+
};
|
|
43
|
+
//# 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,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAEN,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAE9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,KAAK,sBAAsB,EAAiB,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,KAAK,eAAe,EAAyB,MAAM,uBAAuB,CAAC;AAEpF,cAAc;AACd,eAAO,MAAM,4BAA4B,EAAG,wCAAiD,CAAC;AAE9F,cAAc;AACd,wBAAgB,sBAAsB,CACrC,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE;IACN,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc;IACd,MAAM,EAAE,MAAM,CAAC;IACf,cAAc;IACd,UAAU,EAAE,MAAM,CAAC;CACnB,GACC,sBAAsB,CAgBxB;AAED,cAAc;AACd,wBAAgB,4BAA4B,CAC3C,MAAM,EAAE,sBAAsB,EAC9B,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,iBAAiB,GAC5B,mBAAmB,CAAC,sBAAsB,CAAC,CA4B7C;AAED,cAAc;AACd,MAAM,WAAW,oBAAoB;IACpC,cAAc;IACd,MAAM,EAAE,iBAAiB,CAAC;IAC1B,cAAc;IACd,MAAM,EAAE,iBAAiB,CAAC;IAC1B,cAAc;IACd,eAAe,CAAC,EAAE,eAAe,CAAC;CAClC;AAED,cAAc;AACd,wBAAgB,8BAA8B;IA6N5C,cAAc;uBAzNmC,oBAAoB,GAAG,IAAI,KAAG,IAAI;IA2NnF,cAAc;gCArLN,OAAO,cACH,mBAAmB,CAAC,sBAAsB,CAAC,KACrD,SAAS,sBAAsB,CAAC,sBAAsB,CAAC,EAAE;IAqL3D,cAAc;+BAnJmB,MAAM;IAqJvC,cAAc;kCAzIkC,MAAM,KAAG,OAAO,CAAC,iBAAiB,CAAC;IA2InF,cAAc;;EAGf"}
|
package/dist/params.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type RepositoryChangeLaunchParams } from "@leitwerk-dev/coding/repository-change-launch";
|
|
2
|
+
/** @public */
|
|
3
|
+
interface GitHubRepoChangeCommonParams {
|
|
4
|
+
/** @public */
|
|
5
|
+
githubProfile: string;
|
|
6
|
+
/** @public */
|
|
7
|
+
sshCredentialRef: string;
|
|
8
|
+
/** @public */
|
|
9
|
+
owner: string;
|
|
10
|
+
/** @public */
|
|
11
|
+
repo: string;
|
|
12
|
+
}
|
|
13
|
+
/** @public */
|
|
14
|
+
export interface GitHubIssueOriginParams {
|
|
15
|
+
/** @public */
|
|
16
|
+
origin: "issue";
|
|
17
|
+
/** @public */
|
|
18
|
+
issueNumber: number;
|
|
19
|
+
/** @public */
|
|
20
|
+
issueUrl: string;
|
|
21
|
+
/** @public */
|
|
22
|
+
triggerLabel: string;
|
|
23
|
+
/** @public */
|
|
24
|
+
doneLabel: string;
|
|
25
|
+
}
|
|
26
|
+
/** @public */
|
|
27
|
+
export interface GitHubUiOriginParams {
|
|
28
|
+
/** @public */
|
|
29
|
+
origin: "ui";
|
|
30
|
+
/** @public */
|
|
31
|
+
issueNumber: null;
|
|
32
|
+
/** @public */
|
|
33
|
+
issueUrl: null;
|
|
34
|
+
/** @public */
|
|
35
|
+
triggerLabel: null;
|
|
36
|
+
/** @public */
|
|
37
|
+
doneLabel: null;
|
|
38
|
+
}
|
|
39
|
+
/** @public */
|
|
40
|
+
export type GitHubRepoChangeParams = RepositoryChangeLaunchParams<GitHubRepoChangeCommonParams & (GitHubIssueOriginParams | GitHubUiOriginParams)>;
|
|
41
|
+
/** @public */
|
|
42
|
+
export declare function isIssueOrigin(params: GitHubRepoChangeParams): params is GitHubRepoChangeParams & GitHubIssueOriginParams;
|
|
43
|
+
/** @public */
|
|
44
|
+
export declare const githubRepoChangeParamsCodec: import("@leitwerk-dev/process-sdk").Codec<GitHubRepoChangeParams>;
|
|
45
|
+
export {};
|
|
46
|
+
//# 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,4BAA4B;IACrC,cAAc;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc;IACd,KAAK,EAAE,MAAM,CAAC;IACd,cAAc;IACd,IAAI,EAAE,MAAM,CAAC;CACb;AAED,cAAc;AACd,MAAM,WAAW,uBAAuB;IACvC,cAAc;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc;IACd,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,cAAc;AACd,MAAM,WAAW,oBAAoB;IACpC,cAAc;IACd,MAAM,EAAE,IAAI,CAAC;IACb,cAAc;IACd,WAAW,EAAE,IAAI,CAAC;IAClB,cAAc;IACd,QAAQ,EAAE,IAAI,CAAC;IACf,cAAc;IACd,YAAY,EAAE,IAAI,CAAC;IACnB,cAAc;IACd,SAAS,EAAE,IAAI,CAAC;CAChB;AAED,cAAc;AACd,MAAM,MAAM,sBAAsB,GAAG,4BAA4B,CAChE,4BAA4B,GAAG,CAAC,uBAAuB,GAAG,oBAAoB,CAAC,CAC/E,CAAC;AAEF,cAAc;AACd,wBAAgB,aAAa,CAC5B,MAAM,EAAE,sBAAsB,GAC5B,MAAM,IAAI,sBAAsB,GAAG,uBAAuB,CAE5D;AAED,cAAc;AACd,eAAO,MAAM,2BAA2B,mEAgDrC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RepositoryChangeState } from "@leitwerk-dev/coding/repository-change-state";
|
|
2
|
+
import { type createGitHubRepoChangeLauncher } from "./launcher.js";
|
|
3
|
+
import { type GitHubRepoChangeParams } from "./params.js";
|
|
4
|
+
/** @public */
|
|
5
|
+
export declare function createGitHubRepoChangeProcess(launcher: ReturnType<typeof createGitHubRepoChangeLauncher>, docker: boolean): import("@leitwerk-dev/process-sdk").ExtensionProcessDefinition<GitHubRepoChangeParams, RepositoryChangeState>;
|
|
6
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../src/process.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAQ1F,OAAO,EACN,KAAK,8BAA8B,EAGnC,MAAM,eAAe,CAAC;AACvB,OAAO,EAEN,KAAK,sBAAsB,EAG3B,MAAM,aAAa,CAAC;AA8DrB,cAAc;AACd,wBAAgB,6BAA6B,CAC5C,QAAQ,EAAE,UAAU,CAAC,OAAO,8BAA8B,CAAC,EAC3D,MAAM,EAAE,OAAO,iHA0Sf"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Server-owned, non-secret wiring for future launches. */
|
|
2
|
+
/** @public */
|
|
3
|
+
export interface ProfileBinding {
|
|
4
|
+
/** @public */
|
|
5
|
+
sshCredentialRef: string;
|
|
6
|
+
}
|
|
7
|
+
/** @public */
|
|
8
|
+
export type ProfileBindings = Readonly<Record<string, Readonly<ProfileBinding>>>;
|
|
9
|
+
/** @public */
|
|
10
|
+
export declare function parseProfileBindings(raw: unknown): ProfileBindings;
|
|
11
|
+
/** @public */
|
|
12
|
+
export declare function resolveProfileBinding(bindings: ProfileBindings, profile: string): ProfileBinding;
|
|
13
|
+
//# 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,2DAA2D;AAC3D,cAAc;AACd,MAAM,WAAW,cAAc;IAC9B,cAAc;IACd,gBAAgB,EAAE,MAAM,CAAC;CACzB;AACD,cAAc;AACd,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;AAajF,cAAc;AACd,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,CAyBlE;AACD,cAAc;AACd,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc,CAIhG"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,53 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
"name": "@leitwerk-dev/github-repo-change",
|
|
3
|
+
"version": "0.3.0",
|
|
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.0",
|
|
24
|
+
"@leitwerk-dev/external-writes": "0.3.0",
|
|
25
|
+
"@leitwerk-dev/git-ssh": "0.3.0",
|
|
26
|
+
"@leitwerk-dev/process-sdk": "0.3.0",
|
|
27
|
+
"@leitwerk-dev/github": "0.3.0",
|
|
28
|
+
"@leitwerk-dev/repository-rebase": "0.3.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"tsup": "^8.5.1"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/leitwerk-dev/leitwerk.git",
|
|
36
|
+
"directory": "extensions/github-repo-change"
|
|
37
|
+
},
|
|
38
|
+
"license": "Apache-2.0",
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=26 <27"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist/**",
|
|
47
|
+
"src/**",
|
|
48
|
+
"!dist/**/*.test.*",
|
|
49
|
+
"!src/**/*.test.ts",
|
|
50
|
+
"!src/testing/**",
|
|
51
|
+
"!dist/testing/**"
|
|
52
|
+
]
|
|
16
53
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { gitSshIntegration } from "@leitwerk-dev/git-ssh";
|
|
2
|
+
import { githubIntegration } from "@leitwerk-dev/github";
|
|
3
|
+
import type { LeitwerkExtensionModule } from "@leitwerk-dev/process-sdk";
|
|
4
|
+
import { createGitHubRepoChangeLauncher } from "./launcher.js";
|
|
5
|
+
import { createGitHubRepoChangeProcess } from "./process.js";
|
|
6
|
+
import { parseProfileBindings } from "./profile-bindings.js";
|
|
7
|
+
|
|
8
|
+
/** @public */
|
|
9
|
+
export const manifest = {
|
|
10
|
+
/** @public */
|
|
11
|
+
id: "github-repo-change",
|
|
12
|
+
/** @public */
|
|
13
|
+
version: "0.1.9",
|
|
14
|
+
/** @public */
|
|
15
|
+
requires: ["github", "coding", "git-ssh"],
|
|
16
|
+
} as const;
|
|
17
|
+
|
|
18
|
+
/** Load exactly one variant per catalog. Only trusted composition code selects Docker. */
|
|
19
|
+
/** @public */
|
|
20
|
+
/** @public */
|
|
21
|
+
export function createGitHubRepoChange(options: {
|
|
22
|
+
/** @public */
|
|
23
|
+
docker: boolean;
|
|
24
|
+
}) {
|
|
25
|
+
if (typeof options.docker !== "boolean") throw new Error("docker must be a boolean");
|
|
26
|
+
const launcher = createGitHubRepoChangeLauncher();
|
|
27
|
+
const process = createGitHubRepoChangeProcess(launcher, options.docker);
|
|
28
|
+
const extension: LeitwerkExtensionModule = {
|
|
29
|
+
manifest,
|
|
30
|
+
setupCatalog(api) {
|
|
31
|
+
api.registerProcess(process);
|
|
32
|
+
},
|
|
33
|
+
setupServer(api, config) {
|
|
34
|
+
const github = api.require(githubIntegration);
|
|
35
|
+
const gitSsh = api.require(gitSshIntegration);
|
|
36
|
+
if (Array.isArray(github) || Array.isArray(gitSsh))
|
|
37
|
+
throw new Error("Repository delivery integrations must be singular");
|
|
38
|
+
launcher.configure({
|
|
39
|
+
github,
|
|
40
|
+
gitSsh,
|
|
41
|
+
profileBindings: parseProfileBindings(config),
|
|
42
|
+
});
|
|
43
|
+
api.onStop(() => launcher.configure(null));
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
/** @public */
|
|
47
|
+
/** @public */
|
|
48
|
+
return {
|
|
49
|
+
/** @public */
|
|
50
|
+
extension,
|
|
51
|
+
/** @public */
|
|
52
|
+
process,
|
|
53
|
+
/** @public */
|
|
54
|
+
launcher,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export * from "./launcher.js";
|
|
59
|
+
export * from "./params.js";
|
|
60
|
+
export * from "./process.js";
|
|
61
|
+
export * from "./profile-bindings.js";
|
|
62
|
+
/** @public */
|
|
63
|
+
export const {
|
|
64
|
+
extension: defaultExtension,
|
|
65
|
+
process: githubRepoChangeProcess,
|
|
66
|
+
launcher: defaultGitHubRepoChangeLauncher,
|
|
67
|
+
} = createGitHubRepoChange({ docker: true });
|
|
68
|
+
/** @public */
|
|
69
|
+
export const {
|
|
70
|
+
configure: configureGitHubRepoChangeLauncher,
|
|
71
|
+
preparationChecks: githubRepositoryPreparationChecks,
|
|
72
|
+
resolveGitIdentity: resolveGitHubGitIdentity,
|
|
73
|
+
launcher: githubRepoChangeUiLauncher,
|
|
74
|
+
} = defaultGitHubRepoChangeLauncher;
|
|
75
|
+
export default defaultExtension;
|
package/src/launcher.ts
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { buildAutoWorkBranchFromSeed } from "@leitwerk-dev/coding/auto-work-branch";
|
|
2
|
+
import { trimString } from "@leitwerk-dev/domain";
|
|
3
|
+
import type { GitSshIntegration } from "@leitwerk-dev/git-ssh";
|
|
4
|
+
import type { GitHubGitIdentity, GitHubIntegration, GitHubRepository } from "@leitwerk-dev/github";
|
|
5
|
+
import {
|
|
6
|
+
type LauncherValidationError,
|
|
7
|
+
type LaunchPreparationCheck,
|
|
8
|
+
type ProcessLaunchConfig,
|
|
9
|
+
type ProcessLauncherDefinition,
|
|
10
|
+
SafeLaunchPreparationError,
|
|
11
|
+
} from "@leitwerk-dev/process-sdk";
|
|
12
|
+
import { type GitHubRepoChangeParams, isIssueOrigin } from "./params.js";
|
|
13
|
+
import { type ProfileBindings, resolveProfileBinding } from "./profile-bindings.js";
|
|
14
|
+
|
|
15
|
+
/** @public */
|
|
16
|
+
export const githubRepoChangeUiLauncherId = "github_repo_change_process.ui_launcher" as const;
|
|
17
|
+
|
|
18
|
+
/** @public */
|
|
19
|
+
export function githubRepoChangeParams(
|
|
20
|
+
repository: GitHubRepository,
|
|
21
|
+
input: {
|
|
22
|
+
/** @public */
|
|
23
|
+
profile: string;
|
|
24
|
+
/** @public */
|
|
25
|
+
sshCredentialRef: string;
|
|
26
|
+
/** @public */
|
|
27
|
+
prompt: string;
|
|
28
|
+
/** @public */
|
|
29
|
+
workBranch: string;
|
|
30
|
+
},
|
|
31
|
+
): GitHubRepoChangeParams {
|
|
32
|
+
return {
|
|
33
|
+
repoLocator: repository.ssh_url,
|
|
34
|
+
baseBranch: repository.default_branch,
|
|
35
|
+
workBranch: input.workBranch,
|
|
36
|
+
prompt: input.prompt,
|
|
37
|
+
githubProfile: input.profile,
|
|
38
|
+
sshCredentialRef: input.sshCredentialRef,
|
|
39
|
+
owner: repository.owner.login,
|
|
40
|
+
repo: repository.name,
|
|
41
|
+
origin: "ui",
|
|
42
|
+
issueNumber: null,
|
|
43
|
+
issueUrl: null,
|
|
44
|
+
triggerLabel: null,
|
|
45
|
+
doneLabel: null,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @public */
|
|
50
|
+
export function githubRepoChangeLaunchConfig(
|
|
51
|
+
params: GitHubRepoChangeParams,
|
|
52
|
+
title: string,
|
|
53
|
+
gitIdentity: GitHubGitIdentity,
|
|
54
|
+
): ProcessLaunchConfig<GitHubRepoChangeParams> {
|
|
55
|
+
const { owner, repo, githubProfile: profile } = params;
|
|
56
|
+
const issue = isIssueOrigin(params);
|
|
57
|
+
return {
|
|
58
|
+
processId: "github_repo_change_process",
|
|
59
|
+
params,
|
|
60
|
+
title,
|
|
61
|
+
startTurnId: "generate_plan",
|
|
62
|
+
...(issue
|
|
63
|
+
? {
|
|
64
|
+
externalId: `github:${owner}/${repo}#${params.issueNumber}`,
|
|
65
|
+
externalUrl: params.issueUrl,
|
|
66
|
+
}
|
|
67
|
+
: {}),
|
|
68
|
+
projects: [
|
|
69
|
+
{
|
|
70
|
+
key: "repo",
|
|
71
|
+
repoLocator: params.repoLocator,
|
|
72
|
+
baseBranch: params.baseBranch,
|
|
73
|
+
workBranch: params.workBranch,
|
|
74
|
+
...(issue ? { externalId: String(params.issueNumber), externalUrl: params.issueUrl } : {}),
|
|
75
|
+
metadata: {
|
|
76
|
+
github: { owner, repo, profile, ...(issue ? { issueNumber: params.issueNumber } : {}) },
|
|
77
|
+
"leitwerk.gitIdentity": gitIdentity,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** @public */
|
|
85
|
+
export interface LauncherDependencies {
|
|
86
|
+
/** @public */
|
|
87
|
+
github: GitHubIntegration;
|
|
88
|
+
/** @public */
|
|
89
|
+
gitSsh: GitSshIntegration;
|
|
90
|
+
/** @public */
|
|
91
|
+
profileBindings?: ProfileBindings;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** @public */
|
|
95
|
+
export function createGitHubRepoChangeLauncher() {
|
|
96
|
+
let dependencies: LauncherDependencies | null = null;
|
|
97
|
+
|
|
98
|
+
/** @public */
|
|
99
|
+
function configureGitHubRepoChangeLauncher(value: LauncherDependencies | null): void {
|
|
100
|
+
dependencies = value;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function requireDependencies(): LauncherDependencies {
|
|
104
|
+
if (!dependencies) throw new Error("GitHub repository launcher is not configured");
|
|
105
|
+
return dependencies;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function sshPreparationCheck(
|
|
109
|
+
access: "read" | "write",
|
|
110
|
+
params: GitHubRepoChangeParams,
|
|
111
|
+
): LaunchPreparationCheck<GitHubRepoChangeParams> {
|
|
112
|
+
return {
|
|
113
|
+
id: `ssh_${access}`,
|
|
114
|
+
label: `Verify SSH ${access} access`,
|
|
115
|
+
async run({ signal, logger }) {
|
|
116
|
+
signal.throwIfAborted();
|
|
117
|
+
const result = await requireDependencies().gitSsh.preflight({
|
|
118
|
+
credentialRef: params.sshCredentialRef,
|
|
119
|
+
repoLocator: params.repoLocator,
|
|
120
|
+
baseBranch: params.baseBranch,
|
|
121
|
+
requireWrite: access === "write",
|
|
122
|
+
});
|
|
123
|
+
signal.throwIfAborted();
|
|
124
|
+
if (!result.ok) {
|
|
125
|
+
logger.warn(`Git SSH ${result.access} preflight failed: ${result.detail}`);
|
|
126
|
+
throw new SafeLaunchPreparationError(
|
|
127
|
+
`SSH ${result.access} access failed: ${result.detail}`,
|
|
128
|
+
`Authorize Git SSH profile '${params.sshCredentialRef}' for '${params.owner}/${params.repo}' with read/write access, then try again.`,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** @public */
|
|
136
|
+
function githubRepositoryPreparationChecks(
|
|
137
|
+
_input: unknown,
|
|
138
|
+
{ params }: ProcessLaunchConfig<GitHubRepoChangeParams>,
|
|
139
|
+
): readonly LaunchPreparationCheck<GitHubRepoChangeParams>[] {
|
|
140
|
+
return [
|
|
141
|
+
{
|
|
142
|
+
id: "repository_visibility",
|
|
143
|
+
label: "Check repository visibility",
|
|
144
|
+
async run({ signal }) {
|
|
145
|
+
signal.throwIfAborted();
|
|
146
|
+
const repositoryName = `${params.owner}/${params.repo}`;
|
|
147
|
+
const visible = (await repositories(params.githubProfile)).some(
|
|
148
|
+
(candidate) => candidate.full_name === repositoryName,
|
|
149
|
+
);
|
|
150
|
+
signal.throwIfAborted();
|
|
151
|
+
if (!visible) {
|
|
152
|
+
throw new SafeLaunchPreparationError(
|
|
153
|
+
"Repository is not visible",
|
|
154
|
+
"Grant the selected GitHub profile access to the repository, then try again.",
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
sshPreparationCheck("read", params),
|
|
160
|
+
sshPreparationCheck("write", params),
|
|
161
|
+
];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function validationError(
|
|
165
|
+
fieldId: string,
|
|
166
|
+
message: string,
|
|
167
|
+
code: LauncherValidationError["code"] = "required",
|
|
168
|
+
): LauncherValidationError {
|
|
169
|
+
return { code, fieldId, message };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** @public */
|
|
173
|
+
function resolveProfiles(profile: string) {
|
|
174
|
+
const { github, gitSsh, profileBindings = {} } = requireDependencies();
|
|
175
|
+
if (!(github.profiles?.() ?? []).includes(profile))
|
|
176
|
+
throw new Error("GitHub profile is not available");
|
|
177
|
+
const binding = resolveProfileBinding(profileBindings, profile);
|
|
178
|
+
|
|
179
|
+
if (!gitSsh.profiles().includes(binding.sshCredentialRef))
|
|
180
|
+
throw new Error(`Git SSH profile '${binding.sshCredentialRef}' is not available`);
|
|
181
|
+
return binding;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** @public */
|
|
185
|
+
async function resolveGitHubGitIdentity(profile: string): Promise<GitHubGitIdentity> {
|
|
186
|
+
if (!profile) throw new Error("A GitHub profile is required to resolve Git identity");
|
|
187
|
+
return requireDependencies().github.client(profile).resolveGitIdentity(profile);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function repositories(profile: string): Promise<readonly GitHubRepository[]> {
|
|
191
|
+
if (!profile) return [];
|
|
192
|
+
const { github } = requireDependencies();
|
|
193
|
+
if (!(github.profiles?.() ?? []).includes(profile)) return [];
|
|
194
|
+
return github.client(profile).listRepositories();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const githubRepoChangeUiLauncher: ProcessLauncherDefinition<GitHubRepoChangeParams> = {
|
|
198
|
+
id: githubRepoChangeUiLauncherId,
|
|
199
|
+
label: "GitHub Repo Change",
|
|
200
|
+
description: "Plan, implement, review, and publish a GitHub change without a source issue",
|
|
201
|
+
visibility: "ui",
|
|
202
|
+
ui: {
|
|
203
|
+
card: {
|
|
204
|
+
title: "GitHub Repo Change",
|
|
205
|
+
description: "Start a repository change and publish it as a GitHub pull request.",
|
|
206
|
+
},
|
|
207
|
+
launchConfigSchema: {
|
|
208
|
+
id: "github_repo_change_form",
|
|
209
|
+
title: "GitHub Repo Change",
|
|
210
|
+
fields: [
|
|
211
|
+
{
|
|
212
|
+
id: "githubProfile",
|
|
213
|
+
label: "GitHub profile",
|
|
214
|
+
kind: "select",
|
|
215
|
+
required: true,
|
|
216
|
+
description: "GitHub profile with server-configured CI and Git SSH access.",
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
id: "repository",
|
|
220
|
+
label: "Repository",
|
|
221
|
+
kind: "select",
|
|
222
|
+
required: true,
|
|
223
|
+
description: "Repository visible to the selected GitHub profile.",
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
id: "prompt",
|
|
227
|
+
label: "Requested change",
|
|
228
|
+
kind: "textarea",
|
|
229
|
+
required: true,
|
|
230
|
+
placeholder: "Describe the change to plan, implement, review, and publish.",
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
submitLabel: "Start change",
|
|
234
|
+
},
|
|
235
|
+
resolveDefaults() {
|
|
236
|
+
return {
|
|
237
|
+
githubProfile: (requireDependencies().github.profiles?.() ?? [])[0] ?? "",
|
|
238
|
+
repository: "",
|
|
239
|
+
prompt: "",
|
|
240
|
+
};
|
|
241
|
+
},
|
|
242
|
+
async resolveOptions(input) {
|
|
243
|
+
const { github } = requireDependencies();
|
|
244
|
+
const profile = trimString(input.githubProfile);
|
|
245
|
+
return {
|
|
246
|
+
githubProfile: (github.profiles?.() ?? []).map((value) => ({ value, label: value })),
|
|
247
|
+
repository: (await repositories(profile)).map((repository) => ({
|
|
248
|
+
value: repository.full_name,
|
|
249
|
+
label: repository.full_name,
|
|
250
|
+
description: repository.html_url,
|
|
251
|
+
})),
|
|
252
|
+
};
|
|
253
|
+
},
|
|
254
|
+
preparationChecks: githubRepositoryPreparationChecks,
|
|
255
|
+
resolveRelaunchInput(previousInput) {
|
|
256
|
+
return {
|
|
257
|
+
githubProfile: trimString(previousInput.githubProfile),
|
|
258
|
+
repository: trimString(previousInput.repository),
|
|
259
|
+
prompt: trimString(previousInput.prompt),
|
|
260
|
+
};
|
|
261
|
+
},
|
|
262
|
+
async resolveLaunchConfig(input) {
|
|
263
|
+
const profile = trimString(input.githubProfile);
|
|
264
|
+
const repositoryName = trimString(input.repository);
|
|
265
|
+
const prompt = trimString(input.prompt);
|
|
266
|
+
const errors: LauncherValidationError[] = [];
|
|
267
|
+
const invalid = (fieldId: string, message: string) => ({
|
|
268
|
+
ok: false as const,
|
|
269
|
+
errors: [validationError(fieldId, message, "custom_rule")],
|
|
270
|
+
});
|
|
271
|
+
const { github } = requireDependencies();
|
|
272
|
+
if (!profile) errors.push(validationError("githubProfile", "GitHub profile is required"));
|
|
273
|
+
else if (!(github.profiles?.() ?? []).includes(profile))
|
|
274
|
+
errors.push(
|
|
275
|
+
validationError("githubProfile", "GitHub profile is not available", "custom_rule"),
|
|
276
|
+
);
|
|
277
|
+
if (!repositoryName) errors.push(validationError("repository", "Repository is required"));
|
|
278
|
+
if (!prompt) errors.push(validationError("prompt", "Requested change is required"));
|
|
279
|
+
if (errors.length > 0) return { ok: false, errors };
|
|
280
|
+
|
|
281
|
+
const repository = (await repositories(profile)).find(
|
|
282
|
+
(candidate) => candidate.full_name === repositoryName,
|
|
283
|
+
);
|
|
284
|
+
if (!repository)
|
|
285
|
+
return invalid(
|
|
286
|
+
"repository",
|
|
287
|
+
"Repository is not available to the selected GitHub profile",
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
let binding: ReturnType<typeof resolveProfiles>;
|
|
291
|
+
try {
|
|
292
|
+
binding = resolveProfiles(profile);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
return invalid("githubProfile", (error as Error).message);
|
|
295
|
+
}
|
|
296
|
+
const gitIdentity = await resolveGitHubGitIdentity(profile);
|
|
297
|
+
const workBranch = buildAutoWorkBranchFromSeed(
|
|
298
|
+
prompt,
|
|
299
|
+
`${repository.ssh_url}:${repository.default_branch}`,
|
|
300
|
+
);
|
|
301
|
+
const params = githubRepoChangeParams(repository, {
|
|
302
|
+
...binding,
|
|
303
|
+
profile,
|
|
304
|
+
prompt,
|
|
305
|
+
workBranch,
|
|
306
|
+
});
|
|
307
|
+
return {
|
|
308
|
+
ok: true,
|
|
309
|
+
launchConfig: githubRepoChangeLaunchConfig(params, prompt, gitIdentity),
|
|
310
|
+
};
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
return {
|
|
316
|
+
/** @public */
|
|
317
|
+
configure: configureGitHubRepoChangeLauncher,
|
|
318
|
+
/** @public */
|
|
319
|
+
preparationChecks: githubRepositoryPreparationChecks,
|
|
320
|
+
/** @public */
|
|
321
|
+
resolveProfiles,
|
|
322
|
+
/** @public */
|
|
323
|
+
resolveGitIdentity: resolveGitHubGitIdentity,
|
|
324
|
+
/** @public */
|
|
325
|
+
launcher: githubRepoChangeUiLauncher,
|
|
326
|
+
};
|
|
327
|
+
}
|