@leitwerk-dev/coding 0.3.1 → 0.4.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 +86 -1
- package/dist/chunk-ABQH2WZT.js +36 -0
- package/dist/chunk-ABQH2WZT.js.map +1 -0
- package/dist/{chunk-YSC5GEQJ.js → chunk-BI45R2FH.js} +7 -3
- package/dist/chunk-BI45R2FH.js.map +1 -0
- package/dist/chunk-DNG7D77K.js +65 -0
- package/dist/chunk-DNG7D77K.js.map +1 -0
- package/dist/chunk-L2TFD72B.js +16320 -0
- package/dist/chunk-L2TFD72B.js.map +1 -0
- package/dist/chunk-M2VTUPFO.js +265 -0
- package/dist/chunk-M2VTUPFO.js.map +1 -0
- package/dist/chunk-OM2AMDTJ.js +347 -0
- package/dist/chunk-OM2AMDTJ.js.map +1 -0
- package/dist/chunk-Q24RPXOA.js +159 -0
- package/dist/chunk-Q24RPXOA.js.map +1 -0
- package/dist/chunk-SKGB4CZS.js +14 -0
- package/dist/chunk-SKGB4CZS.js.map +1 -0
- package/dist/chunk-SZ4WOGV2.js +120 -0
- package/dist/chunk-SZ4WOGV2.js.map +1 -0
- package/dist/finalization-git-internal.d.ts +3 -0
- package/dist/finalization-git-internal.d.ts.map +1 -1
- package/dist/finalization-git.d.ts +1 -1
- package/dist/finalization-git.d.ts.map +1 -1
- package/dist/finalization-git.js +5 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -591
- package/dist/index.js.map +1 -1
- package/dist/pull-request-publication-internal.d.ts +26 -24
- package/dist/pull-request-publication-internal.d.ts.map +1 -1
- package/dist/repository-change-launch-internal-BudnAfL7.d.ts +88 -0
- package/dist/repository-change-launch-internal.d.ts +32 -11
- package/dist/repository-change-launch-internal.d.ts.map +1 -1
- package/dist/repository-change-launch.d.ts +4 -3
- package/dist/repository-change-launch.d.ts.map +1 -1
- package/dist/repository-change-launch.js +162 -34
- package/dist/repository-change-launch.js.map +1 -1
- package/dist/repository-change-process-DlgF04fU.d.ts +69 -0
- package/dist/repository-change-process.d.ts +30 -25
- package/dist/repository-change-process.d.ts.map +1 -1
- package/dist/repository-change-publication.d.ts +62 -6
- package/dist/repository-change-publication.d.ts.map +1 -1
- package/dist/repository-change-publication.js +364 -90
- package/dist/repository-change-publication.js.map +1 -1
- package/dist/repository-change-state-internal.d.ts +18 -4
- package/dist/repository-change-state-internal.d.ts.map +1 -1
- package/dist/repository-change-ui-launcher-internal.d.ts +34 -22
- package/dist/repository-change-ui-launcher-internal.d.ts.map +1 -1
- package/dist/settings.d.ts +15 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/turns/commit-message-evidence.d.ts +35 -0
- package/dist/turns/commit-message-evidence.d.ts.map +1 -0
- package/dist/turns/commit-message-evidence.js +9 -0
- package/dist/turns/generate-commit-message.d.ts +4 -1
- package/dist/turns/generate-commit-message.d.ts.map +1 -1
- package/dist/turns/generate-commit-message.js +7 -5
- package/dist/turns/generate-plan.d.ts.map +1 -1
- package/dist/turns/generate-plan.js +1 -1
- package/dist/turns/git-inspection-profile.d.ts +25 -0
- package/dist/turns/git-inspection-profile.d.ts.map +1 -0
- package/dist/turns/git-inspection-profile.js +8 -0
- package/dist/turns/implement.d.ts.map +1 -1
- package/dist/turns/implement.js +1 -1
- package/dist/turns/simplify-implementation.d.ts +1 -1
- package/dist/turns/simplify-implementation.d.ts.map +1 -1
- package/dist/turns/simplify-implementation.js +3 -3
- package/package.json +5 -9
- package/src/finalization-git-internal.ts +117 -114
- package/src/finalization-git.ts +1 -1
- package/src/index.ts +4 -1
- package/src/pull-request-publication-internal.ts +156 -78
- package/src/repository-change-launch-internal.ts +119 -12
- package/src/repository-change-launch.ts +8 -4
- package/src/repository-change-process.ts +234 -523
- package/src/repository-change-publication.ts +516 -121
- package/src/repository-change-state-internal.ts +34 -20
- package/src/repository-change-ui-launcher-internal.ts +139 -56
- package/src/settings.ts +79 -0
- package/src/turns/commit-message-evidence.ts +241 -0
- package/src/turns/generate-commit-message.ts +53 -23
- package/src/turns/generate-plan.ts +26 -12
- package/src/turns/git-inspection-profile.ts +134 -0
- package/src/turns/implement.ts +9 -2
- package/src/turns/simplify-implementation.ts +10 -6
- package/dist/chunk-34B3Q75M.js +0 -25
- package/dist/chunk-34B3Q75M.js.map +0 -1
- package/dist/chunk-F6CEEAFE.js +0 -13
- package/dist/chunk-F6CEEAFE.js.map +0 -1
- package/dist/chunk-GO44KCUS.js +0 -154
- package/dist/chunk-GO44KCUS.js.map +0 -1
- package/dist/chunk-R3UCUGY6.js +0 -31
- package/dist/chunk-R3UCUGY6.js.map +0 -1
- package/dist/chunk-W7VJT6AN.js +0 -25
- package/dist/chunk-W7VJT6AN.js.map +0 -1
- package/dist/chunk-WKHVLLKE.js +0 -45
- package/dist/chunk-WKHVLLKE.js.map +0 -1
- package/dist/chunk-YSC5GEQJ.js.map +0 -1
- package/dist/repository-change-launch-internal-Dd-AONUs.d.ts +0 -67
- package/dist/turns/review-implementation.d.ts +0 -4
- package/dist/turns/review-implementation.d.ts.map +0 -1
- package/dist/turns/review-implementation.js +0 -8
- package/dist/turns/review-plan.d.ts +0 -4
- package/dist/turns/review-plan.d.ts.map +0 -1
- package/dist/turns/review-plan.js +0 -8
- package/src/turns/review-implementation.ts +0 -30
- package/src/turns/review-plan.ts +0 -24
- /package/dist/turns/{review-implementation.js.map → commit-message-evidence.js.map} +0 -0
- /package/dist/turns/{review-plan.js.map → git-inspection-profile.js.map} +0 -0
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
defineExternalActionSource,
|
|
3
|
+
ProcessWatcherDefinition,
|
|
3
4
|
RepositoryFeedbackSourceConfig,
|
|
4
5
|
RepositoryIssueCancelledSourceConfig,
|
|
5
6
|
RepositoryPullRequestSourceConfig,
|
|
6
7
|
} from "@leitwerk-dev/process-sdk";
|
|
7
8
|
import type { GitIdentity } from "./finalization-git.js";
|
|
8
9
|
import type { RepositoryIssueOriginParams } from "./repository-change-launch-internal.js";
|
|
10
|
+
import {
|
|
11
|
+
createRepositoryChangeProcess,
|
|
12
|
+
type RepositoryChangeProcessConfig,
|
|
13
|
+
} from "./repository-change-process.js";
|
|
9
14
|
import type {
|
|
10
15
|
PublicationContext,
|
|
11
16
|
PublicationEvidence,
|
|
@@ -16,11 +21,69 @@ import type {
|
|
|
16
21
|
RepositoryChangePublicationAdapter,
|
|
17
22
|
} from "./repository-change-publication.js";
|
|
18
23
|
import {
|
|
24
|
+
createRepositoryChangePublication,
|
|
19
25
|
publicationObject as object,
|
|
20
26
|
readPublicationState,
|
|
21
27
|
} from "./repository-change-publication.js";
|
|
22
28
|
import type { RepositoryChangeState } from "./repository-change-state.js";
|
|
23
29
|
|
|
30
|
+
/** Shared process defaults for SSH-backed pull-request publication. @internal */
|
|
31
|
+
export function createPullRequestChangeProcess<
|
|
32
|
+
P extends PublicationParams & {
|
|
33
|
+
/** @internal */
|
|
34
|
+
sshCredentialRef: string;
|
|
35
|
+
},
|
|
36
|
+
E,
|
|
37
|
+
C,
|
|
38
|
+
>(
|
|
39
|
+
provider: string,
|
|
40
|
+
label: string,
|
|
41
|
+
docker: boolean,
|
|
42
|
+
config: Pick<RepositoryChangeProcessConfig<P>, "paramsCodec" | "launcher" | "workflow"> & {
|
|
43
|
+
/** @internal */ publication: RepositoryChangePublicationAdapter<P>;
|
|
44
|
+
/** @internal */ watcher: Omit<
|
|
45
|
+
ProcessWatcherDefinition<P, E, C>,
|
|
46
|
+
"id" | "label" | "description"
|
|
47
|
+
>;
|
|
48
|
+
},
|
|
49
|
+
) {
|
|
50
|
+
const { watcher, publication: adapter, ...definition } = config;
|
|
51
|
+
const publication = createRepositoryChangePublication(adapter);
|
|
52
|
+
publication.fragment.watcher({
|
|
53
|
+
...watcher,
|
|
54
|
+
id: "use_leitwerk",
|
|
55
|
+
label: `${label} use-leitwerk issues`,
|
|
56
|
+
description: `Launch a remote repository change for ${label} issues carrying the trigger label`,
|
|
57
|
+
});
|
|
58
|
+
const { process } = createRepositoryChangeProcess({
|
|
59
|
+
...definition,
|
|
60
|
+
publication,
|
|
61
|
+
processId: `${provider}_repo_change_process`,
|
|
62
|
+
displayName: `${label} Repo Change`,
|
|
63
|
+
repositoryCredentials: ({ params }) => [
|
|
64
|
+
{ projectKey: "repo", kind: "git_ssh", credentialRef: params.sshCredentialRef },
|
|
65
|
+
],
|
|
66
|
+
});
|
|
67
|
+
process.runtime = { ...process.runtime, docker };
|
|
68
|
+
return process;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Tools implementing the shared pull-request publication protocol. @internal */
|
|
72
|
+
function pullRequestDeliveryTools(provider: string): string[] {
|
|
73
|
+
return [
|
|
74
|
+
"get_pull_request",
|
|
75
|
+
"add_pull_request_comment",
|
|
76
|
+
"resolve_git_identity",
|
|
77
|
+
"ensure_pull_request",
|
|
78
|
+
"add_issue_comment",
|
|
79
|
+
"add_pull_request_feedback_reaction",
|
|
80
|
+
"reply_to_pull_request_feedback",
|
|
81
|
+
"get_issue",
|
|
82
|
+
"ensure_label",
|
|
83
|
+
"update_issue",
|
|
84
|
+
].map((name) => `${provider}_${name}`);
|
|
85
|
+
}
|
|
86
|
+
|
|
24
87
|
const callFor =
|
|
25
88
|
<P>(ctx: PublicationContext<P>, provider: string) =>
|
|
26
89
|
<T>(name: string, args: Record<string, unknown>) =>
|
|
@@ -31,22 +94,24 @@ export async function resolvePullRequestGitIdentity<P>(
|
|
|
31
94
|
ctx: PublicationContext<P>,
|
|
32
95
|
provider: string,
|
|
33
96
|
profile: string,
|
|
97
|
+
allowLookup = true,
|
|
34
98
|
): Promise<GitIdentity> {
|
|
35
|
-
const project = ctx.
|
|
36
|
-
const
|
|
99
|
+
const project = ctx.repo.get("repo");
|
|
100
|
+
const metadata = ctx.projects.find((candidate) => candidate.key === project.key)?.metadata;
|
|
101
|
+
const identity = object(metadata?.["leitwerk.gitIdentity"]);
|
|
37
102
|
if (
|
|
38
103
|
identity.provider === provider &&
|
|
39
104
|
identity.profile === profile &&
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
)
|
|
105
|
+
(!allowLookup || (typeof identity.login === "string" && identity.login.trim())) &&
|
|
106
|
+
[identity.name, identity.email].every((value) => typeof value === "string" && value.trim())
|
|
43
107
|
)
|
|
44
108
|
return identity as unknown as GitIdentity;
|
|
109
|
+
if (!allowLookup) throw new Error(`Pinned ${provider} Git identity is unavailable`);
|
|
45
110
|
return callFor(ctx, provider)<GitIdentity>("resolve_git_identity", {});
|
|
46
111
|
}
|
|
47
112
|
|
|
48
113
|
/** @internal */
|
|
49
|
-
|
|
114
|
+
function readPullRequestFeedback(
|
|
50
115
|
current: PublicationState,
|
|
51
116
|
event: unknown,
|
|
52
117
|
): Extract<PublicationEvidence, { kind: "feedback" }> {
|
|
@@ -61,57 +126,11 @@ export function readPullRequestFeedback(
|
|
|
61
126
|
};
|
|
62
127
|
}
|
|
63
128
|
|
|
64
|
-
/** @internal */
|
|
65
|
-
export function reconcilePullRequestSourceIssue<P extends PublicationParams>(
|
|
66
|
-
provider: string,
|
|
67
|
-
labelKey: "id" | "name",
|
|
68
|
-
issueOrigin: (params: P) =>
|
|
69
|
-
| {
|
|
70
|
-
/** @internal */
|
|
71
|
-
issueNumber: number;
|
|
72
|
-
/** @internal */
|
|
73
|
-
triggerLabel: string;
|
|
74
|
-
/** @internal */
|
|
75
|
-
doneLabel: string;
|
|
76
|
-
}
|
|
77
|
-
| undefined,
|
|
78
|
-
): RepositoryChangePublicationAdapter<P>["reconcileTerminal"] {
|
|
79
|
-
return async (ctx, _current, pr) => {
|
|
80
|
-
const params = issueOrigin(ctx.params);
|
|
81
|
-
if (!params) return;
|
|
82
|
-
const call = callFor(ctx, provider);
|
|
83
|
-
const issue = await call<{ labels: Array<{ id: number; name: string }> }>("get_issue", {
|
|
84
|
-
issueNumber: params.issueNumber,
|
|
85
|
-
});
|
|
86
|
-
let labels = issue.labels
|
|
87
|
-
.filter((label) => label.name !== params.triggerLabel)
|
|
88
|
-
.map((label) => label[labelKey]);
|
|
89
|
-
if (pr.merged) {
|
|
90
|
-
const done = await call<{ id: number; name: string }>("ensure_label", {
|
|
91
|
-
name: params.doneLabel,
|
|
92
|
-
});
|
|
93
|
-
labels = [...new Set([...labels, done[labelKey]])];
|
|
94
|
-
}
|
|
95
|
-
await call("update_issue", {
|
|
96
|
-
issueNumber: params.issueNumber,
|
|
97
|
-
patch: { labels, ...(pr.merged ? { state: "closed" } : {}) },
|
|
98
|
-
writeKey: `${provider}:${ctx.process.id}:${pr.merged ? "complete-source-issue" : "remove-source-trigger"}`,
|
|
99
|
-
});
|
|
100
|
-
await call("add_issue_comment", {
|
|
101
|
-
issueNumber: params.issueNumber,
|
|
102
|
-
body: pr.merged
|
|
103
|
-
? `Merged ${pr.html_url}${pr.merge_commit_sha ? ` at ${pr.merge_commit_sha}` : ""}.`
|
|
104
|
-
: `Leitwerk stopped because ${pr.html_url} was closed without merge.`,
|
|
105
|
-
writeKey: `${provider}:${ctx.process.id}:${pr.merged ? "merged" : "closed"}-pr-comment`,
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
129
|
/** @internal */
|
|
111
130
|
type SourceFactory<C> = ReturnType<typeof defineExternalActionSource<C>>;
|
|
112
131
|
|
|
113
132
|
/** Shared wiring for providers implementing the pull-request source protocol. @internal */
|
|
114
|
-
export function
|
|
133
|
+
export function pullRequestPublicationDefaults<P extends PublicationParams>(
|
|
115
134
|
provider: string,
|
|
116
135
|
label: string,
|
|
117
136
|
external: {
|
|
@@ -126,6 +145,13 @@ export function pullRequestPublicationSources<P extends PublicationParams>(
|
|
|
126
145
|
},
|
|
127
146
|
profile: (params: P) => string,
|
|
128
147
|
issueOrigin: (params: P) => RepositoryIssueOriginParams | undefined,
|
|
148
|
+
labelKey: "id" | "name",
|
|
149
|
+
ci: {
|
|
150
|
+
/** @internal */ id: string;
|
|
151
|
+
/** @internal */ label: string;
|
|
152
|
+
/** @internal */ tools: readonly string[];
|
|
153
|
+
/** @internal */ prompt(current: PublicationState): string;
|
|
154
|
+
},
|
|
129
155
|
) {
|
|
130
156
|
const remote = (state: RepositoryChangeState) =>
|
|
131
157
|
readPublicationState(state, `${provider}RepoChange`);
|
|
@@ -196,32 +222,65 @@ export function pullRequestPublicationSources<P extends PublicationParams>(
|
|
|
196
222
|
}),
|
|
197
223
|
read: () => ({ kind: "cancelled" }),
|
|
198
224
|
};
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
225
|
+
async function finalizeIssue(ctx: PublicationContext<P>, pr: PublicationRequest | null) {
|
|
226
|
+
const params = issueOrigin(ctx.params);
|
|
227
|
+
if (!params) return;
|
|
228
|
+
const call = callFor(ctx, provider);
|
|
229
|
+
const issue = await call<{ labels: Array<{ id: number; name: string }> }>("get_issue", {
|
|
230
|
+
issueNumber: params.issueNumber,
|
|
231
|
+
});
|
|
232
|
+
let labels = issue.labels
|
|
233
|
+
.filter((label) => label.name !== params.triggerLabel)
|
|
234
|
+
.map((label) => label[labelKey]);
|
|
235
|
+
if (pr?.merged) {
|
|
236
|
+
const done = await call<{ id: number; name: string }>("ensure_label", {
|
|
237
|
+
name: params.doneLabel,
|
|
238
|
+
});
|
|
239
|
+
labels = [...new Set([...labels, done[labelKey]])];
|
|
240
|
+
}
|
|
241
|
+
await call("update_issue", {
|
|
242
|
+
issueNumber: params.issueNumber,
|
|
243
|
+
patch: { labels, ...(pr?.merged ? { state: "closed" } : {}) },
|
|
244
|
+
writeKey: `${provider}:${ctx.process.id}:${pr?.merged ? "complete-source-issue" : pr ? "remove-source-trigger" : "no-changes-trigger"}`,
|
|
245
|
+
});
|
|
246
|
+
await call("add_issue_comment", {
|
|
247
|
+
issueNumber: params.issueNumber,
|
|
248
|
+
body: !pr
|
|
249
|
+
? "No repository changes were needed. No pull request was opened."
|
|
250
|
+
: pr.merged
|
|
251
|
+
? `Merged ${pr.html_url}${pr.merge_commit_sha ? ` at ${pr.merge_commit_sha}` : ""}.`
|
|
252
|
+
: `Leitwerk stopped because ${pr.html_url} was closed without merge.`,
|
|
253
|
+
writeKey: `${provider}:${ctx.process.id}:${pr ? `${pr.merged ? "merged" : "closed"}-pr-comment` : "no-changes-comment"}`,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
223
256
|
const call = (ctx: PublicationContext<P>) => callFor(ctx, provider);
|
|
224
|
-
|
|
257
|
+
const adapter: Omit<RepositoryChangePublicationAdapter<P>, "sources"> = {
|
|
258
|
+
/** @internal */ namespace: `${provider}RepoChange`,
|
|
259
|
+
/** @internal */ label: `${label} PR`,
|
|
260
|
+
/** @internal */ ids: {
|
|
261
|
+
/** @internal */ deliver: "deliver_change",
|
|
262
|
+
/** @internal */ feedback: "revise_from_pull_request_feedback",
|
|
263
|
+
/** @internal */ ciRepair: ci.id,
|
|
264
|
+
/** @internal */ operator: "ci_operator_action",
|
|
265
|
+
},
|
|
266
|
+
/** @internal */ tools: {
|
|
267
|
+
/** @internal */ delivery: pullRequestDeliveryTools(provider),
|
|
268
|
+
/** @internal */ feedback: [
|
|
269
|
+
`${provider}_get_pull_request`,
|
|
270
|
+
`${provider}_list_pull_request_feedback`,
|
|
271
|
+
],
|
|
272
|
+
/** @internal */ ci: ci.tools,
|
|
273
|
+
},
|
|
274
|
+
/** @internal */ commitMessage: (kind: "feedback" | "ci") =>
|
|
275
|
+
kind === "feedback" ? `fix: address ${label} review feedback` : `fix: repair ${ci.label}`,
|
|
276
|
+
/** @internal */ prompt: (kind: "feedback" | "ci", current: PublicationState) =>
|
|
277
|
+
kind === "feedback"
|
|
278
|
+
? `Address the unseen ${label} pull-request feedback batch for PR #${current.prNumber}. Feedback identifiers: ${JSON.stringify(current.feedbackIds)}. Inspect the current checkout and use ${label} 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.`
|
|
279
|
+
: ci.prompt(current),
|
|
280
|
+
/** @internal */ identity: (ctx: PublicationContext<P>) =>
|
|
281
|
+
resolvePullRequestGitIdentity(ctx, provider, profile(ctx.params)),
|
|
282
|
+
/** @internal */ reconcileTerminal: (ctx, _current, pr) => finalizeIssue(ctx, pr),
|
|
283
|
+
/** @internal */ unchanged: (ctx) => finalizeIssue(ctx, null),
|
|
225
284
|
async ensureRequest(ctx) {
|
|
226
285
|
const project = ctx.repo.get("repo");
|
|
227
286
|
const issue = issueOrigin(ctx.params);
|
|
@@ -283,4 +342,23 @@ export function pullRequestPublicationCallbacks<P extends PublicationParams>(
|
|
|
283
342
|
});
|
|
284
343
|
},
|
|
285
344
|
};
|
|
345
|
+
return {
|
|
346
|
+
/** @internal */ adapter,
|
|
347
|
+
/** @internal */ conflict(source: PublicationSource<P>["source"]): PublicationSource<P> {
|
|
348
|
+
return {
|
|
349
|
+
id: `${provider}_merge_conflict`,
|
|
350
|
+
kind: "conflict",
|
|
351
|
+
label: "Rebase conflicting pull request",
|
|
352
|
+
source,
|
|
353
|
+
read: ({ event }) => ({
|
|
354
|
+
kind: "conflict",
|
|
355
|
+
conflict: object(event).conflict as NonNullable<PublicationState["conflict"]>,
|
|
356
|
+
}),
|
|
357
|
+
};
|
|
358
|
+
},
|
|
359
|
+
/** @internal */ requirePr,
|
|
360
|
+
/** @internal */ feedback,
|
|
361
|
+
/** @internal */ terminal,
|
|
362
|
+
/** @internal */ cancelled,
|
|
363
|
+
};
|
|
286
364
|
}
|
|
@@ -1,8 +1,66 @@
|
|
|
1
1
|
import { parseRepoLocator, trimString } from "@leitwerk-dev/domain";
|
|
2
|
-
import type { Codec } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import type { Codec, FormDefinition, ProcessLaunchConfig } from "@leitwerk-dev/process-sdk";
|
|
3
|
+
import type { RepositoryChangeWorkflow } from "./repository-change-process.js";
|
|
3
4
|
|
|
4
5
|
/** @public */
|
|
5
|
-
export interface
|
|
6
|
+
export interface RepositoryChangeOptions {
|
|
7
|
+
/** @public */
|
|
8
|
+
skipPlanDecision?: boolean;
|
|
9
|
+
/** @public */
|
|
10
|
+
skipSimplification?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** @internal */
|
|
14
|
+
export const repositoryChangeOptionFields: FormDefinition["fields"] = [
|
|
15
|
+
{
|
|
16
|
+
id: "skipPlanDecision",
|
|
17
|
+
label: "Skip plan approval",
|
|
18
|
+
kind: "boolean",
|
|
19
|
+
description: "Generate a plan, then implement and publish automatically.",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "skipSimplification",
|
|
23
|
+
label: "Skip simplification",
|
|
24
|
+
kind: "boolean",
|
|
25
|
+
description: "Publish after implementation without the simplification pass.",
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
/** @internal */
|
|
30
|
+
export function repositoryChangeOptions(input: RepositoryChangeOptions): RepositoryChangeOptions {
|
|
31
|
+
return {
|
|
32
|
+
skipPlanDecision: input.skipPlanDecision === true,
|
|
33
|
+
skipSimplification: input.skipSimplification === true,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Provider label reads happen only at the implementation route boundary. @internal */
|
|
38
|
+
export function repositoryChangeWorkflow<
|
|
39
|
+
P extends RepositoryChangeOptions & {
|
|
40
|
+
/** @internal */
|
|
41
|
+
origin: string;
|
|
42
|
+
},
|
|
43
|
+
>(readLabels: (params: P) => Promise<readonly string[]>): RepositoryChangeWorkflow<P> {
|
|
44
|
+
return {
|
|
45
|
+
async planDecision(params) {
|
|
46
|
+
return {
|
|
47
|
+
skip: params.origin === "ui" && params.skipPlanDecision === true,
|
|
48
|
+
reason: "Launcher option",
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
async simplification(params) {
|
|
52
|
+
return params.origin === "ui"
|
|
53
|
+
? { skip: params.skipSimplification === true, reason: "Launcher option" }
|
|
54
|
+
: {
|
|
55
|
+
skip: (await readLabels(params)).includes("leitwerk-skip-simplification"),
|
|
56
|
+
reason: "Source labels",
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** @public */
|
|
63
|
+
export interface RepositoryChangeParamsBase extends RepositoryChangeOptions {
|
|
6
64
|
/** @public */
|
|
7
65
|
repoLocator: string;
|
|
8
66
|
/** @public */
|
|
@@ -45,6 +103,63 @@ export interface RepositoryUiOriginParams {
|
|
|
45
103
|
doneLabel: null;
|
|
46
104
|
}
|
|
47
105
|
|
|
106
|
+
/** Input shared by SSH-backed pull-request launchers. @public */
|
|
107
|
+
export interface PullRequestChangeLaunchInput
|
|
108
|
+
extends Pick<RepositoryChangeParamsBase, "prompt" | "workBranch"> {
|
|
109
|
+
/** @public */ profile: string;
|
|
110
|
+
/** @public */ sshCredentialRef: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Shared launch envelope; providers retain ownership of project metadata. @internal */
|
|
114
|
+
export function repositoryIssueChangeLaunchConfig<
|
|
115
|
+
P extends RepositoryChangeParamsBase & (RepositoryIssueOriginParams | RepositoryUiOriginParams),
|
|
116
|
+
>(
|
|
117
|
+
provider: string,
|
|
118
|
+
params: P,
|
|
119
|
+
title: string,
|
|
120
|
+
repository: string,
|
|
121
|
+
metadata: Record<string, unknown>,
|
|
122
|
+
source?: {
|
|
123
|
+
/** @internal */ id?: number;
|
|
124
|
+
/** @internal */ html_url: string;
|
|
125
|
+
/** @internal */ ssh_url: string;
|
|
126
|
+
/** @internal */ clone_url?: string;
|
|
127
|
+
},
|
|
128
|
+
): ProcessLaunchConfig<P> {
|
|
129
|
+
const issue = params.origin === "issue";
|
|
130
|
+
const settingsRepository =
|
|
131
|
+
source?.id !== undefined
|
|
132
|
+
? {
|
|
133
|
+
origin: new URL(source.html_url).origin,
|
|
134
|
+
repositoryId: source.id,
|
|
135
|
+
aliases: [source.ssh_url, ...(source.clone_url ? [source.clone_url] : [])],
|
|
136
|
+
}
|
|
137
|
+
: undefined;
|
|
138
|
+
return {
|
|
139
|
+
processId: `${provider}_repo_change_process`,
|
|
140
|
+
params,
|
|
141
|
+
title,
|
|
142
|
+
startTurnId: "generate_plan",
|
|
143
|
+
...(issue
|
|
144
|
+
? {
|
|
145
|
+
externalId: `${provider}:${repository}#${params.issueNumber}`,
|
|
146
|
+
externalUrl: params.issueUrl,
|
|
147
|
+
}
|
|
148
|
+
: {}),
|
|
149
|
+
projects: [
|
|
150
|
+
{
|
|
151
|
+
key: "repo",
|
|
152
|
+
repoLocator: params.repoLocator,
|
|
153
|
+
...(settingsRepository ? { settingsRepository } : {}),
|
|
154
|
+
baseBranch: params.baseBranch,
|
|
155
|
+
workBranch: params.workBranch,
|
|
156
|
+
...(issue ? { externalId: String(params.issueNumber), externalUrl: params.issueUrl } : {}),
|
|
157
|
+
metadata,
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
48
163
|
/** GitHub/Forgejo legacy origins default to issue; other providers may be stricter. @internal */
|
|
49
164
|
export function normalizeRepositoryIssueOrigin(
|
|
50
165
|
record: Record<string, unknown>,
|
|
@@ -72,16 +187,7 @@ export function normalizeRepositoryIssueOrigin(
|
|
|
72
187
|
}
|
|
73
188
|
|
|
74
189
|
/** @public */
|
|
75
|
-
export interface NormalizedRepositoryChangeParamsInput {
|
|
76
|
-
/** @internal */
|
|
77
|
-
repoLocator: string;
|
|
78
|
-
/** @internal */
|
|
79
|
-
baseBranch: string;
|
|
80
|
-
/** @internal */
|
|
81
|
-
workBranch: string;
|
|
82
|
-
/** @internal */
|
|
83
|
-
prompt: string;
|
|
84
|
-
}
|
|
190
|
+
export interface NormalizedRepositoryChangeParamsInput extends RepositoryChangeParamsBase {}
|
|
85
191
|
|
|
86
192
|
/** @public */
|
|
87
193
|
export function repositoryChangeParamsRecord(
|
|
@@ -102,6 +208,7 @@ export function normalizeRepositoryChangeParamsInput(
|
|
|
102
208
|
const record = repositoryChangeParamsRecord(value, displayName);
|
|
103
209
|
const rawRepoLocator = trimString(record.repoLocator);
|
|
104
210
|
return {
|
|
211
|
+
...repositoryChangeOptions(record),
|
|
105
212
|
repoLocator: parseRepoLocator(rawRepoLocator)?.value ?? rawRepoLocator,
|
|
106
213
|
baseBranch: trimString(record.baseBranch) || "main",
|
|
107
214
|
workBranch: trimString(record.workBranch),
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { parseRepositoryProfileBindings } from "./profile-bindings-internal.js";
|
|
2
2
|
export type {
|
|
3
3
|
NormalizedRepositoryChangeParamsInput,
|
|
4
|
+
PullRequestChangeLaunchInput,
|
|
4
5
|
RepositoryChangeLaunchParams,
|
|
6
|
+
RepositoryChangeOptions,
|
|
5
7
|
RepositoryChangeParamsBase,
|
|
6
8
|
RepositoryIssueOriginParams,
|
|
7
9
|
RepositoryUiOriginParams,
|
|
@@ -11,9 +13,11 @@ export {
|
|
|
11
13
|
normalizeRepositoryChangeParamsInput,
|
|
12
14
|
normalizeRepositoryIssueChangeParams,
|
|
13
15
|
normalizeRepositoryIssueOrigin,
|
|
16
|
+
repositoryChangeOptionFields,
|
|
17
|
+
repositoryChangeOptions,
|
|
14
18
|
repositoryChangeParamsRecord,
|
|
19
|
+
repositoryChangeWorkflow,
|
|
20
|
+
repositoryIssueChangeLaunchConfig,
|
|
15
21
|
} from "./repository-change-launch-internal.js";
|
|
16
|
-
export {
|
|
17
|
-
|
|
18
|
-
repositoryVisibilityCheck,
|
|
19
|
-
} from "./repository-change-ui-launcher-internal.js";
|
|
22
|
+
export type { RepositoryChangeWorkflow } from "./repository-change-process.js";
|
|
23
|
+
export { createRepositoryChangeLauncher } from "./repository-change-ui-launcher-internal.js";
|