@intentius/chant 0.124.79 → 0.124.80

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.
Files changed (75) hide show
  1. package/dist/ci-note-commands.d.ts +199 -0
  2. package/dist/ci-note-commands.d.ts.map +1 -0
  3. package/dist/ci-note-commands.js +372 -0
  4. package/dist/cli/handlers/build.d.ts.map +1 -1
  5. package/dist/cli/handlers/build.js +7 -1
  6. package/dist/cli/handlers/pr-notes.d.ts +13 -0
  7. package/dist/cli/handlers/pr-notes.d.ts.map +1 -0
  8. package/dist/cli/handlers/pr-notes.js +73 -0
  9. package/dist/cli/main.d.ts.map +1 -1
  10. package/dist/cli/main.js +10 -1
  11. package/dist/cli/mcp/product-tools.d.ts.map +1 -1
  12. package/dist/cli/mcp/product-tools.js +1 -2
  13. package/dist/cli/parse-args.d.ts.map +1 -1
  14. package/dist/cli/parse-args.js +10 -0
  15. package/dist/cli/registry.d.ts +4 -0
  16. package/dist/cli/registry.d.ts.map +1 -1
  17. package/dist/components/capability.d.ts +11 -0
  18. package/dist/components/capability.d.ts.map +1 -1
  19. package/dist/components/pr-pipeline.d.ts +22 -0
  20. package/dist/components/pr-pipeline.d.ts.map +1 -1
  21. package/dist/components/pr-pipeline.js +26 -0
  22. package/dist/components/product-pipeline.d.ts +12 -0
  23. package/dist/components/product-pipeline.d.ts.map +1 -1
  24. package/dist/components/product-pipeline.js +5 -1
  25. package/dist/lifecycle/release-version.d.ts.map +1 -1
  26. package/dist/lifecycle/release-version.js +1 -2
  27. package/dist/op/index.d.ts +2 -2
  28. package/dist/op/index.d.ts.map +1 -1
  29. package/dist/op/index.js +1 -1
  30. package/dist/op/op-waves-after-plan.d.ts +33 -0
  31. package/dist/op/op-waves-after-plan.d.ts.map +1 -1
  32. package/dist/op/op-waves-after-plan.js +41 -3
  33. package/dist/op/op-waves-capability.d.ts +4 -1
  34. package/dist/op/op-waves-capability.d.ts.map +1 -1
  35. package/dist/op/op-waves-capability.js +14 -14
  36. package/dist/op/op-waves-run-hooks.d.ts.map +1 -1
  37. package/dist/op/op-waves-run-hooks.js +1 -2
  38. package/dist/op/op-waves-run.d.ts.map +1 -1
  39. package/dist/op/op-waves-run.js +78 -12
  40. package/dist/pr-forge-reads.d.ts +151 -1
  41. package/dist/pr-forge-reads.d.ts.map +1 -1
  42. package/dist/pr-forge-reads.js +265 -1
  43. package/dist/release-floors.d.ts +15 -1
  44. package/dist/release-floors.d.ts.map +1 -1
  45. package/dist/release-floors.js +17 -3
  46. package/dist/wave-runtime.mjs +272 -272
  47. package/package.json +1 -1
  48. package/src/ci-note-commands.test.ts +377 -0
  49. package/src/ci-note-commands.ts +479 -0
  50. package/src/cli/handlers/build.ts +7 -1
  51. package/src/cli/handlers/pr-notes.ts +70 -0
  52. package/src/cli/main.ts +10 -1
  53. package/src/cli/mcp/product-tools.test.ts +1 -2
  54. package/src/cli/mcp/product-tools.ts +1 -2
  55. package/src/cli/parse-args.ts +8 -0
  56. package/src/cli/registry.ts +4 -0
  57. package/src/components/capability.ts +11 -0
  58. package/src/components/pr-pipeline.ts +35 -0
  59. package/src/components/product-pipeline.test.ts +14 -0
  60. package/src/components/product-pipeline.ts +13 -1
  61. package/src/lifecycle/release-version.ts +1 -2
  62. package/src/op/index.ts +2 -2
  63. package/src/op/op-waves-after-plan-wave.test.ts +2 -3
  64. package/src/op/op-waves-after-plan.ts +61 -3
  65. package/src/op/op-waves-capability.test.ts +3 -1
  66. package/src/op/op-waves-capability.ts +17 -17
  67. package/src/op/op-waves-gate-port.test.ts +232 -0
  68. package/src/op/op-waves-run-hooks.test.ts +2 -3
  69. package/src/op/op-waves-run-hooks.ts +1 -2
  70. package/src/op/op-waves-run.ts +78 -14
  71. package/src/op/op-waves-step-wave.test.ts +3 -4
  72. package/src/pr-forge-reads-compare.test.ts +145 -0
  73. package/src/pr-forge-reads.test.ts +203 -0
  74. package/src/pr-forge-reads.ts +398 -1
  75. package/src/release-floors.ts +24 -3
@@ -0,0 +1,199 @@
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
+ import { type CiProductWords, type ParsedProductComment } from "./ci-product-words.js";
30
+ import { type GitlabForgeOptions, type PrForge } from "./pr-forge.js";
31
+ import type { ForgeReads, PullRequestDetail, PullRequestNote } from "./pr-forge-reads.js";
32
+ export { GITLAB_NOTE_COMMANDS_VAR } from "./components/pr-pipeline.js";
33
+ /** How far back the poll reads: merge requests updated, and notes written, in this many minutes. */
34
+ export declare const NOTE_COMMANDS_WINDOW_MINUTES: number;
35
+ /** How many pipelines of the default branch after the merge commit's are read for a later apply. */
36
+ export declare const NOTE_COMMANDS_NEWER_PIPELINES = 50;
37
+ /** GitLab's roles, least first, as `ForgeReads.permission` names them. */
38
+ export declare const GITLAB_ROLES: readonly ["minimal", "guest", "planner", "reporter", "developer", "maintainer", "owner"];
39
+ /** The marker a reply carries, naming the note it answers: `<!-- <product>:note=<id> -->`, terragucci's own. */
40
+ export declare function noteCommandMarker(product: string, id: number): string;
41
+ /** A pipeline the poll started, or the job it retried. */
42
+ export interface StartedRun {
43
+ id?: number;
44
+ url?: string;
45
+ }
46
+ /** The GitLab writes the poll makes, with the token that may make them. */
47
+ export interface GitlabPipelines {
48
+ /** `POST /projects/:id/pipeline`: a pipeline of `ref` with `variables`. */
49
+ start(ref: string, variables: Readonly<Record<string, string>>): Promise<StartedRun>;
50
+ /** `POST /projects/:id/merge_requests/:iid/pipelines`: a new merge request pipeline, which takes no variables. */
51
+ startMergeRequest(iid: number): Promise<StartedRun>;
52
+ /** `POST /projects/:id/jobs/:job/retry`. */
53
+ retryJob(job: number): Promise<StartedRun>;
54
+ }
55
+ /** The writes for a GitLab client's options. */
56
+ export declare function gitlabPipelines(opts: GitlabForgeOptions): GitlabPipelines;
57
+ /** A command the poll read, from an author with the role it needs. */
58
+ export interface NoteCommand {
59
+ mr: PullRequestDetail;
60
+ note: PullRequestNote;
61
+ /** The command, never `refused`: a refusal is answered with its reason first. */
62
+ parsed: Exclude<ParsedProductComment, {
63
+ kind: "refused";
64
+ }>;
65
+ /** The author's role on the project. */
66
+ role: string;
67
+ /** The default branch. */
68
+ base: string;
69
+ words: CiProductWords;
70
+ }
71
+ /** What a command runs. */
72
+ export type NoteRun =
73
+ /** A pipeline of `ref` started with `variables`; `doing` finishes the reply's "started pipeline <url> to ...". */
74
+ {
75
+ kind: "pipeline";
76
+ ref: string;
77
+ variables: Record<string, string>;
78
+ doing: string;
79
+ with?: GitlabPipelines;
80
+ }
81
+ /** A new merge request pipeline of the note's merge request. */
82
+ | {
83
+ kind: "merge-request-pipeline";
84
+ doing: string;
85
+ }
86
+ /**
87
+ * The retry of the first job `jobs` matches that did not succeed, in the
88
+ * newest push pipeline at `sha` (a merged merge request's merge commit)
89
+ * that has such a job. Refused when a later commit of the default branch
90
+ * already carries the product's apply status.
91
+ */
92
+ | {
93
+ kind: "retry";
94
+ sha: string;
95
+ jobs?: RegExp;
96
+ }
97
+ /** A reply, and nothing runs. */
98
+ | {
99
+ kind: "reply";
100
+ text: string;
101
+ }
102
+ /** Something broke: the note gets no reply and is read again next poll. */
103
+ | {
104
+ kind: "fail";
105
+ reason: string;
106
+ };
107
+ /** The product's answer to a command. */
108
+ export type NoteCommandRuns = (c: NoteCommand) => NoteRun | Promise<NoteRun>;
109
+ /** What the poll did with one note. */
110
+ export interface NoteOutcome {
111
+ mr: number;
112
+ note: number;
113
+ author?: string;
114
+ /** The command's kind, when the note parsed as one. */
115
+ command?: string;
116
+ /** True when a pipeline was started or a job retried. */
117
+ ran: boolean;
118
+ /** False when the note got no reply (an author without the role, or a failure). */
119
+ replied: boolean;
120
+ /** True when something broke (a forge answer), not because the note asked for nothing. */
121
+ fail?: boolean;
122
+ reason: string;
123
+ /** The pipeline or job started. */
124
+ url?: string;
125
+ /** When the poll answered it (ISO 8601). */
126
+ at: string;
127
+ }
128
+ /** Where the poll keeps the notes it answered. */
129
+ export interface NoteLog {
130
+ answered(mr: number, note: number): Promise<boolean>;
131
+ /** 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. */
132
+ record(outcome: NoteOutcome): Promise<void>;
133
+ }
134
+ /** A log in memory, for tests and a dry run. */
135
+ export declare function memoryNoteLog(seen?: NoteOutcome[]): NoteLog & {
136
+ outcomes: NoteOutcome[];
137
+ };
138
+ export interface NoteCommandsOptions {
139
+ reads: ForgeReads;
140
+ /** chant's client, holding the job's token: it posts the replies and reads the statuses. */
141
+ forge: PrForge;
142
+ /** The writes, with the token that may start pipelines on the default branch. */
143
+ pipelines: GitlabPipelines;
144
+ words: CiProductWords;
145
+ /** The default branch. */
146
+ base: string;
147
+ runs: NoteCommandRuns;
148
+ log: NoteLog;
149
+ /** The least role that may ask. Default `developer`. */
150
+ minRole?: (typeof GITLAB_ROLES)[number];
151
+ /** The poll's clock. Default: now. */
152
+ now?: Date;
153
+ windowMinutes?: number;
154
+ /** The job's environment, for the words' aliases. */
155
+ env?: Record<string, string | undefined>;
156
+ /** The commit words that take an argument, as `parseProductComment` takes them. */
157
+ commitArgs?: Readonly<Record<string, RegExp>>;
158
+ }
159
+ export interface NotePoll {
160
+ outcomes: NoteOutcome[];
161
+ /** Set when the poll could not list the merge requests or a merge request's notes. */
162
+ fail?: string;
163
+ }
164
+ /** Read, answer and record every new command note of the merge requests updated in the window. */
165
+ export declare function pollNoteCommands(o: NoteCommandsOptions): Promise<NotePoll>;
166
+ /** chant's apply jobs and terragucci's: `apply`, `apply-wave-<n>` and `apply-wave-<n>-share-<m>`, a member's prefixed with its name. */
167
+ export declare const APPLY_JOBS: RegExp;
168
+ /** The jobs chant's GitLab pipeline has, which {@link chantNoteRuns} starts. */
169
+ export interface ChantNoteJobs {
170
+ /** The comment preview (`--preview-comment`): a plan starts it with `CHANT_PREVIEW_PR`. Without it a plan starts a merge request pipeline. */
171
+ preview?: boolean;
172
+ /** The apply before merge (`--apply-before-merge`), started with `CHANT_APPLY_PR`. */
173
+ applyBeforeMerge?: boolean;
174
+ /** The apply on merge (`--apply-on-merge`, waves): an apply on a merged merge request retries its first apply job that did not succeed. */
175
+ applyOnMerge?: boolean;
176
+ /** The lock and unlock jobs (`ci.locks: plan`), started with `CHANT_LOCK_PR` and `CHANT_UNLOCK_PR`. */
177
+ locks?: boolean;
178
+ /** The agent's jobs, started with `CHANT_AGENT_PR` and `CHANT_AGENT_ASK`. */
179
+ agent?: boolean;
180
+ /** The commit jobs, started with `CHANT_COMMIT_PR`, `CHANT_COMMIT` and `CHANT_COMMIT_ARG`. */
181
+ commits?: boolean;
182
+ }
183
+ /** What a command runs in chant's own GitLab pipeline, for the jobs it has. */
184
+ export declare function chantNoteRuns(jobs: ChantNoteJobs): NoteCommandRuns;
185
+ /** The directory on `chant/lifecycle` that keeps the notes the poll answered. */
186
+ export declare const NOTES_DIR = "_notes";
187
+ /** A note's file in {@link NOTES_DIR}. */
188
+ export declare function noteFile(mr: number, note: number): string;
189
+ /**
190
+ * The notes the poll answered, kept on the local `chant/lifecycle` of `cwd`:
191
+ * one file per note, `_notes/<mr>-<note>.json`, written and pushed as each
192
+ * note is answered. The caller fetches the branch first. `push: false`
193
+ * writes the local branch alone.
194
+ */
195
+ export declare function ledgerNoteLog(opts?: {
196
+ cwd?: string;
197
+ push?: boolean;
198
+ }): NoteLog;
199
+ //# sourceMappingURL=ci-note-commands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ci-note-commands.d.ts","sourceRoot":"","sources":["../src/ci-note-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAIH,OAAO,EAA6C,KAAK,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/H,OAAO,EAAkC,KAAK,kBAAkB,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AACnG,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,eAAe,EAAuB,MAAM,kBAAkB,CAAC;AAE5G,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,oGAAoG;AACpG,eAAO,MAAM,4BAA4B,QAAU,CAAC;AAEpD,oGAAoG;AACpG,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD,0EAA0E;AAC1E,eAAO,MAAM,YAAY,YAAI,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,CAAU,CAAC;AAErH,gHAAgH;AAChH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,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C,EAAE,OAAO,CAAC;IAChB,8FAA8F;IAC9F,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,IAAI,EAAE,aAAa,GAAG,eAAe,CA6ClE;AAED,iFAAiF;AACjF,eAAO,MAAM,SAAS,WAAW,CAAC;AAElC,0CAA0C;AAC1C,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,OAAO,CAiBlF"}
@@ -0,0 +1,372 @@
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
+ import { GITLAB_AGENT_ASK_VAR, GITLAB_AGENT_PR_VAR } from "./ci-agent.js";
30
+ import { GITLAB_COMMIT_ARG_VAR, GITLAB_COMMIT_PR_VAR, GITLAB_COMMIT_WORD_VAR } from "./ci-commit.js";
31
+ import { parseProductComment, productStatusContext } from "./ci-product-words.js";
32
+ import { GITLAB_APPLY_PR_VAR, GITLAB_LOCK_PR_VAR, GITLAB_PREVIEW_PR_VAR, GITLAB_UNLOCK_PR_VAR, PREVIEW_COMMENT_ENV } from "./components/pr-pipeline.js";
33
+ import { ForgeApiError } from "./pr-forge.js";
34
+ export { GITLAB_NOTE_COMMANDS_VAR } from "./components/pr-pipeline.js";
35
+ /** How far back the poll reads: merge requests updated, and notes written, in this many minutes. */
36
+ export const NOTE_COMMANDS_WINDOW_MINUTES = 24 * 60;
37
+ /** How many pipelines of the default branch after the merge commit's are read for a later apply. */
38
+ export const NOTE_COMMANDS_NEWER_PIPELINES = 50;
39
+ /** GitLab's roles, least first, as `ForgeReads.permission` names them. */
40
+ export const GITLAB_ROLES = ["minimal", "guest", "planner", "reporter", "developer", "maintainer", "owner"];
41
+ /** The marker a reply carries, naming the note it answers: `<!-- <product>:note=<id> -->`, terragucci's own. */
42
+ export function noteCommandMarker(product, id) {
43
+ return `<!-- ${product}:note=${id} -->`;
44
+ }
45
+ /** The writes for a GitLab client's options. */
46
+ export function gitlabPipelines(opts) {
47
+ const fetchImpl = opts.fetch ?? globalThis.fetch;
48
+ const root = opts.apiBase.replace(/\/+$/, "");
49
+ const project = `/projects/${encodeURIComponent(decodeURIComponent(opts.project))}`;
50
+ const headers = { "Content-Type": "application/json", ...(opts.token ? { [opts.tokenHeader ?? "PRIVATE-TOKEN"]: opts.token } : {}) };
51
+ const post = async (path, body) => {
52
+ const url = `${root}${project}${path}`;
53
+ const res = await fetchImpl(url, { method: "POST", headers, ...(body === undefined ? {} : { body: JSON.stringify(body) }) });
54
+ const text = await res.text();
55
+ if (!res.ok)
56
+ throw new ForgeApiError("POST", url, res.status, text);
57
+ let v;
58
+ try {
59
+ v = text ? JSON.parse(text) : null;
60
+ }
61
+ catch {
62
+ v = null;
63
+ }
64
+ const o = typeof v === "object" && v !== null ? v : {};
65
+ return { ...(typeof o.id === "number" ? { id: o.id } : {}), ...(typeof o.web_url === "string" && /^https?:\/\//.test(o.web_url) ? { url: o.web_url } : {}) };
66
+ };
67
+ return {
68
+ start: (ref, variables) => post("/pipeline", { ref, variables: Object.entries(variables).map(([key, value]) => ({ key, value, variable_type: "env_var" })) }),
69
+ startMergeRequest: (iid) => post(`/merge_requests/${iid}/pipelines`),
70
+ retryJob: (job) => post(`/jobs/${job}/retry`),
71
+ };
72
+ }
73
+ /** A log in memory, for tests and a dry run. */
74
+ export function memoryNoteLog(seen = []) {
75
+ return {
76
+ outcomes: seen,
77
+ answered: async (mr, note) => seen.some((o) => o.mr === mr && o.note === note),
78
+ record: async (o) => void seen.push(o),
79
+ };
80
+ }
81
+ const short = (sha) => sha.slice(0, 8);
82
+ const message = (e) => (e instanceof Error ? e.message : String(e)).split("\n")[0];
83
+ /** Read, answer and record every new command note of the merge requests updated in the window. */
84
+ export async function pollNoteCommands(o) {
85
+ const now = o.now ?? new Date();
86
+ const since = new Date(now.getTime() - (o.windowMinutes ?? NOTE_COMMANDS_WINDOW_MINUTES) * 60000).toISOString();
87
+ const at = now.toISOString();
88
+ const least = GITLAB_ROLES.indexOf(o.minRole ?? "developer");
89
+ let me;
90
+ let mrs;
91
+ try {
92
+ me = await o.reads.tokenUser();
93
+ mrs = await o.reads.pullRequestsUpdated(since);
94
+ }
95
+ catch (e) {
96
+ return { outcomes: [], fail: `could not list the merge requests (${message(e)})` };
97
+ }
98
+ if (!me)
99
+ return { outcomes: [], fail: "GitLab did not say which user the job's token acts as, so no reply can be told apart" };
100
+ const mine = (n) => (me.id !== undefined && n.authorId === me.id) || n.author === me.login;
101
+ const marker = new RegExp(`<!-- ${o.words.product.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}:note=(\\d+) -->`, "g");
102
+ const outcomes = [];
103
+ let unrecorded;
104
+ for (const mr of mrs) {
105
+ let notes;
106
+ try {
107
+ notes = await o.reads.pullRequestNotes(mr.number);
108
+ }
109
+ catch (e) {
110
+ return { outcomes, fail: `could not read the notes of !${mr.number} (${message(e)})${unrecorded ? `; and ${unrecorded}` : ""}` };
111
+ }
112
+ // Only the job's own replies mark a note answered: anyone else writing the marker answers nothing.
113
+ const replied = new Set();
114
+ for (const n of notes)
115
+ if (mine(n))
116
+ for (const m of n.body.matchAll(marker))
117
+ replied.add(Number(m[1]));
118
+ const asks = notes
119
+ .filter((n) => !n.system && !mine(n) && !replied.has(n.id) && n.created !== undefined && Date.parse(n.created) >= Date.parse(since))
120
+ .filter((n) => parseProductComment(o.words, n.body, o.env ?? {}, o.commitArgs ?? {}) !== undefined)
121
+ .sort((a, b) => Date.parse(a.created) - Date.parse(b.created) || a.id - b.id);
122
+ for (const note of asks) {
123
+ if (await o.log.answered(mr.number, note.id))
124
+ continue;
125
+ const out = await answer(o, mr, note, least, at, me.login);
126
+ if (out.ran || out.replied || !out.fail) {
127
+ try {
128
+ await o.log.record(out);
129
+ }
130
+ catch (e) {
131
+ // The reply's marker still answers the note once.
132
+ unrecorded = `could not record note ${note.id} of !${mr.number} on the ledger (${message(e)})`;
133
+ }
134
+ }
135
+ outcomes.push(out);
136
+ }
137
+ }
138
+ return { outcomes, ...(unrecorded ? { fail: unrecorded } : {}) };
139
+ }
140
+ async function answer(o, mr, note, least, at, me) {
141
+ const parsed = parseProductComment(o.words, note.body, o.env ?? {}, o.commitArgs ?? {});
142
+ const base = { mr: mr.number, note: note.id, ...(note.author ? { author: note.author } : {}), ...(parsed.kind !== "refused" ? { command: parsed.kind } : {}), at };
143
+ const marker = noteCommandMarker(o.words.product, note.id);
144
+ const reply = async (text, ran = false, url) => {
145
+ const done = { ...base, ran, ...(url ? { url } : {}) };
146
+ try {
147
+ // One reply per note, found again by its marker.
148
+ await o.forge.upsertComment(mr.number, marker, `${o.words.product}: ${text}\n\n${marker}`, { match: "anywhere", author: me });
149
+ }
150
+ catch (e) {
151
+ return { ...done, replied: false, fail: true, reason: `${text}; and the reply failed (${message(e)})` };
152
+ }
153
+ return { ...done, replied: true, reason: text };
154
+ };
155
+ const broke = (reason) => ({ ...base, ran: false, replied: false, fail: true, reason });
156
+ const silent = (reason) => ({ ...base, ran: false, replied: false, reason });
157
+ // Who asked comes first: someone below the role gets no reply and nothing runs.
158
+ if (!note.author)
159
+ return silent("the note has no usable author");
160
+ let role;
161
+ try {
162
+ role = await o.reads.permission(note.author);
163
+ }
164
+ catch (e) {
165
+ return broke(`could not read ${note.author}'s access, so nothing runs (${message(e)})`);
166
+ }
167
+ if (role === undefined)
168
+ return silent(`${note.author} is not a member of the project, so the note is ignored`);
169
+ const level = GITLAB_ROLES.indexOf(role);
170
+ if (level < least)
171
+ return silent(`${note.author} is ${role} on the project, below ${GITLAB_ROLES[least]}, so the note is ignored`);
172
+ if (parsed.kind === "refused")
173
+ return reply(parsed.reason);
174
+ let run;
175
+ try {
176
+ run = await o.runs({ mr, note, parsed, role, base: o.base, words: o.words });
177
+ }
178
+ catch (e) {
179
+ return broke(`could not decide what ${note.author}'s command runs (${message(e)})`);
180
+ }
181
+ const link = (r) => (r.url ? ` ${r.url}` : "");
182
+ switch (run.kind) {
183
+ case "reply":
184
+ return reply(run.text);
185
+ case "fail":
186
+ return broke(run.reason);
187
+ case "pipeline": {
188
+ let started;
189
+ try {
190
+ started = await (run.with ?? o.pipelines).start(run.ref, run.variables);
191
+ }
192
+ catch (e) {
193
+ return broke(`could not start a pipeline on ${run.ref} for !${mr.number} (${message(e)})`);
194
+ }
195
+ return reply(`started pipeline${link(started)} on ${run.ref} to ${run.doing} for ${note.author}`, true, started.url);
196
+ }
197
+ case "merge-request-pipeline": {
198
+ let started;
199
+ try {
200
+ started = await o.pipelines.startMergeRequest(mr.number);
201
+ }
202
+ catch (e) {
203
+ return broke(`could not start a pipeline for !${mr.number} (${message(e)})`);
204
+ }
205
+ return reply(`started pipeline${link(started)} to ${run.doing} for ${note.author}`, true, started.url);
206
+ }
207
+ case "retry":
208
+ return retry(o, mr, note.author, run, reply, broke);
209
+ }
210
+ }
211
+ /** chant's apply jobs and terragucci's: `apply`, `apply-wave-<n>` and `apply-wave-<n>-share-<m>`, a member's prefixed with its name. */
212
+ export const APPLY_JOBS = /^(?:[a-z0-9][a-z0-9-]*-)?apply(?:-wave-([1-9][0-9]*)(?:-share-([1-9][0-9]*))?)?$/;
213
+ const NOT_DONE = new Set(["created", "pending", "running", "waiting_for_resource", "preparing", "scheduled"]);
214
+ async function retry(o, mr, user, run, reply, broke) {
215
+ const { sha } = run;
216
+ const pattern = run.jobs ?? APPLY_JOBS;
217
+ const iid = mr.number;
218
+ // The newest push pipeline at the merge commit with an apply job: a branch pipeline, or a ci/green tag's.
219
+ let pipeline;
220
+ let jobs = [];
221
+ let newer;
222
+ try {
223
+ for (const p of await o.reads.headRuns(sha, { event: "push" })) {
224
+ const js = (await o.reads.runJobs(p.id)).filter((j) => pattern.test(j.name));
225
+ if (js.length > 0) {
226
+ pipeline = p;
227
+ jobs = js;
228
+ break;
229
+ }
230
+ }
231
+ if (!pipeline)
232
+ 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`);
233
+ newer = await o.reads.branchRuns(o.base, { event: "push", limit: NOTE_COMMANDS_NEWER_PIPELINES });
234
+ }
235
+ catch (e) {
236
+ return broke(`could not read the pipelines at ${short(sha)} (${message(e)})`);
237
+ }
238
+ // A later commit whose apply started applied a newer tree: going back to this one would undo it.
239
+ const applyContext = productStatusContext(o.words, "apply");
240
+ const later = [...new Set(newer.filter((p) => p.id > pipeline.id && p.headSha !== sha).map((p) => p.headSha))];
241
+ for (const c of later) {
242
+ let applied;
243
+ try {
244
+ applied = (await o.forge.commitStatuses?.(c))?.find((s) => s.context === applyContext);
245
+ }
246
+ catch (e) {
247
+ return broke(`could not read the statuses of ${short(c)} (${message(e)})`);
248
+ }
249
+ if (applied) {
250
+ const at = applied.targetUrl && /^https?:\/\//.test(applied.targetUrl) ? ` (${applied.targetUrl})` : "";
251
+ 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`);
252
+ }
253
+ }
254
+ const order = (j) => {
255
+ const m = pattern.exec(j.name);
256
+ return [m?.[1] ? Number(m[1]) : 0, m?.[2] ? Number(m[2]) : 0];
257
+ };
258
+ const sorted = [...jobs].sort((a, b) => order(a)[0] - order(b)[0] || order(a)[1] - order(b)[1]);
259
+ const next = sorted.find((j) => j.status !== "success");
260
+ if (!next)
261
+ return reply(`every apply job of !${iid}'s merge commit ${short(sha)} already succeeded`);
262
+ if (NOT_DONE.has(next.status))
263
+ return reply(`${next.name} at ${short(sha)} is ${next.status} already, so it is not retried`);
264
+ if (next.status !== "failed" && next.status !== "canceled") {
265
+ return reply(`${next.name} at ${short(sha)} was ${next.status}, and GitLab retries only a failed or canceled job; push to ${o.base} again`);
266
+ }
267
+ let retried;
268
+ try {
269
+ retried = await o.pipelines.retryJob(next.id);
270
+ }
271
+ catch (e) {
272
+ return broke(`could not retry ${next.name} of pipeline ${pipeline.id} (${message(e)})`);
273
+ }
274
+ const link = retried.url ? ` (${retried.url})` : "";
275
+ 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);
276
+ }
277
+ /** What a command runs in chant's own GitLab pipeline, for the jobs it has. */
278
+ export function chantNoteRuns(jobs) {
279
+ return ({ mr, note, parsed, base, words }) => {
280
+ const iid = String(mr.number);
281
+ const at = `!${mr.number}`;
282
+ const line = (kind) => `\`/${words.product} ${Object.entries(words.commands).find(([, c]) => c === kind)?.[0] ?? kind}\``;
283
+ if (!mr.sameRepo)
284
+ return { kind: "reply", text: `a merge request from a fork runs no command: its code never runs with this project's credentials` };
285
+ const open = mr.state === "open";
286
+ const intoBase = mr.base === undefined || mr.base === base;
287
+ switch (parsed.kind) {
288
+ case "plan":
289
+ if (!open)
290
+ return { kind: "reply", text: `${at} is not open, so it is not ${words.verbs.plan[1]}` };
291
+ if (jobs.preview)
292
+ 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` };
293
+ return { kind: "merge-request-pipeline", doing: `${words.verbs.plan[0]} ${at} again` };
294
+ case "apply":
295
+ if (open) {
296
+ if (!jobs.applyBeforeMerge)
297
+ 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` };
298
+ if (!intoBase)
299
+ return { kind: "reply", text: `${at} targets ${mr.base}, not the default branch ${base}, so it is not ${words.verbs.apply[1]}` };
300
+ return { kind: "pipeline", ref: base, variables: { [GITLAB_APPLY_PR_VAR]: iid }, doing: `${words.verbs.apply[0]} ${at}'s head${mr.headSha ? ` ${short(mr.headSha)}` : ""}` };
301
+ }
302
+ if (mr.state === "closed")
303
+ return { kind: "reply", text: `${at} was closed without merging, so there is nothing of it to ${words.verbs.apply[0]}` };
304
+ if (!jobs.applyOnMerge) {
305
+ 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` };
306
+ }
307
+ if (parsed.wave !== undefined)
308
+ 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` };
309
+ if (!intoBase)
310
+ return { kind: "reply", text: `${at} was merged into ${mr.base}, not the default branch ${base}, so nothing applies from it` };
311
+ if (!mr.mergeCommit)
312
+ return { kind: "fail", reason: `${at} has no merge commit` };
313
+ return { kind: "retry", sha: mr.mergeCommit };
314
+ case "lock":
315
+ case "unlock":
316
+ if (!jobs.locks)
317
+ return { kind: "reply", text: `${line(parsed.kind)} does not run here: this project takes no locks` };
318
+ if (parsed.kind === "lock" && !open)
319
+ return { kind: "reply", text: `${at} is not open, so it takes no lock` };
320
+ 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}` };
321
+ case "agent":
322
+ if (!jobs.agent)
323
+ return { kind: "reply", text: `the agent command is off in this project` };
324
+ if (!open)
325
+ return { kind: "reply", text: `${at} is not open, so the agent does not run` };
326
+ if (mr.head === base)
327
+ return { kind: "reply", text: `${at}'s source branch is the default branch, and an agent never pushes there` };
328
+ return { kind: "pipeline", ref: base, variables: { [GITLAB_AGENT_PR_VAR]: iid, [GITLAB_AGENT_ASK_VAR]: parsed.ask }, doing: `run the agent on ${at}` };
329
+ case "commit":
330
+ if (!jobs.commits)
331
+ return { kind: "reply", text: `\`/${words.product} ${parsed.word}\` does not run here` };
332
+ if (!open)
333
+ return { kind: "reply", text: `${at} is not open, so \`/${words.product} ${parsed.word}\` does not run` };
334
+ 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}` };
335
+ case "action":
336
+ 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` };
337
+ }
338
+ };
339
+ }
340
+ /** The directory on `chant/lifecycle` that keeps the notes the poll answered. */
341
+ export const NOTES_DIR = "_notes";
342
+ /** A note's file in {@link NOTES_DIR}. */
343
+ export function noteFile(mr, note) {
344
+ return `${mr}-${note}.json`;
345
+ }
346
+ /**
347
+ * The notes the poll answered, kept on the local `chant/lifecycle` of `cwd`:
348
+ * one file per note, `_notes/<mr>-<note>.json`, written and pushed as each
349
+ * note is answered. The caller fetches the branch first. `push: false`
350
+ * writes the local branch alone.
351
+ */
352
+ export function ledgerNoteLog(opts = {}) {
353
+ return {
354
+ async answered(mr, note) {
355
+ const { readBlobFromPath } = await import("./lifecycle/git.js");
356
+ return (await readBlobFromPath(NOTES_DIR, noteFile(mr, note), opts)) !== null;
357
+ },
358
+ async record(outcome) {
359
+ const { ledgerDir, pushLifecycleRebasing, readPathSha, writeLedgerFiles } = await import("./lifecycle/git.js");
360
+ const file = noteFile(outcome.mr, outcome.note);
361
+ const dir = await ledgerDir(NOTES_DIR, opts);
362
+ const prior = await readPathSha(NOTES_DIR, file, opts);
363
+ await writeLedgerFiles([{ path: `${dir}/${file}`, content: `${JSON.stringify(outcome)}\n`, expectPriorSha: prior }], `Note ${outcome.note} on !${outcome.mr}`, opts);
364
+ if (opts.push === false)
365
+ return;
366
+ const pushed = await pushLifecycleRebasing(opts);
367
+ if (pushWarned(pushed))
368
+ throw new Error(`answered note ${outcome.note} on !${outcome.mr}, and could not push chant/lifecycle (${pushed.pushWarning})`);
369
+ },
370
+ };
371
+ }
372
+ const pushWarned = (p) => !p.pushed && p.pushWarning !== undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/cli/handlers/build.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAqGlD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,kBAAkB,GAAG,OAAO,GAAG,eAAe,GAAG,aAAa,GAAG,SAAS,GAAG,eAAe,GAAG,aAAa,GAAG,kBAAkB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,iBAAiB,CAAC,CAAC,GAAG,MAAM,GAAG,SAAS,CAgClT;AAoTD,wBAAsB,QAAQ,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAsJnE"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/cli/handlers/build.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAyGlD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,kBAAkB,GAAG,OAAO,GAAG,eAAe,GAAG,aAAa,GAAG,SAAS,GAAG,eAAe,GAAG,aAAa,GAAG,kBAAkB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,iBAAiB,CAAC,CAAC,GAAG,MAAM,GAAG,SAAS,CAgClT;AAsTD,wBAAsB,QAAQ,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAsJnE"}
@@ -51,6 +51,8 @@ async function engineSetupFor(path) {
51
51
  * `--pr-env` (#4298) adds the jobs of a pull request's environment.
52
52
  * `--apply-before-merge` (#4301) writes the apply job that applies an open
53
53
  * pull request before it merges, beside the record job.
54
+ * `--note-commands` (#4785) writes GitLab's scheduled job that answers the
55
+ * product's comment commands by polling the merge requests' notes.
54
56
  * `--preview-comment` (#4620) writes the jobs that answer the product's plan
55
57
  * comment with a preview of the pull request's head. `--action-job` (#4654)
56
58
  * writes the job that answers the product's action comment and a dispatch
@@ -86,6 +88,8 @@ function prLoopOption(args, reportUrl, requireReview = false, requireRunnerStart
86
88
  ...(args.actionJob ? { actionJob: true } : {}),
87
89
  // #4628: the note carries its target commit, and a push marks the open notes stale.
88
90
  ...(args.staleNotes ? { staleNotes: true } : {}),
91
+ // #4785: GitLab's scheduled job that answers the comment commands from the merge requests' notes.
92
+ ...(args.noteCommands ? { noteCommands: true } : {}),
89
93
  ...(args.requires ? { applyRequires: args.requires } : {}),
90
94
  // #4625: where the jobs run, and what the jobs that plan or apply get.
91
95
  ...(args.prRunners ? { runners: Object.fromEntries(Object.entries(args.prRunners).map(([stage, labels]) => [stage, labels.length === 1 ? labels[0] : labels])) } : {}),
@@ -241,7 +245,9 @@ async function runGenerateComponents(ctx) {
241
245
  const { args } = ctx;
242
246
  const lexicon = args.generate;
243
247
  // #4636, #4629, #4627: the pull request loop's flags are checked before anything loads.
244
- const flagsProblem = prLoopFlagsProblem(args);
248
+ // #4785: the note-commands job polls GitLab's notes; GitHub and Forgejo start a workflow on a comment.
249
+ 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;
250
+ const flagsProblem = notesProblem ?? prLoopFlagsProblem(args);
245
251
  if (flagsProblem) {
246
252
  console.error(formatError({ message: flagsProblem }));
247
253
  return 1;
@@ -0,0 +1,13 @@
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
+ import type { CommandContext } from "../registry.js";
12
+ export declare function runComponentsPrNotes(ctx: CommandContext): Promise<number>;
13
+ //# sourceMappingURL=pr-notes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pr-notes.d.ts","sourceRoot":"","sources":["../../../src/cli/handlers/pr-notes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAOlD,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CA6C/E"}