@leitwerk-dev/forgejo-repo-change 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 +8 -17
- package/dist/index.d.ts +17 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +89 -993
- package/dist/index.js.map +1 -1
- package/dist/launcher.d.ts +16 -20
- package/dist/launcher.d.ts.map +1 -1
- package/dist/params.d.ts +3 -23
- package/dist/params.d.ts.map +1 -1
- package/dist/process.d.ts +1 -1
- package/dist/process.d.ts.map +1 -1
- package/dist/profile-bindings.d.ts.map +1 -1
- package/package.json +7 -8
- package/src/launcher.ts +40 -275
- package/src/params.ts +12 -72
- package/src/process.ts +39 -329
- package/src/profile-bindings.ts +5 -39
package/src/process.ts
CHANGED
|
@@ -1,98 +1,50 @@
|
|
|
1
|
-
import { createRepositoryChangeProcess } from "@leitwerk-dev/coding";
|
|
2
1
|
import {
|
|
3
|
-
|
|
2
|
+
createPullRequestChangeProcess,
|
|
4
3
|
publicationObject as object,
|
|
5
|
-
type PublicationContext,
|
|
6
4
|
type PublicationSource,
|
|
7
5
|
type PublicationState,
|
|
6
|
+
pullRequestPublicationDefaults,
|
|
8
7
|
readPublicationState,
|
|
9
8
|
} from "@leitwerk-dev/coding/repository-change-publication";
|
|
10
9
|
import type { RepositoryChangeState } from "@leitwerk-dev/coding/repository-change-state";
|
|
11
|
-
import {
|
|
12
|
-
type ForgejoGitIdentity,
|
|
13
|
-
type ForgejoPullRequest,
|
|
14
|
-
forgejoExternal,
|
|
15
|
-
forgejoIssueWatcherSource,
|
|
16
|
-
} from "@leitwerk-dev/forgejo";
|
|
17
|
-
import type { FlowAutomaticRunContext } from "@leitwerk-dev/process-sdk";
|
|
10
|
+
import { forgejoExternal, forgejoIssueWatcherSource } from "@leitwerk-dev/forgejo";
|
|
18
11
|
import { woodpeckerExternal } from "@leitwerk-dev/woodpecker";
|
|
12
|
+
import type { createForgejoRepoChangeLauncher } from "./launcher.js";
|
|
19
13
|
import {
|
|
20
|
-
type createForgejoRepoChangeLauncher,
|
|
21
|
-
forgejoRepoChangeLaunchConfig,
|
|
22
|
-
forgejoRepoChangeParams,
|
|
23
|
-
} from "./launcher.js";
|
|
24
|
-
import {
|
|
25
|
-
type ForgejoIssueOriginParams,
|
|
26
14
|
type ForgejoRepoChangeParams,
|
|
27
15
|
forgejoRepoChangeParamsCodec,
|
|
28
16
|
isIssueOrigin,
|
|
29
17
|
} from "./params.js";
|
|
30
18
|
|
|
31
|
-
const processId = "forgejo_repo_change_process";
|
|
32
|
-
const ids = {
|
|
33
|
-
deliver: "deliver_change",
|
|
34
|
-
feedback: "revise_from_pull_request_feedback",
|
|
35
|
-
ciRepair: "repair_woodpecker_pipeline",
|
|
36
|
-
operator: "ci_operator_action",
|
|
37
|
-
};
|
|
38
19
|
const remote = (state: RepositoryChangeState) => readPublicationState(state, "forgejoRepoChange");
|
|
39
|
-
function requirePr(state: RepositoryChangeState) {
|
|
40
|
-
const value = remote(state);
|
|
41
|
-
if (!value.headSha || !value.prNumber || !value.prUrl)
|
|
42
|
-
throw new Error("Pull request delivery state is incomplete");
|
|
43
|
-
return { ...value, headSha: value.headSha, prNumber: value.prNumber, prUrl: value.prUrl };
|
|
44
|
-
}
|
|
45
|
-
const feedbackKey = (value: { kind: string; id: number }) => `${value.kind}:${value.id}`;
|
|
46
|
-
const callFor =
|
|
47
|
-
(ctx: PublicationContext<ForgejoRepoChangeParams>) =>
|
|
48
|
-
<T>(name: string, args: Record<string, unknown>) =>
|
|
49
|
-
ctx.callIntegrationTool(name, { projectKey: "repo", ...args }) as Promise<T>;
|
|
50
|
-
function requireIssueOrigin(
|
|
51
|
-
params: ForgejoRepoChangeParams,
|
|
52
|
-
): ForgejoRepoChangeParams & ForgejoIssueOriginParams {
|
|
53
|
-
if (!isIssueOrigin(params)) throw new Error("Forgejo source issue metadata is unavailable");
|
|
54
|
-
return params;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function pinnedGitIdentity(
|
|
58
|
-
ctx: FlowAutomaticRunContext<ForgejoRepoChangeParams, RepositoryChangeState>,
|
|
59
|
-
): ForgejoGitIdentity | null {
|
|
60
|
-
const project = ctx.projects.find((candidate) => candidate.key === "repo");
|
|
61
|
-
const candidate = object(project?.metadata)?.["leitwerk.gitIdentity"];
|
|
62
|
-
const identity = object(candidate);
|
|
63
|
-
if (
|
|
64
|
-
identity.provider !== "forgejo" ||
|
|
65
|
-
identity.profile !== ctx.params.forgejoProfile ||
|
|
66
|
-
typeof identity.login !== "string" ||
|
|
67
|
-
!identity.login.trim() ||
|
|
68
|
-
typeof identity.name !== "string" ||
|
|
69
|
-
!identity.name.trim() ||
|
|
70
|
-
typeof identity.email !== "string" ||
|
|
71
|
-
!identity.email.trim()
|
|
72
|
-
) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
return identity as unknown as ForgejoGitIdentity;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const deliveryTools = [
|
|
79
|
-
"forgejo_get_pull_request",
|
|
80
|
-
"forgejo_add_pull_request_comment",
|
|
81
|
-
"forgejo_resolve_git_identity",
|
|
82
|
-
"forgejo_ensure_pull_request",
|
|
83
|
-
"forgejo_add_issue_comment",
|
|
84
|
-
"forgejo_add_pull_request_feedback_reaction",
|
|
85
|
-
"forgejo_reply_to_pull_request_feedback",
|
|
86
|
-
"forgejo_get_issue",
|
|
87
|
-
"forgejo_ensure_label",
|
|
88
|
-
"forgejo_update_issue",
|
|
89
|
-
] as const;
|
|
90
20
|
|
|
91
21
|
/** @internal */
|
|
92
22
|
export function createForgejoRepoChangeProcess(
|
|
93
23
|
launcher: ReturnType<typeof createForgejoRepoChangeLauncher>,
|
|
94
24
|
docker: boolean,
|
|
95
25
|
) {
|
|
26
|
+
const sharedSources = pullRequestPublicationDefaults<ForgejoRepoChangeParams>(
|
|
27
|
+
"forgejo",
|
|
28
|
+
"Forgejo",
|
|
29
|
+
forgejoExternal,
|
|
30
|
+
(params) => params.forgejoProfile,
|
|
31
|
+
(params) => (isIssueOrigin(params) ? params : undefined),
|
|
32
|
+
"id",
|
|
33
|
+
{
|
|
34
|
+
id: "repair_woodpecker_pipeline",
|
|
35
|
+
label: "Woodpecker pipeline",
|
|
36
|
+
tools: [
|
|
37
|
+
"woodpecker_lookup_repository",
|
|
38
|
+
"woodpecker_list_pipelines",
|
|
39
|
+
"woodpecker_get_pipeline",
|
|
40
|
+
"woodpecker_get_step_logs",
|
|
41
|
+
"woodpecker_restart_pipeline",
|
|
42
|
+
],
|
|
43
|
+
prompt: (current) =>
|
|
44
|
+
`Diagnose Woodpecker pipeline #${current.pipeline?.number ?? "unknown"} (${current.pipeline?.status ?? "unknown"}) for the current checkout. Use Woodpecker tools to inspect pipeline metadata and bounded failed-step 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.`,
|
|
45
|
+
},
|
|
46
|
+
);
|
|
47
|
+
const { requirePr } = sharedSources;
|
|
96
48
|
const failedPipeline = woodpeckerExternal.pipeline<
|
|
97
49
|
ForgejoRepoChangeParams,
|
|
98
50
|
RepositoryChangeState
|
|
@@ -111,11 +63,8 @@ export function createForgejoRepoChangeProcess(
|
|
|
111
63
|
});
|
|
112
64
|
|
|
113
65
|
const sources: PublicationSource<ForgejoRepoChangeParams>[] = [
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
kind: "conflict",
|
|
117
|
-
label: "Rebase conflicting pull request",
|
|
118
|
-
source: forgejoExternal.pullRequestConflict(({ params, state }) => ({
|
|
66
|
+
sharedSources.conflict(
|
|
67
|
+
forgejoExternal.pullRequestConflict(({ params, state }) => ({
|
|
119
68
|
profile: params.forgejoProfile,
|
|
120
69
|
owner: params.owner,
|
|
121
70
|
repo: params.repo,
|
|
@@ -124,39 +73,8 @@ export function createForgejoRepoChangeProcess(
|
|
|
124
73
|
lastConflictKey: remote(state).lastConflictKey,
|
|
125
74
|
pollInterval: "30s",
|
|
126
75
|
})),
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
conflict: object(event).conflict as NonNullable<PublicationState["conflict"]>,
|
|
130
|
-
}),
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
id: "forgejo_feedback",
|
|
134
|
-
kind: "feedback",
|
|
135
|
-
label: "Forgejo pull request feedback",
|
|
136
|
-
source: forgejoExternal.pullRequestFeedback(({ params, state }) => ({
|
|
137
|
-
profile: params.forgejoProfile,
|
|
138
|
-
owner: params.owner,
|
|
139
|
-
repo: params.repo,
|
|
140
|
-
prNumber: requirePr(state).prNumber,
|
|
141
|
-
conversationCursor: remote(state).conversationCursor,
|
|
142
|
-
reviewCursor: remote(state).reviewCursor,
|
|
143
|
-
inlineCursor: remote(state).inlineCursor,
|
|
144
|
-
quietPeriodMs: 120000,
|
|
145
|
-
pollInterval: "30s",
|
|
146
|
-
})),
|
|
147
|
-
read: ({ state, event }) => {
|
|
148
|
-
const value = object(event);
|
|
149
|
-
const cursors = object(value.cursors);
|
|
150
|
-
const current = remote(state);
|
|
151
|
-
return {
|
|
152
|
-
kind: "feedback",
|
|
153
|
-
conversationCursor: Number(cursors.conversationCursor ?? current.conversationCursor),
|
|
154
|
-
reviewCursor: Number(cursors.reviewCursor ?? current.reviewCursor),
|
|
155
|
-
inlineCursor: Number(cursors.inlineCursor ?? current.inlineCursor),
|
|
156
|
-
feedbackIds: (value.feedbackIds ?? []) as PublicationState["feedbackIds"],
|
|
157
|
-
};
|
|
158
|
-
},
|
|
159
|
-
},
|
|
76
|
+
),
|
|
77
|
+
sharedSources.feedback,
|
|
160
78
|
{
|
|
161
79
|
id: "woodpecker_failure_repair",
|
|
162
80
|
operatorId: "woodpecker_failure_operator",
|
|
@@ -168,226 +86,18 @@ export function createForgejoRepoChangeProcess(
|
|
|
168
86
|
pipeline: object(event).pipeline as NonNullable<PublicationState["pipeline"]>,
|
|
169
87
|
}),
|
|
170
88
|
},
|
|
171
|
-
...
|
|
172
|
-
|
|
173
|
-
kind: "terminal" as const,
|
|
174
|
-
label: `Forgejo pull request ${terminalOutcome}`,
|
|
175
|
-
source: forgejoExternal.pullRequestTerminal<ForgejoRepoChangeParams, RepositoryChangeState>(
|
|
176
|
-
({ params, state }) => ({
|
|
177
|
-
profile: params.forgejoProfile,
|
|
178
|
-
owner: params.owner,
|
|
179
|
-
repo: params.repo,
|
|
180
|
-
prNumber: requirePr(state).prNumber,
|
|
181
|
-
terminalOutcome,
|
|
182
|
-
pollInterval: "30s",
|
|
183
|
-
}),
|
|
184
|
-
),
|
|
185
|
-
read: ({ event }: { event: unknown }) => ({
|
|
186
|
-
kind: "terminal" as const,
|
|
187
|
-
request: object(event).pullRequest as ForgejoPullRequest,
|
|
188
|
-
}),
|
|
189
|
-
})),
|
|
190
|
-
{
|
|
191
|
-
id: "source_cancelled",
|
|
192
|
-
kind: "cancelled",
|
|
193
|
-
label: "Source issue cancelled",
|
|
194
|
-
enabled: isIssueOrigin,
|
|
195
|
-
source: forgejoExternal.issueCancelled(({ params }) => {
|
|
196
|
-
const issue = requireIssueOrigin(params);
|
|
197
|
-
return {
|
|
198
|
-
profile: issue.forgejoProfile,
|
|
199
|
-
owner: issue.owner,
|
|
200
|
-
repo: issue.repo,
|
|
201
|
-
issueNumber: issue.issueNumber,
|
|
202
|
-
triggerLabel: issue.triggerLabel,
|
|
203
|
-
pollInterval: "30s",
|
|
204
|
-
};
|
|
205
|
-
}),
|
|
206
|
-
read: () => ({ kind: "cancelled" }),
|
|
207
|
-
},
|
|
89
|
+
...sharedSources.terminal,
|
|
90
|
+
sharedSources.cancelled,
|
|
208
91
|
];
|
|
209
|
-
|
|
210
|
-
namespace: "forgejoRepoChange",
|
|
211
|
-
label: "Forgejo PR",
|
|
212
|
-
ids,
|
|
213
|
-
sources,
|
|
214
|
-
tools: {
|
|
215
|
-
delivery: deliveryTools,
|
|
216
|
-
feedback: ["forgejo_get_pull_request", "forgejo_list_pull_request_feedback"],
|
|
217
|
-
ci: [
|
|
218
|
-
"woodpecker_lookup_repository",
|
|
219
|
-
"woodpecker_list_pipelines",
|
|
220
|
-
"woodpecker_get_pipeline",
|
|
221
|
-
"woodpecker_get_step_logs",
|
|
222
|
-
"woodpecker_restart_pipeline",
|
|
223
|
-
],
|
|
224
|
-
},
|
|
225
|
-
async identity(ctx) {
|
|
226
|
-
return (
|
|
227
|
-
pinnedGitIdentity(ctx) ??
|
|
228
|
-
(await callFor(ctx)<ForgejoGitIdentity>("forgejo_resolve_git_identity", {}))
|
|
229
|
-
);
|
|
230
|
-
},
|
|
231
|
-
async reconcileTerminal(ctx, _current, pr) {
|
|
232
|
-
const call = callFor(ctx);
|
|
233
|
-
if (isIssueOrigin(ctx.params)) {
|
|
234
|
-
const issue = await call<{
|
|
235
|
-
labels: Array<{ id: number; name: string }>;
|
|
236
|
-
}>("forgejo_get_issue", {
|
|
237
|
-
issueNumber: ctx.params.issueNumber,
|
|
238
|
-
});
|
|
239
|
-
let labels = issue.labels
|
|
240
|
-
.filter((label) => label.name !== ctx.params.triggerLabel)
|
|
241
|
-
.map((label) => label.id);
|
|
242
|
-
if (pr.merged) {
|
|
243
|
-
const done = await call<{ id: number }>("forgejo_ensure_label", {
|
|
244
|
-
name: ctx.params.doneLabel,
|
|
245
|
-
});
|
|
246
|
-
labels = [...new Set([...labels, done.id])];
|
|
247
|
-
}
|
|
248
|
-
await call("forgejo_update_issue", {
|
|
249
|
-
issueNumber: ctx.params.issueNumber,
|
|
250
|
-
patch: { labels, ...(pr.merged ? { state: "closed" } : {}) },
|
|
251
|
-
writeKey: `forgejo:${ctx.process.id}:${pr.merged ? "complete-source-issue" : "remove-source-trigger"}`,
|
|
252
|
-
});
|
|
253
|
-
await call("forgejo_add_issue_comment", {
|
|
254
|
-
issueNumber: ctx.params.issueNumber,
|
|
255
|
-
body: pr.merged
|
|
256
|
-
? `Merged ${pr.html_url}${pr.merge_commit_sha ? ` at ${pr.merge_commit_sha}` : ""}.`
|
|
257
|
-
: `Leitwerk stopped because ${pr.html_url} was closed without merge.`,
|
|
258
|
-
writeKey: `forgejo:${ctx.process.id}:${pr.merged ? "merged" : "closed"}-pr-comment`,
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
|
-
async ensureRequest(ctx) {
|
|
263
|
-
const call = callFor(ctx);
|
|
264
|
-
const project = ctx.repo.get("repo");
|
|
265
|
-
const issueOrigin = isIssueOrigin(ctx.params);
|
|
266
|
-
const pr = await call<ForgejoPullRequest>("forgejo_ensure_pull_request", {
|
|
267
|
-
title:
|
|
268
|
-
ctx.process.title ??
|
|
269
|
-
(issueOrigin ? `Issue #${ctx.params.issueNumber}` : "Leitwerk change"),
|
|
270
|
-
body: issueOrigin
|
|
271
|
-
? `Implements ${ctx.params.issueUrl}\n\nLeitwerk process: ${ctx.process.id}`
|
|
272
|
-
: `Leitwerk process: ${ctx.process.id}`,
|
|
273
|
-
head: project.workBranch,
|
|
274
|
-
base: project.baseBranch,
|
|
275
|
-
});
|
|
276
|
-
if (!pr) throw new Error("Forgejo pull request could not be created or found");
|
|
277
|
-
return pr;
|
|
278
|
-
},
|
|
279
|
-
async linkIssue(ctx, current) {
|
|
280
|
-
const call = callFor(ctx);
|
|
281
|
-
if (isIssueOrigin(ctx.params)) {
|
|
282
|
-
await call("forgejo_add_issue_comment", {
|
|
283
|
-
issueNumber: ctx.params.issueNumber,
|
|
284
|
-
body: `Leitwerk opened pull request ${current.prUrl}.`,
|
|
285
|
-
writeKey: `forgejo:${ctx.process.id}:source-pr-link:${current.prNumber}`,
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
},
|
|
289
|
-
async reply(ctx, current) {
|
|
290
|
-
const call = callFor(ctx);
|
|
291
|
-
for (const feedback of current.feedbackIds) {
|
|
292
|
-
await call("forgejo_reply_to_pull_request_feedback", {
|
|
293
|
-
pullRequestNumber: current.prNumber,
|
|
294
|
-
feedbackKind: feedback.kind,
|
|
295
|
-
feedbackId: feedback.id,
|
|
296
|
-
body: `Addressed in ${current.headSha?.slice(0, 8) ?? "the current revision"}.`,
|
|
297
|
-
writeKey: `forgejo:${ctx.process.id}:feedback-reply:${feedbackKey(feedback)}:${current.headSha}`,
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
},
|
|
301
|
-
async acknowledge(ctx, current) {
|
|
302
|
-
const call = callFor(ctx);
|
|
303
|
-
for (const feedback of current.feedbackIds) {
|
|
304
|
-
if (feedback.kind === "review") continue;
|
|
305
|
-
await call("forgejo_add_pull_request_feedback_reaction", {
|
|
306
|
-
pullRequestNumber: current.prNumber,
|
|
307
|
-
feedbackKind: feedback.kind,
|
|
308
|
-
feedbackId: feedback.id,
|
|
309
|
-
writeKey: `forgejo:${ctx.process.id}:feedback-eyes:${feedbackKey(feedback)}`,
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
},
|
|
313
|
-
async head(ctx, current) {
|
|
314
|
-
return (
|
|
315
|
-
await callFor(ctx)<ForgejoPullRequest>("forgejo_get_pull_request", {
|
|
316
|
-
pullRequestNumber: current.prNumber,
|
|
317
|
-
})
|
|
318
|
-
).head.sha;
|
|
319
|
-
},
|
|
320
|
-
async afterRebase(ctx, current) {
|
|
321
|
-
await callFor(ctx)("forgejo_add_pull_request_comment", {
|
|
322
|
-
pullRequestNumber: current.prNumber,
|
|
323
|
-
body: `Merge conflict repair completed at ${current.headSha}; base ${current.conflict?.baseSha}.`,
|
|
324
|
-
writeKey: `rebase:${ctx.process.id}:${current.lastConflictKey}:${current.headSha}`,
|
|
325
|
-
});
|
|
326
|
-
},
|
|
327
|
-
commitMessage: (kind) =>
|
|
328
|
-
kind === "feedback"
|
|
329
|
-
? "fix: address Forgejo review feedback"
|
|
330
|
-
: "fix: repair Woodpecker pipeline",
|
|
331
|
-
prompt(kind, current) {
|
|
332
|
-
return kind === "feedback"
|
|
333
|
-
? `Address the unseen Forgejo pull-request feedback batch for PR #${current.prNumber}. Feedback identifiers: ${JSON.stringify(current.feedbackIds)}. Inspect the current checkout and use Forgejo 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.`
|
|
334
|
-
: `Diagnose Woodpecker pipeline #${current.pipeline?.number ?? "unknown"} (${current.pipeline?.status ?? "unknown"}) for the current checkout. Use Woodpecker tools to inspect pipeline metadata and bounded failed-step 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.`;
|
|
335
|
-
},
|
|
336
|
-
});
|
|
337
|
-
const publication = publicationConfig.fragment;
|
|
338
|
-
publication.watcher({
|
|
339
|
-
id: "use_leitwerk",
|
|
340
|
-
label: "Forgejo use-leitwerk issues",
|
|
341
|
-
description: "Launch a remote repository change for Forgejo issues carrying the trigger label",
|
|
342
|
-
source: forgejoIssueWatcherSource,
|
|
343
|
-
preparationChecks: launcher.preparationChecks,
|
|
344
|
-
async resolveLaunchConfig({ profile, repository, issue, labels }) {
|
|
345
|
-
const issueNumber = issue.number;
|
|
346
|
-
const title = issue.title.trim();
|
|
347
|
-
const body = issue.body?.trim() ?? "";
|
|
348
|
-
const issueUrl = issue.html_url;
|
|
349
|
-
const binding = launcher.resolveProfiles(profile);
|
|
350
|
-
const gitIdentity = await launcher.resolveGitIdentity(profile);
|
|
351
|
-
const params: ForgejoRepoChangeParams = {
|
|
352
|
-
...forgejoRepoChangeParams(repository, {
|
|
353
|
-
...binding,
|
|
354
|
-
profile,
|
|
355
|
-
workBranch: `leitwerk/issue-${issueNumber}`,
|
|
356
|
-
prompt: `${title}${body ? `\n\n${body}` : ""}`,
|
|
357
|
-
}),
|
|
358
|
-
origin: "issue",
|
|
359
|
-
issueNumber,
|
|
360
|
-
issueUrl,
|
|
361
|
-
triggerLabel: labels.trigger,
|
|
362
|
-
doneLabel: labels.done,
|
|
363
|
-
};
|
|
364
|
-
return forgejoRepoChangeLaunchConfig(params, title, gitIdentity);
|
|
365
|
-
},
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
const definition = createRepositoryChangeProcess<ForgejoRepoChangeParams>({
|
|
369
|
-
processId,
|
|
370
|
-
displayName: "Forgejo Repo Change",
|
|
92
|
+
return createPullRequestChangeProcess("forgejo", "Forgejo", docker, {
|
|
371
93
|
paramsCodec: forgejoRepoChangeParamsCodec,
|
|
372
94
|
launcher: launcher.launcher,
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
95
|
+
workflow: launcher.workflow,
|
|
96
|
+
publication: { ...sharedSources.adapter, sources },
|
|
97
|
+
watcher: {
|
|
98
|
+
source: forgejoIssueWatcherSource,
|
|
99
|
+
preparationChecks: launcher.preparationChecks,
|
|
100
|
+
resolveLaunchConfig: launcher.launcher.resolveIssueLaunchConfig,
|
|
379
101
|
},
|
|
380
|
-
repositoryCredentials: ({ params }) => [
|
|
381
|
-
{
|
|
382
|
-
projectKey: "repo",
|
|
383
|
-
kind: "git_ssh",
|
|
384
|
-
credentialRef: params.sshCredentialRef,
|
|
385
|
-
},
|
|
386
|
-
],
|
|
387
|
-
publication: publicationConfig,
|
|
388
102
|
});
|
|
389
|
-
|
|
390
|
-
definition.process.runtime = { ...definition.process.runtime, docker };
|
|
391
|
-
|
|
392
|
-
return definition.process;
|
|
393
103
|
}
|
package/src/profile-bindings.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { parseRepositoryProfileBindings } from "@leitwerk-dev/coding/repository-change-launch";
|
|
2
|
+
|
|
1
3
|
/** Server-owned, non-secret wiring for future launches. @internal */
|
|
2
4
|
export interface ProfileBinding {
|
|
3
5
|
/** @internal */
|
|
@@ -8,48 +10,12 @@ export interface ProfileBinding {
|
|
|
8
10
|
/** @internal */
|
|
9
11
|
export type ProfileBindings = Readonly<Record<string, Readonly<ProfileBinding>>>;
|
|
10
12
|
|
|
11
|
-
function record(value: unknown, label: string): Record<string, unknown> {
|
|
12
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
13
|
-
throw new Error(`${label} must be an object`);
|
|
14
|
-
return value as Record<string, unknown>;
|
|
15
|
-
}
|
|
16
|
-
function field(value: unknown, fallback: string, label: string): string {
|
|
17
|
-
if (value === undefined) return fallback;
|
|
18
|
-
if (typeof value !== "string" || !value.trim())
|
|
19
|
-
throw new Error(`${label} must be a non-empty string`);
|
|
20
|
-
return value.trim();
|
|
21
|
-
}
|
|
22
13
|
/** @internal */
|
|
23
14
|
export function parseProfileBindings(raw: unknown): ProfileBindings {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const entries = Object.entries(mappings).map(([profile, value]) => {
|
|
28
|
-
if (!profile.trim() || profile.trim() !== profile)
|
|
29
|
-
throw new Error(
|
|
30
|
-
"profile_bindings keys must be non-empty profile names without surrounding whitespace",
|
|
31
|
-
);
|
|
32
|
-
const mapping = record(value, `profile_bindings.${profile}`);
|
|
33
|
-
for (const key of Object.keys(mapping))
|
|
34
|
-
if (key !== "woodpecker_profile" && key !== "ssh_credential_ref")
|
|
35
|
-
throw new Error(`Unknown profile_bindings.${profile}.${key}`);
|
|
36
|
-
return [
|
|
37
|
-
profile,
|
|
38
|
-
Object.freeze({
|
|
39
|
-
woodpeckerProfile: field(
|
|
40
|
-
mapping.woodpecker_profile,
|
|
41
|
-
profile,
|
|
42
|
-
`profile_bindings.${profile}.woodpecker_profile`,
|
|
43
|
-
),
|
|
44
|
-
sshCredentialRef: field(
|
|
45
|
-
mapping.ssh_credential_ref,
|
|
46
|
-
profile,
|
|
47
|
-
`profile_bindings.${profile}.ssh_credential_ref`,
|
|
48
|
-
),
|
|
49
|
-
}),
|
|
50
|
-
];
|
|
15
|
+
return parseRepositoryProfileBindings(raw, "forgejo-repo-change", {
|
|
16
|
+
woodpeckerProfile: "woodpecker_profile",
|
|
17
|
+
sshCredentialRef: "ssh_credential_ref",
|
|
51
18
|
});
|
|
52
|
-
return Object.freeze(Object.fromEntries(entries));
|
|
53
19
|
}
|
|
54
20
|
/** @internal */
|
|
55
21
|
export function resolveProfileBinding(bindings: ProfileBindings, profile: string): ProfileBinding {
|