@leitwerk-dev/jira-issue-split 0.0.0-bootstrap.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 +125 -1
- package/dist/LICENSE +13 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1128 -0
- package/dist/index.js.map +1 -0
- package/dist/model.d.ts +74 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/process.d.ts +8 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/services.d.ts +41 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/test-fixture.d.ts +12 -0
- package/dist/test-fixture.d.ts.map +1 -0
- package/package.json +56 -14
- package/src/index.ts +256 -0
- package/src/model.ts +236 -0
- package/src/process.ts +521 -0
- package/src/services.ts +577 -0
- package/src/test-fixture.ts +30 -0
package/src/process.ts
ADDED
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import { asUnknownRecord } from "@leitwerk-dev/domain";
|
|
2
|
+
import {
|
|
3
|
+
assertJiraTicketText,
|
|
4
|
+
type JiraIssue,
|
|
5
|
+
jiraTicketWritingInstructions,
|
|
6
|
+
} from "@leitwerk-dev/jira";
|
|
7
|
+
import {
|
|
8
|
+
type AutomaticOutcomeBuilder,
|
|
9
|
+
type Codec,
|
|
10
|
+
flow,
|
|
11
|
+
type ProcessLauncherDefinition,
|
|
12
|
+
type ProcessWatcherSource,
|
|
13
|
+
} from "@leitwerk-dev/process-sdk";
|
|
14
|
+
import { wikiInstructions } from "@leitwerk-dev/wiki";
|
|
15
|
+
import {
|
|
16
|
+
batchMarkdown,
|
|
17
|
+
initialSplitState,
|
|
18
|
+
parseDraft,
|
|
19
|
+
type SplitDraft,
|
|
20
|
+
type SplitParams,
|
|
21
|
+
type SplitRepository,
|
|
22
|
+
type SplitState,
|
|
23
|
+
splitParamsCodec,
|
|
24
|
+
splitStateCodec,
|
|
25
|
+
} from "./model.js";
|
|
26
|
+
import { parseLabels } from "./services.js";
|
|
27
|
+
|
|
28
|
+
interface PreparedBatch {
|
|
29
|
+
drafts: SplitDraft[];
|
|
30
|
+
epic: JiraIssue;
|
|
31
|
+
epicRevision: string;
|
|
32
|
+
}
|
|
33
|
+
const inspectionTools = [
|
|
34
|
+
"gitlab_inspect_project",
|
|
35
|
+
"gitlab_repository_tree",
|
|
36
|
+
"gitlab_repository_file",
|
|
37
|
+
"wiki_index",
|
|
38
|
+
"wiki_read",
|
|
39
|
+
"wiki_share",
|
|
40
|
+
];
|
|
41
|
+
const draftShape =
|
|
42
|
+
"{repositoryKey, verdict: applicable|not_applicable|already_compliant|unresolved, reason, evidence, revision: inspected commit SHA, summary, description: detailed change and acceptance criteria, issueType: Story|Task|Sub-task}";
|
|
43
|
+
const repositoryCodec: Codec<SplitRepository> = {
|
|
44
|
+
parse: (value) => value as SplitRepository,
|
|
45
|
+
serialize: (value) => value,
|
|
46
|
+
};
|
|
47
|
+
const draftCodec: Codec<SplitDraft> = { parse: parseDraft, serialize: (value) => value };
|
|
48
|
+
|
|
49
|
+
function requireCleanDraft(draft: SplitDraft): SplitDraft {
|
|
50
|
+
if (draft.verdict === "applicable" && !draft.receipt && !draft.excluded)
|
|
51
|
+
assertJiraTicketText(draft.summary, draft.description);
|
|
52
|
+
return draft;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function publicationState(state: SplitState, input: unknown): SplitState {
|
|
56
|
+
const results = input as {
|
|
57
|
+
repositoryKey: string;
|
|
58
|
+
receipt?: SplitDraft["receipt"];
|
|
59
|
+
reviewRequired?: string;
|
|
60
|
+
}[];
|
|
61
|
+
return {
|
|
62
|
+
...state,
|
|
63
|
+
approved: [],
|
|
64
|
+
drafts: state.drafts.map((draft) => {
|
|
65
|
+
const result = results.find((candidate) => candidate.repositoryKey === draft.repositoryKey);
|
|
66
|
+
return result?.receipt
|
|
67
|
+
? { ...draft, receipt: result.receipt }
|
|
68
|
+
: result?.reviewRequired
|
|
69
|
+
? { ...draft, blocked: result.reviewRequired }
|
|
70
|
+
: draft;
|
|
71
|
+
}),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function recordPublication(outcome: AutomaticOutcomeBuilder<SplitParams, SplitState>) {
|
|
76
|
+
return outcome
|
|
77
|
+
.parameter("results", {
|
|
78
|
+
type: "array",
|
|
79
|
+
description: "Publication receipts",
|
|
80
|
+
items: { type: "object" },
|
|
81
|
+
})
|
|
82
|
+
.effect(({ ctx, event }) => ({ state: publicationState(ctx.state, event.params.results) }));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** @internal */
|
|
86
|
+
export function createSplitProcess(
|
|
87
|
+
launcher: ProcessLauncherDefinition<SplitParams>,
|
|
88
|
+
watcher: {
|
|
89
|
+
source: ProcessWatcherSource<Record<string, unknown>, Record<string, unknown>>;
|
|
90
|
+
resolve: (
|
|
91
|
+
event: Record<string, unknown>,
|
|
92
|
+
) => Promise<import("@leitwerk-dev/process-sdk").ProcessLaunchConfig<SplitParams>>;
|
|
93
|
+
},
|
|
94
|
+
) {
|
|
95
|
+
// Process and turn IDs are durable storage keys; the package rename does not change them.
|
|
96
|
+
return flow
|
|
97
|
+
.process<SplitParams, SplitState>("jira_epic_split_process")
|
|
98
|
+
.displayName("Jira Issue Split")
|
|
99
|
+
.entry("read_epic")
|
|
100
|
+
.runtime({ repositoryCheckout: "on_demand" })
|
|
101
|
+
.codecs({ params: splitParamsCodec, state: splitStateCodec })
|
|
102
|
+
.initialState(initialSplitState)
|
|
103
|
+
.launcher(launcher)
|
|
104
|
+
.watcher({
|
|
105
|
+
id: "epic_split",
|
|
106
|
+
label: "Jira issue splitting",
|
|
107
|
+
description:
|
|
108
|
+
"Split issues labeled leitwerk-issue-split or leitwerk-epic-split into repository tickets",
|
|
109
|
+
source: watcher.source,
|
|
110
|
+
resolveLaunchConfig: watcher.resolve,
|
|
111
|
+
})
|
|
112
|
+
.repositoryCredentials(({ params, projects }) =>
|
|
113
|
+
projects.map((project) => ({
|
|
114
|
+
projectKey: project.key,
|
|
115
|
+
kind: "git_ssh" as const,
|
|
116
|
+
credentialRef: params.sshProfile,
|
|
117
|
+
})),
|
|
118
|
+
)
|
|
119
|
+
.happyPath(
|
|
120
|
+
"read_epic",
|
|
121
|
+
"discover_candidates",
|
|
122
|
+
"assess_repository",
|
|
123
|
+
"prepare_review",
|
|
124
|
+
"batch_review",
|
|
125
|
+
"publish_tickets",
|
|
126
|
+
"complete_split",
|
|
127
|
+
)
|
|
128
|
+
.turn(
|
|
129
|
+
flow
|
|
130
|
+
.automatic<SplitParams, SplitState>("read_epic")
|
|
131
|
+
.description("Read source issue")
|
|
132
|
+
.integrationTools("jira_split_prepare")
|
|
133
|
+
.run(async (ctx) => ({
|
|
134
|
+
outcome: "read",
|
|
135
|
+
params: { prepared: await ctx.callIntegrationTool("jira_split_prepare", {}) },
|
|
136
|
+
}))
|
|
137
|
+
.outcome("read", (outcome) =>
|
|
138
|
+
outcome
|
|
139
|
+
.description("Source issue captured")
|
|
140
|
+
.parameter("prepared", { type: "object", description: "Captured source issue" })
|
|
141
|
+
.effect(({ ctx, event }) => {
|
|
142
|
+
const prepared = event.params.prepared as PreparedBatch;
|
|
143
|
+
return {
|
|
144
|
+
state: { ...ctx.state, epic: prepared.epic, epicRevision: prepared.epicRevision },
|
|
145
|
+
};
|
|
146
|
+
})
|
|
147
|
+
.to("discover_candidates"),
|
|
148
|
+
),
|
|
149
|
+
)
|
|
150
|
+
.turn(
|
|
151
|
+
flow
|
|
152
|
+
.llm<SplitParams, SplitState>("discover_candidates")
|
|
153
|
+
.description("Discover repository candidates")
|
|
154
|
+
.freshPrimary()
|
|
155
|
+
.tools("read", "bash")
|
|
156
|
+
.integrationTools(...inspectionTools)
|
|
157
|
+
.askQuestions()
|
|
158
|
+
.buildPrompt(
|
|
159
|
+
(ctx) =>
|
|
160
|
+
`Read the source issue and identify repository candidates for its requirements. Inspect GitLab metadata/files; checkout_repository is available when needed. Every scoped repository needs a reasoned decision. Inaccessible or ambiguous repositories remain candidates for investigation; never silently exclude them. Inspection only: no code changes or pushes.\n${wikiInstructions}\nSource issue: ${JSON.stringify(ctx.state.epic)}\nRepositories: ${JSON.stringify(ctx.params.repositories)}`,
|
|
161
|
+
)
|
|
162
|
+
.outcomeTool("candidates_identified", (outcome) =>
|
|
163
|
+
outcome
|
|
164
|
+
.description("Record all discovery decisions")
|
|
165
|
+
.requiredString(
|
|
166
|
+
"decisions",
|
|
167
|
+
"JSON array: one {repositoryKey,candidate:boolean,reason} per scoped repository",
|
|
168
|
+
)
|
|
169
|
+
.effect(({ ctx, event }) => {
|
|
170
|
+
const decisions = JSON.parse(String(event.params.decisions)) as {
|
|
171
|
+
repositoryKey: string;
|
|
172
|
+
candidate: boolean;
|
|
173
|
+
reason: string;
|
|
174
|
+
}[];
|
|
175
|
+
if (
|
|
176
|
+
!Array.isArray(decisions) ||
|
|
177
|
+
decisions.length !== ctx.params.repositories.length ||
|
|
178
|
+
new Set(decisions.map((decision) => decision.repositoryKey)).size !==
|
|
179
|
+
decisions.length ||
|
|
180
|
+
decisions.some(
|
|
181
|
+
(decision) =>
|
|
182
|
+
!ctx.params.repositories.some(
|
|
183
|
+
(repository) => repository.key === decision.repositoryKey,
|
|
184
|
+
) ||
|
|
185
|
+
typeof decision.candidate !== "boolean" ||
|
|
186
|
+
typeof decision.reason !== "string" ||
|
|
187
|
+
!decision.reason.trim(),
|
|
188
|
+
)
|
|
189
|
+
)
|
|
190
|
+
throw new Error("Provide one evidence-based decision for every scoped repository");
|
|
191
|
+
return {
|
|
192
|
+
state: {
|
|
193
|
+
...ctx.state,
|
|
194
|
+
candidates: decisions
|
|
195
|
+
.filter((decision) => decision.candidate)
|
|
196
|
+
.map((decision) => decision.repositoryKey),
|
|
197
|
+
drafts: decisions
|
|
198
|
+
.filter((decision) => !decision.candidate)
|
|
199
|
+
.map((decision) =>
|
|
200
|
+
parseDraft({
|
|
201
|
+
...decision,
|
|
202
|
+
verdict: "not_applicable",
|
|
203
|
+
evidence: decision.reason,
|
|
204
|
+
issueType: ctx.params.issueType,
|
|
205
|
+
}),
|
|
206
|
+
),
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
})
|
|
210
|
+
.to("assess_repository"),
|
|
211
|
+
),
|
|
212
|
+
)
|
|
213
|
+
.turn(
|
|
214
|
+
flow
|
|
215
|
+
.mappedLlm<SplitParams, SplitState, SplitRepository, SplitDraft>("assess_repository", {
|
|
216
|
+
items: ({ params, state }) =>
|
|
217
|
+
params.repositories.filter((repository) => state.candidates.includes(repository.key)),
|
|
218
|
+
itemCodec: repositoryCodec,
|
|
219
|
+
resultCodec: draftCodec,
|
|
220
|
+
key: ({ item }) => item.key,
|
|
221
|
+
label: ({ item }) => item.name,
|
|
222
|
+
})
|
|
223
|
+
.description("Assess repository applicability")
|
|
224
|
+
.freshPrimary()
|
|
225
|
+
.tools("read", "bash")
|
|
226
|
+
.integrationTools(...inspectionTools)
|
|
227
|
+
.askQuestions()
|
|
228
|
+
.buildPrompt(
|
|
229
|
+
(ctx) =>
|
|
230
|
+
`Determine whether this repository needs changes for the source issue's requirements. Use GitLab file reads and checkout_repository as needed. Do not change code or publish anything. Distinguish already compliant, not applicable, and unresolved; lack of access is unresolved. For an applicable repository prepare one ticket with concrete acceptance criteria, evidence and inspected commit. ${ctx.params.subtaskType ? `Use issueType Sub-task (${ctx.params.subtaskType.name}); Story and Task are not allowed.` : `Default issue type: ${ctx.params.issueType}; only Story or Task are allowed.`}\n${jiraTicketWritingInstructions}\n${wikiInstructions}\nSource issue: ${JSON.stringify(ctx.state.epic)}\nRepository: ${JSON.stringify(ctx.item)}\nReturn assessment JSON: ${draftShape}`,
|
|
231
|
+
)
|
|
232
|
+
.outcomeTool("repository_assessed", (outcome) =>
|
|
233
|
+
outcome
|
|
234
|
+
.description("Save repository assessment and draft")
|
|
235
|
+
.requiredString("assessment", `JSON ${draftShape}`)
|
|
236
|
+
.yield(({ ctx, event }) => {
|
|
237
|
+
const draft = parseDraft(JSON.parse(String(event.params.assessment)), ctx.params);
|
|
238
|
+
if (draft.repositoryKey !== ctx.item.key)
|
|
239
|
+
throw new Error("Assessment repository mismatch");
|
|
240
|
+
return requireCleanDraft(draft);
|
|
241
|
+
}),
|
|
242
|
+
)
|
|
243
|
+
.collect(({ state }, results) => ({
|
|
244
|
+
...state,
|
|
245
|
+
drafts: [...state.drafts, ...results],
|
|
246
|
+
candidates: [],
|
|
247
|
+
}))
|
|
248
|
+
.to("prepare_review"),
|
|
249
|
+
)
|
|
250
|
+
.turn(
|
|
251
|
+
flow
|
|
252
|
+
.automatic<SplitParams, SplitState>("prepare_review")
|
|
253
|
+
.description("Prepare ticket batch")
|
|
254
|
+
.integrationTools("jira_split_prepare")
|
|
255
|
+
.run(async (ctx) => {
|
|
256
|
+
const prepared = (await ctx.callIntegrationTool(
|
|
257
|
+
"jira_split_prepare",
|
|
258
|
+
{},
|
|
259
|
+
)) as PreparedBatch;
|
|
260
|
+
return {
|
|
261
|
+
outcome: "ready",
|
|
262
|
+
params: {
|
|
263
|
+
prepared,
|
|
264
|
+
batch: batchMarkdown(ctx.params, { ...ctx.state, drafts: prepared.drafts }),
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
})
|
|
268
|
+
.outcome("ready", (outcome) =>
|
|
269
|
+
outcome
|
|
270
|
+
.description("Batch ready for review")
|
|
271
|
+
.parameter("prepared", {
|
|
272
|
+
type: "object",
|
|
273
|
+
description: "Current mappings and source issue",
|
|
274
|
+
})
|
|
275
|
+
.markdown("batch", { publish: true })
|
|
276
|
+
.effect(({ ctx, event }) => {
|
|
277
|
+
const prepared = event.params.prepared as PreparedBatch;
|
|
278
|
+
return {
|
|
279
|
+
state: {
|
|
280
|
+
...ctx.state,
|
|
281
|
+
drafts: prepared.drafts,
|
|
282
|
+
epic: prepared.epic,
|
|
283
|
+
approved: [],
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
})
|
|
287
|
+
.to("batch_review"),
|
|
288
|
+
),
|
|
289
|
+
)
|
|
290
|
+
.turn(
|
|
291
|
+
flow
|
|
292
|
+
.human<SplitParams, SplitState>("batch_review")
|
|
293
|
+
.description("Review repository tickets")
|
|
294
|
+
.reviewProduct("batch")
|
|
295
|
+
.action("approve_batch", (action) =>
|
|
296
|
+
action
|
|
297
|
+
.label("Create approved tickets")
|
|
298
|
+
.form({
|
|
299
|
+
id: "split_approval",
|
|
300
|
+
title: "Publish repository tickets",
|
|
301
|
+
submitLabel: "Create tickets",
|
|
302
|
+
fields: [
|
|
303
|
+
{
|
|
304
|
+
id: "exclude",
|
|
305
|
+
label: "Repositories to exclude",
|
|
306
|
+
kind: "textarea",
|
|
307
|
+
description:
|
|
308
|
+
"One repository path per line. Unresolved rows stay pending unless explicitly excluded.",
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
id: "tasks",
|
|
312
|
+
label: "Create as Tasks",
|
|
313
|
+
kind: "textarea",
|
|
314
|
+
description:
|
|
315
|
+
"Epic splits only: optional repository paths, one per line. Leave blank for subtask splits.",
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
id: "labels",
|
|
319
|
+
label: "Ticket labels",
|
|
320
|
+
kind: "text",
|
|
321
|
+
primaryPrompt: true,
|
|
322
|
+
description:
|
|
323
|
+
"Comma-separated labels. Include use-leitwerk only to start code changes. Blank keeps the displayed labels.",
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
id: "clearLabels",
|
|
327
|
+
label: "Remove all selected ticket labels",
|
|
328
|
+
kind: "boolean",
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
})
|
|
332
|
+
.effect(({ ctx, input }) => {
|
|
333
|
+
const keys = (value: unknown) => {
|
|
334
|
+
const names =
|
|
335
|
+
typeof value === "string" ? value.split(/[\s,]+/).filter(Boolean) : [];
|
|
336
|
+
return names.map((name) => {
|
|
337
|
+
const repository = ctx.params.repositories.find(
|
|
338
|
+
(candidate) => candidate.name === name,
|
|
339
|
+
);
|
|
340
|
+
if (!repository) throw new Error(`Unknown repository: ${name}`);
|
|
341
|
+
return repository.key;
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
const excluded = keys(input.exclude),
|
|
345
|
+
tasks = keys(input.tasks);
|
|
346
|
+
if (ctx.params.subtaskType && tasks.length)
|
|
347
|
+
throw new Error(
|
|
348
|
+
"Subtask splits cannot create Tasks; leave the Task overrides blank",
|
|
349
|
+
);
|
|
350
|
+
const drafts = ctx.state.drafts.map((draft) =>
|
|
351
|
+
draft.receipt
|
|
352
|
+
? draft
|
|
353
|
+
: {
|
|
354
|
+
...draft,
|
|
355
|
+
excluded: draft.excluded || excluded.includes(draft.repositoryKey),
|
|
356
|
+
issueType: tasks.includes(draft.repositoryKey)
|
|
357
|
+
? ("Task" as const)
|
|
358
|
+
: draft.issueType,
|
|
359
|
+
},
|
|
360
|
+
);
|
|
361
|
+
const labels =
|
|
362
|
+
input.clearLabels === true
|
|
363
|
+
? []
|
|
364
|
+
: typeof input.labels === "string" && input.labels.trim()
|
|
365
|
+
? parseLabels(input.labels)
|
|
366
|
+
: ctx.state.labels;
|
|
367
|
+
for (const draft of drafts) {
|
|
368
|
+
if (!draft.blocked) requireCleanDraft(draft);
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
state: {
|
|
372
|
+
...ctx.state,
|
|
373
|
+
drafts,
|
|
374
|
+
labels,
|
|
375
|
+
approved: drafts
|
|
376
|
+
.filter(
|
|
377
|
+
(draft) =>
|
|
378
|
+
draft.verdict === "applicable" &&
|
|
379
|
+
!draft.blocked &&
|
|
380
|
+
!draft.excluded &&
|
|
381
|
+
!draft.receipt,
|
|
382
|
+
)
|
|
383
|
+
.map((draft) => draft.repositoryKey),
|
|
384
|
+
},
|
|
385
|
+
};
|
|
386
|
+
})
|
|
387
|
+
.to("publish_tickets"),
|
|
388
|
+
)
|
|
389
|
+
.action("revise_batch", (action) =>
|
|
390
|
+
action
|
|
391
|
+
.label("Revise tickets or assessments")
|
|
392
|
+
.form({
|
|
393
|
+
id: "split_revision",
|
|
394
|
+
title: "Revise batch",
|
|
395
|
+
fields: [
|
|
396
|
+
{
|
|
397
|
+
id: "message",
|
|
398
|
+
label: "Instructions",
|
|
399
|
+
kind: "textarea",
|
|
400
|
+
required: true,
|
|
401
|
+
primaryPrompt: true,
|
|
402
|
+
},
|
|
403
|
+
],
|
|
404
|
+
})
|
|
405
|
+
.effect(({ ctx, input }) => ({
|
|
406
|
+
state: { ...ctx.state, feedback: String(input.message ?? ""), approved: [] },
|
|
407
|
+
}))
|
|
408
|
+
.to("revise_drafts"),
|
|
409
|
+
)
|
|
410
|
+
.action("refresh_mappings", (action) =>
|
|
411
|
+
action.label("Refresh component mappings").to("prepare_review"),
|
|
412
|
+
)
|
|
413
|
+
.action("exclude_remaining", (action) =>
|
|
414
|
+
action
|
|
415
|
+
.label("Finish without remaining tickets")
|
|
416
|
+
.effect(({ ctx }) => ({
|
|
417
|
+
state: {
|
|
418
|
+
...ctx.state,
|
|
419
|
+
approved: [],
|
|
420
|
+
drafts: ctx.state.drafts.map((draft) =>
|
|
421
|
+
draft.receipt ? draft : { ...draft, excluded: true },
|
|
422
|
+
),
|
|
423
|
+
},
|
|
424
|
+
}))
|
|
425
|
+
.to("complete_split"),
|
|
426
|
+
),
|
|
427
|
+
)
|
|
428
|
+
.turn(
|
|
429
|
+
flow
|
|
430
|
+
.llm<SplitParams, SplitState>("revise_drafts")
|
|
431
|
+
.description("Revise the ticket batch")
|
|
432
|
+
.tools("read", "bash")
|
|
433
|
+
.integrationTools(...inspectionTools, "jira_split_prepare")
|
|
434
|
+
.prepare(
|
|
435
|
+
async (ctx) => (await ctx.callIntegrationTool("jira_split_prepare", {})) as PreparedBatch,
|
|
436
|
+
)
|
|
437
|
+
.buildPrompt(
|
|
438
|
+
(ctx) =>
|
|
439
|
+
`Revise the unpublished repository assessments and ticket drafts using the operator feedback. Reinspect when the source issue or evidence changed. Preserve published rows and repository identities. Return every unpublished row in drafts JSON. ${ctx.params.subtaskType ? "Use issueType Sub-task for every row." : "Use issueType Story or Task for every row."} Do not create issues. ${jiraTicketWritingInstructions}\n${wikiInstructions}\nSource issue: ${JSON.stringify(ctx.prepared.epic)}\nFeedback: ${ctx.state.feedback}\nRepositories: ${JSON.stringify(ctx.params.repositories)}\nCurrent drafts: ${JSON.stringify(ctx.state.drafts)}\nEach draft has shape ${draftShape}`,
|
|
440
|
+
)
|
|
441
|
+
.outcomeTool("drafts_revised", (outcome) =>
|
|
442
|
+
outcome
|
|
443
|
+
.description("Replace unpublished drafts")
|
|
444
|
+
.requiredString("drafts", "JSON array of all unpublished repository drafts")
|
|
445
|
+
.effect(({ ctx, event }) => {
|
|
446
|
+
const value: unknown = JSON.parse(String(event.params.drafts));
|
|
447
|
+
if (!Array.isArray(value)) throw new Error("Expected draft array");
|
|
448
|
+
const drafts = value.map((draft) => requireCleanDraft(parseDraft(draft, ctx.params)));
|
|
449
|
+
const pending = ctx.state.drafts.filter((draft) => !draft.receipt);
|
|
450
|
+
if (
|
|
451
|
+
drafts.length !== pending.length ||
|
|
452
|
+
new Set(drafts.map((draft) => draft.repositoryKey)).size !== drafts.length ||
|
|
453
|
+
drafts.some(
|
|
454
|
+
(draft) => !pending.some((old) => old.repositoryKey === draft.repositoryKey),
|
|
455
|
+
)
|
|
456
|
+
)
|
|
457
|
+
throw new Error("Preserve all unpublished repository identities");
|
|
458
|
+
const prepared = event.prepared as PreparedBatch;
|
|
459
|
+
return {
|
|
460
|
+
state: {
|
|
461
|
+
...ctx.state,
|
|
462
|
+
drafts: [...ctx.state.drafts.filter((draft) => draft.receipt), ...drafts],
|
|
463
|
+
approved: [],
|
|
464
|
+
epic: prepared.epic,
|
|
465
|
+
epicRevision: prepared.epicRevision,
|
|
466
|
+
},
|
|
467
|
+
};
|
|
468
|
+
})
|
|
469
|
+
.to("prepare_review"),
|
|
470
|
+
),
|
|
471
|
+
)
|
|
472
|
+
.turn(
|
|
473
|
+
flow
|
|
474
|
+
.automatic<SplitParams, SplitState>("publish_tickets")
|
|
475
|
+
.description("Create approved Jira tickets")
|
|
476
|
+
.integrationTools("jira_split_publish")
|
|
477
|
+
.run(async (ctx) => {
|
|
478
|
+
const results = [];
|
|
479
|
+
for (const repositoryKey of ctx.state.approved)
|
|
480
|
+
results.push({
|
|
481
|
+
repositoryKey,
|
|
482
|
+
...asUnknownRecord(
|
|
483
|
+
await ctx.callIntegrationTool("jira_split_publish", { repositoryKey }),
|
|
484
|
+
),
|
|
485
|
+
});
|
|
486
|
+
const pending = publicationState(ctx.state, results).drafts.some(
|
|
487
|
+
(draft) =>
|
|
488
|
+
!draft.receipt &&
|
|
489
|
+
!draft.excluded &&
|
|
490
|
+
(draft.verdict === "applicable" || draft.verdict === "unresolved"),
|
|
491
|
+
);
|
|
492
|
+
return { outcome: pending ? "published" : "finished", params: { results } };
|
|
493
|
+
})
|
|
494
|
+
.outcome("published", (outcome) =>
|
|
495
|
+
recordPublication(outcome)
|
|
496
|
+
.description("Partial ticket publication recorded")
|
|
497
|
+
.to("prepare_review"),
|
|
498
|
+
)
|
|
499
|
+
.outcome("finished", (outcome) =>
|
|
500
|
+
recordPublication(outcome)
|
|
501
|
+
.description("All ticket dispositions recorded")
|
|
502
|
+
.to("complete_split"),
|
|
503
|
+
),
|
|
504
|
+
)
|
|
505
|
+
.turn(
|
|
506
|
+
flow
|
|
507
|
+
.automatic<SplitParams, SplitState>("complete_split")
|
|
508
|
+
.description("Issue split result")
|
|
509
|
+
.run((ctx) => ({
|
|
510
|
+
outcome: "done",
|
|
511
|
+
params: { result: batchMarkdown(ctx.params, ctx.state) },
|
|
512
|
+
}))
|
|
513
|
+
.outcome("done", (outcome) =>
|
|
514
|
+
outcome
|
|
515
|
+
.description("Ticket batch finished")
|
|
516
|
+
.markdown("result", { publish: true })
|
|
517
|
+
.complete(),
|
|
518
|
+
),
|
|
519
|
+
)
|
|
520
|
+
.define();
|
|
521
|
+
}
|