@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
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
-
commitAndPushWorkBranch
|
|
3
|
-
|
|
2
|
+
commitAndPushWorkBranch,
|
|
3
|
+
repositoryHasChanges
|
|
4
|
+
} from "./chunk-Q24RPXOA.js";
|
|
5
|
+
import {
|
|
6
|
+
createRepositoryChangeProcess
|
|
7
|
+
} from "./chunk-OM2AMDTJ.js";
|
|
8
|
+
import "./chunk-DNG7D77K.js";
|
|
9
|
+
import "./chunk-ABQH2WZT.js";
|
|
10
|
+
import "./chunk-BI45R2FH.js";
|
|
11
|
+
import "./chunk-SKGB4CZS.js";
|
|
12
|
+
import {
|
|
13
|
+
conflictKey,
|
|
14
|
+
validateConflict
|
|
15
|
+
} from "./chunk-KFELB7ZC.js";
|
|
16
|
+
import {
|
|
17
|
+
codingPurposes
|
|
18
|
+
} from "./chunk-M2VTUPFO.js";
|
|
19
|
+
import "./chunk-SZ4WOGV2.js";
|
|
4
20
|
import "./chunk-PX6F3LHL.js";
|
|
5
21
|
|
|
6
22
|
// src/repository-change-publication.ts
|
|
@@ -8,12 +24,503 @@ import { asUnknownRecord } from "@leitwerk-dev/domain";
|
|
|
8
24
|
import {
|
|
9
25
|
flow
|
|
10
26
|
} from "@leitwerk-dev/process-sdk";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} from "
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
27
|
+
|
|
28
|
+
// src/repository-rebase/git.ts
|
|
29
|
+
import { execFileSync } from "child_process";
|
|
30
|
+
import { existsSync, readFileSync, renameSync, writeFileSync } from "fs";
|
|
31
|
+
import { join } from "path";
|
|
32
|
+
import { repositoryGitArgs, repositoryGitSubprocessEnv } from "@leitwerk-dev/process-sdk";
|
|
33
|
+
import { resolveGitBinary } from "@leitwerk-dev/process-sdk/git-binary";
|
|
34
|
+
|
|
35
|
+
// src/repository-rebase/policy.ts
|
|
36
|
+
function requireRebaseTarget(workBranch, conflict, record) {
|
|
37
|
+
if (workBranch !== conflict.headBranch || workBranch === conflict.baseBranch)
|
|
38
|
+
throw new Error("Expected evidence for the tracked work branch and a distinct base");
|
|
39
|
+
if (record && (record.branch !== workBranch || record.originalHead !== conflict.headSha))
|
|
40
|
+
throw new Error("Missing matching rebase metadata");
|
|
41
|
+
if (record?.baseBranch && record.baseBranch !== conflict.baseBranch)
|
|
42
|
+
throw new Error("Rebase base branch changed since preparation");
|
|
43
|
+
}
|
|
44
|
+
function requireRebaseOrigin(record, origin) {
|
|
45
|
+
if (record?.originUrl && origin.originUrl !== record.originUrl || record?.originPushUrl && origin.originPushUrl !== record.originPushUrl)
|
|
46
|
+
throw new Error("Rebase origin changed since preparation");
|
|
47
|
+
}
|
|
48
|
+
function requireRebaseWorktree(workBranch, observation) {
|
|
49
|
+
if (observation.branch !== workBranch) throw new Error("Expected tracked work branch for rebase");
|
|
50
|
+
if (observation.dirty)
|
|
51
|
+
throw new Error("Rebase requires a clean worktree with no unresolved conflicts");
|
|
52
|
+
}
|
|
53
|
+
function requireRebaseHead(expected, local, remote) {
|
|
54
|
+
if (remote !== expected || local !== expected)
|
|
55
|
+
throw new Error("Tracked branch changed before repair");
|
|
56
|
+
}
|
|
57
|
+
function rebasePublicationDecision(originalHead, headSha, remoteHead2) {
|
|
58
|
+
if (remoteHead2 === headSha) return "already_published";
|
|
59
|
+
if (remoteHead2 !== originalHead)
|
|
60
|
+
throw new Error("Concurrent remote change rejected by rebase lease");
|
|
61
|
+
return "push";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/repository-rebase/git.ts
|
|
65
|
+
function git(input, ...args) {
|
|
66
|
+
return execFileSync(resolveGitBinary(), repositoryGitArgs(args), {
|
|
67
|
+
cwd: input.path,
|
|
68
|
+
encoding: "utf8",
|
|
69
|
+
env: repositoryGitSubprocessEnv(input.projectKey, {
|
|
70
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
71
|
+
GIT_EDITOR: "true"
|
|
72
|
+
}),
|
|
73
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
74
|
+
}).trim();
|
|
75
|
+
}
|
|
76
|
+
function area(input) {
|
|
77
|
+
return git(input, "rev-parse", "--absolute-git-dir");
|
|
78
|
+
}
|
|
79
|
+
function active(gitDir) {
|
|
80
|
+
return ["rebase-merge", "rebase-apply"].some((name) => existsSync(join(gitDir, name)));
|
|
81
|
+
}
|
|
82
|
+
function save(gitDir, record) {
|
|
83
|
+
const path = join(gitDir, "leitwerk-rebase.json");
|
|
84
|
+
writeFileSync(`${path}.tmp`, JSON.stringify(record), { mode: 384 });
|
|
85
|
+
renameSync(`${path}.tmp`, path);
|
|
86
|
+
}
|
|
87
|
+
function read(gitDir) {
|
|
88
|
+
const file = join(gitDir, "leitwerk-rebase.json");
|
|
89
|
+
return existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : null;
|
|
90
|
+
}
|
|
91
|
+
function requireWorktree(input) {
|
|
92
|
+
requireRebaseWorktree(input.workBranch, {
|
|
93
|
+
branch: git(input, "branch", "--show-current"),
|
|
94
|
+
dirty: Boolean(git(input, "status", "--porcelain"))
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function remoteHead(input) {
|
|
98
|
+
return git(input, "ls-remote", "--heads", "origin", `refs/heads/${input.workBranch}`).split(
|
|
99
|
+
/\s+/
|
|
100
|
+
)[0];
|
|
101
|
+
}
|
|
102
|
+
function requireTarget(input, record) {
|
|
103
|
+
requireRebaseTarget(input.workBranch, input.conflict, record);
|
|
104
|
+
git(input, "check-ref-format", `refs/heads/${input.workBranch}`);
|
|
105
|
+
git(input, "check-ref-format", `refs/heads/${input.conflict.baseBranch}`);
|
|
106
|
+
requireRebaseOrigin(record, {
|
|
107
|
+
originUrl: record?.originUrl ? git(input, "remote", "get-url", "origin") : void 0,
|
|
108
|
+
originPushUrl: record?.originPushUrl ? git(input, "remote", "get-url", "--push", "--all", "origin") : void 0
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function verifyCurrentBase(input, record) {
|
|
112
|
+
git(
|
|
113
|
+
input,
|
|
114
|
+
"fetch",
|
|
115
|
+
"origin",
|
|
116
|
+
`+refs/heads/${input.conflict.baseBranch}:refs/leitwerk/rebase-base`
|
|
117
|
+
);
|
|
118
|
+
git(input, "merge-base", "--is-ancestor", record.baseSha, "refs/leitwerk/rebase-base");
|
|
119
|
+
}
|
|
120
|
+
function verifyNoRepairNeeded(input, headSha, baseSha) {
|
|
121
|
+
if (input.conflict.reason === "behind")
|
|
122
|
+
git(input, "merge-base", "--is-ancestor", baseSha, headSha);
|
|
123
|
+
else git(input, "merge-tree", "--write-tree", headSha, baseSha);
|
|
124
|
+
}
|
|
125
|
+
function prepareRebase(input) {
|
|
126
|
+
const gitDir = area(input);
|
|
127
|
+
const old = read(gitDir);
|
|
128
|
+
requireTarget(input, old?.key === conflictKey(input.conflict) ? old : null);
|
|
129
|
+
if (old?.key === conflictKey(input.conflict)) {
|
|
130
|
+
verifyCurrentBase(input, old);
|
|
131
|
+
return old;
|
|
132
|
+
}
|
|
133
|
+
if (active(gitDir)) throw new Error("An unrelated rebase is already in progress");
|
|
134
|
+
requireWorktree(input);
|
|
135
|
+
git(
|
|
136
|
+
input,
|
|
137
|
+
"fetch",
|
|
138
|
+
"origin",
|
|
139
|
+
`+refs/heads/${input.workBranch}:refs/leitwerk/rebase-head`,
|
|
140
|
+
`+refs/heads/${input.conflict.baseBranch}:refs/leitwerk/rebase-base`
|
|
141
|
+
);
|
|
142
|
+
const [remoteSha, headSha, baseSha] = git(
|
|
143
|
+
input,
|
|
144
|
+
"rev-parse",
|
|
145
|
+
"refs/leitwerk/rebase-head",
|
|
146
|
+
"HEAD",
|
|
147
|
+
"refs/leitwerk/rebase-base"
|
|
148
|
+
).split("\n");
|
|
149
|
+
requireRebaseHead(input.conflict.headSha, headSha, remoteSha);
|
|
150
|
+
git(input, "merge-base", "--is-ancestor", input.conflict.baseSha, baseSha);
|
|
151
|
+
const record = {
|
|
152
|
+
key: conflictKey(input.conflict),
|
|
153
|
+
branch: input.workBranch,
|
|
154
|
+
originalHead: input.conflict.headSha,
|
|
155
|
+
baseSha,
|
|
156
|
+
status: "prepared",
|
|
157
|
+
originUrl: git(input, "remote", "get-url", "origin"),
|
|
158
|
+
originPushUrl: git(input, "remote", "get-url", "--push", "--all", "origin"),
|
|
159
|
+
baseBranch: input.conflict.baseBranch
|
|
160
|
+
};
|
|
161
|
+
git(input, "update-ref", "refs/leitwerk/rebase-original", record.originalHead);
|
|
162
|
+
save(gitDir, record);
|
|
163
|
+
return record;
|
|
164
|
+
}
|
|
165
|
+
function startRebase(input) {
|
|
166
|
+
const record = prepareRebase(input);
|
|
167
|
+
const gitDir = area(input);
|
|
168
|
+
if (active(gitDir)) return record;
|
|
169
|
+
if (record.status === "clean") return record;
|
|
170
|
+
requireWorktree(input);
|
|
171
|
+
if (record.status === "rebasing" && git(input, "rev-parse", "HEAD") !== record.originalHead)
|
|
172
|
+
return record;
|
|
173
|
+
try {
|
|
174
|
+
verifyNoRepairNeeded(input, record.originalHead, record.baseSha);
|
|
175
|
+
record.status = "clean";
|
|
176
|
+
save(gitDir, record);
|
|
177
|
+
return record;
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (error.status !== 1) throw error;
|
|
180
|
+
}
|
|
181
|
+
record.status = "rebasing";
|
|
182
|
+
save(gitDir, record);
|
|
183
|
+
try {
|
|
184
|
+
git(input, "rebase", "--rebase-merges", record.baseSha);
|
|
185
|
+
} catch (error) {
|
|
186
|
+
if (!active(gitDir)) throw error;
|
|
187
|
+
}
|
|
188
|
+
return record;
|
|
189
|
+
}
|
|
190
|
+
function verifyRebase(input) {
|
|
191
|
+
const gitDir = area(input);
|
|
192
|
+
const record = read(gitDir);
|
|
193
|
+
if (!record || record.key !== conflictKey(input.conflict))
|
|
194
|
+
throw new Error("Missing matching rebase metadata");
|
|
195
|
+
requireTarget(input, record);
|
|
196
|
+
if (active(gitDir)) throw new Error("Rebase is incomplete");
|
|
197
|
+
requireWorktree(input);
|
|
198
|
+
const headSha = git(input, "rev-parse", "HEAD");
|
|
199
|
+
if (record.status === "clean") {
|
|
200
|
+
if (headSha !== record.originalHead)
|
|
201
|
+
throw new Error("Clean conflict report must not rewrite the branch");
|
|
202
|
+
verifyNoRepairNeeded(input, headSha, record.baseSha);
|
|
203
|
+
} else {
|
|
204
|
+
if (record.status !== "rebasing") throw new Error("Rebase was not started");
|
|
205
|
+
git(input, "merge-base", "--is-ancestor", record.baseSha, headSha);
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
headSha,
|
|
209
|
+
changed: headSha !== record.originalHead,
|
|
210
|
+
originalHead: record.originalHead,
|
|
211
|
+
baseSha: record.baseSha
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function publishRebase(input) {
|
|
215
|
+
const result = verifyRebase(input);
|
|
216
|
+
const gitDir = area(input);
|
|
217
|
+
const record = read(gitDir);
|
|
218
|
+
if (!record) throw new Error("Missing matching rebase metadata");
|
|
219
|
+
verifyCurrentBase(input, record);
|
|
220
|
+
const remote = remoteHead(input);
|
|
221
|
+
if (rebasePublicationDecision(result.originalHead, result.headSha, remote) === "already_published")
|
|
222
|
+
return result;
|
|
223
|
+
git(
|
|
224
|
+
input,
|
|
225
|
+
"push",
|
|
226
|
+
`--force-with-lease=refs/heads/${input.workBranch}:${result.originalHead}`,
|
|
227
|
+
"origin",
|
|
228
|
+
`${result.headSha}:refs/heads/${input.workBranch}`
|
|
229
|
+
);
|
|
230
|
+
if (remoteHead(input) !== result.headSha)
|
|
231
|
+
throw new Error("Rebase publication could not be verified");
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/repository-rebase/prompt.ts
|
|
236
|
+
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.`;
|
|
237
|
+
|
|
238
|
+
// src/pull-request-publication-internal.ts
|
|
239
|
+
function createPullRequestChangeProcess(provider, label, docker, config) {
|
|
240
|
+
const { watcher, publication: adapter, ...definition } = config;
|
|
241
|
+
const publication = createRepositoryChangePublication(adapter);
|
|
242
|
+
publication.fragment.watcher({
|
|
243
|
+
...watcher,
|
|
244
|
+
id: "use_leitwerk",
|
|
245
|
+
label: `${label} use-leitwerk issues`,
|
|
246
|
+
description: `Launch a remote repository change for ${label} issues carrying the trigger label`
|
|
247
|
+
});
|
|
248
|
+
const { process } = createRepositoryChangeProcess({
|
|
249
|
+
...definition,
|
|
250
|
+
publication,
|
|
251
|
+
processId: `${provider}_repo_change_process`,
|
|
252
|
+
displayName: `${label} Repo Change`,
|
|
253
|
+
repositoryCredentials: ({ params }) => [
|
|
254
|
+
{ projectKey: "repo", kind: "git_ssh", credentialRef: params.sshCredentialRef }
|
|
255
|
+
]
|
|
256
|
+
});
|
|
257
|
+
process.runtime = { ...process.runtime, docker };
|
|
258
|
+
return process;
|
|
259
|
+
}
|
|
260
|
+
function pullRequestDeliveryTools(provider) {
|
|
261
|
+
return [
|
|
262
|
+
"get_pull_request",
|
|
263
|
+
"add_pull_request_comment",
|
|
264
|
+
"resolve_git_identity",
|
|
265
|
+
"ensure_pull_request",
|
|
266
|
+
"add_issue_comment",
|
|
267
|
+
"add_pull_request_feedback_reaction",
|
|
268
|
+
"reply_to_pull_request_feedback",
|
|
269
|
+
"get_issue",
|
|
270
|
+
"ensure_label",
|
|
271
|
+
"update_issue"
|
|
272
|
+
].map((name) => `${provider}_${name}`);
|
|
273
|
+
}
|
|
274
|
+
var callFor = (ctx, provider) => (name, args) => ctx.callIntegrationTool(`${provider}_${name}`, { projectKey: "repo", ...args });
|
|
275
|
+
async function resolvePullRequestGitIdentity(ctx, provider, profile, allowLookup = true) {
|
|
276
|
+
const project = ctx.repo.get("repo");
|
|
277
|
+
const metadata = ctx.projects.find((candidate) => candidate.key === project.key)?.metadata;
|
|
278
|
+
const identity = publicationObject(metadata?.["leitwerk.gitIdentity"]);
|
|
279
|
+
if (identity.provider === provider && identity.profile === profile && (!allowLookup || typeof identity.login === "string" && identity.login.trim()) && [identity.name, identity.email].every((value) => typeof value === "string" && value.trim()))
|
|
280
|
+
return identity;
|
|
281
|
+
if (!allowLookup) throw new Error(`Pinned ${provider} Git identity is unavailable`);
|
|
282
|
+
return callFor(ctx, provider)("resolve_git_identity", {});
|
|
283
|
+
}
|
|
284
|
+
function readPullRequestFeedback(current, event) {
|
|
285
|
+
const value = publicationObject(event);
|
|
286
|
+
const cursors = publicationObject(value.cursors);
|
|
287
|
+
return {
|
|
288
|
+
kind: "feedback",
|
|
289
|
+
conversationCursor: Number(cursors.conversationCursor ?? current.conversationCursor),
|
|
290
|
+
reviewCursor: Number(cursors.reviewCursor ?? current.reviewCursor),
|
|
291
|
+
inlineCursor: Number(cursors.inlineCursor ?? current.inlineCursor),
|
|
292
|
+
feedbackIds: value.feedbackIds ?? []
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function pullRequestPublicationDefaults(provider, label, external, profile, issueOrigin, labelKey, ci) {
|
|
296
|
+
const remote = (state) => readPublicationState(state, `${provider}RepoChange`);
|
|
297
|
+
function requirePr(state) {
|
|
298
|
+
const value = remote(state);
|
|
299
|
+
if (!value.headSha || !value.prNumber || !value.prUrl)
|
|
300
|
+
throw new Error("Pull request delivery state is incomplete");
|
|
301
|
+
return {
|
|
302
|
+
...value,
|
|
303
|
+
/** @internal */
|
|
304
|
+
headSha: value.headSha,
|
|
305
|
+
/** @internal */
|
|
306
|
+
prNumber: value.prNumber,
|
|
307
|
+
/** @internal */
|
|
308
|
+
prUrl: value.prUrl
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
const feedback = {
|
|
312
|
+
id: `${provider}_feedback`,
|
|
313
|
+
kind: "feedback",
|
|
314
|
+
label: `${label} pull request feedback`,
|
|
315
|
+
source: external.pullRequestFeedback(({ params, state }) => ({
|
|
316
|
+
profile: profile(params),
|
|
317
|
+
owner: params.owner,
|
|
318
|
+
repo: params.repo,
|
|
319
|
+
prNumber: requirePr(state).prNumber,
|
|
320
|
+
conversationCursor: remote(state).conversationCursor,
|
|
321
|
+
reviewCursor: remote(state).reviewCursor,
|
|
322
|
+
inlineCursor: remote(state).inlineCursor,
|
|
323
|
+
quietPeriodMs: 12e4,
|
|
324
|
+
pollInterval: "30s"
|
|
325
|
+
})),
|
|
326
|
+
read: ({ state, event }) => readPullRequestFeedback(remote(state), event)
|
|
327
|
+
};
|
|
328
|
+
const terminal = ["merged", "closed"].map(
|
|
329
|
+
(terminalOutcome) => ({
|
|
330
|
+
id: `${provider}_pr_${terminalOutcome}`,
|
|
331
|
+
kind: "terminal",
|
|
332
|
+
label: `${label} pull request ${terminalOutcome}`,
|
|
333
|
+
source: external.pullRequestTerminal(({ params, state }) => ({
|
|
334
|
+
profile: profile(params),
|
|
335
|
+
owner: params.owner,
|
|
336
|
+
repo: params.repo,
|
|
337
|
+
prNumber: requirePr(state).prNumber,
|
|
338
|
+
terminalOutcome,
|
|
339
|
+
pollInterval: "30s"
|
|
340
|
+
})),
|
|
341
|
+
read: ({ event }) => ({
|
|
342
|
+
kind: "terminal",
|
|
343
|
+
request: publicationObject(event).pullRequest
|
|
344
|
+
})
|
|
345
|
+
})
|
|
346
|
+
);
|
|
347
|
+
const cancelled = {
|
|
348
|
+
id: "source_cancelled",
|
|
349
|
+
kind: "cancelled",
|
|
350
|
+
label: "Source issue cancelled",
|
|
351
|
+
enabled: (params) => issueOrigin(params) !== void 0,
|
|
352
|
+
source: external.issueCancelled(({ params }) => {
|
|
353
|
+
const issue = issueOrigin(params);
|
|
354
|
+
if (!issue) throw new Error(`${label} source issue metadata is unavailable`);
|
|
355
|
+
return {
|
|
356
|
+
profile: profile(params),
|
|
357
|
+
owner: params.owner,
|
|
358
|
+
repo: params.repo,
|
|
359
|
+
issueNumber: issue.issueNumber,
|
|
360
|
+
triggerLabel: issue.triggerLabel,
|
|
361
|
+
pollInterval: "30s"
|
|
362
|
+
};
|
|
363
|
+
}),
|
|
364
|
+
read: () => ({ kind: "cancelled" })
|
|
365
|
+
};
|
|
366
|
+
async function finalizeIssue(ctx, pr) {
|
|
367
|
+
const params = issueOrigin(ctx.params);
|
|
368
|
+
if (!params) return;
|
|
369
|
+
const call2 = callFor(ctx, provider);
|
|
370
|
+
const issue = await call2("get_issue", {
|
|
371
|
+
issueNumber: params.issueNumber
|
|
372
|
+
});
|
|
373
|
+
let labels = issue.labels.filter((label2) => label2.name !== params.triggerLabel).map((label2) => label2[labelKey]);
|
|
374
|
+
if (pr?.merged) {
|
|
375
|
+
const done = await call2("ensure_label", {
|
|
376
|
+
name: params.doneLabel
|
|
377
|
+
});
|
|
378
|
+
labels = [.../* @__PURE__ */ new Set([...labels, done[labelKey]])];
|
|
379
|
+
}
|
|
380
|
+
await call2("update_issue", {
|
|
381
|
+
issueNumber: params.issueNumber,
|
|
382
|
+
patch: { labels, ...pr?.merged ? { state: "closed" } : {} },
|
|
383
|
+
writeKey: `${provider}:${ctx.process.id}:${pr?.merged ? "complete-source-issue" : pr ? "remove-source-trigger" : "no-changes-trigger"}`
|
|
384
|
+
});
|
|
385
|
+
await call2("add_issue_comment", {
|
|
386
|
+
issueNumber: params.issueNumber,
|
|
387
|
+
body: !pr ? "No repository changes were needed. No pull request was opened." : 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.`,
|
|
388
|
+
writeKey: `${provider}:${ctx.process.id}:${pr ? `${pr.merged ? "merged" : "closed"}-pr-comment` : "no-changes-comment"}`
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
const call = (ctx) => callFor(ctx, provider);
|
|
392
|
+
const adapter = {
|
|
393
|
+
/** @internal */
|
|
394
|
+
namespace: `${provider}RepoChange`,
|
|
395
|
+
/** @internal */
|
|
396
|
+
label: `${label} PR`,
|
|
397
|
+
/** @internal */
|
|
398
|
+
ids: {
|
|
399
|
+
/** @internal */
|
|
400
|
+
deliver: "deliver_change",
|
|
401
|
+
/** @internal */
|
|
402
|
+
feedback: "revise_from_pull_request_feedback",
|
|
403
|
+
/** @internal */
|
|
404
|
+
ciRepair: ci.id,
|
|
405
|
+
/** @internal */
|
|
406
|
+
operator: "ci_operator_action"
|
|
407
|
+
},
|
|
408
|
+
/** @internal */
|
|
409
|
+
tools: {
|
|
410
|
+
/** @internal */
|
|
411
|
+
delivery: pullRequestDeliveryTools(provider),
|
|
412
|
+
/** @internal */
|
|
413
|
+
feedback: [
|
|
414
|
+
`${provider}_get_pull_request`,
|
|
415
|
+
`${provider}_list_pull_request_feedback`
|
|
416
|
+
],
|
|
417
|
+
/** @internal */
|
|
418
|
+
ci: ci.tools
|
|
419
|
+
},
|
|
420
|
+
/** @internal */
|
|
421
|
+
commitMessage: (kind) => kind === "feedback" ? `fix: address ${label} review feedback` : `fix: repair ${ci.label}`,
|
|
422
|
+
/** @internal */
|
|
423
|
+
prompt: (kind, current) => kind === "feedback" ? `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.` : ci.prompt(current),
|
|
424
|
+
/** @internal */
|
|
425
|
+
identity: (ctx) => resolvePullRequestGitIdentity(ctx, provider, profile(ctx.params)),
|
|
426
|
+
/** @internal */
|
|
427
|
+
reconcileTerminal: (ctx, _current, pr) => finalizeIssue(ctx, pr),
|
|
428
|
+
/** @internal */
|
|
429
|
+
unchanged: (ctx) => finalizeIssue(ctx, null),
|
|
430
|
+
async ensureRequest(ctx) {
|
|
431
|
+
const project = ctx.repo.get("repo");
|
|
432
|
+
const issue = issueOrigin(ctx.params);
|
|
433
|
+
const pr = await call(ctx)("ensure_pull_request", {
|
|
434
|
+
title: ctx.process.title ?? (issue ? `Issue #${issue.issueNumber}` : "Leitwerk change"),
|
|
435
|
+
body: issue ? `Implements ${issue.issueUrl}
|
|
436
|
+
|
|
437
|
+
Leitwerk process: ${ctx.process.id}` : `Leitwerk process: ${ctx.process.id}`,
|
|
438
|
+
head: project.workBranch,
|
|
439
|
+
base: project.baseBranch
|
|
440
|
+
});
|
|
441
|
+
if (!pr) throw new Error(`${label} pull request could not be created or found`);
|
|
442
|
+
return pr;
|
|
443
|
+
},
|
|
444
|
+
async linkIssue(ctx, current) {
|
|
445
|
+
const issue = issueOrigin(ctx.params);
|
|
446
|
+
if (issue)
|
|
447
|
+
await call(ctx)("add_issue_comment", {
|
|
448
|
+
issueNumber: issue.issueNumber,
|
|
449
|
+
body: `Leitwerk opened pull request ${current.prUrl}.`,
|
|
450
|
+
writeKey: `${provider}:${ctx.process.id}:source-pr-link:${current.prNumber}`
|
|
451
|
+
});
|
|
452
|
+
},
|
|
453
|
+
async reply(ctx, current) {
|
|
454
|
+
const invoke = call(ctx);
|
|
455
|
+
for (const feedback2 of current.feedbackIds)
|
|
456
|
+
await invoke("reply_to_pull_request_feedback", {
|
|
457
|
+
pullRequestNumber: current.prNumber,
|
|
458
|
+
feedbackKind: feedback2.kind,
|
|
459
|
+
feedbackId: feedback2.id,
|
|
460
|
+
body: `Addressed in ${current.headSha?.slice(0, 8) ?? "the current revision"}.`,
|
|
461
|
+
writeKey: `${provider}:${ctx.process.id}:feedback-reply:${feedback2.kind}:${feedback2.id}:${current.headSha}`
|
|
462
|
+
});
|
|
463
|
+
},
|
|
464
|
+
async acknowledge(ctx, current) {
|
|
465
|
+
const invoke = call(ctx);
|
|
466
|
+
for (const feedback2 of current.feedbackIds) {
|
|
467
|
+
if (feedback2.kind === "review") continue;
|
|
468
|
+
await invoke("add_pull_request_feedback_reaction", {
|
|
469
|
+
pullRequestNumber: current.prNumber,
|
|
470
|
+
feedbackKind: feedback2.kind,
|
|
471
|
+
feedbackId: feedback2.id,
|
|
472
|
+
writeKey: `${provider}:${ctx.process.id}:feedback-eyes:${feedback2.kind}:${feedback2.id}`
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
async head(ctx, current) {
|
|
477
|
+
return (await call(ctx)("get_pull_request", {
|
|
478
|
+
pullRequestNumber: current.prNumber
|
|
479
|
+
})).head.sha;
|
|
480
|
+
},
|
|
481
|
+
async afterRebase(ctx, current) {
|
|
482
|
+
await call(ctx)("add_pull_request_comment", {
|
|
483
|
+
pullRequestNumber: current.prNumber,
|
|
484
|
+
body: `Merge conflict repair completed at ${current.headSha}; base ${current.conflict?.baseSha}.`,
|
|
485
|
+
writeKey: `rebase:${ctx.process.id}:${current.lastConflictKey}:${current.headSha}`
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
return {
|
|
490
|
+
/** @internal */
|
|
491
|
+
adapter,
|
|
492
|
+
/** @internal */
|
|
493
|
+
conflict(source) {
|
|
494
|
+
return {
|
|
495
|
+
id: `${provider}_merge_conflict`,
|
|
496
|
+
kind: "conflict",
|
|
497
|
+
label: "Rebase conflicting pull request",
|
|
498
|
+
source,
|
|
499
|
+
read: ({ event }) => ({
|
|
500
|
+
kind: "conflict",
|
|
501
|
+
conflict: publicationObject(event).conflict
|
|
502
|
+
})
|
|
503
|
+
};
|
|
504
|
+
},
|
|
505
|
+
/** @internal */
|
|
506
|
+
requirePr,
|
|
507
|
+
/** @internal */
|
|
508
|
+
feedback,
|
|
509
|
+
/** @internal */
|
|
510
|
+
terminal,
|
|
511
|
+
/** @internal */
|
|
512
|
+
cancelled
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// src/repository-change-publication.ts
|
|
517
|
+
function requirePublicationParams(params) {
|
|
518
|
+
const value = asUnknownRecord(params);
|
|
519
|
+
for (const key of ["owner", "repo", "workBranch", "baseBranch"])
|
|
520
|
+
if (typeof value?.[key] !== "string" || !value[key])
|
|
521
|
+
throw new Error("Repository binding is not resolved");
|
|
522
|
+
return params;
|
|
523
|
+
}
|
|
17
524
|
var initialDeliveryState = {
|
|
18
525
|
stage: "not_started",
|
|
19
526
|
issueLinked: false,
|
|
@@ -33,6 +540,21 @@ var initialPublicationState = {
|
|
|
33
540
|
delivery: initialDeliveryState
|
|
34
541
|
};
|
|
35
542
|
var publicationObject = (value) => asUnknownRecord(value) ?? {};
|
|
543
|
+
function createPublicationSelection(namespace) {
|
|
544
|
+
return {
|
|
545
|
+
/** @internal */
|
|
546
|
+
activeKey: (state) => publicationObject(state.extensionState?.[`${namespace()}.coordination`]).activeKey,
|
|
547
|
+
/** @internal */
|
|
548
|
+
select: (state, key) => ({
|
|
549
|
+
...state,
|
|
550
|
+
extensionState: {
|
|
551
|
+
...state.extensionState,
|
|
552
|
+
[`${namespace()}.coordination`]: { activeKey: key }
|
|
553
|
+
}
|
|
554
|
+
})
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
var publicationFinished = (current) => !!(current.stopped || current.noChanges || current.delivery.terminalPullRequest);
|
|
36
558
|
function readPublicationState(state, namespace) {
|
|
37
559
|
const stored = publicationObject(publicationObject(state.extensionState)[namespace]);
|
|
38
560
|
return {
|
|
@@ -74,15 +596,16 @@ function applyPublicationEvidence(params, current, evidence, countFailure = true
|
|
|
74
596
|
ciRecoveryCycles: current.ciRecoveryCycles + (countFailure ? 1 : 0)
|
|
75
597
|
};
|
|
76
598
|
case "conflict": {
|
|
599
|
+
const repository = requirePublicationParams(params);
|
|
77
600
|
const conflict = validateConflict(
|
|
78
601
|
evidence.conflict,
|
|
79
602
|
{
|
|
80
|
-
owner:
|
|
81
|
-
repo:
|
|
603
|
+
owner: repository.owner,
|
|
604
|
+
repo: repository.repo,
|
|
82
605
|
prNumber: current.prNumber ?? 0,
|
|
83
606
|
headSha: current.headSha ?? "",
|
|
84
|
-
headBranch:
|
|
85
|
-
baseBranch:
|
|
607
|
+
headBranch: repository.workBranch,
|
|
608
|
+
baseBranch: repository.baseBranch
|
|
86
609
|
},
|
|
87
610
|
current.lastConflictKey
|
|
88
611
|
);
|
|
@@ -142,33 +665,50 @@ function deliveryProgress(value, label, activeStepId) {
|
|
|
142
665
|
};
|
|
143
666
|
}
|
|
144
667
|
function createRepositoryChangePublication(adapter) {
|
|
145
|
-
const applyEvidence = applyPublicationEvidence;
|
|
146
668
|
const ids = adapter.ids;
|
|
147
669
|
const publication = flow.fragment(`${adapter.namespace}-publication`);
|
|
148
|
-
const
|
|
149
|
-
const
|
|
670
|
+
const { activeKey, select } = createPublicationSelection(() => adapter.namespace);
|
|
671
|
+
const namespace = (state) => adapter.repositories ? `${adapter.namespace}:${activeKey(state)}` : adapter.namespace;
|
|
672
|
+
const remote = (state) => readPublicationState(state, namespace(state));
|
|
673
|
+
const repositoryContext = (ctx) => {
|
|
674
|
+
if (!adapter.repositories) return ctx;
|
|
675
|
+
const selected = adapter.repositories(ctx.params).find((repo) => repo.key === activeKey(ctx.state));
|
|
676
|
+
if (!selected) throw new Error("Missing coordinated repository selection");
|
|
677
|
+
return {
|
|
678
|
+
...ctx,
|
|
679
|
+
params: selected.params,
|
|
680
|
+
repo: { ...ctx.repo, get: (key) => ctx.repo.get(key === "repo" ? selected.key : key) },
|
|
681
|
+
callIntegrationTool: (name, args) => ctx.callIntegrationTool(name, { ...args, projectKey: selected.key })
|
|
682
|
+
};
|
|
683
|
+
};
|
|
684
|
+
const patchRemote = (state, patch) => patchPublicationState(state, namespace(state), patch);
|
|
150
685
|
async function commitWorkBranch(ctx, commitMessage) {
|
|
151
686
|
const repo = ctx.repo.get("repo");
|
|
687
|
+
const gitIdentity = await adapter.identity(ctx);
|
|
688
|
+
if (adapter.maintenance)
|
|
689
|
+
await ctx.callIntegrationTool(adapter.maintenance.ownershipTool, { projectKey: repo.key });
|
|
152
690
|
return commitAndPushWorkBranch({
|
|
153
691
|
repoPath: repo.fsPath,
|
|
692
|
+
projectKey: repo.key,
|
|
154
693
|
workBranch: repo.workBranch,
|
|
155
694
|
commitMessage,
|
|
156
|
-
gitIdentity
|
|
695
|
+
gitIdentity
|
|
157
696
|
});
|
|
158
697
|
}
|
|
159
|
-
const
|
|
698
|
+
const runRepository = async (ctx) => {
|
|
160
699
|
let current = remote(ctx.state);
|
|
161
700
|
const update = (patch) => {
|
|
162
701
|
current = { ...current, ...patch, delivery: { ...current.delivery, ...patch.delivery } };
|
|
163
702
|
};
|
|
164
|
-
const result = (
|
|
165
|
-
outcome,
|
|
703
|
+
const result = (outcome2) => ({
|
|
704
|
+
outcome: outcome2,
|
|
166
705
|
params: { nextState: patchRemote(ctx.state, current) }
|
|
167
706
|
});
|
|
707
|
+
if (current.stopped) return result("aborted");
|
|
168
708
|
if (current.pendingEvidence) {
|
|
169
709
|
const evidence = current.pendingEvidence;
|
|
170
710
|
const needsOperator = evidence.kind === "failure" && current.ciRecoveryCycles >= 3;
|
|
171
|
-
current =
|
|
711
|
+
current = applyPublicationEvidence(ctx.params, current, evidence, !needsOperator);
|
|
172
712
|
current.pendingEvidence = null;
|
|
173
713
|
if (evidence.kind === "cancelled") return result("aborted");
|
|
174
714
|
if (evidence.kind === "failure")
|
|
@@ -183,11 +723,20 @@ function createRepositoryChangePublication(adapter) {
|
|
|
183
723
|
ctx.reportProgress(deliveryProgress(current, adapter.label));
|
|
184
724
|
return result(pr.merged ? "completed" : "aborted");
|
|
185
725
|
}
|
|
726
|
+
if (!current.headSha && (adapter.repositories || adapter.unchanged) && !repositoryHasChanges(
|
|
727
|
+
ctx.repo.get("repo").fsPath,
|
|
728
|
+
ctx.repo.get("repo").baseBranch,
|
|
729
|
+
ctx.repo.get("repo").key
|
|
730
|
+
)) {
|
|
731
|
+
update({ noChanges: true });
|
|
732
|
+
await adapter.unchanged?.(ctx);
|
|
733
|
+
return result("completed");
|
|
734
|
+
}
|
|
186
735
|
if (!current.headSha) {
|
|
187
736
|
ctx.reportProgress(deliveryProgress(current, adapter.label, "publish_branch"));
|
|
188
737
|
const published = await commitWorkBranch(
|
|
189
738
|
ctx,
|
|
190
|
-
ctx.state.finalization.generatedCommitMessage ?? ""
|
|
739
|
+
ctx.state.finalization.commitMessages?.[ctx.repo.get("repo").key] ?? ctx.state.finalization.generatedCommitMessage ?? ""
|
|
191
740
|
);
|
|
192
741
|
update({ headSha: published.headSha, pipeline: null });
|
|
193
742
|
}
|
|
@@ -205,6 +754,10 @@ function createRepositoryChangePublication(adapter) {
|
|
|
205
754
|
const adjustment = current.delivery.adjustment;
|
|
206
755
|
if (adjustment.publishRequired || adjustment.origin === "rebase") {
|
|
207
756
|
ctx.reportProgress(deliveryProgress(current, adapter.label, "publish_adjustment"));
|
|
757
|
+
if (adapter.maintenance)
|
|
758
|
+
await ctx.callIntegrationTool(adapter.maintenance.ownershipTool, {
|
|
759
|
+
projectKey: ctx.repo.get("repo").key
|
|
760
|
+
});
|
|
208
761
|
const published = adjustment.origin === "rebase" ? publishRebase(rebaseInput(ctx)) : await commitWorkBranch(ctx, adapter.commitMessage(adjustment.origin));
|
|
209
762
|
if (adjustment.origin === "rebase") {
|
|
210
763
|
const head = await adapter.head(ctx, current);
|
|
@@ -214,16 +767,25 @@ function createRepositoryChangePublication(adapter) {
|
|
|
214
767
|
update({ headSha: published.headSha, pipeline: null });
|
|
215
768
|
}
|
|
216
769
|
if (adjustment.origin === "rebase") await adapter.afterRebase(ctx, current);
|
|
217
|
-
if (adjustment.origin === "feedback") {
|
|
770
|
+
if (adjustment.origin === "feedback" && !adapter.maintenance) {
|
|
218
771
|
ctx.reportProgress(deliveryProgress(current, adapter.label, "reply_feedback"));
|
|
219
772
|
await adapter.reply(ctx, current);
|
|
220
773
|
}
|
|
221
774
|
update({
|
|
222
|
-
...adjustment.origin === "feedback" ? { feedbackIds: [] } : {},
|
|
223
|
-
|
|
775
|
+
...adjustment.origin === "feedback" && !adapter.maintenance ? { feedbackIds: [] } : {},
|
|
776
|
+
...adjustment.origin === "rebase" ? { conflict: null } : {},
|
|
777
|
+
delivery: {
|
|
778
|
+
adjustment: null,
|
|
779
|
+
...adjustment.origin === "feedback" && adapter.maintenance ? {
|
|
780
|
+
feedbackResult: {
|
|
781
|
+
published: adjustment.publishRequired,
|
|
782
|
+
summary: "Review adjustment published"
|
|
783
|
+
}
|
|
784
|
+
} : {}
|
|
785
|
+
}
|
|
224
786
|
});
|
|
225
787
|
}
|
|
226
|
-
if (current.feedbackIds.length > 0) {
|
|
788
|
+
if (current.feedbackIds.length > 0 && !adapter.maintenance) {
|
|
227
789
|
ctx.reportProgress(deliveryProgress(current, adapter.label, "reply_feedback"));
|
|
228
790
|
await adapter.acknowledge(ctx, current);
|
|
229
791
|
return result("feedback_ready");
|
|
@@ -231,33 +793,90 @@ function createRepositoryChangePublication(adapter) {
|
|
|
231
793
|
update({ delivery: { stage: "awaiting" } });
|
|
232
794
|
ctx.reportProgress(deliveryProgress(current, adapter.label, "await_evidence"));
|
|
233
795
|
return result("awaiting");
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
).
|
|
796
|
+
};
|
|
797
|
+
const delivery = flow.automatic(ids.deliver).description("Deliver").waitFor(({ state, params }) => {
|
|
798
|
+
const states = adapter.repositories ? adapter.repositories(params).map(({ key }) => select(state, key)) : [state];
|
|
799
|
+
return states.some((state2) => {
|
|
800
|
+
const current = remote(state2);
|
|
801
|
+
if (adapter.maintenance)
|
|
802
|
+
return !current.stopped && !current.noChanges && !current.delivery.terminalPullRequest && (current.delivery.stage !== "awaiting" || !!(current.delivery.adjustment && (current.delivery.adjustment.publishRequired || current.delivery.adjustment.origin === "rebase")));
|
|
803
|
+
return current.delivery.stage !== "awaiting" || !!current.pendingEvidence || !!current.delivery.adjustment || current.feedbackIds.length > 0 || !!current.delivery.terminalPullRequest;
|
|
804
|
+
});
|
|
805
|
+
}).integrationTools(...adapter.tools.delivery).run(async (ctx) => {
|
|
806
|
+
if (!adapter.repositories) return runRepository(ctx);
|
|
807
|
+
let state = ctx.state;
|
|
808
|
+
const repositories = adapter.repositories(ctx.params);
|
|
809
|
+
if (!repositories.length) throw new Error("No repositories are bound");
|
|
810
|
+
const results = () => repositories.map(({ key }) => ({ key, current: remote(select(state, key)) }));
|
|
811
|
+
const finished = () => results().every(({ current }) => publicationFinished(current));
|
|
812
|
+
const reconcileTerminals = async () => {
|
|
813
|
+
for (const { key } of repositories) {
|
|
814
|
+
state = select(state, key);
|
|
815
|
+
const current = remote(state);
|
|
816
|
+
if (publicationFinished(current)) continue;
|
|
817
|
+
const terminal = await adapter.observeTerminal?.(
|
|
818
|
+
repositoryContext({ ...ctx, state }),
|
|
819
|
+
current
|
|
820
|
+
);
|
|
821
|
+
if (terminal)
|
|
822
|
+
state = patchRemote(state, {
|
|
823
|
+
prNumber: terminal.number,
|
|
824
|
+
prUrl: terminal.html_url,
|
|
825
|
+
delivery: { terminalPullRequest: terminal }
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
await reconcileTerminals();
|
|
830
|
+
let cancelled = false;
|
|
831
|
+
for (const { key } of repositories) {
|
|
832
|
+
state = select(state, key);
|
|
833
|
+
if (publicationFinished(remote(state))) continue;
|
|
834
|
+
if (await adapter.sourceCancelled?.({ ...ctx, state })) {
|
|
835
|
+
await reconcileTerminals();
|
|
836
|
+
cancelled = !finished();
|
|
837
|
+
break;
|
|
838
|
+
}
|
|
839
|
+
const result = await runRepository(repositoryContext({ ...ctx, state }));
|
|
840
|
+
state = result.params.nextState;
|
|
841
|
+
if (!["awaiting", "completed", "aborted"].includes(result.outcome))
|
|
842
|
+
return { ...result, params: { nextState: state } };
|
|
843
|
+
}
|
|
844
|
+
if (cancelled || finished()) {
|
|
845
|
+
await adapter.reconcileAll?.({ ...ctx, state }, results(), cancelled);
|
|
846
|
+
const requests = results().flatMap(
|
|
847
|
+
({ current }) => current.delivery.terminalPullRequest ? [current.delivery.terminalPullRequest] : []
|
|
848
|
+
);
|
|
849
|
+
return {
|
|
850
|
+
outcome: cancelled || requests.length > 0 && requests.every((request) => !request.merged) ? "aborted" : "completed",
|
|
851
|
+
params: { nextState: state }
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
return { outcome: "awaiting", params: { nextState: state } };
|
|
855
|
+
});
|
|
856
|
+
const outcome = (o, description) => o.description(description).object("nextState").state(({ event }) => event.params.nextState);
|
|
857
|
+
delivery.outcome("awaiting", (o) => outcome(o, "Delivery is waiting for external evidence").wait()).outcome("completed", (o) => outcome(o, "Merged pull request was reconciled").complete()).outcome(
|
|
244
858
|
"aborted",
|
|
245
|
-
(
|
|
859
|
+
(o) => outcome(o, "Closed pull request was reconciled").lifecycleStatus("aborted")
|
|
246
860
|
);
|
|
247
|
-
|
|
861
|
+
if (!adapter.maintenance)
|
|
862
|
+
delivery.outcome(
|
|
863
|
+
"feedback_ready",
|
|
864
|
+
(o) => outcome(o, "Pull request feedback is acknowledged and ready for revision").to(ids.feedback)
|
|
865
|
+
);
|
|
866
|
+
for (const [name, target] of adapter.maintenance ? [] : [
|
|
248
867
|
["ci_ready", ids.ciRepair],
|
|
249
868
|
["conflict_ready", ids.feedback],
|
|
250
869
|
["operator_action", ids.operator]
|
|
251
870
|
]) {
|
|
252
|
-
delivery.outcome(
|
|
253
|
-
outcome,
|
|
254
|
-
(o) => o.description("Route observed delivery evidence").object("nextState").to(target).state(({ event }) => event.params.nextState)
|
|
255
|
-
);
|
|
871
|
+
delivery.outcome(name, (o) => outcome(o, "Route observed delivery evidence").to(target));
|
|
256
872
|
}
|
|
257
873
|
for (const source of adapter.sources) {
|
|
874
|
+
if (adapter.maintenance && source.kind === "observation") continue;
|
|
258
875
|
const attach = (id, operator) => delivery.externalAction(id, source.source, (external) => {
|
|
259
876
|
external.label(source.label).when(
|
|
260
|
-
({ params, state }) => (!source.enabled || source.enabled(params)) && (source.kind
|
|
877
|
+
({ params, state }) => (!source.enabled || source.enabled(params, state)) && (source.kind === "cancelled" || (adapter.repositories ? adapter.repositories(params).map(({ key }) => remote(select(state, key))) : [remote(state)]).every(
|
|
878
|
+
(current) => current.noChanges || current.delivery.terminalPullRequest || !!(current.headSha && current.prNumber && current.prUrl)
|
|
879
|
+
)) && (source.kind !== "failure" || remote(state).ciRecoveryCycles >= 3 === operator)
|
|
261
880
|
);
|
|
262
881
|
if (source.kind === "cancelled") return external.lifecycleStatus("aborted");
|
|
263
882
|
external.to(
|
|
@@ -265,11 +884,12 @@ function createRepositoryChangePublication(adapter) {
|
|
|
265
884
|
);
|
|
266
885
|
return external.effect((input) => {
|
|
267
886
|
const evidence = source.read(input);
|
|
268
|
-
const
|
|
887
|
+
const state = adapter.repositories && evidence.projectKey ? select(input.state, evidence.projectKey) : input.state;
|
|
888
|
+
const current = remote(state);
|
|
269
889
|
return {
|
|
270
890
|
state: patchRemote(
|
|
271
|
-
|
|
272
|
-
source.kind === "observation" ? { pendingEvidence: evidence } :
|
|
891
|
+
state,
|
|
892
|
+
source.kind === "observation" ? { pendingEvidence: evidence } : applyPublicationEvidence(input.params, current, evidence, !operator)
|
|
273
893
|
)
|
|
274
894
|
};
|
|
275
895
|
});
|
|
@@ -277,12 +897,30 @@ function createRepositoryChangePublication(adapter) {
|
|
|
277
897
|
attach(source.id, false);
|
|
278
898
|
if (source.kind === "failure") attach(source.operatorId ?? `${source.id}_operator`, true);
|
|
279
899
|
}
|
|
900
|
+
if (adapter.maintenance) {
|
|
901
|
+
for (const [id, target] of [
|
|
902
|
+
["feedback", ids.feedback],
|
|
903
|
+
["conflict", ids.feedback],
|
|
904
|
+
["ci", ids.ciRepair],
|
|
905
|
+
["operator", ids.operator]
|
|
906
|
+
])
|
|
907
|
+
delivery.externalAction(
|
|
908
|
+
`maintenance_${id}`,
|
|
909
|
+
adapter.maintenance.source,
|
|
910
|
+
(action) => action.label("Maintain MR").to(target).effect(({ event }) => ({ state: event.state }))
|
|
911
|
+
);
|
|
912
|
+
}
|
|
280
913
|
publication.turn(delivery);
|
|
281
914
|
function rebaseInput(ctx) {
|
|
282
|
-
const project = ctx.repo.get("repo");
|
|
915
|
+
const project = ctx.repo.get(activeKey(ctx.state) ?? "repo");
|
|
283
916
|
const conflict = remote(ctx.state).conflict;
|
|
284
917
|
if (!conflict) throw new Error("Missing conflict evidence");
|
|
285
|
-
return {
|
|
918
|
+
return {
|
|
919
|
+
projectKey: activeKey(ctx.state) ?? "repo",
|
|
920
|
+
path: project.fsPath,
|
|
921
|
+
workBranch: project.workBranch,
|
|
922
|
+
conflict
|
|
923
|
+
};
|
|
286
924
|
}
|
|
287
925
|
function repairReason(state, kind) {
|
|
288
926
|
return kind === "feedback" && remote(state).repairReason === "rebase" ? "rebase" : kind;
|
|
@@ -292,11 +930,14 @@ function createRepositoryChangePublication(adapter) {
|
|
|
292
930
|
const current = remote(ctx.state);
|
|
293
931
|
if (repairReason(ctx.state, kind) === "rebase")
|
|
294
932
|
return `${rebasePrompt} Evidence: ${JSON.stringify(current.conflict)}. Call changes_ready or no_changes when verified complete, cannot_repair when blocked.`;
|
|
295
|
-
return adapter.prompt(kind, current)
|
|
933
|
+
return `${adapter.repositories ? `Repository: ${activeKey(ctx.state)}. Apply changes only to this checkout. ` : ""}${adapter.prompt(kind, current)}`;
|
|
296
934
|
};
|
|
297
935
|
}
|
|
298
936
|
function revisionTurn(id, kind) {
|
|
299
|
-
const turn = flow.llm(id).description(kind === "feedback" ? "Address Feedback" : "Fix CI").
|
|
937
|
+
const turn = flow.llm(id).description(kind === "feedback" ? "Address Feedback" : "Fix CI").waitFor(({ state }) => {
|
|
938
|
+
const current = remote(state);
|
|
939
|
+
return !current.stopped && !current.delivery.terminalPullRequest && (kind === "feedback" ? current.feedbackIds.length > 0 || !!current.conflict : current.repairReason === "ci" && current.pipeline !== null);
|
|
940
|
+
}).executionPurpose(codingPurposes.implementation).tools("read", "bash", "edit", "write").resolveIntegrationTools(
|
|
300
941
|
(_params, state) => repairReason(state, kind) === "rebase" ? [] : adapter.tools[kind]
|
|
301
942
|
).prepare(
|
|
302
943
|
(ctx) => repairReason(ctx.state, kind) === "rebase" ? startRebase(rebaseInput(ctx)) : {}
|
|
@@ -308,25 +949,53 @@ function createRepositoryChangePublication(adapter) {
|
|
|
308
949
|
turn.outcomeTool(
|
|
309
950
|
name,
|
|
310
951
|
(tool) => tool.resultSummary().description(description).to(ids.deliver).state(
|
|
311
|
-
({ ctx }) => patchRemote(ctx.state, {
|
|
312
|
-
|
|
952
|
+
({ ctx, event }) => patchRemote(ctx.state, {
|
|
953
|
+
repairPending: false,
|
|
954
|
+
delivery: {
|
|
955
|
+
adjustment: { origin: repairReason(ctx.state, kind), publishRequired },
|
|
956
|
+
...!publishRequired && adapter.maintenance && repairReason(ctx.state, kind) !== "rebase" ? {
|
|
957
|
+
feedbackResult: {
|
|
958
|
+
published: false,
|
|
959
|
+
summary: String(
|
|
960
|
+
event.params.resultSummary ?? "No repository change was required"
|
|
961
|
+
)
|
|
962
|
+
}
|
|
963
|
+
} : {}
|
|
964
|
+
}
|
|
313
965
|
})
|
|
314
966
|
)
|
|
315
967
|
);
|
|
316
968
|
}
|
|
317
|
-
return turn.outcomeTool(
|
|
318
|
-
"
|
|
319
|
-
(
|
|
320
|
-
);
|
|
969
|
+
return turn.outcomeTool("cannot_repair", (tool) => {
|
|
970
|
+
const outcome2 = tool.description("The adjustment requires operator action").to(ids.operator);
|
|
971
|
+
return adapter.maintenance ? outcome2.state(({ ctx }) => patchRemote(ctx.state, { repairPending: false })) : outcome2;
|
|
972
|
+
});
|
|
321
973
|
}
|
|
322
974
|
publication.turn(revisionTurn(ids.feedback, "feedback"));
|
|
323
975
|
publication.turn(revisionTurn(ids.ciRepair, "ci"));
|
|
976
|
+
const maintenanceSource = adapter.maintenance?.source;
|
|
324
977
|
publication.turn({
|
|
325
978
|
id: ids.operator,
|
|
326
979
|
definition: {
|
|
327
980
|
kind: "human",
|
|
328
981
|
description: "Repository repair needs operator action",
|
|
329
982
|
operatorAttention: "required",
|
|
983
|
+
...maintenanceSource ? {
|
|
984
|
+
externalActions: Object.fromEntries(
|
|
985
|
+
["feedback", "conflict"].map((id) => [
|
|
986
|
+
`maintenance_${id}`,
|
|
987
|
+
{
|
|
988
|
+
id: `maintenance_${id}`,
|
|
989
|
+
source: maintenanceSource,
|
|
990
|
+
to: ids.feedback,
|
|
991
|
+
label: "Maintain MR",
|
|
992
|
+
effect: ({ event }) => ({
|
|
993
|
+
state: event.state
|
|
994
|
+
})
|
|
995
|
+
}
|
|
996
|
+
])
|
|
997
|
+
)
|
|
998
|
+
} : {},
|
|
330
999
|
actions: {
|
|
331
1000
|
retry_repair: {
|
|
332
1001
|
label: "Retry repair",
|
|
@@ -340,6 +1009,7 @@ function createRepositoryChangePublication(adapter) {
|
|
|
340
1009
|
to: ids.deliver,
|
|
341
1010
|
effect: ({ ctx }) => ({
|
|
342
1011
|
state: patchRemote(ctx.state, {
|
|
1012
|
+
repairPending: false,
|
|
343
1013
|
feedbackIds: [],
|
|
344
1014
|
delivery: { adjustment: null }
|
|
345
1015
|
})
|
|
@@ -360,9 +1030,15 @@ function createRepositoryChangePublication(adapter) {
|
|
|
360
1030
|
}
|
|
361
1031
|
export {
|
|
362
1032
|
applyPublicationEvidence,
|
|
1033
|
+
createPublicationSelection,
|
|
1034
|
+
createPullRequestChangeProcess,
|
|
363
1035
|
createRepositoryChangePublication,
|
|
364
1036
|
patchPublicationState,
|
|
1037
|
+
publicationFinished,
|
|
365
1038
|
publicationObject,
|
|
366
|
-
|
|
1039
|
+
pullRequestPublicationDefaults,
|
|
1040
|
+
readPublicationState,
|
|
1041
|
+
requirePublicationParams,
|
|
1042
|
+
resolvePullRequestGitIdentity
|
|
367
1043
|
};
|
|
368
1044
|
//# sourceMappingURL=repository-change-publication.js.map
|