@intentius/chant 0.124.79 → 0.124.81
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/dist/ci-note-commands.d.ts +199 -0
- package/dist/ci-note-commands.d.ts.map +1 -0
- package/dist/ci-note-commands.js +372 -0
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +7 -1
- package/dist/cli/handlers/pr-notes.d.ts +13 -0
- package/dist/cli/handlers/pr-notes.d.ts.map +1 -0
- package/dist/cli/handlers/pr-notes.js +73 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +10 -1
- package/dist/cli/mcp/product-tools.d.ts.map +1 -1
- package/dist/cli/mcp/product-tools.js +1 -2
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +10 -0
- package/dist/cli/registry.d.ts +4 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/capability.d.ts +22 -0
- package/dist/components/capability.d.ts.map +1 -1
- package/dist/components/pr-pipeline.d.ts +22 -0
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +26 -0
- package/dist/components/product-pipeline.d.ts +12 -0
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +5 -1
- package/dist/lifecycle/release-version.d.ts.map +1 -1
- package/dist/lifecycle/release-version.js +1 -2
- package/dist/op/index.d.ts +3 -3
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +2 -2
- package/dist/op/op-waves-after-plan.d.ts +33 -0
- package/dist/op/op-waves-after-plan.d.ts.map +1 -1
- package/dist/op/op-waves-after-plan.js +41 -4
- package/dist/op/op-waves-capability.d.ts +13 -1
- package/dist/op/op-waves-capability.d.ts.map +1 -1
- package/dist/op/op-waves-capability.js +22 -14
- package/dist/op/op-waves-run-hooks.d.ts.map +1 -1
- package/dist/op/op-waves-run-hooks.js +1 -2
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +125 -20
- package/dist/op/op-waves.d.ts +9 -5
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/parallelism.d.ts +9 -0
- package/dist/parallelism.d.ts.map +1 -1
- package/dist/parallelism.js +15 -0
- package/dist/pr-forge-reads.d.ts +151 -1
- package/dist/pr-forge-reads.d.ts.map +1 -1
- package/dist/pr-forge-reads.js +265 -1
- package/dist/release-floors.d.ts +15 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +17 -3
- package/dist/wave-runtime.mjs +288 -288
- package/package.json +1 -1
- package/src/ci-note-commands.test.ts +377 -0
- package/src/ci-note-commands.ts +479 -0
- package/src/cli/handlers/build.ts +7 -1
- package/src/cli/handlers/pr-notes.ts +70 -0
- package/src/cli/main.ts +10 -1
- package/src/cli/mcp/product-tools.test.ts +1 -2
- package/src/cli/mcp/product-tools.ts +1 -2
- package/src/cli/parse-args.ts +8 -0
- package/src/cli/registry.ts +4 -0
- package/src/components/capability.ts +22 -0
- package/src/components/pr-pipeline.ts +35 -0
- package/src/components/product-pipeline.test.ts +14 -0
- package/src/components/product-pipeline.ts +13 -1
- package/src/lifecycle/release-version.ts +1 -2
- package/src/op/index.ts +3 -2
- package/src/op/op-waves-after-plan-wave.test.ts +2 -3
- package/src/op/op-waves-after-plan.ts +61 -4
- package/src/op/op-waves-capability.test.ts +3 -1
- package/src/op/op-waves-capability.ts +27 -18
- package/src/op/op-waves-gate-port.test.ts +231 -0
- package/src/op/op-waves-parallel-plans.test.ts +185 -0
- package/src/op/op-waves-parallelism.test.ts +5 -0
- package/src/op/op-waves-run-hooks.test.ts +2 -3
- package/src/op/op-waves-run-hooks.ts +1 -2
- package/src/op/op-waves-run.ts +123 -23
- package/src/op/op-waves-step-wave.test.ts +3 -4
- package/src/op/op-waves.ts +9 -5
- package/src/parallelism.ts +26 -0
- package/src/pr-forge-reads-compare.test.ts +145 -0
- package/src/pr-forge-reads.test.ts +203 -0
- package/src/pr-forge-reads.ts +398 -1
- package/src/release-floors.ts +24 -3
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comment commands on GitLab by polling merge request notes (#4785, moved
|
|
3
|
+
* from terragucci's comment-gitlab.ts).
|
|
4
|
+
*
|
|
5
|
+
* GitLab starts no pipeline for a merge request note. So a scheduled
|
|
6
|
+
* pipeline of the default branch runs {@link pollNoteCommands}: it lists the
|
|
7
|
+
* merge requests updated in the last day, reads their notes through chant's
|
|
8
|
+
* forge reads, and answers each note addressed to the product once.
|
|
9
|
+
*
|
|
10
|
+
* - A note is read against the product's words (`parseProductComment`): the
|
|
11
|
+
* product supplies its command words, and chant's grammar refuses the rest.
|
|
12
|
+
* - Its author must hold `minRole` or more on the project (Developer by
|
|
13
|
+
* default). Anyone else gets no reply and nothing runs, as on GitHub.
|
|
14
|
+
* - Each note is answered once: the note's id is recorded on the ledger
|
|
15
|
+
* ({@link NoteLog}, `_notes/<mr>-<note>.json` on `chant/lifecycle` in
|
|
16
|
+
* {@link ledgerNoteLog}), and the reply carries the note's marker, so a
|
|
17
|
+
* poll that runs twice answers once.
|
|
18
|
+
* - What a command runs is the product's ({@link NoteCommandRuns}): a
|
|
19
|
+
* pipeline of a branch started with the command's variables, a new merge
|
|
20
|
+
* request pipeline, the retry of the first apply job that did not succeed
|
|
21
|
+
* at a merged merge request's merge commit, or a reply alone.
|
|
22
|
+
* {@link chantNoteRuns} answers for the jobs chant's own GitLab pipeline
|
|
23
|
+
* writes (`CHANT_PREVIEW_PR`, `CHANT_APPLY_PR`, `CHANT_LOCK_PR`,
|
|
24
|
+
* `CHANT_UNLOCK_PR`, `CHANT_AGENT_PR`, `CHANT_COMMIT_PR`).
|
|
25
|
+
*
|
|
26
|
+
* The job runs nothing it reads: it calls GitLab's API with the project's
|
|
27
|
+
* token and holds no cloud credentials.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { GITLAB_AGENT_ASK_VAR, GITLAB_AGENT_PR_VAR } from "./ci-agent";
|
|
31
|
+
import { GITLAB_COMMIT_ARG_VAR, GITLAB_COMMIT_PR_VAR, GITLAB_COMMIT_WORD_VAR } from "./ci-commit";
|
|
32
|
+
import { parseProductComment, productStatusContext, type CiProductWords, type ParsedProductComment } from "./ci-product-words";
|
|
33
|
+
import { GITLAB_APPLY_PR_VAR, GITLAB_LOCK_PR_VAR, GITLAB_PREVIEW_PR_VAR, GITLAB_UNLOCK_PR_VAR, PREVIEW_COMMENT_ENV } from "./components/pr-pipeline";
|
|
34
|
+
import { ForgeApiError, type ForgeFetch, type GitlabForgeOptions, type PrForge } from "./pr-forge";
|
|
35
|
+
import type { ForgeReads, PullRequestDetail, PullRequestNote, RunJob, WorkflowRun } from "./pr-forge-reads";
|
|
36
|
+
|
|
37
|
+
export { GITLAB_NOTE_COMMANDS_VAR } from "./components/pr-pipeline";
|
|
38
|
+
|
|
39
|
+
/** How far back the poll reads: merge requests updated, and notes written, in this many minutes. */
|
|
40
|
+
export const NOTE_COMMANDS_WINDOW_MINUTES = 24 * 60;
|
|
41
|
+
|
|
42
|
+
/** How many pipelines of the default branch after the merge commit's are read for a later apply. */
|
|
43
|
+
export const NOTE_COMMANDS_NEWER_PIPELINES = 50;
|
|
44
|
+
|
|
45
|
+
/** GitLab's roles, least first, as `ForgeReads.permission` names them. */
|
|
46
|
+
export const GITLAB_ROLES = ["minimal", "guest", "planner", "reporter", "developer", "maintainer", "owner"] as const;
|
|
47
|
+
|
|
48
|
+
/** The marker a reply carries, naming the note it answers: `<!-- <product>:note=<id> -->`, terragucci's own. */
|
|
49
|
+
export function noteCommandMarker(product: string, id: number): string {
|
|
50
|
+
return `<!-- ${product}:note=${id} -->`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A pipeline the poll started, or the job it retried. */
|
|
54
|
+
export interface StartedRun {
|
|
55
|
+
id?: number;
|
|
56
|
+
url?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The GitLab writes the poll makes, with the token that may make them. */
|
|
60
|
+
export interface GitlabPipelines {
|
|
61
|
+
/** `POST /projects/:id/pipeline`: a pipeline of `ref` with `variables`. */
|
|
62
|
+
start(ref: string, variables: Readonly<Record<string, string>>): Promise<StartedRun>;
|
|
63
|
+
/** `POST /projects/:id/merge_requests/:iid/pipelines`: a new merge request pipeline, which takes no variables. */
|
|
64
|
+
startMergeRequest(iid: number): Promise<StartedRun>;
|
|
65
|
+
/** `POST /projects/:id/jobs/:job/retry`. */
|
|
66
|
+
retryJob(job: number): Promise<StartedRun>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The writes for a GitLab client's options. */
|
|
70
|
+
export function gitlabPipelines(opts: GitlabForgeOptions): GitlabPipelines {
|
|
71
|
+
const fetchImpl = opts.fetch ?? (globalThis.fetch as unknown as ForgeFetch);
|
|
72
|
+
const root = opts.apiBase.replace(/\/+$/, "");
|
|
73
|
+
const project = `/projects/${encodeURIComponent(decodeURIComponent(opts.project))}`;
|
|
74
|
+
const headers = { "Content-Type": "application/json", ...(opts.token ? { [opts.tokenHeader ?? "PRIVATE-TOKEN"]: opts.token } : {}) };
|
|
75
|
+
const post = async (path: string, body?: unknown): Promise<StartedRun> => {
|
|
76
|
+
const url = `${root}${project}${path}`;
|
|
77
|
+
const res = await fetchImpl(url, { method: "POST", headers, ...(body === undefined ? {} : { body: JSON.stringify(body) }) });
|
|
78
|
+
const text = await res.text();
|
|
79
|
+
if (!res.ok) throw new ForgeApiError("POST", url, res.status, text);
|
|
80
|
+
let v: unknown;
|
|
81
|
+
try {
|
|
82
|
+
v = text ? JSON.parse(text) : null;
|
|
83
|
+
} catch {
|
|
84
|
+
v = null;
|
|
85
|
+
}
|
|
86
|
+
const o = typeof v === "object" && v !== null ? (v as Record<string, unknown>) : {};
|
|
87
|
+
return { ...(typeof o.id === "number" ? { id: o.id } : {}), ...(typeof o.web_url === "string" && /^https?:\/\//.test(o.web_url) ? { url: o.web_url } : {}) };
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
start: (ref, variables) => post("/pipeline", { ref, variables: Object.entries(variables).map(([key, value]) => ({ key, value, variable_type: "env_var" })) }),
|
|
91
|
+
startMergeRequest: (iid) => post(`/merge_requests/${iid}/pipelines`),
|
|
92
|
+
retryJob: (job) => post(`/jobs/${job}/retry`),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** A command the poll read, from an author with the role it needs. */
|
|
97
|
+
export interface NoteCommand {
|
|
98
|
+
mr: PullRequestDetail;
|
|
99
|
+
note: PullRequestNote;
|
|
100
|
+
/** The command, never `refused`: a refusal is answered with its reason first. */
|
|
101
|
+
parsed: Exclude<ParsedProductComment, { kind: "refused" }>;
|
|
102
|
+
/** The author's role on the project. */
|
|
103
|
+
role: string;
|
|
104
|
+
/** The default branch. */
|
|
105
|
+
base: string;
|
|
106
|
+
words: CiProductWords;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** What a command runs. */
|
|
110
|
+
export type NoteRun =
|
|
111
|
+
/** A pipeline of `ref` started with `variables`; `doing` finishes the reply's "started pipeline <url> to ...". */
|
|
112
|
+
| { kind: "pipeline"; ref: string; variables: Record<string, string>; doing: string; with?: GitlabPipelines }
|
|
113
|
+
/** A new merge request pipeline of the note's merge request. */
|
|
114
|
+
| { kind: "merge-request-pipeline"; doing: string }
|
|
115
|
+
/**
|
|
116
|
+
* The retry of the first job `jobs` matches that did not succeed, in the
|
|
117
|
+
* newest push pipeline at `sha` (a merged merge request's merge commit)
|
|
118
|
+
* that has such a job. Refused when a later commit of the default branch
|
|
119
|
+
* already carries the product's apply status.
|
|
120
|
+
*/
|
|
121
|
+
| { kind: "retry"; sha: string; jobs?: RegExp }
|
|
122
|
+
/** A reply, and nothing runs. */
|
|
123
|
+
| { kind: "reply"; text: string }
|
|
124
|
+
/** Something broke: the note gets no reply and is read again next poll. */
|
|
125
|
+
| { kind: "fail"; reason: string };
|
|
126
|
+
|
|
127
|
+
/** The product's answer to a command. */
|
|
128
|
+
export type NoteCommandRuns = (c: NoteCommand) => NoteRun | Promise<NoteRun>;
|
|
129
|
+
|
|
130
|
+
/** What the poll did with one note. */
|
|
131
|
+
export interface NoteOutcome {
|
|
132
|
+
mr: number;
|
|
133
|
+
note: number;
|
|
134
|
+
author?: string;
|
|
135
|
+
/** The command's kind, when the note parsed as one. */
|
|
136
|
+
command?: string;
|
|
137
|
+
/** True when a pipeline was started or a job retried. */
|
|
138
|
+
ran: boolean;
|
|
139
|
+
/** False when the note got no reply (an author without the role, or a failure). */
|
|
140
|
+
replied: boolean;
|
|
141
|
+
/** True when something broke (a forge answer), not because the note asked for nothing. */
|
|
142
|
+
fail?: boolean;
|
|
143
|
+
reason: string;
|
|
144
|
+
/** The pipeline or job started. */
|
|
145
|
+
url?: string;
|
|
146
|
+
/** When the poll answered it (ISO 8601). */
|
|
147
|
+
at: string;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Where the poll keeps the notes it answered. */
|
|
151
|
+
export interface NoteLog {
|
|
152
|
+
answered(mr: number, note: number): Promise<boolean>;
|
|
153
|
+
/** Called once a note is answered: replied to, ignored for its author, or run. A failure that ran nothing is not recorded, so the next poll reads it again. */
|
|
154
|
+
record(outcome: NoteOutcome): Promise<void>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** A log in memory, for tests and a dry run. */
|
|
158
|
+
export function memoryNoteLog(seen: NoteOutcome[] = []): NoteLog & { outcomes: NoteOutcome[] } {
|
|
159
|
+
return {
|
|
160
|
+
outcomes: seen,
|
|
161
|
+
answered: async (mr, note) => seen.some((o) => o.mr === mr && o.note === note),
|
|
162
|
+
record: async (o) => void seen.push(o),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface NoteCommandsOptions {
|
|
167
|
+
reads: ForgeReads;
|
|
168
|
+
/** chant's client, holding the job's token: it posts the replies and reads the statuses. */
|
|
169
|
+
forge: PrForge;
|
|
170
|
+
/** The writes, with the token that may start pipelines on the default branch. */
|
|
171
|
+
pipelines: GitlabPipelines;
|
|
172
|
+
words: CiProductWords;
|
|
173
|
+
/** The default branch. */
|
|
174
|
+
base: string;
|
|
175
|
+
runs: NoteCommandRuns;
|
|
176
|
+
log: NoteLog;
|
|
177
|
+
/** The least role that may ask. Default `developer`. */
|
|
178
|
+
minRole?: (typeof GITLAB_ROLES)[number];
|
|
179
|
+
/** The poll's clock. Default: now. */
|
|
180
|
+
now?: Date;
|
|
181
|
+
windowMinutes?: number;
|
|
182
|
+
/** The job's environment, for the words' aliases. */
|
|
183
|
+
env?: Record<string, string | undefined>;
|
|
184
|
+
/** The commit words that take an argument, as `parseProductComment` takes them. */
|
|
185
|
+
commitArgs?: Readonly<Record<string, RegExp>>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export interface NotePoll {
|
|
189
|
+
outcomes: NoteOutcome[];
|
|
190
|
+
/** Set when the poll could not list the merge requests or a merge request's notes. */
|
|
191
|
+
fail?: string;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const short = (sha: string): string => sha.slice(0, 8);
|
|
195
|
+
const message = (e: unknown): string => (e instanceof Error ? e.message : String(e)).split("\n")[0]!;
|
|
196
|
+
|
|
197
|
+
/** Read, answer and record every new command note of the merge requests updated in the window. */
|
|
198
|
+
export async function pollNoteCommands(o: NoteCommandsOptions): Promise<NotePoll> {
|
|
199
|
+
const now = o.now ?? new Date();
|
|
200
|
+
const since = new Date(now.getTime() - (o.windowMinutes ?? NOTE_COMMANDS_WINDOW_MINUTES) * 60_000).toISOString();
|
|
201
|
+
const at = now.toISOString();
|
|
202
|
+
const least = GITLAB_ROLES.indexOf(o.minRole ?? "developer");
|
|
203
|
+
let me: { login: string; id?: number } | undefined;
|
|
204
|
+
let mrs: PullRequestDetail[];
|
|
205
|
+
try {
|
|
206
|
+
me = await o.reads.tokenUser();
|
|
207
|
+
mrs = await o.reads.pullRequestsUpdated(since);
|
|
208
|
+
} catch (e) {
|
|
209
|
+
return { outcomes: [], fail: `could not list the merge requests (${message(e)})` };
|
|
210
|
+
}
|
|
211
|
+
if (!me) return { outcomes: [], fail: "GitLab did not say which user the job's token acts as, so no reply can be told apart" };
|
|
212
|
+
const mine = (n: PullRequestNote): boolean => (me!.id !== undefined && n.authorId === me!.id) || n.author === me!.login;
|
|
213
|
+
const marker = new RegExp(`<!-- ${o.words.product.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}:note=(\\d+) -->`, "g");
|
|
214
|
+
const outcomes: NoteOutcome[] = [];
|
|
215
|
+
let unrecorded: string | undefined;
|
|
216
|
+
for (const mr of mrs) {
|
|
217
|
+
let notes: PullRequestNote[];
|
|
218
|
+
try {
|
|
219
|
+
notes = await o.reads.pullRequestNotes(mr.number);
|
|
220
|
+
} catch (e) {
|
|
221
|
+
return { outcomes, fail: `could not read the notes of !${mr.number} (${message(e)})${unrecorded ? `; and ${unrecorded}` : ""}` };
|
|
222
|
+
}
|
|
223
|
+
// Only the job's own replies mark a note answered: anyone else writing the marker answers nothing.
|
|
224
|
+
const replied = new Set<number>();
|
|
225
|
+
for (const n of notes) if (mine(n)) for (const m of n.body.matchAll(marker)) replied.add(Number(m[1]));
|
|
226
|
+
const asks = notes
|
|
227
|
+
.filter((n) => !n.system && !mine(n) && !replied.has(n.id) && n.created !== undefined && Date.parse(n.created) >= Date.parse(since))
|
|
228
|
+
.filter((n) => parseProductComment(o.words, n.body, o.env ?? {}, o.commitArgs ?? {}) !== undefined)
|
|
229
|
+
.sort((a, b) => Date.parse(a.created!) - Date.parse(b.created!) || a.id - b.id);
|
|
230
|
+
for (const note of asks) {
|
|
231
|
+
if (await o.log.answered(mr.number, note.id)) continue;
|
|
232
|
+
const out = await answer(o, mr, note, least, at, me.login);
|
|
233
|
+
if (out.ran || out.replied || !out.fail) {
|
|
234
|
+
try {
|
|
235
|
+
await o.log.record(out);
|
|
236
|
+
} catch (e) {
|
|
237
|
+
// The reply's marker still answers the note once.
|
|
238
|
+
unrecorded = `could not record note ${note.id} of !${mr.number} on the ledger (${message(e)})`;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
outcomes.push(out);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return { outcomes, ...(unrecorded ? { fail: unrecorded } : {}) };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async function answer(o: NoteCommandsOptions, mr: PullRequestDetail, note: PullRequestNote, least: number, at: string, me: string): Promise<NoteOutcome> {
|
|
248
|
+
const parsed = parseProductComment(o.words, note.body, o.env ?? {}, o.commitArgs ?? {})!;
|
|
249
|
+
const base = { mr: mr.number, note: note.id, ...(note.author ? { author: note.author } : {}), ...(parsed.kind !== "refused" ? { command: parsed.kind } : {}), at };
|
|
250
|
+
const marker = noteCommandMarker(o.words.product, note.id);
|
|
251
|
+
const reply = async (text: string, ran = false, url?: string): Promise<NoteOutcome> => {
|
|
252
|
+
const done = { ...base, ran, ...(url ? { url } : {}) };
|
|
253
|
+
try {
|
|
254
|
+
// One reply per note, found again by its marker.
|
|
255
|
+
await o.forge.upsertComment(mr.number, marker, `${o.words.product}: ${text}\n\n${marker}`, { match: "anywhere", author: me });
|
|
256
|
+
} catch (e) {
|
|
257
|
+
return { ...done, replied: false, fail: true, reason: `${text}; and the reply failed (${message(e)})` };
|
|
258
|
+
}
|
|
259
|
+
return { ...done, replied: true, reason: text };
|
|
260
|
+
};
|
|
261
|
+
const broke = (reason: string): NoteOutcome => ({ ...base, ran: false, replied: false, fail: true, reason });
|
|
262
|
+
const silent = (reason: string): NoteOutcome => ({ ...base, ran: false, replied: false, reason });
|
|
263
|
+
|
|
264
|
+
// Who asked comes first: someone below the role gets no reply and nothing runs.
|
|
265
|
+
if (!note.author) return silent("the note has no usable author");
|
|
266
|
+
let role: string | undefined;
|
|
267
|
+
try {
|
|
268
|
+
role = await o.reads.permission(note.author);
|
|
269
|
+
} catch (e) {
|
|
270
|
+
return broke(`could not read ${note.author}'s access, so nothing runs (${message(e)})`);
|
|
271
|
+
}
|
|
272
|
+
if (role === undefined) return silent(`${note.author} is not a member of the project, so the note is ignored`);
|
|
273
|
+
const level = GITLAB_ROLES.indexOf(role as (typeof GITLAB_ROLES)[number]);
|
|
274
|
+
if (level < least) return silent(`${note.author} is ${role} on the project, below ${GITLAB_ROLES[least]}, so the note is ignored`);
|
|
275
|
+
if (parsed.kind === "refused") return reply(parsed.reason);
|
|
276
|
+
|
|
277
|
+
let run: NoteRun;
|
|
278
|
+
try {
|
|
279
|
+
run = await o.runs({ mr, note, parsed, role, base: o.base, words: o.words });
|
|
280
|
+
} catch (e) {
|
|
281
|
+
return broke(`could not decide what ${note.author}'s command runs (${message(e)})`);
|
|
282
|
+
}
|
|
283
|
+
const link = (r: StartedRun): string => (r.url ? ` ${r.url}` : "");
|
|
284
|
+
switch (run.kind) {
|
|
285
|
+
case "reply":
|
|
286
|
+
return reply(run.text);
|
|
287
|
+
case "fail":
|
|
288
|
+
return broke(run.reason);
|
|
289
|
+
case "pipeline": {
|
|
290
|
+
let started: StartedRun;
|
|
291
|
+
try {
|
|
292
|
+
started = await (run.with ?? o.pipelines).start(run.ref, run.variables);
|
|
293
|
+
} catch (e) {
|
|
294
|
+
return broke(`could not start a pipeline on ${run.ref} for !${mr.number} (${message(e)})`);
|
|
295
|
+
}
|
|
296
|
+
return reply(`started pipeline${link(started)} on ${run.ref} to ${run.doing} for ${note.author}`, true, started.url);
|
|
297
|
+
}
|
|
298
|
+
case "merge-request-pipeline": {
|
|
299
|
+
let started: StartedRun;
|
|
300
|
+
try {
|
|
301
|
+
started = await o.pipelines.startMergeRequest(mr.number);
|
|
302
|
+
} catch (e) {
|
|
303
|
+
return broke(`could not start a pipeline for !${mr.number} (${message(e)})`);
|
|
304
|
+
}
|
|
305
|
+
return reply(`started pipeline${link(started)} to ${run.doing} for ${note.author}`, true, started.url);
|
|
306
|
+
}
|
|
307
|
+
case "retry":
|
|
308
|
+
return retry(o, mr, note.author, run, reply, broke);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** chant's apply jobs and terragucci's: `apply`, `apply-wave-<n>` and `apply-wave-<n>-share-<m>`, a member's prefixed with its name. */
|
|
313
|
+
export const APPLY_JOBS = /^(?:[a-z0-9][a-z0-9-]*-)?apply(?:-wave-([1-9][0-9]*)(?:-share-([1-9][0-9]*))?)?$/;
|
|
314
|
+
|
|
315
|
+
const NOT_DONE = new Set(["created", "pending", "running", "waiting_for_resource", "preparing", "scheduled"]);
|
|
316
|
+
|
|
317
|
+
async function retry(
|
|
318
|
+
o: NoteCommandsOptions,
|
|
319
|
+
mr: PullRequestDetail,
|
|
320
|
+
user: string,
|
|
321
|
+
run: Extract<NoteRun, { kind: "retry" }>,
|
|
322
|
+
reply: (text: string, ran?: boolean, url?: string) => Promise<NoteOutcome>,
|
|
323
|
+
broke: (reason: string) => NoteOutcome,
|
|
324
|
+
): Promise<NoteOutcome> {
|
|
325
|
+
const { sha } = run;
|
|
326
|
+
const pattern = run.jobs ?? APPLY_JOBS;
|
|
327
|
+
const iid = mr.number;
|
|
328
|
+
// The newest push pipeline at the merge commit with an apply job: a branch pipeline, or a ci/green tag's.
|
|
329
|
+
let pipeline: WorkflowRun | undefined;
|
|
330
|
+
let jobs: RunJob[] = [];
|
|
331
|
+
let newer: WorkflowRun[];
|
|
332
|
+
try {
|
|
333
|
+
for (const p of await o.reads.headRuns(sha, { event: "push" })) {
|
|
334
|
+
const js = (await o.reads.runJobs(p.id)).filter((j) => pattern.test(j.name));
|
|
335
|
+
if (js.length > 0) {
|
|
336
|
+
pipeline = p;
|
|
337
|
+
jobs = js;
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
if (!pipeline) return reply(`no pipeline at the merge commit ${short(sha)} of !${iid} has an apply job, so there is nothing to retry; push to ${o.base} again`);
|
|
342
|
+
newer = await o.reads.branchRuns(o.base, { event: "push", limit: NOTE_COMMANDS_NEWER_PIPELINES });
|
|
343
|
+
} catch (e) {
|
|
344
|
+
return broke(`could not read the pipelines at ${short(sha)} (${message(e)})`);
|
|
345
|
+
}
|
|
346
|
+
// A later commit whose apply started applied a newer tree: going back to this one would undo it.
|
|
347
|
+
const applyContext = productStatusContext(o.words, "apply");
|
|
348
|
+
const later = [...new Set(newer.filter((p) => p.id > pipeline!.id && p.headSha !== sha).map((p) => p.headSha))];
|
|
349
|
+
for (const c of later) {
|
|
350
|
+
let applied: { targetUrl?: string } | undefined;
|
|
351
|
+
try {
|
|
352
|
+
applied = (await o.forge.commitStatuses?.(c))?.find((s) => s.context === applyContext);
|
|
353
|
+
} catch (e) {
|
|
354
|
+
return broke(`could not read the statuses of ${short(c)} (${message(e)})`);
|
|
355
|
+
}
|
|
356
|
+
if (applied) {
|
|
357
|
+
const at = applied.targetUrl && /^https?:\/\//.test(applied.targetUrl) ? ` (${applied.targetUrl})` : "";
|
|
358
|
+
return reply(`a later apply already ran on ${o.base} at ${short(c)}${at}, so the merge commit ${short(sha)} of !${iid} is not applied: comment on the merge request that commit came from, or push again`);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
const order = (j: RunJob): [number, number] => {
|
|
362
|
+
const m = pattern.exec(j.name);
|
|
363
|
+
return [m?.[1] ? Number(m[1]) : 0, m?.[2] ? Number(m[2]) : 0];
|
|
364
|
+
};
|
|
365
|
+
const sorted = [...jobs].sort((a, b) => order(a)[0] - order(b)[0] || order(a)[1] - order(b)[1]);
|
|
366
|
+
const next = sorted.find((j) => j.status !== "success");
|
|
367
|
+
if (!next) return reply(`every apply job of !${iid}'s merge commit ${short(sha)} already succeeded`);
|
|
368
|
+
if (NOT_DONE.has(next.status)) return reply(`${next.name} at ${short(sha)} is ${next.status} already, so it is not retried`);
|
|
369
|
+
if (next.status !== "failed" && next.status !== "canceled") {
|
|
370
|
+
return reply(`${next.name} at ${short(sha)} was ${next.status}, and GitLab retries only a failed or canceled job; push to ${o.base} again`);
|
|
371
|
+
}
|
|
372
|
+
let retried: StartedRun;
|
|
373
|
+
try {
|
|
374
|
+
retried = await o.pipelines.retryJob(next.id);
|
|
375
|
+
} catch (e) {
|
|
376
|
+
return broke(`could not retry ${next.name} of pipeline ${pipeline.id} (${message(e)})`);
|
|
377
|
+
}
|
|
378
|
+
const link = retried.url ? ` (${retried.url})` : "";
|
|
379
|
+
return reply(`retried ${next.name} of !${iid}'s merge commit ${short(sha)}${link} for ${user}; its gate decides again, and the jobs after it follow, each behind its own gate`, true, retried.url);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** The jobs chant's GitLab pipeline has, which {@link chantNoteRuns} starts. */
|
|
383
|
+
export interface ChantNoteJobs {
|
|
384
|
+
/** The comment preview (`--preview-comment`): a plan starts it with `CHANT_PREVIEW_PR`. Without it a plan starts a merge request pipeline. */
|
|
385
|
+
preview?: boolean;
|
|
386
|
+
/** The apply before merge (`--apply-before-merge`), started with `CHANT_APPLY_PR`. */
|
|
387
|
+
applyBeforeMerge?: boolean;
|
|
388
|
+
/** The apply on merge (`--apply-on-merge`, waves): an apply on a merged merge request retries its first apply job that did not succeed. */
|
|
389
|
+
applyOnMerge?: boolean;
|
|
390
|
+
/** The lock and unlock jobs (`ci.locks: plan`), started with `CHANT_LOCK_PR` and `CHANT_UNLOCK_PR`. */
|
|
391
|
+
locks?: boolean;
|
|
392
|
+
/** The agent's jobs, started with `CHANT_AGENT_PR` and `CHANT_AGENT_ASK`. */
|
|
393
|
+
agent?: boolean;
|
|
394
|
+
/** The commit jobs, started with `CHANT_COMMIT_PR`, `CHANT_COMMIT` and `CHANT_COMMIT_ARG`. */
|
|
395
|
+
commits?: boolean;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** What a command runs in chant's own GitLab pipeline, for the jobs it has. */
|
|
399
|
+
export function chantNoteRuns(jobs: ChantNoteJobs): NoteCommandRuns {
|
|
400
|
+
return ({ mr, note, parsed, base, words }): NoteRun => {
|
|
401
|
+
const iid = String(mr.number);
|
|
402
|
+
const at = `!${mr.number}`;
|
|
403
|
+
const line = (kind: string): string => `\`/${words.product} ${Object.entries(words.commands).find(([, c]) => c === kind)?.[0] ?? kind}\``;
|
|
404
|
+
if (!mr.sameRepo) return { kind: "reply", text: `a merge request from a fork runs no command: its code never runs with this project's credentials` };
|
|
405
|
+
const open = mr.state === "open";
|
|
406
|
+
const intoBase = mr.base === undefined || mr.base === base;
|
|
407
|
+
switch (parsed.kind) {
|
|
408
|
+
case "plan":
|
|
409
|
+
if (!open) return { kind: "reply", text: `${at} is not open, so it is not ${words.verbs.plan[1]}` };
|
|
410
|
+
if (jobs.preview) return { kind: "pipeline", ref: base, variables: { [GITLAB_PREVIEW_PR_VAR]: iid, [PREVIEW_COMMENT_ENV]: note.body.trim() }, doing: `${words.verbs.plan[0]} ${at}'s head again` };
|
|
411
|
+
return { kind: "merge-request-pipeline", doing: `${words.verbs.plan[0]} ${at} again` };
|
|
412
|
+
case "apply":
|
|
413
|
+
if (open) {
|
|
414
|
+
if (!jobs.applyBeforeMerge) return { kind: "reply", text: `${at} is not merged, and this project ${words.verbs.apply[0]}s after a merge request merges, never from its branch` };
|
|
415
|
+
if (!intoBase) return { kind: "reply", text: `${at} targets ${mr.base}, not the default branch ${base}, so it is not ${words.verbs.apply[1]}` };
|
|
416
|
+
return { kind: "pipeline", ref: base, variables: { [GITLAB_APPLY_PR_VAR]: iid }, doing: `${words.verbs.apply[0]} ${at}'s head${mr.headSha ? ` ${short(mr.headSha)}` : ""}` };
|
|
417
|
+
}
|
|
418
|
+
if (mr.state === "closed") return { kind: "reply", text: `${at} was closed without merging, so there is nothing of it to ${words.verbs.apply[0]}` };
|
|
419
|
+
if (!jobs.applyOnMerge) {
|
|
420
|
+
return { kind: "reply", text: jobs.applyBeforeMerge ? `${at} is merged, and this project ${words.verbs.apply[0]}s a merge request before it merges, so there is nothing of it left to ${words.verbs.apply[0]}` : `${at} is merged, and a merge here records the plan: a release deploys it` };
|
|
421
|
+
}
|
|
422
|
+
if (parsed.wave !== undefined) return { kind: "reply", text: `GitLab runs the waves after a retried apply job by itself, so \`wave-${parsed.wave}\` cannot stop them; write ${line("apply")}, and each wave still waits behind its own gate` };
|
|
423
|
+
if (!intoBase) return { kind: "reply", text: `${at} was merged into ${mr.base}, not the default branch ${base}, so nothing applies from it` };
|
|
424
|
+
if (!mr.mergeCommit) return { kind: "fail", reason: `${at} has no merge commit` };
|
|
425
|
+
return { kind: "retry", sha: mr.mergeCommit };
|
|
426
|
+
case "lock":
|
|
427
|
+
case "unlock":
|
|
428
|
+
if (!jobs.locks) return { kind: "reply", text: `${line(parsed.kind)} does not run here: this project takes no locks` };
|
|
429
|
+
if (parsed.kind === "lock" && !open) return { kind: "reply", text: `${at} is not open, so it takes no lock` };
|
|
430
|
+
return { kind: "pipeline", ref: base, variables: { [parsed.kind === "lock" ? GITLAB_LOCK_PR_VAR : GITLAB_UNLOCK_PR_VAR]: iid }, doing: `${parsed.kind} the ${words.noun[1]} of ${at}` };
|
|
431
|
+
case "agent":
|
|
432
|
+
if (!jobs.agent) return { kind: "reply", text: `the agent command is off in this project` };
|
|
433
|
+
if (!open) return { kind: "reply", text: `${at} is not open, so the agent does not run` };
|
|
434
|
+
if (mr.head === base) return { kind: "reply", text: `${at}'s source branch is the default branch, and an agent never pushes there` };
|
|
435
|
+
return { kind: "pipeline", ref: base, variables: { [GITLAB_AGENT_PR_VAR]: iid, [GITLAB_AGENT_ASK_VAR]: parsed.ask }, doing: `run the agent on ${at}` };
|
|
436
|
+
case "commit":
|
|
437
|
+
if (!jobs.commits) return { kind: "reply", text: `\`/${words.product} ${parsed.word}\` does not run here` };
|
|
438
|
+
if (!open) return { kind: "reply", text: `${at} is not open, so \`/${words.product} ${parsed.word}\` does not run` };
|
|
439
|
+
return { kind: "pipeline", ref: base, variables: { [GITLAB_COMMIT_PR_VAR]: iid, [GITLAB_COMMIT_WORD_VAR]: parsed.word, ...(parsed.arg !== undefined ? { [GITLAB_COMMIT_ARG_VAR]: parsed.arg } : {}) }, doing: `run \`${parsed.word}\` on ${at}` };
|
|
440
|
+
case "action":
|
|
441
|
+
return { kind: "reply", text: `${line("action")} does not run from a merge request note on GitLab: run \`${words.bin ?? words.product} action ${parsed.member} ${parsed.address}\` from a checkout of the default branch` };
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** The directory on `chant/lifecycle` that keeps the notes the poll answered. */
|
|
447
|
+
export const NOTES_DIR = "_notes";
|
|
448
|
+
|
|
449
|
+
/** A note's file in {@link NOTES_DIR}. */
|
|
450
|
+
export function noteFile(mr: number, note: number): string {
|
|
451
|
+
return `${mr}-${note}.json`;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* The notes the poll answered, kept on the local `chant/lifecycle` of `cwd`:
|
|
456
|
+
* one file per note, `_notes/<mr>-<note>.json`, written and pushed as each
|
|
457
|
+
* note is answered. The caller fetches the branch first. `push: false`
|
|
458
|
+
* writes the local branch alone.
|
|
459
|
+
*/
|
|
460
|
+
export function ledgerNoteLog(opts: { cwd?: string; push?: boolean } = {}): NoteLog {
|
|
461
|
+
return {
|
|
462
|
+
async answered(mr, note) {
|
|
463
|
+
const { readBlobFromPath } = await import("./lifecycle/git");
|
|
464
|
+
return (await readBlobFromPath(NOTES_DIR, noteFile(mr, note), opts)) !== null;
|
|
465
|
+
},
|
|
466
|
+
async record(outcome) {
|
|
467
|
+
const { ledgerDir, pushLifecycleRebasing, readPathSha, writeLedgerFiles } = await import("./lifecycle/git");
|
|
468
|
+
const file = noteFile(outcome.mr, outcome.note);
|
|
469
|
+
const dir = await ledgerDir(NOTES_DIR, opts);
|
|
470
|
+
const prior = await readPathSha(NOTES_DIR, file, opts);
|
|
471
|
+
await writeLedgerFiles([{ path: `${dir}/${file}`, content: `${JSON.stringify(outcome)}\n`, expectPriorSha: prior }], `Note ${outcome.note} on !${outcome.mr}`, opts);
|
|
472
|
+
if (opts.push === false) return;
|
|
473
|
+
const pushed = await pushLifecycleRebasing(opts);
|
|
474
|
+
if (pushWarned(pushed)) throw new Error(`answered note ${outcome.note} on !${outcome.mr}, and could not push chant/lifecycle (${pushed.pushWarning})`);
|
|
475
|
+
},
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const pushWarned = (p: { pushed: boolean; pushWarning?: string }): p is { pushed: boolean; pushWarning: string } => !p.pushed && p.pushWarning !== undefined;
|
|
@@ -53,6 +53,8 @@ async function engineSetupFor(path: string): Promise<string[]> {
|
|
|
53
53
|
* `--pr-env` (#4298) adds the jobs of a pull request's environment.
|
|
54
54
|
* `--apply-before-merge` (#4301) writes the apply job that applies an open
|
|
55
55
|
* pull request before it merges, beside the record job.
|
|
56
|
+
* `--note-commands` (#4785) writes GitLab's scheduled job that answers the
|
|
57
|
+
* product's comment commands by polling the merge requests' notes.
|
|
56
58
|
* `--preview-comment` (#4620) writes the jobs that answer the product's plan
|
|
57
59
|
* comment with a preview of the pull request's head. `--action-job` (#4654)
|
|
58
60
|
* writes the job that answers the product's action comment and a dispatch
|
|
@@ -88,6 +90,8 @@ function prLoopOption(args: CommandContext["args"], reportUrl: string | undefine
|
|
|
88
90
|
...(args.actionJob ? { actionJob: true } : {}),
|
|
89
91
|
// #4628: the note carries its target commit, and a push marks the open notes stale.
|
|
90
92
|
...(args.staleNotes ? { staleNotes: true } : {}),
|
|
93
|
+
// #4785: GitLab's scheduled job that answers the comment commands from the merge requests' notes.
|
|
94
|
+
...(args.noteCommands ? { noteCommands: true } : {}),
|
|
91
95
|
...(args.requires ? { applyRequires: args.requires } : {}),
|
|
92
96
|
// #4625: where the jobs run, and what the jobs that plan or apply get.
|
|
93
97
|
...(args.prRunners ? { runners: Object.fromEntries(Object.entries(args.prRunners).map(([stage, labels]) => [stage, labels.length === 1 ? labels[0]! : labels])) } : {}),
|
|
@@ -225,7 +229,9 @@ async function runGenerateComponents(ctx: CommandContext): Promise<number> {
|
|
|
225
229
|
const lexicon = args.generate as string;
|
|
226
230
|
|
|
227
231
|
// #4636, #4629, #4627: the pull request loop's flags are checked before anything loads.
|
|
228
|
-
|
|
232
|
+
// #4785: the note-commands job polls GitLab's notes; GitHub and Forgejo start a workflow on a comment.
|
|
233
|
+
const notesProblem = args.noteCommands && !args.prLoop ? "--note-commands adds a job to the pull request loop, so it needs --pr-loop" : args.noteCommands && lexicon !== "gitlab" ? `--note-commands polls GitLab's merge request notes, and ${lexicon} starts a workflow on a comment; drop --note-commands` : undefined;
|
|
234
|
+
const flagsProblem = notesProblem ?? prLoopFlagsProblem(args);
|
|
229
235
|
if (flagsProblem) {
|
|
230
236
|
console.error(formatError({ message: flagsProblem }));
|
|
231
237
|
return 1;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant components pr-notes --forge gitlab` (#4785): the note-commands job.
|
|
3
|
+
*
|
|
4
|
+
* GitLab starts no pipeline on a note, so a scheduled pipeline of the default
|
|
5
|
+
* branch runs this: it reads the merge requests' notes through chant's forge
|
|
6
|
+
* reads, and for each new command from a Developer or above starts the job
|
|
7
|
+
* that answers it (`../../ci-note-commands.ts`). The flags name the jobs the
|
|
8
|
+
* pipeline has, as `chant build --pr-loop --note-commands` wrote them. Each
|
|
9
|
+
* answered note is recorded on `chant/lifecycle`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { resolve } from "node:path";
|
|
13
|
+
import { activeProductWords } from "../../ci-product-words";
|
|
14
|
+
import { chantNoteRuns, gitlabPipelines, ledgerNoteLog, pollNoteCommands } from "../../ci-note-commands";
|
|
15
|
+
import { forgeFromEnv, forgeTargetFromEnv, type PrForge } from "../../pr-forge";
|
|
16
|
+
import { forgeReadsFor } from "../../pr-forge-reads";
|
|
17
|
+
import { formatError, formatInfo, formatWarning } from "../format";
|
|
18
|
+
import type { CommandContext } from "../registry";
|
|
19
|
+
|
|
20
|
+
const fail = (message: string): number => {
|
|
21
|
+
console.error(formatError({ message }));
|
|
22
|
+
return 1;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export async function runComponentsPrNotes(ctx: CommandContext): Promise<number> {
|
|
26
|
+
const { args } = ctx;
|
|
27
|
+
if (args.forge !== "gitlab") return fail("pr-notes polls GitLab's merge request notes: --forge gitlab (GitHub and Forgejo start a workflow on a comment)");
|
|
28
|
+
const env = process.env;
|
|
29
|
+
const base = args.branch ?? env.CI_DEFAULT_BRANCH;
|
|
30
|
+
if (!base) return fail("pr-notes needs the target branch: --branch <name>, or CI_DEFAULT_BRANCH in the environment");
|
|
31
|
+
let forge: PrForge;
|
|
32
|
+
let target: ReturnType<typeof forgeTargetFromEnv>;
|
|
33
|
+
try {
|
|
34
|
+
forge = forgeFromEnv("gitlab", env);
|
|
35
|
+
target = forgeTargetFromEnv(env, { kind: "gitlab" });
|
|
36
|
+
} catch (err) {
|
|
37
|
+
return fail(err instanceof Error ? err.message : String(err));
|
|
38
|
+
}
|
|
39
|
+
const cwd = resolve(".");
|
|
40
|
+
const { fetchLifecycle } = await import("../../lifecycle/git");
|
|
41
|
+
// The ledger keeps the notes answered: read it as the remote has it.
|
|
42
|
+
await fetchLifecycle({ cwd });
|
|
43
|
+
const words = activeProductWords();
|
|
44
|
+
const polled = await pollNoteCommands({
|
|
45
|
+
reads: forgeReadsFor(target),
|
|
46
|
+
forge,
|
|
47
|
+
pipelines: gitlabPipelines({ apiBase: target.apiBase, project: target.repo, token: target.token, host: target.host, ...(target.tokenHeader ? { tokenHeader: target.tokenHeader } : {}) }),
|
|
48
|
+
words,
|
|
49
|
+
base,
|
|
50
|
+
runs: chantNoteRuns({
|
|
51
|
+
...(args.previewComment ? { preview: true } : {}),
|
|
52
|
+
...(args.applyBeforeMerge ? { applyBeforeMerge: true } : {}),
|
|
53
|
+
...(args.applyOnMerge ? { applyOnMerge: true } : {}),
|
|
54
|
+
...(args.locks ? { locks: true } : {}),
|
|
55
|
+
}),
|
|
56
|
+
log: ledgerNoteLog({ cwd }),
|
|
57
|
+
env,
|
|
58
|
+
});
|
|
59
|
+
let failed = polled.fail !== undefined;
|
|
60
|
+
for (const o of polled.outcomes) {
|
|
61
|
+
const line = `pr-notes: !${o.mr} note ${o.note}: ${o.reason}`;
|
|
62
|
+
if (o.fail) {
|
|
63
|
+
failed = true;
|
|
64
|
+
console.error(formatWarning({ message: line }));
|
|
65
|
+
} else console.error(formatInfo(line));
|
|
66
|
+
}
|
|
67
|
+
if (polled.fail) console.error(formatError({ message: `pr-notes: ${polled.fail}` }));
|
|
68
|
+
if (polled.outcomes.length === 0 && !polled.fail) console.error(formatInfo("pr-notes: no new command"));
|
|
69
|
+
return failed ? 1 : 0;
|
|
70
|
+
}
|
package/src/cli/main.ts
CHANGED
|
@@ -1312,7 +1312,14 @@ Component release ledger + status:
|
|
|
1312
1312
|
--decide-model <id> asks whether the
|
|
1313
1313
|
description leaves out a destroy or a
|
|
1314
1314
|
replacement and posts the finding (#4629)
|
|
1315
|
-
components pr-
|
|
1315
|
+
components pr-notes GitLab (#4785): read the merge requests' notes,
|
|
1316
|
+
and for each new comment command from a
|
|
1317
|
+
Developer or above start the job that answers
|
|
1318
|
+
it (--forge gitlab [--branch <b>]
|
|
1319
|
+
[--preview-comment] [--apply-before-merge]
|
|
1320
|
+
[--apply-on-merge] [--locks]); each answered
|
|
1321
|
+
note is recorded on chant/lifecycle
|
|
1322
|
+
components pr-record On merge (#4168): plan the same members again,
|
|
1316
1323
|
store the change set and write the merge record
|
|
1317
1324
|
_merges/<commit>.json; applies and refuses
|
|
1318
1325
|
nothing, and a plan that differs from the
|
|
@@ -2075,6 +2082,8 @@ export const commandRegistry: CommandDef[] = [
|
|
|
2075
2082
|
{ name: "components apply-wave", requiresPlugins: true, handler: async (ctx) => (await import("./handlers/pr")).runComponentsApplyWave(ctx) },
|
|
2076
2083
|
// #4295: posts from the plan report in a job that runs none of the change's code, so it loads no plugins.
|
|
2077
2084
|
{ name: "components pr-post", handler: async (ctx) => (await import("./handlers/pr")).runComponentsPrPost(ctx) },
|
|
2085
|
+
// #4785: GitLab's comment commands, polled from the notes in a job that runs none of the change's code, so it loads no plugins.
|
|
2086
|
+
{ name: "components pr-notes", handler: async (ctx) => (await import("./handlers/pr-notes")).runComponentsPrNotes(ctx) },
|
|
2078
2087
|
{ name: "components pr-record", requiresPlugins: true, handler: async (ctx) => (await import("./handlers/pr")).runComponentsPrRecord(ctx) },
|
|
2079
2088
|
// #4616: the agent jobs' three steps. Imported on first use; none loads plugins.
|
|
2080
2089
|
{ name: "agent prepare", handler: async (ctx) => (await import("./handlers/agent")).runAgentCommandLine(ctx) },
|
|
@@ -17,7 +17,6 @@ import * as ciProduct from "../../ci-product";
|
|
|
17
17
|
import { reportReader, reportToolKey, safeReportKey } from "./report-tools";
|
|
18
18
|
import type { ToolDefinition } from "./types";
|
|
19
19
|
import type { McpToolContribution } from "../../mcp/types";
|
|
20
|
-
import { NEXT_RELEASE } from "../../release-floors";
|
|
21
20
|
|
|
22
21
|
const tool = (name: string, readOnly?: boolean, handler: McpToolContribution["handler"] = async () => ({ name })): McpToolContribution => ({
|
|
23
22
|
name,
|
|
@@ -223,6 +222,6 @@ describe("tool annotations in tools/list (#4823)", () => {
|
|
|
223
222
|
});
|
|
224
223
|
|
|
225
224
|
test("the floor names the next release", () => {
|
|
226
|
-
expect(ciProduct.MCP_TOOL_ANNOTATIONS_FLOOR).toBe(
|
|
225
|
+
expect(ciProduct.MCP_TOOL_ANNOTATIONS_FLOOR).toBe("0.124.79");
|
|
227
226
|
});
|
|
228
227
|
});
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
import type { McpToolContribution } from "../../mcp/types";
|
|
36
|
-
import { NEXT_RELEASE } from "../../release-floors";
|
|
37
36
|
import { reportReader, reportUrlFor, type ReportReader } from "./report-tools";
|
|
38
37
|
|
|
39
38
|
/** What a product's tools are handed. */
|
|
@@ -84,7 +83,7 @@ export const PRODUCT_MCP_PROPOSE_FLOOR = "0.124.58";
|
|
|
84
83
|
* `annotations`, and `readOnlyHint`/`destructiveHint` from `readOnly: true`
|
|
85
84
|
* or `forgeWrite: true` (chant#4823).
|
|
86
85
|
*/
|
|
87
|
-
export const MCP_TOOL_ANNOTATIONS_FLOOR =
|
|
86
|
+
export const MCP_TOOL_ANNOTATIONS_FLOOR = "0.124.79";
|
|
88
87
|
|
|
89
88
|
/** The words a `forgeWrite` tool's name may hold on the `--propose` tier, which the write-word check passes over (chant#4655). */
|
|
90
89
|
export const PRODUCT_TOOL_PROPOSE_WORDS = ["request", "propose"] as const;
|
package/src/cli/parse-args.ts
CHANGED
|
@@ -20,6 +20,8 @@ import type { ParsedArgs } from "./registry";
|
|
|
20
20
|
const BOOLEAN_FLAGS = new Set([
|
|
21
21
|
"--help",
|
|
22
22
|
"--open",
|
|
23
|
+
"--note-commands",
|
|
24
|
+
"--locks",
|
|
23
25
|
"--version",
|
|
24
26
|
"--agents",
|
|
25
27
|
"--agent",
|
|
@@ -906,6 +908,12 @@ export function parseArgs(args: string[]): ParsedArgs {
|
|
|
906
908
|
const m = /^(op|member|readTokenSecret|tokenSecret|forge|ref|apiBase|sentCheck|markSent)=(.+)$/s.exec(raw);
|
|
907
909
|
if (!m) throw new Error(`--control-setting needs <key>=<value>, the key one of op, member, readTokenSecret, tokenSecret, forge, ref, apiBase, sentCheck, markSent: got "${raw}"`);
|
|
908
910
|
(result.controlSettings ??= {})[m[1]!] = m[2]!;
|
|
911
|
+
} else if (arg === "--note-commands") {
|
|
912
|
+
// `chant build --pr-loop --note-commands` (#4785).
|
|
913
|
+
result.noteCommands = true;
|
|
914
|
+
} else if (arg === "--locks") {
|
|
915
|
+
// `chant components pr-notes --locks` (#4785).
|
|
916
|
+
result.locks = true;
|
|
909
917
|
} else if (arg === "--stale-notes") {
|
|
910
918
|
// `chant build --pr-loop --stale-notes` (#4628).
|
|
911
919
|
result.staleNotes = true;
|