@leitwerk-dev/coding 0.3.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 +34 -1
- 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-KFELB7ZC.js +70 -0
- package/dist/chunk-KFELB7ZC.js.map +1 -0
- 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 +73 -0
- package/dist/pull-request-publication-internal.d.ts.map +1 -0
- package/dist/repository-change-launch-internal-Dd-AONUs.d.ts +67 -0
- package/dist/repository-change-launch-internal.d.ts +30 -0
- package/dist/repository-change-launch-internal.d.ts.map +1 -1
- package/dist/repository-change-launch.d.ts +4 -2
- package/dist/repository-change-launch.d.ts.map +1 -1
- package/dist/repository-change-launch.js +235 -6
- package/dist/repository-change-launch.js.map +1 -1
- package/dist/repository-change-publication.d.ts +2 -2
- package/dist/repository-change-publication.d.ts.map +1 -1
- package/dist/repository-change-publication.js +429 -27
- package/dist/repository-change-publication.js.map +1 -1
- package/dist/repository-change-ui-launcher-internal.d.ts +53 -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/index.js.map +1 -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/package.json +9 -5
- package/src/profile-bindings-internal.ts +39 -0
- package/src/pull-request-publication-internal.ts +286 -0
- package/src/repository-change-launch-internal.ts +76 -0
- package/src/repository-change-launch.ts +9 -0
- package/src/repository-change-publication.ts +29 -45
- package/src/repository-change-ui-launcher-internal.ts +225 -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
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
commitAndPushWorkBranch
|
|
3
3
|
} from "./chunk-GO44KCUS.js";
|
|
4
|
+
import {
|
|
5
|
+
conflictKey,
|
|
6
|
+
validateConflict
|
|
7
|
+
} from "./chunk-KFELB7ZC.js";
|
|
4
8
|
import "./chunk-PX6F3LHL.js";
|
|
5
9
|
|
|
6
10
|
// src/repository-change-publication.ts
|
|
@@ -8,12 +12,413 @@ import { asUnknownRecord } from "@leitwerk-dev/domain";
|
|
|
8
12
|
import {
|
|
9
13
|
flow
|
|
10
14
|
} from "@leitwerk-dev/process-sdk";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} from "
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
15
|
+
|
|
16
|
+
// src/repository-rebase/git.ts
|
|
17
|
+
import { execFileSync } from "child_process";
|
|
18
|
+
import { existsSync, readFileSync, renameSync, writeFileSync } from "fs";
|
|
19
|
+
import { join } from "path";
|
|
20
|
+
import { repositoryGitArgs, repositoryGitSubprocessEnv } from "@leitwerk-dev/process-sdk";
|
|
21
|
+
import { resolveGitBinary } from "@leitwerk-dev/process-sdk/git-binary";
|
|
22
|
+
|
|
23
|
+
// src/repository-rebase/policy.ts
|
|
24
|
+
function requireRebaseTarget(workBranch, conflict, record) {
|
|
25
|
+
if (workBranch !== conflict.headBranch || workBranch === conflict.baseBranch)
|
|
26
|
+
throw new Error("Expected evidence for the tracked work branch and a distinct base");
|
|
27
|
+
if (record && (record.branch !== workBranch || record.originalHead !== conflict.headSha))
|
|
28
|
+
throw new Error("Missing matching rebase metadata");
|
|
29
|
+
if (record?.baseBranch && record.baseBranch !== conflict.baseBranch)
|
|
30
|
+
throw new Error("Rebase base branch changed since preparation");
|
|
31
|
+
}
|
|
32
|
+
function requireRebaseOrigin(record, origin) {
|
|
33
|
+
if (record?.originUrl && origin.originUrl !== record.originUrl || record?.originPushUrl && origin.originPushUrl !== record.originPushUrl)
|
|
34
|
+
throw new Error("Rebase origin changed since preparation");
|
|
35
|
+
}
|
|
36
|
+
function requireRebaseWorktree(workBranch, observation) {
|
|
37
|
+
if (observation.branch !== workBranch) throw new Error("Expected tracked work branch for rebase");
|
|
38
|
+
if (observation.dirty)
|
|
39
|
+
throw new Error("Rebase requires a clean worktree with no unresolved conflicts");
|
|
40
|
+
}
|
|
41
|
+
function requireRebaseHead(expected, local, remote) {
|
|
42
|
+
if (remote !== expected || local !== expected)
|
|
43
|
+
throw new Error("Tracked branch changed before repair");
|
|
44
|
+
}
|
|
45
|
+
function rebasePublicationDecision(originalHead, headSha, remoteHead2) {
|
|
46
|
+
if (remoteHead2 === headSha) return "already_published";
|
|
47
|
+
if (remoteHead2 !== originalHead)
|
|
48
|
+
throw new Error("Concurrent remote change rejected by rebase lease");
|
|
49
|
+
return "push";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/repository-rebase/git.ts
|
|
53
|
+
function git(input, ...args) {
|
|
54
|
+
return execFileSync(resolveGitBinary(), repositoryGitArgs(args), {
|
|
55
|
+
cwd: input.path,
|
|
56
|
+
encoding: "utf8",
|
|
57
|
+
env: repositoryGitSubprocessEnv(input.projectKey, {
|
|
58
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
59
|
+
GIT_EDITOR: "true"
|
|
60
|
+
}),
|
|
61
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
62
|
+
}).trim();
|
|
63
|
+
}
|
|
64
|
+
function area(input) {
|
|
65
|
+
return git(input, "rev-parse", "--absolute-git-dir");
|
|
66
|
+
}
|
|
67
|
+
function active(gitDir) {
|
|
68
|
+
return ["rebase-merge", "rebase-apply"].some((name) => existsSync(join(gitDir, name)));
|
|
69
|
+
}
|
|
70
|
+
function save(gitDir, record) {
|
|
71
|
+
const path = join(gitDir, "leitwerk-rebase.json");
|
|
72
|
+
writeFileSync(`${path}.tmp`, JSON.stringify(record), { mode: 384 });
|
|
73
|
+
renameSync(`${path}.tmp`, path);
|
|
74
|
+
}
|
|
75
|
+
function read(gitDir) {
|
|
76
|
+
const file = join(gitDir, "leitwerk-rebase.json");
|
|
77
|
+
return existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : null;
|
|
78
|
+
}
|
|
79
|
+
function requireWorktree(input) {
|
|
80
|
+
requireRebaseWorktree(input.workBranch, {
|
|
81
|
+
branch: git(input, "branch", "--show-current"),
|
|
82
|
+
dirty: Boolean(git(input, "status", "--porcelain"))
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function remoteHead(input) {
|
|
86
|
+
return git(input, "ls-remote", "--heads", "origin", `refs/heads/${input.workBranch}`).split(
|
|
87
|
+
/\s+/
|
|
88
|
+
)[0];
|
|
89
|
+
}
|
|
90
|
+
function requireTarget(input, record) {
|
|
91
|
+
requireRebaseTarget(input.workBranch, input.conflict, record);
|
|
92
|
+
git(input, "check-ref-format", `refs/heads/${input.workBranch}`);
|
|
93
|
+
git(input, "check-ref-format", `refs/heads/${input.conflict.baseBranch}`);
|
|
94
|
+
requireRebaseOrigin(record, {
|
|
95
|
+
originUrl: record?.originUrl ? git(input, "remote", "get-url", "origin") : void 0,
|
|
96
|
+
originPushUrl: record?.originPushUrl ? git(input, "remote", "get-url", "--push", "--all", "origin") : void 0
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function verifyCurrentBase(input, record) {
|
|
100
|
+
git(
|
|
101
|
+
input,
|
|
102
|
+
"fetch",
|
|
103
|
+
"origin",
|
|
104
|
+
`+refs/heads/${input.conflict.baseBranch}:refs/leitwerk/rebase-base`
|
|
105
|
+
);
|
|
106
|
+
git(input, "merge-base", "--is-ancestor", record.baseSha, "refs/leitwerk/rebase-base");
|
|
107
|
+
}
|
|
108
|
+
function verifyNoRepairNeeded(input, headSha, baseSha) {
|
|
109
|
+
if (input.conflict.reason === "behind")
|
|
110
|
+
git(input, "merge-base", "--is-ancestor", baseSha, headSha);
|
|
111
|
+
else git(input, "merge-tree", "--write-tree", headSha, baseSha);
|
|
112
|
+
}
|
|
113
|
+
function prepareRebase(input) {
|
|
114
|
+
const gitDir = area(input);
|
|
115
|
+
const old = read(gitDir);
|
|
116
|
+
requireTarget(input, old?.key === conflictKey(input.conflict) ? old : null);
|
|
117
|
+
if (old?.key === conflictKey(input.conflict)) {
|
|
118
|
+
verifyCurrentBase(input, old);
|
|
119
|
+
return old;
|
|
120
|
+
}
|
|
121
|
+
if (active(gitDir)) throw new Error("An unrelated rebase is already in progress");
|
|
122
|
+
requireWorktree(input);
|
|
123
|
+
git(
|
|
124
|
+
input,
|
|
125
|
+
"fetch",
|
|
126
|
+
"origin",
|
|
127
|
+
`+refs/heads/${input.workBranch}:refs/leitwerk/rebase-head`,
|
|
128
|
+
`+refs/heads/${input.conflict.baseBranch}:refs/leitwerk/rebase-base`
|
|
129
|
+
);
|
|
130
|
+
const [remoteSha, headSha, baseSha] = git(
|
|
131
|
+
input,
|
|
132
|
+
"rev-parse",
|
|
133
|
+
"refs/leitwerk/rebase-head",
|
|
134
|
+
"HEAD",
|
|
135
|
+
"refs/leitwerk/rebase-base"
|
|
136
|
+
).split("\n");
|
|
137
|
+
requireRebaseHead(input.conflict.headSha, headSha, remoteSha);
|
|
138
|
+
git(input, "merge-base", "--is-ancestor", input.conflict.baseSha, baseSha);
|
|
139
|
+
const record = {
|
|
140
|
+
key: conflictKey(input.conflict),
|
|
141
|
+
branch: input.workBranch,
|
|
142
|
+
originalHead: input.conflict.headSha,
|
|
143
|
+
baseSha,
|
|
144
|
+
status: "prepared",
|
|
145
|
+
originUrl: git(input, "remote", "get-url", "origin"),
|
|
146
|
+
originPushUrl: git(input, "remote", "get-url", "--push", "--all", "origin"),
|
|
147
|
+
baseBranch: input.conflict.baseBranch
|
|
148
|
+
};
|
|
149
|
+
git(input, "update-ref", "refs/leitwerk/rebase-original", record.originalHead);
|
|
150
|
+
save(gitDir, record);
|
|
151
|
+
return record;
|
|
152
|
+
}
|
|
153
|
+
function startRebase(input) {
|
|
154
|
+
const record = prepareRebase(input);
|
|
155
|
+
const gitDir = area(input);
|
|
156
|
+
if (active(gitDir)) return record;
|
|
157
|
+
if (record.status === "clean") return record;
|
|
158
|
+
requireWorktree(input);
|
|
159
|
+
if (record.status === "rebasing" && git(input, "rev-parse", "HEAD") !== record.originalHead)
|
|
160
|
+
return record;
|
|
161
|
+
try {
|
|
162
|
+
verifyNoRepairNeeded(input, record.originalHead, record.baseSha);
|
|
163
|
+
record.status = "clean";
|
|
164
|
+
save(gitDir, record);
|
|
165
|
+
return record;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
if (error.status !== 1) throw error;
|
|
168
|
+
}
|
|
169
|
+
record.status = "rebasing";
|
|
170
|
+
save(gitDir, record);
|
|
171
|
+
try {
|
|
172
|
+
git(input, "rebase", "--rebase-merges", record.baseSha);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if (!active(gitDir)) throw error;
|
|
175
|
+
}
|
|
176
|
+
return record;
|
|
177
|
+
}
|
|
178
|
+
function verifyRebase(input) {
|
|
179
|
+
const gitDir = area(input);
|
|
180
|
+
const record = read(gitDir);
|
|
181
|
+
if (!record || record.key !== conflictKey(input.conflict))
|
|
182
|
+
throw new Error("Missing matching rebase metadata");
|
|
183
|
+
requireTarget(input, record);
|
|
184
|
+
if (active(gitDir)) throw new Error("Rebase is incomplete");
|
|
185
|
+
requireWorktree(input);
|
|
186
|
+
const headSha = git(input, "rev-parse", "HEAD");
|
|
187
|
+
if (record.status === "clean") {
|
|
188
|
+
if (headSha !== record.originalHead)
|
|
189
|
+
throw new Error("Clean conflict report must not rewrite the branch");
|
|
190
|
+
verifyNoRepairNeeded(input, headSha, record.baseSha);
|
|
191
|
+
} else {
|
|
192
|
+
if (record.status !== "rebasing") throw new Error("Rebase was not started");
|
|
193
|
+
git(input, "merge-base", "--is-ancestor", record.baseSha, headSha);
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
headSha,
|
|
197
|
+
changed: headSha !== record.originalHead,
|
|
198
|
+
originalHead: record.originalHead,
|
|
199
|
+
baseSha: record.baseSha
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function publishRebase(input) {
|
|
203
|
+
const result = verifyRebase(input);
|
|
204
|
+
const gitDir = area(input);
|
|
205
|
+
const record = read(gitDir);
|
|
206
|
+
if (!record) throw new Error("Missing matching rebase metadata");
|
|
207
|
+
verifyCurrentBase(input, record);
|
|
208
|
+
const remote = remoteHead(input);
|
|
209
|
+
if (rebasePublicationDecision(result.originalHead, result.headSha, remote) === "already_published")
|
|
210
|
+
return result;
|
|
211
|
+
git(
|
|
212
|
+
input,
|
|
213
|
+
"push",
|
|
214
|
+
`--force-with-lease=refs/heads/${input.workBranch}:${result.originalHead}`,
|
|
215
|
+
"origin",
|
|
216
|
+
`${result.headSha}:refs/heads/${input.workBranch}`
|
|
217
|
+
);
|
|
218
|
+
if (remoteHead(input) !== result.headSha)
|
|
219
|
+
throw new Error("Rebase publication could not be verified");
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// src/repository-rebase/prompt.ts
|
|
224
|
+
var rebasePrompt = `Repair only the recorded pull request merge conflict or behind-base condition. Deterministic preparation has fetched and verified the tracked head and current base, retained the original head and lease in .git/leitwerk-rebase.json, and started the rebase if the conflict or missing base commits are confirmed locally. Inspect that metadata and git status first. For behind-base evidence, incorporate the fetched base even when merging would be clean. A clean preparation result means no rewrite is needed. Resolve conflicts preserving the requested behavior, original authors, and existing Signed-off-by trailers. You may use git add and GIT_EDITOR=true git rebase --continue until finished. This explicitly overrides the prohibition on creating commits only for rebase continuation. Do not create unrelated commits, reset the branch, skip commits, abort the rebase, or push. Run focused repository checks after resolution. Delivery verifies the completed rebase and publishes with the recorded pre-repair lease. If blocked, retain the workspace and explain the failure for retry or abort. Record a concise repair result.`;
|
|
225
|
+
|
|
226
|
+
// src/pull-request-publication-internal.ts
|
|
227
|
+
var callFor = (ctx, provider) => (name, args) => ctx.callIntegrationTool(`${provider}_${name}`, { projectKey: "repo", ...args });
|
|
228
|
+
async function resolvePullRequestGitIdentity(ctx, provider, profile) {
|
|
229
|
+
const project = ctx.projects.find((candidate) => candidate.key === "repo");
|
|
230
|
+
const identity = publicationObject(publicationObject(project?.metadata)["leitwerk.gitIdentity"]);
|
|
231
|
+
if (identity.provider === provider && identity.profile === profile && [identity.login, identity.name, identity.email].every(
|
|
232
|
+
(value) => typeof value === "string" && value.trim()
|
|
233
|
+
))
|
|
234
|
+
return identity;
|
|
235
|
+
return callFor(ctx, provider)("resolve_git_identity", {});
|
|
236
|
+
}
|
|
237
|
+
function readPullRequestFeedback(current, event) {
|
|
238
|
+
const value = publicationObject(event);
|
|
239
|
+
const cursors = publicationObject(value.cursors);
|
|
240
|
+
return {
|
|
241
|
+
kind: "feedback",
|
|
242
|
+
conversationCursor: Number(cursors.conversationCursor ?? current.conversationCursor),
|
|
243
|
+
reviewCursor: Number(cursors.reviewCursor ?? current.reviewCursor),
|
|
244
|
+
inlineCursor: Number(cursors.inlineCursor ?? current.inlineCursor),
|
|
245
|
+
feedbackIds: value.feedbackIds ?? []
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function reconcilePullRequestSourceIssue(provider, labelKey, issueOrigin) {
|
|
249
|
+
return async (ctx, _current, pr) => {
|
|
250
|
+
const params = issueOrigin(ctx.params);
|
|
251
|
+
if (!params) return;
|
|
252
|
+
const call = callFor(ctx, provider);
|
|
253
|
+
const issue = await call("get_issue", {
|
|
254
|
+
issueNumber: params.issueNumber
|
|
255
|
+
});
|
|
256
|
+
let labels = issue.labels.filter((label) => label.name !== params.triggerLabel).map((label) => label[labelKey]);
|
|
257
|
+
if (pr.merged) {
|
|
258
|
+
const done = await call("ensure_label", {
|
|
259
|
+
name: params.doneLabel
|
|
260
|
+
});
|
|
261
|
+
labels = [.../* @__PURE__ */ new Set([...labels, done[labelKey]])];
|
|
262
|
+
}
|
|
263
|
+
await call("update_issue", {
|
|
264
|
+
issueNumber: params.issueNumber,
|
|
265
|
+
patch: { labels, ...pr.merged ? { state: "closed" } : {} },
|
|
266
|
+
writeKey: `${provider}:${ctx.process.id}:${pr.merged ? "complete-source-issue" : "remove-source-trigger"}`
|
|
267
|
+
});
|
|
268
|
+
await call("add_issue_comment", {
|
|
269
|
+
issueNumber: params.issueNumber,
|
|
270
|
+
body: pr.merged ? `Merged ${pr.html_url}${pr.merge_commit_sha ? ` at ${pr.merge_commit_sha}` : ""}.` : `Leitwerk stopped because ${pr.html_url} was closed without merge.`,
|
|
271
|
+
writeKey: `${provider}:${ctx.process.id}:${pr.merged ? "merged" : "closed"}-pr-comment`
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function pullRequestPublicationSources(provider, label, external, profile, issueOrigin) {
|
|
276
|
+
const remote = (state) => readPublicationState(state, `${provider}RepoChange`);
|
|
277
|
+
function requirePr(state) {
|
|
278
|
+
const value = remote(state);
|
|
279
|
+
if (!value.headSha || !value.prNumber || !value.prUrl)
|
|
280
|
+
throw new Error("Pull request delivery state is incomplete");
|
|
281
|
+
return {
|
|
282
|
+
...value,
|
|
283
|
+
/** @internal */
|
|
284
|
+
headSha: value.headSha,
|
|
285
|
+
/** @internal */
|
|
286
|
+
prNumber: value.prNumber,
|
|
287
|
+
/** @internal */
|
|
288
|
+
prUrl: value.prUrl
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
const feedback = {
|
|
292
|
+
id: `${provider}_feedback`,
|
|
293
|
+
kind: "feedback",
|
|
294
|
+
label: `${label} pull request feedback`,
|
|
295
|
+
source: external.pullRequestFeedback(({ params, state }) => ({
|
|
296
|
+
profile: profile(params),
|
|
297
|
+
owner: params.owner,
|
|
298
|
+
repo: params.repo,
|
|
299
|
+
prNumber: requirePr(state).prNumber,
|
|
300
|
+
conversationCursor: remote(state).conversationCursor,
|
|
301
|
+
reviewCursor: remote(state).reviewCursor,
|
|
302
|
+
inlineCursor: remote(state).inlineCursor,
|
|
303
|
+
quietPeriodMs: 12e4,
|
|
304
|
+
pollInterval: "30s"
|
|
305
|
+
})),
|
|
306
|
+
read: ({ state, event }) => readPullRequestFeedback(remote(state), event)
|
|
307
|
+
};
|
|
308
|
+
const terminal = ["merged", "closed"].map(
|
|
309
|
+
(terminalOutcome) => ({
|
|
310
|
+
id: `${provider}_pr_${terminalOutcome}`,
|
|
311
|
+
kind: "terminal",
|
|
312
|
+
label: `${label} pull request ${terminalOutcome}`,
|
|
313
|
+
source: external.pullRequestTerminal(({ params, state }) => ({
|
|
314
|
+
profile: profile(params),
|
|
315
|
+
owner: params.owner,
|
|
316
|
+
repo: params.repo,
|
|
317
|
+
prNumber: requirePr(state).prNumber,
|
|
318
|
+
terminalOutcome,
|
|
319
|
+
pollInterval: "30s"
|
|
320
|
+
})),
|
|
321
|
+
read: ({ event }) => ({
|
|
322
|
+
kind: "terminal",
|
|
323
|
+
request: publicationObject(event).pullRequest
|
|
324
|
+
})
|
|
325
|
+
})
|
|
326
|
+
);
|
|
327
|
+
const cancelled = {
|
|
328
|
+
id: "source_cancelled",
|
|
329
|
+
kind: "cancelled",
|
|
330
|
+
label: "Source issue cancelled",
|
|
331
|
+
enabled: (params) => issueOrigin(params) !== void 0,
|
|
332
|
+
source: external.issueCancelled(({ params }) => {
|
|
333
|
+
const issue = issueOrigin(params);
|
|
334
|
+
if (!issue) throw new Error(`${label} source issue metadata is unavailable`);
|
|
335
|
+
return {
|
|
336
|
+
profile: profile(params),
|
|
337
|
+
owner: params.owner,
|
|
338
|
+
repo: params.repo,
|
|
339
|
+
issueNumber: issue.issueNumber,
|
|
340
|
+
triggerLabel: issue.triggerLabel,
|
|
341
|
+
pollInterval: "30s"
|
|
342
|
+
};
|
|
343
|
+
}),
|
|
344
|
+
read: () => ({ kind: "cancelled" })
|
|
345
|
+
};
|
|
346
|
+
return {
|
|
347
|
+
/** @internal */
|
|
348
|
+
requirePr,
|
|
349
|
+
/** @internal */
|
|
350
|
+
feedback,
|
|
351
|
+
/** @internal */
|
|
352
|
+
terminal,
|
|
353
|
+
/** @internal */
|
|
354
|
+
cancelled
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
function pullRequestPublicationCallbacks(provider, label, issueOrigin) {
|
|
358
|
+
const call = (ctx) => callFor(ctx, provider);
|
|
359
|
+
return {
|
|
360
|
+
async ensureRequest(ctx) {
|
|
361
|
+
const project = ctx.repo.get("repo");
|
|
362
|
+
const issue = issueOrigin(ctx.params);
|
|
363
|
+
const pr = await call(ctx)("ensure_pull_request", {
|
|
364
|
+
title: ctx.process.title ?? (issue ? `Issue #${issue.issueNumber}` : "Leitwerk change"),
|
|
365
|
+
body: issue ? `Implements ${issue.issueUrl}
|
|
366
|
+
|
|
367
|
+
Leitwerk process: ${ctx.process.id}` : `Leitwerk process: ${ctx.process.id}`,
|
|
368
|
+
head: project.workBranch,
|
|
369
|
+
base: project.baseBranch
|
|
370
|
+
});
|
|
371
|
+
if (!pr) throw new Error(`${label} pull request could not be created or found`);
|
|
372
|
+
return pr;
|
|
373
|
+
},
|
|
374
|
+
async linkIssue(ctx, current) {
|
|
375
|
+
const issue = issueOrigin(ctx.params);
|
|
376
|
+
if (issue)
|
|
377
|
+
await call(ctx)("add_issue_comment", {
|
|
378
|
+
issueNumber: issue.issueNumber,
|
|
379
|
+
body: `Leitwerk opened pull request ${current.prUrl}.`,
|
|
380
|
+
writeKey: `${provider}:${ctx.process.id}:source-pr-link:${current.prNumber}`
|
|
381
|
+
});
|
|
382
|
+
},
|
|
383
|
+
async reply(ctx, current) {
|
|
384
|
+
const invoke = call(ctx);
|
|
385
|
+
for (const feedback of current.feedbackIds)
|
|
386
|
+
await invoke("reply_to_pull_request_feedback", {
|
|
387
|
+
pullRequestNumber: current.prNumber,
|
|
388
|
+
feedbackKind: feedback.kind,
|
|
389
|
+
feedbackId: feedback.id,
|
|
390
|
+
body: `Addressed in ${current.headSha?.slice(0, 8) ?? "the current revision"}.`,
|
|
391
|
+
writeKey: `${provider}:${ctx.process.id}:feedback-reply:${feedback.kind}:${feedback.id}:${current.headSha}`
|
|
392
|
+
});
|
|
393
|
+
},
|
|
394
|
+
async acknowledge(ctx, current) {
|
|
395
|
+
const invoke = call(ctx);
|
|
396
|
+
for (const feedback of current.feedbackIds) {
|
|
397
|
+
if (feedback.kind === "review") continue;
|
|
398
|
+
await invoke("add_pull_request_feedback_reaction", {
|
|
399
|
+
pullRequestNumber: current.prNumber,
|
|
400
|
+
feedbackKind: feedback.kind,
|
|
401
|
+
feedbackId: feedback.id,
|
|
402
|
+
writeKey: `${provider}:${ctx.process.id}:feedback-eyes:${feedback.kind}:${feedback.id}`
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
},
|
|
406
|
+
async head(ctx, current) {
|
|
407
|
+
return (await call(ctx)("get_pull_request", {
|
|
408
|
+
pullRequestNumber: current.prNumber
|
|
409
|
+
})).head.sha;
|
|
410
|
+
},
|
|
411
|
+
async afterRebase(ctx, current) {
|
|
412
|
+
await call(ctx)("add_pull_request_comment", {
|
|
413
|
+
pullRequestNumber: current.prNumber,
|
|
414
|
+
body: `Merge conflict repair completed at ${current.headSha}; base ${current.conflict?.baseSha}.`,
|
|
415
|
+
writeKey: `rebase:${ctx.process.id}:${current.lastConflictKey}:${current.headSha}`
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// src/repository-change-publication.ts
|
|
17
422
|
var initialDeliveryState = {
|
|
18
423
|
stage: "not_started",
|
|
19
424
|
issueLinked: false,
|
|
@@ -142,7 +547,6 @@ function deliveryProgress(value, label, activeStepId) {
|
|
|
142
547
|
};
|
|
143
548
|
}
|
|
144
549
|
function createRepositoryChangePublication(adapter) {
|
|
145
|
-
const applyEvidence = applyPublicationEvidence;
|
|
146
550
|
const ids = adapter.ids;
|
|
147
551
|
const publication = flow.fragment(`${adapter.namespace}-publication`);
|
|
148
552
|
const remote = (state) => readPublicationState(state, adapter.namespace);
|
|
@@ -161,14 +565,14 @@ function createRepositoryChangePublication(adapter) {
|
|
|
161
565
|
const update = (patch) => {
|
|
162
566
|
current = { ...current, ...patch, delivery: { ...current.delivery, ...patch.delivery } };
|
|
163
567
|
};
|
|
164
|
-
const result = (
|
|
165
|
-
outcome,
|
|
568
|
+
const result = (outcome2) => ({
|
|
569
|
+
outcome: outcome2,
|
|
166
570
|
params: { nextState: patchRemote(ctx.state, current) }
|
|
167
571
|
});
|
|
168
572
|
if (current.pendingEvidence) {
|
|
169
573
|
const evidence = current.pendingEvidence;
|
|
170
574
|
const needsOperator = evidence.kind === "failure" && current.ciRecoveryCycles >= 3;
|
|
171
|
-
current =
|
|
575
|
+
current = applyPublicationEvidence(ctx.params, current, evidence, !needsOperator);
|
|
172
576
|
current.pendingEvidence = null;
|
|
173
577
|
if (evidence.kind === "cancelled") return result("aborted");
|
|
174
578
|
if (evidence.kind === "failure")
|
|
@@ -231,28 +635,21 @@ function createRepositoryChangePublication(adapter) {
|
|
|
231
635
|
update({ delivery: { stage: "awaiting" } });
|
|
232
636
|
ctx.reportProgress(deliveryProgress(current, adapter.label, "await_evidence"));
|
|
233
637
|
return result("awaiting");
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
).outcome(
|
|
638
|
+
});
|
|
639
|
+
const outcome = (o, description) => o.description(description).object("nextState").state(({ event }) => event.params.nextState);
|
|
640
|
+
delivery.outcome("awaiting", (o) => outcome(o, "Delivery is waiting for external evidence").wait()).outcome(
|
|
238
641
|
"feedback_ready",
|
|
239
|
-
(
|
|
240
|
-
).outcome(
|
|
241
|
-
"completed",
|
|
242
|
-
(outcome) => outcome.description("Merged pull request was reconciled").object("nextState").complete().state(({ event }) => event.params.nextState)
|
|
243
|
-
).outcome(
|
|
642
|
+
(o) => outcome(o, "Pull request feedback is acknowledged and ready for revision").to(ids.feedback)
|
|
643
|
+
).outcome("completed", (o) => outcome(o, "Merged pull request was reconciled").complete()).outcome(
|
|
244
644
|
"aborted",
|
|
245
|
-
(
|
|
645
|
+
(o) => outcome(o, "Closed pull request was reconciled").lifecycleStatus("aborted")
|
|
246
646
|
);
|
|
247
|
-
for (const [
|
|
647
|
+
for (const [name, target] of [
|
|
248
648
|
["ci_ready", ids.ciRepair],
|
|
249
649
|
["conflict_ready", ids.feedback],
|
|
250
650
|
["operator_action", ids.operator]
|
|
251
651
|
]) {
|
|
252
|
-
delivery.outcome(
|
|
253
|
-
outcome,
|
|
254
|
-
(o) => o.description("Route observed delivery evidence").object("nextState").to(target).state(({ event }) => event.params.nextState)
|
|
255
|
-
);
|
|
652
|
+
delivery.outcome(name, (o) => outcome(o, "Route observed delivery evidence").to(target));
|
|
256
653
|
}
|
|
257
654
|
for (const source of adapter.sources) {
|
|
258
655
|
const attach = (id, operator) => delivery.externalAction(id, source.source, (external) => {
|
|
@@ -269,7 +666,7 @@ function createRepositoryChangePublication(adapter) {
|
|
|
269
666
|
return {
|
|
270
667
|
state: patchRemote(
|
|
271
668
|
input.state,
|
|
272
|
-
source.kind === "observation" ? { pendingEvidence: evidence } :
|
|
669
|
+
source.kind === "observation" ? { pendingEvidence: evidence } : applyPublicationEvidence(input.params, current, evidence, !operator)
|
|
273
670
|
)
|
|
274
671
|
};
|
|
275
672
|
});
|
|
@@ -363,6 +760,11 @@ export {
|
|
|
363
760
|
createRepositoryChangePublication,
|
|
364
761
|
patchPublicationState,
|
|
365
762
|
publicationObject,
|
|
366
|
-
|
|
763
|
+
pullRequestPublicationCallbacks,
|
|
764
|
+
pullRequestPublicationSources,
|
|
765
|
+
readPublicationState,
|
|
766
|
+
readPullRequestFeedback,
|
|
767
|
+
reconcilePullRequestSourceIssue,
|
|
768
|
+
resolvePullRequestGitIdentity
|
|
367
769
|
};
|
|
368
770
|
//# sourceMappingURL=repository-change-publication.js.map
|