@leitwerk-dev/coding 0.3.0 → 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 +120 -2
- package/dist/auto-work-branch.js +3 -24
- package/dist/auto-work-branch.js.map +1 -1
- package/dist/chunk-6E5VQPC4.js +28 -0
- package/dist/chunk-6E5VQPC4.js.map +1 -0
- 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-KFELB7ZC.js +70 -0
- package/dist/chunk-KFELB7ZC.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/profile-bindings-internal.d.ts +3 -0
- package/dist/profile-bindings-internal.d.ts.map +1 -0
- package/dist/pull-request-publication-internal.d.ts +75 -0
- package/dist/pull-request-publication-internal.d.ts.map +1 -0
- package/dist/repository-change-launch-internal-BudnAfL7.d.ts +88 -0
- package/dist/repository-change-launch-internal.d.ts +62 -11
- package/dist/repository-change-launch-internal.d.ts.map +1 -1
- package/dist/repository-change-launch.d.ts +5 -2
- package/dist/repository-change-launch.d.ts.map +1 -1
- package/dist/repository-change-launch.js +363 -6
- 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 +63 -7
- package/dist/repository-change-publication.d.ts.map +1 -1
- package/dist/repository-change-publication.js +732 -56
- 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 +65 -0
- package/dist/repository-change-ui-launcher-internal.d.ts.map +1 -0
- package/dist/repository-rebase/git.d.ts +31 -0
- package/dist/repository-rebase/git.d.ts.map +1 -0
- package/dist/repository-rebase/index.d.ts +42 -0
- package/dist/repository-rebase/index.d.ts.map +1 -0
- package/dist/repository-rebase/index.js +16 -0
- package/dist/repository-rebase/policy.d.ts +37 -0
- package/dist/repository-rebase/policy.d.ts.map +1 -0
- package/dist/repository-rebase/prompt.d.ts +3 -0
- package/dist/repository-rebase/prompt.d.ts.map +1 -0
- 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/git-inspection-profile.js.map +1 -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 +10 -10
- package/src/finalization-git-internal.ts +117 -114
- package/src/finalization-git.ts +1 -1
- package/src/index.ts +4 -1
- package/src/profile-bindings-internal.ts +39 -0
- package/src/pull-request-publication-internal.ts +364 -0
- package/src/repository-change-launch-internal.ts +194 -11
- package/src/repository-change-launch.ts +13 -0
- package/src/repository-change-process.ts +234 -523
- package/src/repository-change-publication.ts +535 -156
- package/src/repository-change-state-internal.ts +34 -20
- package/src/repository-change-ui-launcher-internal.ts +308 -0
- package/src/repository-rebase/git.ts +219 -0
- package/src/repository-rebase/index.ts +144 -0
- package/src/repository-rebase/policy.ts +75 -0
- package/src/repository-rebase/prompt.ts +2 -0
- 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/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 → repository-rebase/index.js.map} +0 -0
- /package/dist/turns/{review-plan.js.map → commit-message-evidence.js.map} +0 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
defineExternalActionSource,
|
|
3
|
+
ProcessWatcherDefinition,
|
|
4
|
+
RepositoryFeedbackSourceConfig,
|
|
5
|
+
RepositoryIssueCancelledSourceConfig,
|
|
6
|
+
RepositoryPullRequestSourceConfig,
|
|
7
|
+
} from "@leitwerk-dev/process-sdk";
|
|
8
|
+
import type { GitIdentity } from "./finalization-git.js";
|
|
9
|
+
import type { RepositoryIssueOriginParams } from "./repository-change-launch-internal.js";
|
|
10
|
+
import {
|
|
11
|
+
createRepositoryChangeProcess,
|
|
12
|
+
type RepositoryChangeProcessConfig,
|
|
13
|
+
} from "./repository-change-process.js";
|
|
14
|
+
import type {
|
|
15
|
+
PublicationContext,
|
|
16
|
+
PublicationEvidence,
|
|
17
|
+
PublicationParams,
|
|
18
|
+
PublicationRequest,
|
|
19
|
+
PublicationSource,
|
|
20
|
+
PublicationState,
|
|
21
|
+
RepositoryChangePublicationAdapter,
|
|
22
|
+
} from "./repository-change-publication.js";
|
|
23
|
+
import {
|
|
24
|
+
createRepositoryChangePublication,
|
|
25
|
+
publicationObject as object,
|
|
26
|
+
readPublicationState,
|
|
27
|
+
} from "./repository-change-publication.js";
|
|
28
|
+
import type { RepositoryChangeState } from "./repository-change-state.js";
|
|
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
|
+
|
|
87
|
+
const callFor =
|
|
88
|
+
<P>(ctx: PublicationContext<P>, provider: string) =>
|
|
89
|
+
<T>(name: string, args: Record<string, unknown>) =>
|
|
90
|
+
ctx.callIntegrationTool(`${provider}_${name}`, { projectKey: "repo", ...args }) as Promise<T>;
|
|
91
|
+
|
|
92
|
+
/** @internal */
|
|
93
|
+
export async function resolvePullRequestGitIdentity<P>(
|
|
94
|
+
ctx: PublicationContext<P>,
|
|
95
|
+
provider: string,
|
|
96
|
+
profile: string,
|
|
97
|
+
allowLookup = true,
|
|
98
|
+
): Promise<GitIdentity> {
|
|
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"]);
|
|
102
|
+
if (
|
|
103
|
+
identity.provider === provider &&
|
|
104
|
+
identity.profile === profile &&
|
|
105
|
+
(!allowLookup || (typeof identity.login === "string" && identity.login.trim())) &&
|
|
106
|
+
[identity.name, identity.email].every((value) => typeof value === "string" && value.trim())
|
|
107
|
+
)
|
|
108
|
+
return identity as unknown as GitIdentity;
|
|
109
|
+
if (!allowLookup) throw new Error(`Pinned ${provider} Git identity is unavailable`);
|
|
110
|
+
return callFor(ctx, provider)<GitIdentity>("resolve_git_identity", {});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** @internal */
|
|
114
|
+
function readPullRequestFeedback(
|
|
115
|
+
current: PublicationState,
|
|
116
|
+
event: unknown,
|
|
117
|
+
): Extract<PublicationEvidence, { kind: "feedback" }> {
|
|
118
|
+
const value = object(event);
|
|
119
|
+
const cursors = object(value.cursors);
|
|
120
|
+
return {
|
|
121
|
+
kind: "feedback",
|
|
122
|
+
conversationCursor: Number(cursors.conversationCursor ?? current.conversationCursor),
|
|
123
|
+
reviewCursor: Number(cursors.reviewCursor ?? current.reviewCursor),
|
|
124
|
+
inlineCursor: Number(cursors.inlineCursor ?? current.inlineCursor),
|
|
125
|
+
feedbackIds: (value.feedbackIds ?? []) as PublicationState["feedbackIds"],
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** @internal */
|
|
130
|
+
type SourceFactory<C> = ReturnType<typeof defineExternalActionSource<C>>;
|
|
131
|
+
|
|
132
|
+
/** Shared wiring for providers implementing the pull-request source protocol. @internal */
|
|
133
|
+
export function pullRequestPublicationDefaults<P extends PublicationParams>(
|
|
134
|
+
provider: string,
|
|
135
|
+
label: string,
|
|
136
|
+
external: {
|
|
137
|
+
/** @internal */
|
|
138
|
+
pullRequestFeedback: SourceFactory<
|
|
139
|
+
Omit<RepositoryFeedbackSourceConfig, "disabled" | "terminalOutcome">
|
|
140
|
+
>;
|
|
141
|
+
/** @internal */
|
|
142
|
+
pullRequestTerminal: SourceFactory<Omit<RepositoryPullRequestSourceConfig, "disabled">>;
|
|
143
|
+
/** @internal */
|
|
144
|
+
issueCancelled: SourceFactory<RepositoryIssueCancelledSourceConfig>;
|
|
145
|
+
},
|
|
146
|
+
profile: (params: P) => string,
|
|
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
|
+
},
|
|
155
|
+
) {
|
|
156
|
+
const remote = (state: RepositoryChangeState) =>
|
|
157
|
+
readPublicationState(state, `${provider}RepoChange`);
|
|
158
|
+
/** @internal */
|
|
159
|
+
function requirePr(state: RepositoryChangeState) {
|
|
160
|
+
const value = remote(state);
|
|
161
|
+
if (!value.headSha || !value.prNumber || !value.prUrl)
|
|
162
|
+
throw new Error("Pull request delivery state is incomplete");
|
|
163
|
+
return {
|
|
164
|
+
...value,
|
|
165
|
+
/** @internal */ headSha: value.headSha,
|
|
166
|
+
/** @internal */ prNumber: value.prNumber,
|
|
167
|
+
/** @internal */ prUrl: value.prUrl,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const feedback: PublicationSource<P> = {
|
|
171
|
+
id: `${provider}_feedback`,
|
|
172
|
+
kind: "feedback",
|
|
173
|
+
label: `${label} pull request feedback`,
|
|
174
|
+
source: external.pullRequestFeedback<P, RepositoryChangeState>(({ params, state }) => ({
|
|
175
|
+
profile: profile(params),
|
|
176
|
+
owner: params.owner,
|
|
177
|
+
repo: params.repo,
|
|
178
|
+
prNumber: requirePr(state).prNumber,
|
|
179
|
+
conversationCursor: remote(state).conversationCursor,
|
|
180
|
+
reviewCursor: remote(state).reviewCursor,
|
|
181
|
+
inlineCursor: remote(state).inlineCursor,
|
|
182
|
+
quietPeriodMs: 120000,
|
|
183
|
+
pollInterval: "30s",
|
|
184
|
+
})),
|
|
185
|
+
read: ({ state, event }) => readPullRequestFeedback(remote(state), event),
|
|
186
|
+
};
|
|
187
|
+
const terminal: PublicationSource<P>[] = (["merged", "closed"] as const).map(
|
|
188
|
+
(terminalOutcome) => ({
|
|
189
|
+
id: `${provider}_pr_${terminalOutcome}`,
|
|
190
|
+
kind: "terminal",
|
|
191
|
+
label: `${label} pull request ${terminalOutcome}`,
|
|
192
|
+
source: external.pullRequestTerminal<P, RepositoryChangeState>(({ params, state }) => ({
|
|
193
|
+
profile: profile(params),
|
|
194
|
+
owner: params.owner,
|
|
195
|
+
repo: params.repo,
|
|
196
|
+
prNumber: requirePr(state).prNumber,
|
|
197
|
+
terminalOutcome,
|
|
198
|
+
pollInterval: "30s",
|
|
199
|
+
})),
|
|
200
|
+
read: ({ event }) => ({
|
|
201
|
+
kind: "terminal",
|
|
202
|
+
request: object(event).pullRequest as PublicationRequest,
|
|
203
|
+
}),
|
|
204
|
+
}),
|
|
205
|
+
);
|
|
206
|
+
const cancelled: PublicationSource<P> = {
|
|
207
|
+
id: "source_cancelled",
|
|
208
|
+
kind: "cancelled",
|
|
209
|
+
label: "Source issue cancelled",
|
|
210
|
+
enabled: (params) => issueOrigin(params) !== undefined,
|
|
211
|
+
source: external.issueCancelled<P, RepositoryChangeState>(({ params }) => {
|
|
212
|
+
const issue = issueOrigin(params);
|
|
213
|
+
if (!issue) throw new Error(`${label} source issue metadata is unavailable`);
|
|
214
|
+
return {
|
|
215
|
+
profile: profile(params),
|
|
216
|
+
owner: params.owner,
|
|
217
|
+
repo: params.repo,
|
|
218
|
+
issueNumber: issue.issueNumber,
|
|
219
|
+
triggerLabel: issue.triggerLabel,
|
|
220
|
+
pollInterval: "30s",
|
|
221
|
+
};
|
|
222
|
+
}),
|
|
223
|
+
read: () => ({ kind: "cancelled" }),
|
|
224
|
+
};
|
|
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
|
+
}
|
|
256
|
+
const call = (ctx: PublicationContext<P>) => callFor(ctx, provider);
|
|
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),
|
|
284
|
+
async ensureRequest(ctx) {
|
|
285
|
+
const project = ctx.repo.get("repo");
|
|
286
|
+
const issue = issueOrigin(ctx.params);
|
|
287
|
+
const pr = await call(ctx)<PublicationRequest>("ensure_pull_request", {
|
|
288
|
+
title: ctx.process.title ?? (issue ? `Issue #${issue.issueNumber}` : "Leitwerk change"),
|
|
289
|
+
body: issue
|
|
290
|
+
? `Implements ${issue.issueUrl}\n\nLeitwerk process: ${ctx.process.id}`
|
|
291
|
+
: `Leitwerk process: ${ctx.process.id}`,
|
|
292
|
+
head: project.workBranch,
|
|
293
|
+
base: project.baseBranch,
|
|
294
|
+
});
|
|
295
|
+
if (!pr) throw new Error(`${label} pull request could not be created or found`);
|
|
296
|
+
return pr;
|
|
297
|
+
},
|
|
298
|
+
async linkIssue(ctx, current) {
|
|
299
|
+
const issue = issueOrigin(ctx.params);
|
|
300
|
+
if (issue)
|
|
301
|
+
await call(ctx)("add_issue_comment", {
|
|
302
|
+
issueNumber: issue.issueNumber,
|
|
303
|
+
body: `Leitwerk opened pull request ${current.prUrl}.`,
|
|
304
|
+
writeKey: `${provider}:${ctx.process.id}:source-pr-link:${current.prNumber}`,
|
|
305
|
+
});
|
|
306
|
+
},
|
|
307
|
+
async reply(ctx, current) {
|
|
308
|
+
const invoke = call(ctx);
|
|
309
|
+
for (const feedback of current.feedbackIds)
|
|
310
|
+
await invoke("reply_to_pull_request_feedback", {
|
|
311
|
+
pullRequestNumber: current.prNumber,
|
|
312
|
+
feedbackKind: feedback.kind,
|
|
313
|
+
feedbackId: feedback.id,
|
|
314
|
+
body: `Addressed in ${current.headSha?.slice(0, 8) ?? "the current revision"}.`,
|
|
315
|
+
writeKey: `${provider}:${ctx.process.id}:feedback-reply:${feedback.kind}:${feedback.id}:${current.headSha}`,
|
|
316
|
+
});
|
|
317
|
+
},
|
|
318
|
+
async acknowledge(ctx, current) {
|
|
319
|
+
const invoke = call(ctx);
|
|
320
|
+
for (const feedback of current.feedbackIds) {
|
|
321
|
+
if (feedback.kind === "review") continue;
|
|
322
|
+
await invoke("add_pull_request_feedback_reaction", {
|
|
323
|
+
pullRequestNumber: current.prNumber,
|
|
324
|
+
feedbackKind: feedback.kind,
|
|
325
|
+
feedbackId: feedback.id,
|
|
326
|
+
writeKey: `${provider}:${ctx.process.id}:feedback-eyes:${feedback.kind}:${feedback.id}`,
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
async head(ctx, current) {
|
|
331
|
+
return (
|
|
332
|
+
await call(ctx)<{ head: { sha: string } }>("get_pull_request", {
|
|
333
|
+
pullRequestNumber: current.prNumber,
|
|
334
|
+
})
|
|
335
|
+
).head.sha;
|
|
336
|
+
},
|
|
337
|
+
async afterRebase(ctx, current) {
|
|
338
|
+
await call(ctx)("add_pull_request_comment", {
|
|
339
|
+
pullRequestNumber: current.prNumber,
|
|
340
|
+
body: `Merge conflict repair completed at ${current.headSha}; base ${current.conflict?.baseSha}.`,
|
|
341
|
+
writeKey: `rebase:${ctx.process.id}:${current.lastConflictKey}:${current.headSha}`,
|
|
342
|
+
});
|
|
343
|
+
},
|
|
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
|
+
};
|
|
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 */
|
|
@@ -17,18 +75,120 @@ export interface RepositoryChangeParamsBase {
|
|
|
17
75
|
export type RepositoryChangeLaunchParams<TExtra extends object = Record<never, never>> = TExtra &
|
|
18
76
|
RepositoryChangeParamsBase;
|
|
19
77
|
|
|
78
|
+
/** Shared source metadata; provider-specific interfaces retain their exported names. @public */
|
|
79
|
+
export interface RepositoryIssueOriginParams {
|
|
80
|
+
/** @public */
|
|
81
|
+
origin: "issue";
|
|
82
|
+
/** @public */
|
|
83
|
+
issueNumber: number;
|
|
84
|
+
/** @public */
|
|
85
|
+
issueUrl: string;
|
|
86
|
+
/** @public */
|
|
87
|
+
triggerLabel: string;
|
|
88
|
+
/** @public */
|
|
89
|
+
doneLabel: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
20
92
|
/** @public */
|
|
21
|
-
export interface
|
|
22
|
-
/** @
|
|
23
|
-
|
|
24
|
-
/** @
|
|
25
|
-
|
|
26
|
-
/** @
|
|
27
|
-
|
|
28
|
-
/** @
|
|
29
|
-
|
|
93
|
+
export interface RepositoryUiOriginParams {
|
|
94
|
+
/** @public */
|
|
95
|
+
origin: "ui";
|
|
96
|
+
/** @public */
|
|
97
|
+
issueNumber: null;
|
|
98
|
+
/** @public */
|
|
99
|
+
issueUrl: null;
|
|
100
|
+
/** @public */
|
|
101
|
+
triggerLabel: null;
|
|
102
|
+
/** @public */
|
|
103
|
+
doneLabel: null;
|
|
104
|
+
}
|
|
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
|
+
|
|
163
|
+
/** GitHub/Forgejo legacy origins default to issue; other providers may be stricter. @internal */
|
|
164
|
+
export function normalizeRepositoryIssueOrigin(
|
|
165
|
+
record: Record<string, unknown>,
|
|
166
|
+
displayName: string,
|
|
167
|
+
text: (name: string) => string,
|
|
168
|
+
): RepositoryIssueOriginParams | RepositoryUiOriginParams {
|
|
169
|
+
const origin = trimString(record.origin);
|
|
170
|
+
if (origin === "ui") {
|
|
171
|
+
return { origin: "ui", issueNumber: null, issueUrl: null, triggerLabel: null, doneLabel: null };
|
|
172
|
+
}
|
|
173
|
+
if (origin && origin !== "issue") throw new Error(`${displayName} requires a valid origin`);
|
|
174
|
+
if (
|
|
175
|
+
typeof record.issueNumber !== "number" ||
|
|
176
|
+
!Number.isInteger(record.issueNumber) ||
|
|
177
|
+
record.issueNumber <= 0
|
|
178
|
+
)
|
|
179
|
+
throw new Error(`${displayName} requires issueNumber`);
|
|
180
|
+
return {
|
|
181
|
+
origin: "issue",
|
|
182
|
+
issueNumber: record.issueNumber,
|
|
183
|
+
issueUrl: text("issueUrl"),
|
|
184
|
+
triggerLabel: text("triggerLabel"),
|
|
185
|
+
doneLabel: text("doneLabel"),
|
|
186
|
+
};
|
|
30
187
|
}
|
|
31
188
|
|
|
189
|
+
/** @public */
|
|
190
|
+
export interface NormalizedRepositoryChangeParamsInput extends RepositoryChangeParamsBase {}
|
|
191
|
+
|
|
32
192
|
/** @public */
|
|
33
193
|
export function repositoryChangeParamsRecord(
|
|
34
194
|
value: unknown,
|
|
@@ -48,6 +208,7 @@ export function normalizeRepositoryChangeParamsInput(
|
|
|
48
208
|
const record = repositoryChangeParamsRecord(value, displayName);
|
|
49
209
|
const rawRepoLocator = trimString(record.repoLocator);
|
|
50
210
|
return {
|
|
211
|
+
...repositoryChangeOptions(record),
|
|
51
212
|
repoLocator: parseRepoLocator(rawRepoLocator)?.value ?? rawRepoLocator,
|
|
52
213
|
baseBranch: trimString(record.baseBranch) || "main",
|
|
53
214
|
workBranch: trimString(record.workBranch),
|
|
@@ -55,6 +216,28 @@ export function normalizeRepositoryChangeParamsInput(
|
|
|
55
216
|
};
|
|
56
217
|
}
|
|
57
218
|
|
|
219
|
+
/** Normalize issue-capable repository params with provider-owned required text fields. @internal */
|
|
220
|
+
export function normalizeRepositoryIssueChangeParams<K extends string>(
|
|
221
|
+
value: unknown,
|
|
222
|
+
displayName: string,
|
|
223
|
+
fields: readonly K[],
|
|
224
|
+
): NormalizedRepositoryChangeParamsInput &
|
|
225
|
+
Record<K, string> &
|
|
226
|
+
(RepositoryIssueOriginParams | RepositoryUiOriginParams) {
|
|
227
|
+
const shared = normalizeRepositoryChangeParamsInput(value, displayName);
|
|
228
|
+
const record = repositoryChangeParamsRecord(value, displayName);
|
|
229
|
+
const text = (name: string) => {
|
|
230
|
+
const value = trimString(record[name]);
|
|
231
|
+
if (!value) throw new Error(`${displayName} requires ${name}`);
|
|
232
|
+
return value;
|
|
233
|
+
};
|
|
234
|
+
return {
|
|
235
|
+
...shared,
|
|
236
|
+
...(Object.fromEntries(fields.map((name) => [name, text(name)])) as Record<K, string>),
|
|
237
|
+
...normalizeRepositoryIssueOrigin(record, displayName, text),
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
58
241
|
/** @public */
|
|
59
242
|
export function createRepositoryChangeParamsCodec<T extends RepositoryChangeParamsBase>(input: {
|
|
60
243
|
/** @public */
|
|
@@ -1,10 +1,23 @@
|
|
|
1
|
+
export { parseRepositoryProfileBindings } from "./profile-bindings-internal.js";
|
|
1
2
|
export type {
|
|
2
3
|
NormalizedRepositoryChangeParamsInput,
|
|
4
|
+
PullRequestChangeLaunchInput,
|
|
3
5
|
RepositoryChangeLaunchParams,
|
|
6
|
+
RepositoryChangeOptions,
|
|
4
7
|
RepositoryChangeParamsBase,
|
|
8
|
+
RepositoryIssueOriginParams,
|
|
9
|
+
RepositoryUiOriginParams,
|
|
5
10
|
} from "./repository-change-launch-internal.js";
|
|
6
11
|
export {
|
|
7
12
|
createRepositoryChangeParamsCodec,
|
|
8
13
|
normalizeRepositoryChangeParamsInput,
|
|
14
|
+
normalizeRepositoryIssueChangeParams,
|
|
15
|
+
normalizeRepositoryIssueOrigin,
|
|
16
|
+
repositoryChangeOptionFields,
|
|
17
|
+
repositoryChangeOptions,
|
|
9
18
|
repositoryChangeParamsRecord,
|
|
19
|
+
repositoryChangeWorkflow,
|
|
20
|
+
repositoryIssueChangeLaunchConfig,
|
|
10
21
|
} from "./repository-change-launch-internal.js";
|
|
22
|
+
export type { RepositoryChangeWorkflow } from "./repository-change-process.js";
|
|
23
|
+
export { createRepositoryChangeLauncher } from "./repository-change-ui-launcher-internal.js";
|