@leitwerk-dev/github-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 +69 -1
- package/dist/LICENSE +13 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +386 -0
- package/dist/index.js.map +1 -0
- package/dist/launcher.d.ts +55 -0
- package/dist/launcher.d.ts.map +1 -0
- package/dist/params.d.ts +26 -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 +50 -14
- package/src/index.ts +75 -0
- package/src/launcher.ts +171 -0
- package/src/params.ts +50 -0
- package/src/process.ts +177 -0
- package/src/profile-bindings.ts +23 -0
package/README.md
CHANGED
|
@@ -1 +1,69 @@
|
|
|
1
|
-
|
|
1
|
+
# GitHub repository change
|
|
2
|
+
|
|
3
|
+
`@leitwerk-dev/github-repo-change` plans, implements, reviews, and publishes a
|
|
4
|
+
repository change as a GitHub pull request. Load `github`, `git-ssh`, `coding`,
|
|
5
|
+
and this extension on the server and worker. The extension is opt-in.
|
|
6
|
+
|
|
7
|
+
The UI launcher selects a server-owned GitHub profile, a visible repository, and
|
|
8
|
+
a requested change. Launch checks repository visibility and SSH read/write access,
|
|
9
|
+
pins the bot Git identity, and uses the default branch as the base. Replaying a UI
|
|
10
|
+
launch generates a new work branch. Plans and implementations require operator
|
|
11
|
+
approval before publication.
|
|
12
|
+
|
|
13
|
+
## Configuration
|
|
14
|
+
|
|
15
|
+
Configure API access in [github](../github/README.md) and checkout credentials in
|
|
16
|
+
[git-ssh](../git-ssh/README.md). The SSH credential defaults to the GitHub profile
|
|
17
|
+
name. Override it for future launches:
|
|
18
|
+
|
|
19
|
+
```yaml
|
|
20
|
+
extensions:
|
|
21
|
+
github-repo-change:
|
|
22
|
+
profile_bindings:
|
|
23
|
+
team:
|
|
24
|
+
ssh_credential_ref: repository-writer
|
|
25
|
+
process_configs:
|
|
26
|
+
github_repo_change_process:
|
|
27
|
+
watchers:
|
|
28
|
+
use_leitwerk:
|
|
29
|
+
enabled: true
|
|
30
|
+
profile: team
|
|
31
|
+
poll_interval: 30s
|
|
32
|
+
repositories:
|
|
33
|
+
include: [team/service]
|
|
34
|
+
labels:
|
|
35
|
+
trigger: use-leitwerk
|
|
36
|
+
done: leitwerk-done
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The issue watcher uses the integration's trigger-actor authorization and rechecks
|
|
40
|
+
it before launch. Issue launches use `leitwerk/issue-N`. Profile mappings cannot
|
|
41
|
+
be overridden through launcher input; existing instances retain resolved wiring.
|
|
42
|
+
|
|
43
|
+
## Delivery and recovery
|
|
44
|
+
|
|
45
|
+
The shared coding publication lifecycle commits and pushes the work branch, then
|
|
46
|
+
creates or reconciles one PR. It settles human feedback for two minutes, acknowledges
|
|
47
|
+
it, and starts a fresh repair turn. Replies and other provider writes reconcile
|
|
48
|
+
across retries. GitHub checks trigger repair only for the tracked request revision;
|
|
49
|
+
diagnostics include failed check annotations and bounded Actions job logs. Consumed
|
|
50
|
+
failure evidence is retained so rearming cannot repeatedly repair the same failure.
|
|
51
|
+
After three automatic CI cycles, the operator chooses retry, resume waiting, or
|
|
52
|
+
abort. Missing or successful checks do not complete the process.
|
|
53
|
+
|
|
54
|
+
Confirmed conflicts and GitHub's clean-but-behind condition use the shared rebase
|
|
55
|
+
implementation and the original-head push lease. Merge completes delivery; closing
|
|
56
|
+
an unmerged PR aborts it. An issue-origin merge removes the trigger, adds the done
|
|
57
|
+
label, comments, and closes the issue. Unmerged closure removes the trigger and
|
|
58
|
+
comments without closing the issue. Source cancellation aborts waiting delivery;
|
|
59
|
+
terminal PR reconciliation takes precedence. UI-origin processes never need a
|
|
60
|
+
source issue.
|
|
61
|
+
|
|
62
|
+
## Composition
|
|
63
|
+
|
|
64
|
+
The default extension requires Docker. Trusted local compositions can use
|
|
65
|
+
`createGitHubRepoChange({ docker: false })`; load exactly one variant. Both retain
|
|
66
|
+
`github_repo_change_process`. Custom GitHub integrations must supply `profiles()`
|
|
67
|
+
to expose profiles to the launcher. The factory owns its launcher configuration
|
|
68
|
+
and clears it when the server stops. Automatic merging, existing-PR adoption,
|
|
69
|
+
fork publication, and release delivery are not provided.
|
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2026 Leitwerk contributors.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { LeitwerkExtensionModule } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
/** @public */
|
|
3
|
+
export declare const manifest: {
|
|
4
|
+
/** @public */
|
|
5
|
+
readonly id: "github-repo-change";
|
|
6
|
+
/** @public */
|
|
7
|
+
readonly version: "0.1.9";
|
|
8
|
+
/** @public */
|
|
9
|
+
readonly requires: readonly ["github", "coding", "git-ssh"];
|
|
10
|
+
};
|
|
11
|
+
/** Load exactly one variant per catalog. Only trusted composition code selects Docker. */
|
|
12
|
+
/** @public */
|
|
13
|
+
/** @public */
|
|
14
|
+
export declare function createGitHubRepoChange(options: {
|
|
15
|
+
/** @public */
|
|
16
|
+
docker: boolean;
|
|
17
|
+
}): {
|
|
18
|
+
/** @public */
|
|
19
|
+
extension: LeitwerkExtensionModule;
|
|
20
|
+
/** @public */
|
|
21
|
+
process: import("@leitwerk-dev/process-sdk").ExtensionProcessDefinition<import("./params.js").GitHubRepoChangeParams, import("@leitwerk-dev/coding/repository-change-state").RepositoryChangeState>;
|
|
22
|
+
/** @public */
|
|
23
|
+
launcher: {
|
|
24
|
+
/** @public */
|
|
25
|
+
configure: (value: import("./launcher.js").LauncherDependencies | null) => void;
|
|
26
|
+
/** @public */
|
|
27
|
+
preparationChecks: (_input: unknown, { params }: import("@leitwerk-dev/process-sdk").ProcessLaunchConfig<import("./params.js").GitHubRepoChangeParams>) => readonly import("@leitwerk-dev/process-sdk").LaunchPreparationCheck<import("./params.js").GitHubRepoChangeParams>[];
|
|
28
|
+
/** @public */
|
|
29
|
+
resolveProfiles: (profile: string) => import("./profile-bindings.js").ProfileBinding;
|
|
30
|
+
/** @public */
|
|
31
|
+
resolveGitIdentity: (profile: string) => Promise<import("@leitwerk-dev/github").GitHubGitIdentity>;
|
|
32
|
+
/** @public */
|
|
33
|
+
launcher: import("@leitwerk-dev/process-sdk").ProcessLauncherDefinition<import("./params.js").GitHubRepoChangeParams> & {
|
|
34
|
+
/** @internal */
|
|
35
|
+
resolveIssueLaunchConfig(event: {
|
|
36
|
+
/** @internal */
|
|
37
|
+
profile: string;
|
|
38
|
+
/** @internal */
|
|
39
|
+
repository: import("@leitwerk-dev/github").GitHubRepository;
|
|
40
|
+
/** @internal */
|
|
41
|
+
issue: Pick<import("@leitwerk-dev/github").GitHubIssue, "number" | "title" | "body" | "html_url">;
|
|
42
|
+
/** @internal */
|
|
43
|
+
labels: import("@leitwerk-dev/process-sdk").RepositoryIssueWatcherConfig["labels"];
|
|
44
|
+
}): Promise<import("@leitwerk-dev/process-sdk").ProcessLaunchConfig<import("./params.js").GitHubRepoChangeParams>>;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export * from "./launcher.js";
|
|
49
|
+
export * from "./params.js";
|
|
50
|
+
export * from "./process.js";
|
|
51
|
+
export * from "./profile-bindings.js";
|
|
52
|
+
/** @public */
|
|
53
|
+
export declare const defaultExtension: LeitwerkExtensionModule, githubRepoChangeProcess: import("@leitwerk-dev/process-sdk").ExtensionProcessDefinition<import("./params.js").GitHubRepoChangeParams, import("@leitwerk-dev/coding/repository-change-state").RepositoryChangeState>, defaultGitHubRepoChangeLauncher: {
|
|
54
|
+
/** @public */
|
|
55
|
+
configure: (value: import("./launcher.js").LauncherDependencies | null) => void;
|
|
56
|
+
/** @public */
|
|
57
|
+
preparationChecks: (_input: unknown, { params }: import("@leitwerk-dev/process-sdk").ProcessLaunchConfig<import("./params.js").GitHubRepoChangeParams>) => readonly import("@leitwerk-dev/process-sdk").LaunchPreparationCheck<import("./params.js").GitHubRepoChangeParams>[];
|
|
58
|
+
/** @public */
|
|
59
|
+
resolveProfiles: (profile: string) => import("./profile-bindings.js").ProfileBinding;
|
|
60
|
+
/** @public */
|
|
61
|
+
resolveGitIdentity: (profile: string) => Promise<import("@leitwerk-dev/github").GitHubGitIdentity>;
|
|
62
|
+
/** @public */
|
|
63
|
+
launcher: import("@leitwerk-dev/process-sdk").ProcessLauncherDefinition<import("./params.js").GitHubRepoChangeParams> & {
|
|
64
|
+
/** @internal */
|
|
65
|
+
resolveIssueLaunchConfig(event: {
|
|
66
|
+
/** @internal */
|
|
67
|
+
profile: string;
|
|
68
|
+
/** @internal */
|
|
69
|
+
repository: import("@leitwerk-dev/github").GitHubRepository;
|
|
70
|
+
/** @internal */
|
|
71
|
+
issue: Pick<import("@leitwerk-dev/github").GitHubIssue, "number" | "title" | "body" | "html_url">;
|
|
72
|
+
/** @internal */
|
|
73
|
+
labels: import("@leitwerk-dev/process-sdk").RepositoryIssueWatcherConfig["labels"];
|
|
74
|
+
}): Promise<import("@leitwerk-dev/process-sdk").ProcessLaunchConfig<import("./params.js").GitHubRepoChangeParams>>;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
/** @public */
|
|
78
|
+
export declare const configureGitHubRepoChangeLauncher: (value: import("./launcher.js").LauncherDependencies | null) => void, githubRepositoryPreparationChecks: (_input: unknown, { params }: import("@leitwerk-dev/process-sdk").ProcessLaunchConfig<import("./params.js").GitHubRepoChangeParams>) => readonly import("@leitwerk-dev/process-sdk").LaunchPreparationCheck<import("./params.js").GitHubRepoChangeParams>[], resolveGitHubGitIdentity: (profile: string) => Promise<import("@leitwerk-dev/github").GitHubGitIdentity>, githubRepoChangeUiLauncher: import("@leitwerk-dev/process-sdk").ProcessLauncherDefinition<import("./params.js").GitHubRepoChangeParams> & {
|
|
79
|
+
/** @internal */
|
|
80
|
+
resolveIssueLaunchConfig(event: {
|
|
81
|
+
/** @internal */
|
|
82
|
+
profile: string;
|
|
83
|
+
/** @internal */
|
|
84
|
+
repository: import("@leitwerk-dev/github").GitHubRepository;
|
|
85
|
+
/** @internal */
|
|
86
|
+
issue: Pick<import("@leitwerk-dev/github").GitHubIssue, "number" | "title" | "body" | "html_url">;
|
|
87
|
+
/** @internal */
|
|
88
|
+
labels: import("@leitwerk-dev/process-sdk").RepositoryIssueWatcherConfig["labels"];
|
|
89
|
+
}): Promise<import("@leitwerk-dev/process-sdk").ProcessLaunchConfig<import("./params.js").GitHubRepoChangeParams>>;
|
|
90
|
+
};
|
|
91
|
+
export default defaultExtension;
|
|
92
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAKzE,cAAc;AACd,eAAO,MAAM,QAAQ;IACpB,cAAc;;IAEd,cAAc;;IAEd,cAAc;;CAEL,CAAC;AAEX,0FAA0F;AAC1F,cAAc;AACd,cAAc;AACd,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC/C,cAAc;IACd,MAAM,EAAE,OAAO,CAAC;CAChB;IAyBC,cAAc;;IAEd,cAAc;;IAEd,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;EAGf;AAED,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc;AACd,eAAO,MACK,gBAAgB,2BAClB,uBAAuB,8LACtB,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;CACE,CAAC;AAC7C,cAAc;AACd,eAAO,MACK,iCAAiC,wEACzB,iCAAiC,+PAChC,wBAAwB,kFAClC,0BAA0B;;;;;;;;;;;;CACF,CAAC;AACpC,eAAe,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { gitSshIntegration } from "@leitwerk-dev/git-ssh";
|
|
3
|
+
import { githubIntegration } from "@leitwerk-dev/github";
|
|
4
|
+
|
|
5
|
+
// src/launcher.ts
|
|
6
|
+
import {
|
|
7
|
+
createRepositoryChangeUiLauncher,
|
|
8
|
+
repositoryVisibilityCheck
|
|
9
|
+
} from "@leitwerk-dev/coding/repository-change-launch";
|
|
10
|
+
import { createGitSshPreparationCheck } from "@leitwerk-dev/git-ssh";
|
|
11
|
+
|
|
12
|
+
// src/params.ts
|
|
13
|
+
import {
|
|
14
|
+
createRepositoryChangeParamsCodec,
|
|
15
|
+
normalizeRepositoryIssueChangeParams
|
|
16
|
+
} from "@leitwerk-dev/coding/repository-change-launch";
|
|
17
|
+
function isIssueOrigin(params) {
|
|
18
|
+
return params.origin === "issue";
|
|
19
|
+
}
|
|
20
|
+
var githubRepoChangeParamsCodec = createRepositoryChangeParamsCodec({
|
|
21
|
+
normalize(value) {
|
|
22
|
+
return normalizeRepositoryIssueChangeParams(value, "GitHub Repo Change", [
|
|
23
|
+
"githubProfile",
|
|
24
|
+
"sshCredentialRef",
|
|
25
|
+
"owner",
|
|
26
|
+
"repo"
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// src/profile-bindings.ts
|
|
32
|
+
import { parseRepositoryProfileBindings } from "@leitwerk-dev/coding/repository-change-launch";
|
|
33
|
+
function parseProfileBindings(raw) {
|
|
34
|
+
return parseRepositoryProfileBindings(raw, "github-repo-change", {
|
|
35
|
+
sshCredentialRef: "ssh_credential_ref"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function resolveProfileBinding(bindings, profile) {
|
|
39
|
+
return Object.hasOwn(bindings, profile) ? { ...bindings[profile] } : { sshCredentialRef: profile };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/launcher.ts
|
|
43
|
+
var githubRepoChangeUiLauncherId = "github_repo_change_process.ui_launcher";
|
|
44
|
+
function githubRepoChangeParams(repository, input) {
|
|
45
|
+
return {
|
|
46
|
+
repoLocator: repository.ssh_url,
|
|
47
|
+
baseBranch: repository.default_branch,
|
|
48
|
+
workBranch: input.workBranch,
|
|
49
|
+
prompt: input.prompt,
|
|
50
|
+
githubProfile: input.profile,
|
|
51
|
+
sshCredentialRef: input.sshCredentialRef,
|
|
52
|
+
owner: repository.owner.login,
|
|
53
|
+
repo: repository.name,
|
|
54
|
+
origin: "ui",
|
|
55
|
+
issueNumber: null,
|
|
56
|
+
issueUrl: null,
|
|
57
|
+
triggerLabel: null,
|
|
58
|
+
doneLabel: null
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function githubRepoChangeLaunchConfig(params, title, gitIdentity) {
|
|
62
|
+
const { owner, repo, githubProfile: profile } = params;
|
|
63
|
+
const issue = isIssueOrigin(params);
|
|
64
|
+
return {
|
|
65
|
+
processId: "github_repo_change_process",
|
|
66
|
+
params,
|
|
67
|
+
title,
|
|
68
|
+
startTurnId: "generate_plan",
|
|
69
|
+
...issue ? {
|
|
70
|
+
externalId: `github:${owner}/${repo}#${params.issueNumber}`,
|
|
71
|
+
externalUrl: params.issueUrl
|
|
72
|
+
} : {},
|
|
73
|
+
projects: [
|
|
74
|
+
{
|
|
75
|
+
key: "repo",
|
|
76
|
+
repoLocator: params.repoLocator,
|
|
77
|
+
baseBranch: params.baseBranch,
|
|
78
|
+
workBranch: params.workBranch,
|
|
79
|
+
...issue ? { externalId: String(params.issueNumber), externalUrl: params.issueUrl } : {},
|
|
80
|
+
metadata: {
|
|
81
|
+
github: { owner, repo, profile, ...issue ? { issueNumber: params.issueNumber } : {} },
|
|
82
|
+
"leitwerk.gitIdentity": gitIdentity
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function createGitHubRepoChangeLauncher() {
|
|
89
|
+
let dependencies = null;
|
|
90
|
+
function configureGitHubRepoChangeLauncher2(value) {
|
|
91
|
+
dependencies = value;
|
|
92
|
+
}
|
|
93
|
+
function requireDependencies() {
|
|
94
|
+
if (!dependencies) throw new Error("GitHub repository launcher is not configured");
|
|
95
|
+
return dependencies;
|
|
96
|
+
}
|
|
97
|
+
function githubRepositoryPreparationChecks2(_input, { params }) {
|
|
98
|
+
return [
|
|
99
|
+
repositoryVisibilityCheck(
|
|
100
|
+
"GitHub",
|
|
101
|
+
async () => (await repositories(params.githubProfile)).some(
|
|
102
|
+
(candidate) => candidate.full_name === `${params.owner}/${params.repo}`
|
|
103
|
+
)
|
|
104
|
+
),
|
|
105
|
+
createGitSshPreparationCheck("read", params, () => requireDependencies().gitSsh),
|
|
106
|
+
createGitSshPreparationCheck("write", params, () => requireDependencies().gitSsh)
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
function resolveProfiles(profile) {
|
|
110
|
+
const { github, gitSsh, profileBindings = {} } = requireDependencies();
|
|
111
|
+
if (!(github.profiles?.() ?? []).includes(profile))
|
|
112
|
+
throw new Error("GitHub profile is not available");
|
|
113
|
+
const binding = resolveProfileBinding(profileBindings, profile);
|
|
114
|
+
if (!gitSsh.profiles().includes(binding.sshCredentialRef))
|
|
115
|
+
throw new Error(`Git SSH profile '${binding.sshCredentialRef}' is not available`);
|
|
116
|
+
return binding;
|
|
117
|
+
}
|
|
118
|
+
async function resolveGitHubGitIdentity2(profile) {
|
|
119
|
+
if (!profile) throw new Error("A GitHub profile is required to resolve Git identity");
|
|
120
|
+
return requireDependencies().github.client(profile).resolveGitIdentity(profile);
|
|
121
|
+
}
|
|
122
|
+
async function repositories(profile) {
|
|
123
|
+
if (!profile) return [];
|
|
124
|
+
const { github } = requireDependencies();
|
|
125
|
+
if (!(github.profiles?.() ?? []).includes(profile)) return [];
|
|
126
|
+
return github.client(profile).listRepositories();
|
|
127
|
+
}
|
|
128
|
+
const githubRepoChangeUiLauncher2 = createRepositoryChangeUiLauncher({
|
|
129
|
+
id: githubRepoChangeUiLauncherId,
|
|
130
|
+
provider: "GitHub",
|
|
131
|
+
providerId: "github",
|
|
132
|
+
assertConfigured: requireDependencies,
|
|
133
|
+
profiles: () => requireDependencies().github.profiles?.() ?? [],
|
|
134
|
+
repositories,
|
|
135
|
+
resolveProfiles,
|
|
136
|
+
resolveGitIdentity: resolveGitHubGitIdentity2,
|
|
137
|
+
params: githubRepoChangeParams,
|
|
138
|
+
launchConfig: githubRepoChangeLaunchConfig,
|
|
139
|
+
preparationChecks: githubRepositoryPreparationChecks2
|
|
140
|
+
});
|
|
141
|
+
return {
|
|
142
|
+
/** @public */
|
|
143
|
+
configure: configureGitHubRepoChangeLauncher2,
|
|
144
|
+
/** @public */
|
|
145
|
+
preparationChecks: githubRepositoryPreparationChecks2,
|
|
146
|
+
/** @public */
|
|
147
|
+
resolveProfiles,
|
|
148
|
+
/** @public */
|
|
149
|
+
resolveGitIdentity: resolveGitHubGitIdentity2,
|
|
150
|
+
/** @public */
|
|
151
|
+
launcher: githubRepoChangeUiLauncher2
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/process.ts
|
|
156
|
+
import { createRepositoryChangeProcess } from "@leitwerk-dev/coding";
|
|
157
|
+
import {
|
|
158
|
+
createRepositoryChangePublication,
|
|
159
|
+
publicationObject as object,
|
|
160
|
+
pullRequestPublicationCallbacks,
|
|
161
|
+
pullRequestPublicationSources,
|
|
162
|
+
readPublicationState,
|
|
163
|
+
reconcilePullRequestSourceIssue,
|
|
164
|
+
resolvePullRequestGitIdentity
|
|
165
|
+
} from "@leitwerk-dev/coding/repository-change-publication";
|
|
166
|
+
import { githubExternal, githubIssueWatcherSource } from "@leitwerk-dev/github";
|
|
167
|
+
var processId = "github_repo_change_process";
|
|
168
|
+
var ids = {
|
|
169
|
+
deliver: "deliver_change",
|
|
170
|
+
feedback: "revise_from_pull_request_feedback",
|
|
171
|
+
ciRepair: "repair_github_checks",
|
|
172
|
+
operator: "ci_operator_action"
|
|
173
|
+
};
|
|
174
|
+
var remote = (state) => readPublicationState(state, "githubRepoChange");
|
|
175
|
+
var deliveryTools = [
|
|
176
|
+
"github_get_pull_request",
|
|
177
|
+
"github_add_pull_request_comment",
|
|
178
|
+
"github_resolve_git_identity",
|
|
179
|
+
"github_ensure_pull_request",
|
|
180
|
+
"github_add_issue_comment",
|
|
181
|
+
"github_add_pull_request_feedback_reaction",
|
|
182
|
+
"github_reply_to_pull_request_feedback",
|
|
183
|
+
"github_get_issue",
|
|
184
|
+
"github_ensure_label",
|
|
185
|
+
"github_update_issue"
|
|
186
|
+
];
|
|
187
|
+
function createGitHubRepoChangeProcess(launcher, docker) {
|
|
188
|
+
const sharedSources = pullRequestPublicationSources(
|
|
189
|
+
"github",
|
|
190
|
+
"GitHub",
|
|
191
|
+
githubExternal,
|
|
192
|
+
(params) => params.githubProfile,
|
|
193
|
+
(params) => isIssueOrigin(params) ? params : void 0
|
|
194
|
+
);
|
|
195
|
+
const { requirePr } = sharedSources;
|
|
196
|
+
const failedPipeline = githubExternal.checks(
|
|
197
|
+
({ params, state }) => ({
|
|
198
|
+
profile: params.githubProfile,
|
|
199
|
+
owner: params.owner,
|
|
200
|
+
repo: params.repo,
|
|
201
|
+
prNumber: requirePr(state).prNumber,
|
|
202
|
+
headSha: requirePr(state).headSha,
|
|
203
|
+
afterKey: remote(state).pipeline?.evidenceKey
|
|
204
|
+
})
|
|
205
|
+
);
|
|
206
|
+
const sources = [
|
|
207
|
+
{
|
|
208
|
+
id: "github_merge_conflict",
|
|
209
|
+
kind: "conflict",
|
|
210
|
+
label: "Rebase conflicting pull request",
|
|
211
|
+
source: githubExternal.pullRequestState(({ params, state }) => ({
|
|
212
|
+
profile: params.githubProfile,
|
|
213
|
+
owner: params.owner,
|
|
214
|
+
repo: params.repo,
|
|
215
|
+
prNumber: requirePr(state).prNumber,
|
|
216
|
+
headSha: requirePr(state).headSha,
|
|
217
|
+
lastConflictKey: remote(state).lastConflictKey,
|
|
218
|
+
feedbackCursor: 0,
|
|
219
|
+
eventKinds: ["merge_conflict"],
|
|
220
|
+
pollInterval: "30s"
|
|
221
|
+
})),
|
|
222
|
+
read: ({ event }) => ({
|
|
223
|
+
kind: "conflict",
|
|
224
|
+
conflict: object(event).conflict
|
|
225
|
+
})
|
|
226
|
+
},
|
|
227
|
+
sharedSources.feedback,
|
|
228
|
+
{
|
|
229
|
+
id: "github_failure_repair",
|
|
230
|
+
operatorId: "github_failure_operator",
|
|
231
|
+
kind: "failure",
|
|
232
|
+
label: "Repair failed GitHub checks",
|
|
233
|
+
source: failedPipeline,
|
|
234
|
+
read: ({ state, event }) => {
|
|
235
|
+
const checks = object(object(event).checks);
|
|
236
|
+
const current = requirePr(state);
|
|
237
|
+
if (checks.headSha !== current.headSha) throw new Error("Stale GitHub check evidence");
|
|
238
|
+
const failed = Array.isArray(checks.failed) ? checks.failed : [];
|
|
239
|
+
return {
|
|
240
|
+
kind: "failure",
|
|
241
|
+
pipeline: {
|
|
242
|
+
number: 0,
|
|
243
|
+
status: "failure",
|
|
244
|
+
...checks,
|
|
245
|
+
evidenceKey: `${checks.headSha}:${failed.map((run) => object(run).url).join(":")}`
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
...sharedSources.terminal,
|
|
251
|
+
sharedSources.cancelled
|
|
252
|
+
];
|
|
253
|
+
const publicationConfig = createRepositoryChangePublication({
|
|
254
|
+
namespace: "githubRepoChange",
|
|
255
|
+
label: "GitHub PR",
|
|
256
|
+
ids,
|
|
257
|
+
sources,
|
|
258
|
+
tools: {
|
|
259
|
+
delivery: deliveryTools,
|
|
260
|
+
feedback: ["github_get_pull_request", "github_list_pull_request_feedback"],
|
|
261
|
+
ci: ["github_get_ci_diagnostics"]
|
|
262
|
+
},
|
|
263
|
+
identity: (ctx) => resolvePullRequestGitIdentity(ctx, "github", ctx.params.githubProfile),
|
|
264
|
+
reconcileTerminal: reconcilePullRequestSourceIssue(
|
|
265
|
+
"github",
|
|
266
|
+
"name",
|
|
267
|
+
(params) => isIssueOrigin(params) ? params : void 0
|
|
268
|
+
),
|
|
269
|
+
...pullRequestPublicationCallbacks(
|
|
270
|
+
"github",
|
|
271
|
+
"GitHub",
|
|
272
|
+
(params) => isIssueOrigin(params) ? params : void 0
|
|
273
|
+
),
|
|
274
|
+
commitMessage: (kind) => kind === "feedback" ? "fix: address GitHub review feedback" : "fix: repair GitHub checks",
|
|
275
|
+
prompt(kind, current) {
|
|
276
|
+
return kind === "feedback" ? `Address the unseen GitHub pull-request feedback batch for PR #${current.prNumber}. Feedback identifiers: ${JSON.stringify(current.feedbackIds)}. Inspect the current checkout and use GitHub tools to read the full feedback. Do not rely on an earlier plan or conversation. Make only justified repository changes. Call changes_ready if files need publishing, no_changes after an explicit diagnosis that no repository change is needed, or cannot_repair when operator action is required.` : `Diagnose failed GitHub checks for request #${current.prNumber}, head ${current.headSha}. Use github_get_ci_diagnostics with pullRequestNumber and headSha to inspect failed check annotations and bounded Actions job logs before changing anything. Fix repository causes. Call changes_ready for repository changes, no_changes only after an explicit provider restart or a justified diagnosis that no repository change is needed, or cannot_repair when operator action is required.`;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
const publication = publicationConfig.fragment;
|
|
280
|
+
publication.watcher({
|
|
281
|
+
id: "use_leitwerk",
|
|
282
|
+
label: "GitHub use-leitwerk issues",
|
|
283
|
+
description: "Launch a remote repository change for GitHub issues carrying the trigger label",
|
|
284
|
+
source: githubIssueWatcherSource,
|
|
285
|
+
preparationChecks: launcher.preparationChecks,
|
|
286
|
+
resolveLaunchConfig: launcher.launcher.resolveIssueLaunchConfig
|
|
287
|
+
});
|
|
288
|
+
const definition = createRepositoryChangeProcess({
|
|
289
|
+
processId,
|
|
290
|
+
displayName: "GitHub Repo Change",
|
|
291
|
+
paramsCodec: githubRepoChangeParamsCodec,
|
|
292
|
+
launcher: launcher.launcher,
|
|
293
|
+
finalizeLabel: "Publish pull request",
|
|
294
|
+
finalizeForm: {
|
|
295
|
+
id: "github_publish",
|
|
296
|
+
title: "Publish pull request",
|
|
297
|
+
fields: [],
|
|
298
|
+
submitLabel: "Publish"
|
|
299
|
+
},
|
|
300
|
+
repositoryCredentials: ({ params }) => [
|
|
301
|
+
{
|
|
302
|
+
projectKey: "repo",
|
|
303
|
+
kind: "git_ssh",
|
|
304
|
+
credentialRef: params.sshCredentialRef
|
|
305
|
+
}
|
|
306
|
+
],
|
|
307
|
+
publication: publicationConfig
|
|
308
|
+
});
|
|
309
|
+
definition.process.runtime = { ...definition.process.runtime, docker };
|
|
310
|
+
return definition.process;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/index.ts
|
|
314
|
+
var manifest = {
|
|
315
|
+
/** @public */
|
|
316
|
+
id: "github-repo-change",
|
|
317
|
+
/** @public */
|
|
318
|
+
version: "0.1.9",
|
|
319
|
+
/** @public */
|
|
320
|
+
requires: ["github", "coding", "git-ssh"]
|
|
321
|
+
};
|
|
322
|
+
function createGitHubRepoChange(options) {
|
|
323
|
+
if (typeof options.docker !== "boolean") throw new Error("docker must be a boolean");
|
|
324
|
+
const launcher = createGitHubRepoChangeLauncher();
|
|
325
|
+
const process = createGitHubRepoChangeProcess(launcher, options.docker);
|
|
326
|
+
const extension = {
|
|
327
|
+
manifest,
|
|
328
|
+
setupCatalog(api) {
|
|
329
|
+
api.registerProcess(process);
|
|
330
|
+
},
|
|
331
|
+
setupServer(api, config) {
|
|
332
|
+
const github = api.require(githubIntegration);
|
|
333
|
+
const gitSsh = api.require(gitSshIntegration);
|
|
334
|
+
if (Array.isArray(github) || Array.isArray(gitSsh))
|
|
335
|
+
throw new Error("Repository delivery integrations must be singular");
|
|
336
|
+
launcher.configure({
|
|
337
|
+
github,
|
|
338
|
+
gitSsh,
|
|
339
|
+
profileBindings: parseProfileBindings(config)
|
|
340
|
+
});
|
|
341
|
+
api.onStop(() => launcher.configure(null));
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
return {
|
|
345
|
+
/** @public */
|
|
346
|
+
extension,
|
|
347
|
+
/** @public */
|
|
348
|
+
process,
|
|
349
|
+
/** @public */
|
|
350
|
+
launcher
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
var {
|
|
354
|
+
extension: defaultExtension,
|
|
355
|
+
process: githubRepoChangeProcess,
|
|
356
|
+
launcher: defaultGitHubRepoChangeLauncher
|
|
357
|
+
} = createGitHubRepoChange({ docker: true });
|
|
358
|
+
var {
|
|
359
|
+
configure: configureGitHubRepoChangeLauncher,
|
|
360
|
+
preparationChecks: githubRepositoryPreparationChecks,
|
|
361
|
+
resolveGitIdentity: resolveGitHubGitIdentity,
|
|
362
|
+
launcher: githubRepoChangeUiLauncher
|
|
363
|
+
} = defaultGitHubRepoChangeLauncher;
|
|
364
|
+
var index_default = defaultExtension;
|
|
365
|
+
export {
|
|
366
|
+
configureGitHubRepoChangeLauncher,
|
|
367
|
+
createGitHubRepoChange,
|
|
368
|
+
createGitHubRepoChangeLauncher,
|
|
369
|
+
createGitHubRepoChangeProcess,
|
|
370
|
+
index_default as default,
|
|
371
|
+
defaultExtension,
|
|
372
|
+
defaultGitHubRepoChangeLauncher,
|
|
373
|
+
githubRepoChangeLaunchConfig,
|
|
374
|
+
githubRepoChangeParams,
|
|
375
|
+
githubRepoChangeParamsCodec,
|
|
376
|
+
githubRepoChangeProcess,
|
|
377
|
+
githubRepoChangeUiLauncher,
|
|
378
|
+
githubRepoChangeUiLauncherId,
|
|
379
|
+
githubRepositoryPreparationChecks,
|
|
380
|
+
isIssueOrigin,
|
|
381
|
+
manifest,
|
|
382
|
+
parseProfileBindings,
|
|
383
|
+
resolveGitHubGitIdentity,
|
|
384
|
+
resolveProfileBinding
|
|
385
|
+
};
|
|
386
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/launcher.ts","../src/params.ts","../src/profile-bindings.ts","../src/process.ts"],"sourcesContent":["import { gitSshIntegration } from \"@leitwerk-dev/git-ssh\";\nimport { githubIntegration } from \"@leitwerk-dev/github\";\nimport type { LeitwerkExtensionModule } from \"@leitwerk-dev/process-sdk\";\nimport { createGitHubRepoChangeLauncher } from \"./launcher.js\";\nimport { createGitHubRepoChangeProcess } from \"./process.js\";\nimport { parseProfileBindings } from \"./profile-bindings.js\";\n\n/** @public */\nexport const manifest = {\n\t/** @public */\n\tid: \"github-repo-change\",\n\t/** @public */\n\tversion: \"0.1.9\",\n\t/** @public */\n\trequires: [\"github\", \"coding\", \"git-ssh\"],\n} as const;\n\n/** Load exactly one variant per catalog. Only trusted composition code selects Docker. */\n/** @public */\n/** @public */\nexport function createGitHubRepoChange(options: {\n\t/** @public */\n\tdocker: boolean;\n}) {\n\tif (typeof options.docker !== \"boolean\") throw new Error(\"docker must be a boolean\");\n\tconst launcher = createGitHubRepoChangeLauncher();\n\tconst process = createGitHubRepoChangeProcess(launcher, options.docker);\n\tconst extension: LeitwerkExtensionModule = {\n\t\tmanifest,\n\t\tsetupCatalog(api) {\n\t\t\tapi.registerProcess(process);\n\t\t},\n\t\tsetupServer(api, config) {\n\t\t\tconst github = api.require(githubIntegration);\n\t\t\tconst gitSsh = api.require(gitSshIntegration);\n\t\t\tif (Array.isArray(github) || Array.isArray(gitSsh))\n\t\t\t\tthrow new Error(\"Repository delivery integrations must be singular\");\n\t\t\tlauncher.configure({\n\t\t\t\tgithub,\n\t\t\t\tgitSsh,\n\t\t\t\tprofileBindings: parseProfileBindings(config),\n\t\t\t});\n\t\t\tapi.onStop(() => launcher.configure(null));\n\t\t},\n\t};\n\t/** @public */\n\t/** @public */\n\treturn {\n\t\t/** @public */\n\t\textension,\n\t\t/** @public */\n\t\tprocess,\n\t\t/** @public */\n\t\tlauncher,\n\t};\n}\n\nexport * from \"./launcher.js\";\nexport * from \"./params.js\";\nexport * from \"./process.js\";\nexport * from \"./profile-bindings.js\";\n/** @public */\nexport const {\n\textension: defaultExtension,\n\tprocess: githubRepoChangeProcess,\n\tlauncher: defaultGitHubRepoChangeLauncher,\n} = createGitHubRepoChange({ docker: true });\n/** @public */\nexport const {\n\tconfigure: configureGitHubRepoChangeLauncher,\n\tpreparationChecks: githubRepositoryPreparationChecks,\n\tresolveGitIdentity: resolveGitHubGitIdentity,\n\tlauncher: githubRepoChangeUiLauncher,\n} = defaultGitHubRepoChangeLauncher;\nexport default defaultExtension;\n","import {\n\tcreateRepositoryChangeUiLauncher,\n\trepositoryVisibilityCheck,\n} from \"@leitwerk-dev/coding/repository-change-launch\";\nimport { createGitSshPreparationCheck, type GitSshIntegration } from \"@leitwerk-dev/git-ssh\";\nimport type { GitHubGitIdentity, GitHubIntegration, GitHubRepository } from \"@leitwerk-dev/github\";\nimport type { LaunchPreparationCheck, ProcessLaunchConfig } from \"@leitwerk-dev/process-sdk\";\nimport { type GitHubRepoChangeParams, isIssueOrigin } from \"./params.js\";\nimport { type ProfileBindings, resolveProfileBinding } from \"./profile-bindings.js\";\n\n/** @public */\nexport const githubRepoChangeUiLauncherId = \"github_repo_change_process.ui_launcher\" as const;\n\n/** @public */\nexport function githubRepoChangeParams(\n\trepository: GitHubRepository,\n\tinput: {\n\t\t/** @public */\n\t\tprofile: string;\n\t\t/** @public */\n\t\tsshCredentialRef: string;\n\t\t/** @public */\n\t\tprompt: string;\n\t\t/** @public */\n\t\tworkBranch: string;\n\t},\n): GitHubRepoChangeParams {\n\treturn {\n\t\trepoLocator: repository.ssh_url,\n\t\tbaseBranch: repository.default_branch,\n\t\tworkBranch: input.workBranch,\n\t\tprompt: input.prompt,\n\t\tgithubProfile: input.profile,\n\t\tsshCredentialRef: input.sshCredentialRef,\n\t\towner: repository.owner.login,\n\t\trepo: repository.name,\n\t\torigin: \"ui\",\n\t\tissueNumber: null,\n\t\tissueUrl: null,\n\t\ttriggerLabel: null,\n\t\tdoneLabel: null,\n\t};\n}\n\n/** @public */\nexport function githubRepoChangeLaunchConfig(\n\tparams: GitHubRepoChangeParams,\n\ttitle: string,\n\tgitIdentity: GitHubGitIdentity,\n): ProcessLaunchConfig<GitHubRepoChangeParams> {\n\tconst { owner, repo, githubProfile: profile } = params;\n\tconst issue = isIssueOrigin(params);\n\treturn {\n\t\tprocessId: \"github_repo_change_process\",\n\t\tparams,\n\t\ttitle,\n\t\tstartTurnId: \"generate_plan\",\n\t\t...(issue\n\t\t\t? {\n\t\t\t\t\texternalId: `github:${owner}/${repo}#${params.issueNumber}`,\n\t\t\t\t\texternalUrl: params.issueUrl,\n\t\t\t\t}\n\t\t\t: {}),\n\t\tprojects: [\n\t\t\t{\n\t\t\t\tkey: \"repo\",\n\t\t\t\trepoLocator: params.repoLocator,\n\t\t\t\tbaseBranch: params.baseBranch,\n\t\t\t\tworkBranch: params.workBranch,\n\t\t\t\t...(issue ? { externalId: String(params.issueNumber), externalUrl: params.issueUrl } : {}),\n\t\t\t\tmetadata: {\n\t\t\t\t\tgithub: { owner, repo, profile, ...(issue ? { issueNumber: params.issueNumber } : {}) },\n\t\t\t\t\t\"leitwerk.gitIdentity\": gitIdentity,\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t};\n}\n\n/** @public */\nexport interface LauncherDependencies {\n\t/** @public */\n\tgithub: GitHubIntegration;\n\t/** @public */\n\tgitSsh: GitSshIntegration;\n\t/** @public */\n\tprofileBindings?: ProfileBindings;\n}\n\n/** @public */\nexport function createGitHubRepoChangeLauncher() {\n\tlet dependencies: LauncherDependencies | null = null;\n\n\t/** @public */\n\tfunction configureGitHubRepoChangeLauncher(value: LauncherDependencies | null): void {\n\t\tdependencies = value;\n\t}\n\n\tfunction requireDependencies(): LauncherDependencies {\n\t\tif (!dependencies) throw new Error(\"GitHub repository launcher is not configured\");\n\t\treturn dependencies;\n\t}\n\n\t/** @public */\n\tfunction githubRepositoryPreparationChecks(\n\t\t_input: unknown,\n\t\t{ params }: ProcessLaunchConfig<GitHubRepoChangeParams>,\n\t): readonly LaunchPreparationCheck<GitHubRepoChangeParams>[] {\n\t\treturn [\n\t\t\trepositoryVisibilityCheck(\"GitHub\", async () =>\n\t\t\t\t(await repositories(params.githubProfile)).some(\n\t\t\t\t\t(candidate) => candidate.full_name === `${params.owner}/${params.repo}`,\n\t\t\t\t),\n\t\t\t),\n\t\t\tcreateGitSshPreparationCheck(\"read\", params, () => requireDependencies().gitSsh),\n\t\t\tcreateGitSshPreparationCheck(\"write\", params, () => requireDependencies().gitSsh),\n\t\t];\n\t}\n\n\t/** @public */\n\tfunction resolveProfiles(profile: string) {\n\t\tconst { github, gitSsh, profileBindings = {} } = requireDependencies();\n\t\tif (!(github.profiles?.() ?? []).includes(profile))\n\t\t\tthrow new Error(\"GitHub profile is not available\");\n\t\tconst binding = resolveProfileBinding(profileBindings, profile);\n\n\t\tif (!gitSsh.profiles().includes(binding.sshCredentialRef))\n\t\t\tthrow new Error(`Git SSH profile '${binding.sshCredentialRef}' is not available`);\n\t\treturn binding;\n\t}\n\n\t/** @public */\n\tasync function resolveGitHubGitIdentity(profile: string): Promise<GitHubGitIdentity> {\n\t\tif (!profile) throw new Error(\"A GitHub profile is required to resolve Git identity\");\n\t\treturn requireDependencies().github.client(profile).resolveGitIdentity(profile);\n\t}\n\n\tasync function repositories(profile: string): Promise<readonly GitHubRepository[]> {\n\t\tif (!profile) return [];\n\t\tconst { github } = requireDependencies();\n\t\tif (!(github.profiles?.() ?? []).includes(profile)) return [];\n\t\treturn github.client(profile).listRepositories();\n\t}\n\n\tconst githubRepoChangeUiLauncher = createRepositoryChangeUiLauncher({\n\t\tid: githubRepoChangeUiLauncherId,\n\t\tprovider: \"GitHub\",\n\t\tproviderId: \"github\",\n\t\tassertConfigured: requireDependencies,\n\t\tprofiles: () => requireDependencies().github.profiles?.() ?? [],\n\t\trepositories,\n\t\tresolveProfiles,\n\t\tresolveGitIdentity: resolveGitHubGitIdentity,\n\t\tparams: githubRepoChangeParams,\n\t\tlaunchConfig: githubRepoChangeLaunchConfig,\n\t\tpreparationChecks: githubRepositoryPreparationChecks,\n\t});\n\n\treturn {\n\t\t/** @public */\n\t\tconfigure: configureGitHubRepoChangeLauncher,\n\t\t/** @public */\n\t\tpreparationChecks: githubRepositoryPreparationChecks,\n\t\t/** @public */\n\t\tresolveProfiles,\n\t\t/** @public */\n\t\tresolveGitIdentity: resolveGitHubGitIdentity,\n\t\t/** @public */\n\t\tlauncher: githubRepoChangeUiLauncher,\n\t};\n}\n","import {\n\tcreateRepositoryChangeParamsCodec,\n\tnormalizeRepositoryIssueChangeParams,\n\ttype RepositoryChangeLaunchParams,\n\ttype RepositoryIssueOriginParams,\n\ttype RepositoryUiOriginParams,\n} from \"@leitwerk-dev/coding/repository-change-launch\";\n\n/** @public */\ninterface GitHubRepoChangeCommonParams {\n\t/** @public */\n\tgithubProfile: string;\n\t/** @public */\n\tsshCredentialRef: string;\n\t/** @public */\n\towner: string;\n\t/** @public */\n\trepo: string;\n}\n\n/** @public */\nexport interface GitHubIssueOriginParams extends RepositoryIssueOriginParams {}\n\n/** @public */\nexport interface GitHubUiOriginParams extends RepositoryUiOriginParams {}\n\n/** @public */\nexport type GitHubRepoChangeParams = RepositoryChangeLaunchParams<\n\tGitHubRepoChangeCommonParams & (GitHubIssueOriginParams | GitHubUiOriginParams)\n>;\n\n/** @public */\nexport function isIssueOrigin(\n\tparams: GitHubRepoChangeParams,\n): params is GitHubRepoChangeParams & GitHubIssueOriginParams {\n\treturn params.origin === \"issue\";\n}\n\n/** @public */\nexport const githubRepoChangeParamsCodec =\n\tcreateRepositoryChangeParamsCodec<GitHubRepoChangeParams>({\n\t\tnormalize(value) {\n\t\t\treturn normalizeRepositoryIssueChangeParams(value, \"GitHub Repo Change\", [\n\t\t\t\t\"githubProfile\",\n\t\t\t\t\"sshCredentialRef\",\n\t\t\t\t\"owner\",\n\t\t\t\t\"repo\",\n\t\t\t]);\n\t\t},\n\t});\n","import { parseRepositoryProfileBindings } from \"@leitwerk-dev/coding/repository-change-launch\";\n\n/** Server-owned, non-secret wiring for future launches. */\n/** @public */\nexport interface ProfileBinding {\n\t/** @public */\n\tsshCredentialRef: string;\n}\n/** @public */\nexport type ProfileBindings = Readonly<Record<string, Readonly<ProfileBinding>>>;\n\n/** @public */\nexport function parseProfileBindings(raw: unknown): ProfileBindings {\n\treturn parseRepositoryProfileBindings(raw, \"github-repo-change\", {\n\t\tsshCredentialRef: \"ssh_credential_ref\",\n\t});\n}\n/** @public */\nexport function resolveProfileBinding(bindings: ProfileBindings, profile: string): ProfileBinding {\n\treturn Object.hasOwn(bindings, profile)\n\t\t? { ...bindings[profile] }\n\t\t: { sshCredentialRef: profile };\n}\n","import { createRepositoryChangeProcess } from \"@leitwerk-dev/coding\";\nimport {\n\tcreateRepositoryChangePublication,\n\tpublicationObject as object,\n\ttype PublicationSource,\n\ttype PublicationState,\n\tpullRequestPublicationCallbacks,\n\tpullRequestPublicationSources,\n\treadPublicationState,\n\treconcilePullRequestSourceIssue,\n\tresolvePullRequestGitIdentity,\n} from \"@leitwerk-dev/coding/repository-change-publication\";\nimport type { RepositoryChangeState } from \"@leitwerk-dev/coding/repository-change-state\";\nimport { githubExternal, githubIssueWatcherSource } from \"@leitwerk-dev/github\";\nimport type { createGitHubRepoChangeLauncher } from \"./launcher.js\";\nimport {\n\ttype GitHubRepoChangeParams,\n\tgithubRepoChangeParamsCodec,\n\tisIssueOrigin,\n} from \"./params.js\";\n\nconst processId = \"github_repo_change_process\";\nconst ids = {\n\tdeliver: \"deliver_change\",\n\tfeedback: \"revise_from_pull_request_feedback\",\n\tciRepair: \"repair_github_checks\",\n\toperator: \"ci_operator_action\",\n};\nconst remote = (state: RepositoryChangeState) => readPublicationState(state, \"githubRepoChange\");\n\nconst deliveryTools = [\n\t\"github_get_pull_request\",\n\t\"github_add_pull_request_comment\",\n\t\"github_resolve_git_identity\",\n\t\"github_ensure_pull_request\",\n\t\"github_add_issue_comment\",\n\t\"github_add_pull_request_feedback_reaction\",\n\t\"github_reply_to_pull_request_feedback\",\n\t\"github_get_issue\",\n\t\"github_ensure_label\",\n\t\"github_update_issue\",\n] as const;\n\n/** @public */\nexport function createGitHubRepoChangeProcess(\n\tlauncher: ReturnType<typeof createGitHubRepoChangeLauncher>,\n\tdocker: boolean,\n) {\n\tconst sharedSources = pullRequestPublicationSources<GitHubRepoChangeParams>(\n\t\t\"github\",\n\t\t\"GitHub\",\n\t\tgithubExternal,\n\t\t(params) => params.githubProfile,\n\t\t(params) => (isIssueOrigin(params) ? params : undefined),\n\t);\n\tconst { requirePr } = sharedSources;\n\tconst failedPipeline = githubExternal.checks<GitHubRepoChangeParams, RepositoryChangeState>(\n\t\t({ params, state }) => ({\n\t\t\tprofile: params.githubProfile,\n\t\t\towner: params.owner,\n\t\t\trepo: params.repo,\n\t\t\tprNumber: requirePr(state).prNumber,\n\t\t\theadSha: requirePr(state).headSha,\n\t\t\tafterKey: remote(state).pipeline?.evidenceKey as string | undefined,\n\t\t}),\n\t);\n\n\tconst sources: PublicationSource<GitHubRepoChangeParams>[] = [\n\t\t{\n\t\t\tid: \"github_merge_conflict\",\n\t\t\tkind: \"conflict\",\n\t\t\tlabel: \"Rebase conflicting pull request\",\n\t\t\tsource: githubExternal.pullRequestState(({ params, state }) => ({\n\t\t\t\tprofile: params.githubProfile,\n\t\t\t\towner: params.owner,\n\t\t\t\trepo: params.repo,\n\t\t\t\tprNumber: requirePr(state).prNumber,\n\t\t\t\theadSha: requirePr(state).headSha,\n\t\t\t\tlastConflictKey: remote(state).lastConflictKey,\n\t\t\t\tfeedbackCursor: 0,\n\t\t\t\teventKinds: [\"merge_conflict\"],\n\t\t\t\tpollInterval: \"30s\",\n\t\t\t})),\n\t\t\tread: ({ event }) => ({\n\t\t\t\tkind: \"conflict\",\n\t\t\t\tconflict: object(event).conflict as NonNullable<PublicationState[\"conflict\"]>,\n\t\t\t}),\n\t\t},\n\t\tsharedSources.feedback,\n\t\t{\n\t\t\tid: \"github_failure_repair\",\n\t\t\toperatorId: \"github_failure_operator\",\n\t\t\tkind: \"failure\",\n\t\t\tlabel: \"Repair failed GitHub checks\",\n\t\t\tsource: failedPipeline,\n\t\t\tread: ({ state, event }) => {\n\t\t\t\tconst checks = object(object(event).checks);\n\t\t\t\tconst current = requirePr(state);\n\t\t\t\tif (checks.headSha !== current.headSha) throw new Error(\"Stale GitHub check evidence\");\n\t\t\t\tconst failed = Array.isArray(checks.failed) ? checks.failed : [];\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"failure\",\n\t\t\t\t\tpipeline: {\n\t\t\t\t\t\tnumber: 0,\n\t\t\t\t\t\tstatus: \"failure\",\n\t\t\t\t\t\t...checks,\n\t\t\t\t\t\tevidenceKey: `${checks.headSha}:${failed.map((run) => object(run).url).join(\":\")}`,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t},\n\t\t},\n\t\t...sharedSources.terminal,\n\t\tsharedSources.cancelled,\n\t];\n\tconst publicationConfig = createRepositoryChangePublication<GitHubRepoChangeParams>({\n\t\tnamespace: \"githubRepoChange\",\n\t\tlabel: \"GitHub PR\",\n\t\tids,\n\t\tsources,\n\t\ttools: {\n\t\t\tdelivery: deliveryTools,\n\t\t\tfeedback: [\"github_get_pull_request\", \"github_list_pull_request_feedback\"],\n\t\t\tci: [\"github_get_ci_diagnostics\"],\n\t\t},\n\t\tidentity: (ctx) => resolvePullRequestGitIdentity(ctx, \"github\", ctx.params.githubProfile),\n\t\treconcileTerminal: reconcilePullRequestSourceIssue<GitHubRepoChangeParams>(\n\t\t\t\"github\",\n\t\t\t\"name\",\n\t\t\t(params) => (isIssueOrigin(params) ? params : undefined),\n\t\t),\n\t\t...pullRequestPublicationCallbacks<GitHubRepoChangeParams>(\"github\", \"GitHub\", (params) =>\n\t\t\tisIssueOrigin(params) ? params : undefined,\n\t\t),\n\t\tcommitMessage: (kind) =>\n\t\t\tkind === \"feedback\" ? \"fix: address GitHub review feedback\" : \"fix: repair GitHub checks\",\n\t\tprompt(kind, current) {\n\t\t\treturn kind === \"feedback\"\n\t\t\t\t? `Address the unseen GitHub pull-request feedback batch for PR #${current.prNumber}. Feedback identifiers: ${JSON.stringify(current.feedbackIds)}. Inspect the current checkout and use GitHub tools to read the full feedback. Do not rely on an earlier plan or conversation. Make only justified repository changes. Call changes_ready if files need publishing, no_changes after an explicit diagnosis that no repository change is needed, or cannot_repair when operator action is required.`\n\t\t\t\t: `Diagnose failed GitHub checks for request #${current.prNumber}, head ${current.headSha}. Use github_get_ci_diagnostics with pullRequestNumber and headSha to inspect failed check annotations and bounded Actions job logs before changing anything. Fix repository causes. Call changes_ready for repository changes, no_changes only after an explicit provider restart or a justified diagnosis that no repository change is needed, or cannot_repair when operator action is required.`;\n\t\t},\n\t});\n\tconst publication = publicationConfig.fragment;\n\tpublication.watcher({\n\t\tid: \"use_leitwerk\",\n\t\tlabel: \"GitHub use-leitwerk issues\",\n\t\tdescription: \"Launch a remote repository change for GitHub issues carrying the trigger label\",\n\t\tsource: githubIssueWatcherSource,\n\t\tpreparationChecks: launcher.preparationChecks,\n\t\tresolveLaunchConfig: launcher.launcher.resolveIssueLaunchConfig,\n\t});\n\n\tconst definition = createRepositoryChangeProcess<GitHubRepoChangeParams>({\n\t\tprocessId,\n\t\tdisplayName: \"GitHub Repo Change\",\n\t\tparamsCodec: githubRepoChangeParamsCodec,\n\t\tlauncher: launcher.launcher,\n\t\tfinalizeLabel: \"Publish pull request\",\n\t\tfinalizeForm: {\n\t\t\tid: \"github_publish\",\n\t\t\ttitle: \"Publish pull request\",\n\t\t\tfields: [],\n\t\t\tsubmitLabel: \"Publish\",\n\t\t},\n\t\trepositoryCredentials: ({ params }) => [\n\t\t\t{\n\t\t\t\tprojectKey: \"repo\",\n\t\t\t\tkind: \"git_ssh\",\n\t\t\t\tcredentialRef: params.sshCredentialRef,\n\t\t\t},\n\t\t],\n\t\tpublication: publicationConfig,\n\t});\n\n\tdefinition.process.runtime = { ...definition.process.runtime, docker };\n\n\treturn definition.process;\n}\n"],"mappings":";AAAA,SAAS,yBAAyB;AAClC,SAAS,yBAAyB;;;ACDlC;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,oCAA4D;;;ACJrE;AAAA,EACC;AAAA,EACA;AAAA,OAIM;AA0BA,SAAS,cACf,QAC6D;AAC7D,SAAO,OAAO,WAAW;AAC1B;AAGO,IAAM,8BACZ,kCAA0D;AAAA,EACzD,UAAU,OAAO;AAChB,WAAO,qCAAqC,OAAO,sBAAsB;AAAA,MACxE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD,CAAC;AAAA,EACF;AACD,CAAC;;;ACjDF,SAAS,sCAAsC;AAYxC,SAAS,qBAAqB,KAA+B;AACnE,SAAO,+BAA+B,KAAK,sBAAsB;AAAA,IAChE,kBAAkB;AAAA,EACnB,CAAC;AACF;AAEO,SAAS,sBAAsB,UAA2B,SAAiC;AACjG,SAAO,OAAO,OAAO,UAAU,OAAO,IACnC,EAAE,GAAG,SAAS,OAAO,EAAE,IACvB,EAAE,kBAAkB,QAAQ;AAChC;;;AFXO,IAAM,+BAA+B;AAGrC,SAAS,uBACf,YACA,OAUyB;AACzB,SAAO;AAAA,IACN,aAAa,WAAW;AAAA,IACxB,YAAY,WAAW;AAAA,IACvB,YAAY,MAAM;AAAA,IAClB,QAAQ,MAAM;AAAA,IACd,eAAe,MAAM;AAAA,IACrB,kBAAkB,MAAM;AAAA,IACxB,OAAO,WAAW,MA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AAA;AAAA,EAEvB,IAAI;AAAA;AAAA,EAEJ,SAAS;AAAA;AAAA,EAET,UAAU,CAAC,UAAU,UAAU,SAAS;AACzC;AAKO,SAAS,uBAAuB,SAGpC;AACF,MAAI,OAAO,QAAQ,WAAW,UAAW,OAAM,IAAI,MAAM,0BAA0B;AACnF,QAAM,WAAW,+BAA+B;AAChD,QAAM,UAAU,8BAA8B,UAAU,QAAQ,MAAM;AACtE,QAAM,YAAqC;AAAA,IAC1C;AAAA,IACA,aAAa,KAAK;AACjB,UAAI,gBAAgB,OAAO;AAAA,IAC5B;AAAA,IACA,YAAY,KAAK,QAAQ;AACxB,YAAM,SAAS,IAAI,QAAQ,iBAAiB;AAC5C,YAAM,SAAS,IAAI,QAAQ,iBAAiB;AAC5C,UAAI,MAAM,QAAQ,MAAM,KAAK,MAAM,QAAQ,MAAM;AAChD,cAAM,IAAI,MAAM,mDAAmD;AACpE,eAAS,UAAU;AAAA,QAClB;AAAA,QACA;AAAA,QACA,iBAAiB,qBAAqB,MAAM;AAAA,MAC7C,CAAC;AACD,UAAI,OAAO,MAAM,SAAS,UAAU,IAAI,CAAC;AAAA,IAC1C;AAAA,EACD;AAGA,SAAO;AAAA;AAAA,IAEN;AAAA;AAAA,IAEA;AAAA;AAAA,IAEA;AAAA,EACD;AACD;AAOO,IAAM;AAAA,EACZ,WAAW;AAAA,EACX,SAAS;AAAA,EACT,UAAU;AACX,IAAI,uBAAuB,EAAE,QAAQ,KAAK,CAAC;AAEpC,IAAM;AAAA,EACZ,WAAW;AAAA,EACX,mBAAmB;AAAA,EACnB,oBAAoB;AAAA,EACpB,UAAU;AACX,IAAI;AACJ,IAAO,gBAAQ;","names":["configureGitHubRepoChangeLauncher","githubRepositoryPreparationChecks","resolveGitHubGitIdentity","githubRepoChangeUiLauncher"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type GitSshIntegration } from "@leitwerk-dev/git-ssh";
|
|
2
|
+
import type { GitHubGitIdentity, GitHubIntegration, GitHubRepository } from "@leitwerk-dev/github";
|
|
3
|
+
import type { LaunchPreparationCheck, ProcessLaunchConfig } 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: import("@leitwerk-dev/process-sdk").ProcessLauncherDefinition<GitHubRepoChangeParams> & {
|
|
42
|
+
/** @internal */
|
|
43
|
+
resolveIssueLaunchConfig(event: {
|
|
44
|
+
/** @internal */
|
|
45
|
+
profile: string;
|
|
46
|
+
/** @internal */
|
|
47
|
+
repository: GitHubRepository;
|
|
48
|
+
/** @internal */
|
|
49
|
+
issue: Pick<import("@leitwerk-dev/github").GitHubIssue, "number" | "title" | "body" | "html_url">;
|
|
50
|
+
/** @internal */
|
|
51
|
+
labels: import("@leitwerk-dev/process-sdk").RepositoryIssueWatcherConfig["labels"];
|
|
52
|
+
}): Promise<ProcessLaunchConfig<GitHubRepoChangeParams>>;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=launcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launcher.d.ts","sourceRoot":"","sources":["../src/launcher.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgC,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC7F,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,KAAK,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAC7F,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;IAqE5C,cAAc;uBAjEmC,oBAAoB,GAAG,IAAI,KAAG,IAAI;IAmEnF,cAAc;gCAxDN,OAAO,cACH,mBAAmB,CAAC,sBAAsB,CAAC,KACrD,SAAS,sBAAsB,CAAC,sBAAsB,CAAC,EAAE;IAwD3D,cAAc;+BA3CmB,MAAM;IA6CvC,cAAc;kCAjCkC,MAAM,KAAG,OAAO,CAAC,iBAAiB,CAAC;IAmCnF,cAAc;;;;;;;;;;;;;;EAGf"}
|
package/dist/params.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type RepositoryChangeLaunchParams, type RepositoryIssueOriginParams, type RepositoryUiOriginParams } 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 extends RepositoryIssueOriginParams {
|
|
15
|
+
}
|
|
16
|
+
/** @public */
|
|
17
|
+
export interface GitHubUiOriginParams extends RepositoryUiOriginParams {
|
|
18
|
+
}
|
|
19
|
+
/** @public */
|
|
20
|
+
export type GitHubRepoChangeParams = RepositoryChangeLaunchParams<GitHubRepoChangeCommonParams & (GitHubIssueOriginParams | GitHubUiOriginParams)>;
|
|
21
|
+
/** @public */
|
|
22
|
+
export declare function isIssueOrigin(params: GitHubRepoChangeParams): params is GitHubRepoChangeParams & GitHubIssueOriginParams;
|
|
23
|
+
/** @public */
|
|
24
|
+
export declare const githubRepoChangeParamsCodec: import("@leitwerk-dev/process-sdk").Codec<GitHubRepoChangeParams>;
|
|
25
|
+
export {};
|
|
26
|
+
//# 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,EAC7B,MAAM,+CAA+C,CAAC;AAEvD,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,uBAAwB,SAAQ,2BAA2B;CAAG;AAE/E,cAAc;AACd,MAAM,WAAW,oBAAqB,SAAQ,wBAAwB;CAAG;AAEzE,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,mEAUrC,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":"AAYA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAE1F,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EACN,KAAK,sBAAsB,EAG3B,MAAM,aAAa,CAAC;AAwBrB,cAAc;AACd,wBAAgB,6BAA6B,CAC5C,QAAQ,EAAE,UAAU,CAAC,OAAO,8BAA8B,CAAC,EAC3D,MAAM,EAAE,OAAO,iHAkIf"}
|
|
@@ -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":"AAEA,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;AAEjF,cAAc;AACd,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,CAIlE;AACD,cAAc;AACd,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc,CAIhG"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,52 @@
|
|
|
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.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/git-ssh": "0.3.1",
|
|
26
|
+
"@leitwerk-dev/process-sdk": "0.3.1",
|
|
27
|
+
"@leitwerk-dev/github": "0.3.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"tsup": "^8.5.1"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/leitwerk-dev/leitwerk.git",
|
|
35
|
+
"directory": "extensions/github-repo-change"
|
|
36
|
+
},
|
|
37
|
+
"license": "Apache-2.0",
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=26 <27"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist/**",
|
|
46
|
+
"src/**",
|
|
47
|
+
"!dist/**/*.test.*",
|
|
48
|
+
"!src/**/*.test.ts",
|
|
49
|
+
"!src/testing/**",
|
|
50
|
+
"!dist/testing/**"
|
|
51
|
+
]
|
|
16
52
|
}
|
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,171 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createRepositoryChangeUiLauncher,
|
|
3
|
+
repositoryVisibilityCheck,
|
|
4
|
+
} from "@leitwerk-dev/coding/repository-change-launch";
|
|
5
|
+
import { createGitSshPreparationCheck, type GitSshIntegration } from "@leitwerk-dev/git-ssh";
|
|
6
|
+
import type { GitHubGitIdentity, GitHubIntegration, GitHubRepository } from "@leitwerk-dev/github";
|
|
7
|
+
import type { LaunchPreparationCheck, ProcessLaunchConfig } from "@leitwerk-dev/process-sdk";
|
|
8
|
+
import { type GitHubRepoChangeParams, isIssueOrigin } from "./params.js";
|
|
9
|
+
import { type ProfileBindings, resolveProfileBinding } from "./profile-bindings.js";
|
|
10
|
+
|
|
11
|
+
/** @public */
|
|
12
|
+
export const githubRepoChangeUiLauncherId = "github_repo_change_process.ui_launcher" as const;
|
|
13
|
+
|
|
14
|
+
/** @public */
|
|
15
|
+
export function githubRepoChangeParams(
|
|
16
|
+
repository: GitHubRepository,
|
|
17
|
+
input: {
|
|
18
|
+
/** @public */
|
|
19
|
+
profile: string;
|
|
20
|
+
/** @public */
|
|
21
|
+
sshCredentialRef: string;
|
|
22
|
+
/** @public */
|
|
23
|
+
prompt: string;
|
|
24
|
+
/** @public */
|
|
25
|
+
workBranch: string;
|
|
26
|
+
},
|
|
27
|
+
): GitHubRepoChangeParams {
|
|
28
|
+
return {
|
|
29
|
+
repoLocator: repository.ssh_url,
|
|
30
|
+
baseBranch: repository.default_branch,
|
|
31
|
+
workBranch: input.workBranch,
|
|
32
|
+
prompt: input.prompt,
|
|
33
|
+
githubProfile: input.profile,
|
|
34
|
+
sshCredentialRef: input.sshCredentialRef,
|
|
35
|
+
owner: repository.owner.login,
|
|
36
|
+
repo: repository.name,
|
|
37
|
+
origin: "ui",
|
|
38
|
+
issueNumber: null,
|
|
39
|
+
issueUrl: null,
|
|
40
|
+
triggerLabel: null,
|
|
41
|
+
doneLabel: null,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** @public */
|
|
46
|
+
export function githubRepoChangeLaunchConfig(
|
|
47
|
+
params: GitHubRepoChangeParams,
|
|
48
|
+
title: string,
|
|
49
|
+
gitIdentity: GitHubGitIdentity,
|
|
50
|
+
): ProcessLaunchConfig<GitHubRepoChangeParams> {
|
|
51
|
+
const { owner, repo, githubProfile: profile } = params;
|
|
52
|
+
const issue = isIssueOrigin(params);
|
|
53
|
+
return {
|
|
54
|
+
processId: "github_repo_change_process",
|
|
55
|
+
params,
|
|
56
|
+
title,
|
|
57
|
+
startTurnId: "generate_plan",
|
|
58
|
+
...(issue
|
|
59
|
+
? {
|
|
60
|
+
externalId: `github:${owner}/${repo}#${params.issueNumber}`,
|
|
61
|
+
externalUrl: params.issueUrl,
|
|
62
|
+
}
|
|
63
|
+
: {}),
|
|
64
|
+
projects: [
|
|
65
|
+
{
|
|
66
|
+
key: "repo",
|
|
67
|
+
repoLocator: params.repoLocator,
|
|
68
|
+
baseBranch: params.baseBranch,
|
|
69
|
+
workBranch: params.workBranch,
|
|
70
|
+
...(issue ? { externalId: String(params.issueNumber), externalUrl: params.issueUrl } : {}),
|
|
71
|
+
metadata: {
|
|
72
|
+
github: { owner, repo, profile, ...(issue ? { issueNumber: params.issueNumber } : {}) },
|
|
73
|
+
"leitwerk.gitIdentity": gitIdentity,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** @public */
|
|
81
|
+
export interface LauncherDependencies {
|
|
82
|
+
/** @public */
|
|
83
|
+
github: GitHubIntegration;
|
|
84
|
+
/** @public */
|
|
85
|
+
gitSsh: GitSshIntegration;
|
|
86
|
+
/** @public */
|
|
87
|
+
profileBindings?: ProfileBindings;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** @public */
|
|
91
|
+
export function createGitHubRepoChangeLauncher() {
|
|
92
|
+
let dependencies: LauncherDependencies | null = null;
|
|
93
|
+
|
|
94
|
+
/** @public */
|
|
95
|
+
function configureGitHubRepoChangeLauncher(value: LauncherDependencies | null): void {
|
|
96
|
+
dependencies = value;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function requireDependencies(): LauncherDependencies {
|
|
100
|
+
if (!dependencies) throw new Error("GitHub repository launcher is not configured");
|
|
101
|
+
return dependencies;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** @public */
|
|
105
|
+
function githubRepositoryPreparationChecks(
|
|
106
|
+
_input: unknown,
|
|
107
|
+
{ params }: ProcessLaunchConfig<GitHubRepoChangeParams>,
|
|
108
|
+
): readonly LaunchPreparationCheck<GitHubRepoChangeParams>[] {
|
|
109
|
+
return [
|
|
110
|
+
repositoryVisibilityCheck("GitHub", async () =>
|
|
111
|
+
(await repositories(params.githubProfile)).some(
|
|
112
|
+
(candidate) => candidate.full_name === `${params.owner}/${params.repo}`,
|
|
113
|
+
),
|
|
114
|
+
),
|
|
115
|
+
createGitSshPreparationCheck("read", params, () => requireDependencies().gitSsh),
|
|
116
|
+
createGitSshPreparationCheck("write", params, () => requireDependencies().gitSsh),
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** @public */
|
|
121
|
+
function resolveProfiles(profile: string) {
|
|
122
|
+
const { github, gitSsh, profileBindings = {} } = requireDependencies();
|
|
123
|
+
if (!(github.profiles?.() ?? []).includes(profile))
|
|
124
|
+
throw new Error("GitHub profile is not available");
|
|
125
|
+
const binding = resolveProfileBinding(profileBindings, profile);
|
|
126
|
+
|
|
127
|
+
if (!gitSsh.profiles().includes(binding.sshCredentialRef))
|
|
128
|
+
throw new Error(`Git SSH profile '${binding.sshCredentialRef}' is not available`);
|
|
129
|
+
return binding;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** @public */
|
|
133
|
+
async function resolveGitHubGitIdentity(profile: string): Promise<GitHubGitIdentity> {
|
|
134
|
+
if (!profile) throw new Error("A GitHub profile is required to resolve Git identity");
|
|
135
|
+
return requireDependencies().github.client(profile).resolveGitIdentity(profile);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function repositories(profile: string): Promise<readonly GitHubRepository[]> {
|
|
139
|
+
if (!profile) return [];
|
|
140
|
+
const { github } = requireDependencies();
|
|
141
|
+
if (!(github.profiles?.() ?? []).includes(profile)) return [];
|
|
142
|
+
return github.client(profile).listRepositories();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const githubRepoChangeUiLauncher = createRepositoryChangeUiLauncher({
|
|
146
|
+
id: githubRepoChangeUiLauncherId,
|
|
147
|
+
provider: "GitHub",
|
|
148
|
+
providerId: "github",
|
|
149
|
+
assertConfigured: requireDependencies,
|
|
150
|
+
profiles: () => requireDependencies().github.profiles?.() ?? [],
|
|
151
|
+
repositories,
|
|
152
|
+
resolveProfiles,
|
|
153
|
+
resolveGitIdentity: resolveGitHubGitIdentity,
|
|
154
|
+
params: githubRepoChangeParams,
|
|
155
|
+
launchConfig: githubRepoChangeLaunchConfig,
|
|
156
|
+
preparationChecks: githubRepositoryPreparationChecks,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
/** @public */
|
|
161
|
+
configure: configureGitHubRepoChangeLauncher,
|
|
162
|
+
/** @public */
|
|
163
|
+
preparationChecks: githubRepositoryPreparationChecks,
|
|
164
|
+
/** @public */
|
|
165
|
+
resolveProfiles,
|
|
166
|
+
/** @public */
|
|
167
|
+
resolveGitIdentity: resolveGitHubGitIdentity,
|
|
168
|
+
/** @public */
|
|
169
|
+
launcher: githubRepoChangeUiLauncher,
|
|
170
|
+
};
|
|
171
|
+
}
|
package/src/params.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createRepositoryChangeParamsCodec,
|
|
3
|
+
normalizeRepositoryIssueChangeParams,
|
|
4
|
+
type RepositoryChangeLaunchParams,
|
|
5
|
+
type RepositoryIssueOriginParams,
|
|
6
|
+
type RepositoryUiOriginParams,
|
|
7
|
+
} from "@leitwerk-dev/coding/repository-change-launch";
|
|
8
|
+
|
|
9
|
+
/** @public */
|
|
10
|
+
interface GitHubRepoChangeCommonParams {
|
|
11
|
+
/** @public */
|
|
12
|
+
githubProfile: string;
|
|
13
|
+
/** @public */
|
|
14
|
+
sshCredentialRef: string;
|
|
15
|
+
/** @public */
|
|
16
|
+
owner: string;
|
|
17
|
+
/** @public */
|
|
18
|
+
repo: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** @public */
|
|
22
|
+
export interface GitHubIssueOriginParams extends RepositoryIssueOriginParams {}
|
|
23
|
+
|
|
24
|
+
/** @public */
|
|
25
|
+
export interface GitHubUiOriginParams extends RepositoryUiOriginParams {}
|
|
26
|
+
|
|
27
|
+
/** @public */
|
|
28
|
+
export type GitHubRepoChangeParams = RepositoryChangeLaunchParams<
|
|
29
|
+
GitHubRepoChangeCommonParams & (GitHubIssueOriginParams | GitHubUiOriginParams)
|
|
30
|
+
>;
|
|
31
|
+
|
|
32
|
+
/** @public */
|
|
33
|
+
export function isIssueOrigin(
|
|
34
|
+
params: GitHubRepoChangeParams,
|
|
35
|
+
): params is GitHubRepoChangeParams & GitHubIssueOriginParams {
|
|
36
|
+
return params.origin === "issue";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @public */
|
|
40
|
+
export const githubRepoChangeParamsCodec =
|
|
41
|
+
createRepositoryChangeParamsCodec<GitHubRepoChangeParams>({
|
|
42
|
+
normalize(value) {
|
|
43
|
+
return normalizeRepositoryIssueChangeParams(value, "GitHub Repo Change", [
|
|
44
|
+
"githubProfile",
|
|
45
|
+
"sshCredentialRef",
|
|
46
|
+
"owner",
|
|
47
|
+
"repo",
|
|
48
|
+
]);
|
|
49
|
+
},
|
|
50
|
+
});
|
package/src/process.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { createRepositoryChangeProcess } from "@leitwerk-dev/coding";
|
|
2
|
+
import {
|
|
3
|
+
createRepositoryChangePublication,
|
|
4
|
+
publicationObject as object,
|
|
5
|
+
type PublicationSource,
|
|
6
|
+
type PublicationState,
|
|
7
|
+
pullRequestPublicationCallbacks,
|
|
8
|
+
pullRequestPublicationSources,
|
|
9
|
+
readPublicationState,
|
|
10
|
+
reconcilePullRequestSourceIssue,
|
|
11
|
+
resolvePullRequestGitIdentity,
|
|
12
|
+
} from "@leitwerk-dev/coding/repository-change-publication";
|
|
13
|
+
import type { RepositoryChangeState } from "@leitwerk-dev/coding/repository-change-state";
|
|
14
|
+
import { githubExternal, githubIssueWatcherSource } from "@leitwerk-dev/github";
|
|
15
|
+
import type { createGitHubRepoChangeLauncher } from "./launcher.js";
|
|
16
|
+
import {
|
|
17
|
+
type GitHubRepoChangeParams,
|
|
18
|
+
githubRepoChangeParamsCodec,
|
|
19
|
+
isIssueOrigin,
|
|
20
|
+
} from "./params.js";
|
|
21
|
+
|
|
22
|
+
const processId = "github_repo_change_process";
|
|
23
|
+
const ids = {
|
|
24
|
+
deliver: "deliver_change",
|
|
25
|
+
feedback: "revise_from_pull_request_feedback",
|
|
26
|
+
ciRepair: "repair_github_checks",
|
|
27
|
+
operator: "ci_operator_action",
|
|
28
|
+
};
|
|
29
|
+
const remote = (state: RepositoryChangeState) => readPublicationState(state, "githubRepoChange");
|
|
30
|
+
|
|
31
|
+
const deliveryTools = [
|
|
32
|
+
"github_get_pull_request",
|
|
33
|
+
"github_add_pull_request_comment",
|
|
34
|
+
"github_resolve_git_identity",
|
|
35
|
+
"github_ensure_pull_request",
|
|
36
|
+
"github_add_issue_comment",
|
|
37
|
+
"github_add_pull_request_feedback_reaction",
|
|
38
|
+
"github_reply_to_pull_request_feedback",
|
|
39
|
+
"github_get_issue",
|
|
40
|
+
"github_ensure_label",
|
|
41
|
+
"github_update_issue",
|
|
42
|
+
] as const;
|
|
43
|
+
|
|
44
|
+
/** @public */
|
|
45
|
+
export function createGitHubRepoChangeProcess(
|
|
46
|
+
launcher: ReturnType<typeof createGitHubRepoChangeLauncher>,
|
|
47
|
+
docker: boolean,
|
|
48
|
+
) {
|
|
49
|
+
const sharedSources = pullRequestPublicationSources<GitHubRepoChangeParams>(
|
|
50
|
+
"github",
|
|
51
|
+
"GitHub",
|
|
52
|
+
githubExternal,
|
|
53
|
+
(params) => params.githubProfile,
|
|
54
|
+
(params) => (isIssueOrigin(params) ? params : undefined),
|
|
55
|
+
);
|
|
56
|
+
const { requirePr } = sharedSources;
|
|
57
|
+
const failedPipeline = githubExternal.checks<GitHubRepoChangeParams, RepositoryChangeState>(
|
|
58
|
+
({ params, state }) => ({
|
|
59
|
+
profile: params.githubProfile,
|
|
60
|
+
owner: params.owner,
|
|
61
|
+
repo: params.repo,
|
|
62
|
+
prNumber: requirePr(state).prNumber,
|
|
63
|
+
headSha: requirePr(state).headSha,
|
|
64
|
+
afterKey: remote(state).pipeline?.evidenceKey as string | undefined,
|
|
65
|
+
}),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const sources: PublicationSource<GitHubRepoChangeParams>[] = [
|
|
69
|
+
{
|
|
70
|
+
id: "github_merge_conflict",
|
|
71
|
+
kind: "conflict",
|
|
72
|
+
label: "Rebase conflicting pull request",
|
|
73
|
+
source: githubExternal.pullRequestState(({ params, state }) => ({
|
|
74
|
+
profile: params.githubProfile,
|
|
75
|
+
owner: params.owner,
|
|
76
|
+
repo: params.repo,
|
|
77
|
+
prNumber: requirePr(state).prNumber,
|
|
78
|
+
headSha: requirePr(state).headSha,
|
|
79
|
+
lastConflictKey: remote(state).lastConflictKey,
|
|
80
|
+
feedbackCursor: 0,
|
|
81
|
+
eventKinds: ["merge_conflict"],
|
|
82
|
+
pollInterval: "30s",
|
|
83
|
+
})),
|
|
84
|
+
read: ({ event }) => ({
|
|
85
|
+
kind: "conflict",
|
|
86
|
+
conflict: object(event).conflict as NonNullable<PublicationState["conflict"]>,
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
sharedSources.feedback,
|
|
90
|
+
{
|
|
91
|
+
id: "github_failure_repair",
|
|
92
|
+
operatorId: "github_failure_operator",
|
|
93
|
+
kind: "failure",
|
|
94
|
+
label: "Repair failed GitHub checks",
|
|
95
|
+
source: failedPipeline,
|
|
96
|
+
read: ({ state, event }) => {
|
|
97
|
+
const checks = object(object(event).checks);
|
|
98
|
+
const current = requirePr(state);
|
|
99
|
+
if (checks.headSha !== current.headSha) throw new Error("Stale GitHub check evidence");
|
|
100
|
+
const failed = Array.isArray(checks.failed) ? checks.failed : [];
|
|
101
|
+
return {
|
|
102
|
+
kind: "failure",
|
|
103
|
+
pipeline: {
|
|
104
|
+
number: 0,
|
|
105
|
+
status: "failure",
|
|
106
|
+
...checks,
|
|
107
|
+
evidenceKey: `${checks.headSha}:${failed.map((run) => object(run).url).join(":")}`,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
...sharedSources.terminal,
|
|
113
|
+
sharedSources.cancelled,
|
|
114
|
+
];
|
|
115
|
+
const publicationConfig = createRepositoryChangePublication<GitHubRepoChangeParams>({
|
|
116
|
+
namespace: "githubRepoChange",
|
|
117
|
+
label: "GitHub PR",
|
|
118
|
+
ids,
|
|
119
|
+
sources,
|
|
120
|
+
tools: {
|
|
121
|
+
delivery: deliveryTools,
|
|
122
|
+
feedback: ["github_get_pull_request", "github_list_pull_request_feedback"],
|
|
123
|
+
ci: ["github_get_ci_diagnostics"],
|
|
124
|
+
},
|
|
125
|
+
identity: (ctx) => resolvePullRequestGitIdentity(ctx, "github", ctx.params.githubProfile),
|
|
126
|
+
reconcileTerminal: reconcilePullRequestSourceIssue<GitHubRepoChangeParams>(
|
|
127
|
+
"github",
|
|
128
|
+
"name",
|
|
129
|
+
(params) => (isIssueOrigin(params) ? params : undefined),
|
|
130
|
+
),
|
|
131
|
+
...pullRequestPublicationCallbacks<GitHubRepoChangeParams>("github", "GitHub", (params) =>
|
|
132
|
+
isIssueOrigin(params) ? params : undefined,
|
|
133
|
+
),
|
|
134
|
+
commitMessage: (kind) =>
|
|
135
|
+
kind === "feedback" ? "fix: address GitHub review feedback" : "fix: repair GitHub checks",
|
|
136
|
+
prompt(kind, current) {
|
|
137
|
+
return kind === "feedback"
|
|
138
|
+
? `Address the unseen GitHub pull-request feedback batch for PR #${current.prNumber}. Feedback identifiers: ${JSON.stringify(current.feedbackIds)}. Inspect the current checkout and use GitHub tools to read the full feedback. Do not rely on an earlier plan or conversation. Make only justified repository changes. Call changes_ready if files need publishing, no_changes after an explicit diagnosis that no repository change is needed, or cannot_repair when operator action is required.`
|
|
139
|
+
: `Diagnose failed GitHub checks for request #${current.prNumber}, head ${current.headSha}. Use github_get_ci_diagnostics with pullRequestNumber and headSha to inspect failed check annotations and bounded Actions job logs before changing anything. Fix repository causes. Call changes_ready for repository changes, no_changes only after an explicit provider restart or a justified diagnosis that no repository change is needed, or cannot_repair when operator action is required.`;
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
const publication = publicationConfig.fragment;
|
|
143
|
+
publication.watcher({
|
|
144
|
+
id: "use_leitwerk",
|
|
145
|
+
label: "GitHub use-leitwerk issues",
|
|
146
|
+
description: "Launch a remote repository change for GitHub issues carrying the trigger label",
|
|
147
|
+
source: githubIssueWatcherSource,
|
|
148
|
+
preparationChecks: launcher.preparationChecks,
|
|
149
|
+
resolveLaunchConfig: launcher.launcher.resolveIssueLaunchConfig,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const definition = createRepositoryChangeProcess<GitHubRepoChangeParams>({
|
|
153
|
+
processId,
|
|
154
|
+
displayName: "GitHub Repo Change",
|
|
155
|
+
paramsCodec: githubRepoChangeParamsCodec,
|
|
156
|
+
launcher: launcher.launcher,
|
|
157
|
+
finalizeLabel: "Publish pull request",
|
|
158
|
+
finalizeForm: {
|
|
159
|
+
id: "github_publish",
|
|
160
|
+
title: "Publish pull request",
|
|
161
|
+
fields: [],
|
|
162
|
+
submitLabel: "Publish",
|
|
163
|
+
},
|
|
164
|
+
repositoryCredentials: ({ params }) => [
|
|
165
|
+
{
|
|
166
|
+
projectKey: "repo",
|
|
167
|
+
kind: "git_ssh",
|
|
168
|
+
credentialRef: params.sshCredentialRef,
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
publication: publicationConfig,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
definition.process.runtime = { ...definition.process.runtime, docker };
|
|
175
|
+
|
|
176
|
+
return definition.process;
|
|
177
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { parseRepositoryProfileBindings } from "@leitwerk-dev/coding/repository-change-launch";
|
|
2
|
+
|
|
3
|
+
/** Server-owned, non-secret wiring for future launches. */
|
|
4
|
+
/** @public */
|
|
5
|
+
export interface ProfileBinding {
|
|
6
|
+
/** @public */
|
|
7
|
+
sshCredentialRef: string;
|
|
8
|
+
}
|
|
9
|
+
/** @public */
|
|
10
|
+
export type ProfileBindings = Readonly<Record<string, Readonly<ProfileBinding>>>;
|
|
11
|
+
|
|
12
|
+
/** @public */
|
|
13
|
+
export function parseProfileBindings(raw: unknown): ProfileBindings {
|
|
14
|
+
return parseRepositoryProfileBindings(raw, "github-repo-change", {
|
|
15
|
+
sshCredentialRef: "ssh_credential_ref",
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** @public */
|
|
19
|
+
export function resolveProfileBinding(bindings: ProfileBindings, profile: string): ProfileBinding {
|
|
20
|
+
return Object.hasOwn(bindings, profile)
|
|
21
|
+
? { ...bindings[profile] }
|
|
22
|
+
: { sshCredentialRef: profile };
|
|
23
|
+
}
|