@intentius/chant 0.124.88 → 0.124.89
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/actor.d.ts +36 -1
- package/dist/actor.d.ts.map +1 -1
- package/dist/actor.js +39 -1
- package/dist/chant-install.d.ts.map +1 -1
- package/dist/chant-install.js +1 -2
- package/dist/ci-base.d.ts +30 -0
- package/dist/ci-base.d.ts.map +1 -0
- package/dist/ci-base.js +33 -0
- package/dist/ci-comment-commands.d.ts +177 -0
- package/dist/ci-comment-commands.d.ts.map +1 -0
- package/dist/ci-comment-commands.js +325 -0
- package/dist/ci-comment-replies.d.ts +40 -0
- package/dist/ci-comment-replies.d.ts.map +1 -0
- package/dist/ci-comment-replies.js +59 -0
- package/dist/ci-evidence-from-job.d.ts +25 -0
- package/dist/ci-evidence-from-job.d.ts.map +1 -1
- package/dist/ci-evidence-from-job.js +43 -2
- package/dist/ci-evidence-jobs.d.ts +30 -1
- package/dist/ci-evidence-jobs.d.ts.map +1 -1
- package/dist/ci-evidence-jobs.js +46 -3
- package/dist/ci-image.d.ts +21 -4
- package/dist/ci-image.d.ts.map +1 -1
- package/dist/ci-image.js +62 -10
- package/dist/ci-note-commands.d.ts +63 -3
- package/dist/ci-note-commands.d.ts.map +1 -1
- package/dist/ci-note-commands.js +69 -35
- package/dist/ci-product-words.d.ts +42 -0
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +25 -0
- package/dist/ci-product.d.ts +31 -0
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +34 -4
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +29 -2
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +2 -1
- package/dist/cli/handlers/ci-check.d.ts +1 -1
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +17 -7
- package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
- package/dist/cli/handlers/ci-evidence.js +33 -7
- package/dist/cli/handlers/components.d.ts.map +1 -1
- package/dist/cli/handlers/components.js +3 -1
- package/dist/cli/handlers/generated-check.d.ts +8 -0
- package/dist/cli/handlers/generated-check.d.ts.map +1 -1
- package/dist/cli/handlers/generated-check.js +31 -1
- package/dist/cli/handlers/lock.d.ts.map +1 -1
- package/dist/cli/handlers/lock.js +121 -4
- package/dist/cli/handlers/pr-comment.d.ts +21 -0
- package/dist/cli/handlers/pr-comment.d.ts.map +1 -0
- package/dist/cli/handlers/pr-comment.js +112 -0
- package/dist/cli/handlers/pr-env.d.ts.map +1 -1
- package/dist/cli/handlers/pr-env.js +6 -3
- package/dist/cli/handlers/pr.d.ts +23 -1
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +55 -9
- package/dist/cli/handlers/promote.d.ts.map +1 -1
- package/dist/cli/handlers/promote.js +2 -1
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +11 -2
- package/dist/cli/handlers/run-wave.d.ts.map +1 -1
- package/dist/cli/handlers/run-wave.js +28 -2
- package/dist/cli/handlers/run.d.ts.map +1 -1
- package/dist/cli/handlers/run.js +2 -1
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +24 -2
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +16 -0
- package/dist/cli/registry.d.ts +11 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/auto-release.d.ts.map +1 -1
- package/dist/components/auto-release.js +2 -1
- package/dist/components/pr-checks.d.ts +70 -6
- package/dist/components/pr-checks.d.ts.map +1 -1
- package/dist/components/pr-checks.js +74 -13
- package/dist/components/pr-pipeline.d.ts +16 -12
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +3 -11
- package/dist/components/product-pipeline.d.ts +42 -1
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +64 -12
- package/dist/components/product-plan.d.ts +190 -5
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +220 -39
- package/dist/drift-record.d.ts +7 -0
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/drift-record.js +19 -0
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +54 -31
- package/dist/forge-check/contract.d.ts +11 -1
- package/dist/forge-check/contract.d.ts.map +1 -1
- package/dist/forge-check/contract.js +4 -1
- package/dist/forge-check/index.d.ts +2 -0
- package/dist/forge-check/index.d.ts.map +1 -1
- package/dist/forge-check/index.js +2 -0
- package/dist/gate-resume-run.d.ts +9 -1
- package/dist/gate-resume-run.d.ts.map +1 -1
- package/dist/gate-resume-run.js +26 -3
- package/dist/generated-check.d.ts +18 -4
- package/dist/generated-check.d.ts.map +1 -1
- package/dist/generated-check.js +37 -5
- package/dist/image-pins.d.ts +26 -0
- package/dist/image-pins.d.ts.map +1 -0
- package/dist/image-pins.js +19 -0
- package/dist/lexicon.d.ts +11 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/git.d.ts +11 -0
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +30 -3
- package/dist/lifecycle/publish-npm.d.ts +11 -0
- package/dist/lifecycle/publish-npm.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.js +27 -1
- package/dist/lifecycle/reach-locks.d.ts +131 -0
- package/dist/lifecycle/reach-locks.d.ts.map +1 -0
- package/dist/lifecycle/reach-locks.js +118 -0
- package/dist/lifecycle/release-cut.d.ts +3 -1
- package/dist/lifecycle/release-cut.d.ts.map +1 -1
- package/dist/lifecycle/release-cut.js +15 -0
- package/dist/lifecycle/release-images.d.ts.map +1 -1
- package/dist/lifecycle/release-images.js +1 -2
- package/dist/notify-product.d.ts +12 -3
- package/dist/notify-product.d.ts.map +1 -1
- package/dist/notify-product.js +10 -6
- package/dist/op/activities/source-release.d.ts.map +1 -1
- package/dist/op/activities/source-release.js +2 -1
- package/dist/op/activities/source-rollback.d.ts.map +1 -1
- package/dist/op/activities/source-rollback.js +2 -1
- package/dist/op/index.d.ts +2 -0
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +1 -0
- package/dist/op/op-waves-evidence-jobs.d.ts +6 -1
- package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -1
- package/dist/op/op-waves-evidence-jobs.js +9 -3
- package/dist/op/op-waves-render-spec.d.ts +100 -0
- package/dist/op/op-waves-render-spec.d.ts.map +1 -0
- package/dist/op/op-waves-render-spec.js +162 -0
- package/dist/op/op-waves-run.d.ts +2 -0
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +2 -1
- package/dist/op/op-waves.d.ts +4 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +4 -1
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +59 -3
- package/dist/op/wave-stop.d.ts +64 -0
- package/dist/op/wave-stop.d.ts.map +1 -0
- package/dist/op/wave-stop.js +127 -0
- package/dist/planned-files.d.ts +76 -0
- package/dist/planned-files.d.ts.map +1 -0
- package/dist/planned-files.js +108 -0
- package/dist/pr-forge-job.d.ts +22 -0
- package/dist/pr-forge-job.d.ts.map +1 -0
- package/dist/pr-forge-job.js +46 -0
- package/dist/pr-loop.d.ts +3 -6
- package/dist/pr-loop.d.ts.map +1 -1
- package/dist/pr-loop.js +4 -81
- package/dist/pr-plan-note.d.ts +97 -0
- package/dist/pr-plan-note.d.ts.map +1 -1
- package/dist/pr-plan-note.js +94 -1
- package/dist/pr-post.d.ts +28 -3
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +145 -13
- package/dist/pr-status.d.ts +16 -0
- package/dist/pr-status.d.ts.map +1 -0
- package/dist/pr-status.js +90 -0
- package/dist/ref-gate-init.d.ts +16 -2
- package/dist/ref-gate-init.d.ts.map +1 -1
- package/dist/ref-gate-init.js +24 -13
- package/dist/release-floors.d.ts +37 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +61 -25
- package/dist/render-module.d.ts +15 -0
- package/dist/render-module.d.ts.map +1 -0
- package/dist/render-module.js +73 -0
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +1 -2
- package/dist/wave-runtime.mjs +304 -301
- package/dist/workspace/ci-green-cli.d.ts.map +1 -1
- package/dist/workspace/ci-green-cli.js +3 -2
- package/dist/workspace/release-train.d.ts.map +1 -1
- package/dist/workspace/release-train.js +2 -1
- package/dist/workspace/release-workflow.d.ts +4 -3
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +10 -7
- package/dist/workspace/trust/check-evidence-report.d.ts +7 -2
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence-report.js +15 -8
- package/dist/workspace/trust/ref-gate-cli.d.ts +10 -1
- package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
- package/dist/workspace/trust/ref-gate-cli.js +30 -10
- package/dist/workspace/workspace-run.d.ts.map +1 -1
- package/dist/workspace/workspace-run.js +2 -1
- package/package.json +1 -1
- package/src/actor.test.ts +68 -2
- package/src/actor.ts +61 -1
- package/src/chant-install.test.ts +2 -3
- package/src/chant-install.ts +1 -2
- package/src/ci-base.test.ts +41 -0
- package/src/ci-base.ts +43 -0
- package/src/ci-comment-commands.test.ts +376 -0
- package/src/ci-comment-commands.ts +389 -0
- package/src/ci-comment-replies.ts +78 -0
- package/src/ci-commit.test.ts +2 -3
- package/src/ci-evidence-from-job.test.ts +18 -0
- package/src/ci-evidence-from-job.ts +58 -2
- package/src/ci-evidence-jobs.ts +50 -5
- package/src/ci-image.test.ts +130 -9
- package/src/ci-image.ts +85 -12
- package/src/ci-note-commands.ts +104 -41
- package/src/ci-product-words.ts +59 -0
- package/src/ci-product.ts +40 -4
- package/src/cli/commands/build.test.ts +41 -0
- package/src/cli/commands/build.ts +27 -2
- package/src/cli/handlers/approve.ts +2 -1
- package/src/cli/handlers/ci-check.ts +19 -7
- package/src/cli/handlers/ci-evidence.ts +29 -8
- package/src/cli/handlers/components.ts +3 -1
- package/src/cli/handlers/generated-check.ts +31 -1
- package/src/cli/handlers/lock-reach.test.ts +103 -0
- package/src/cli/handlers/lock.ts +100 -4
- package/src/cli/handlers/pr-comment.ts +104 -0
- package/src/cli/handlers/pr-env.ts +6 -3
- package/src/cli/handlers/pr-record.test.ts +1 -1
- package/src/cli/handlers/pr.ts +50 -10
- package/src/cli/handlers/promote.ts +2 -1
- package/src/cli/handlers/release.e2e.test.ts +35 -0
- package/src/cli/handlers/release.ts +14 -2
- package/src/cli/handlers/run-wave.ts +28 -2
- package/src/cli/handlers/run.ts +2 -1
- package/src/cli/main.ts +24 -2
- package/src/cli/parse-args.ts +12 -0
- package/src/cli/registry.ts +11 -0
- package/src/components/auto-release.ts +2 -1
- package/src/components/pr-checks.ts +112 -17
- package/src/components/pr-pipeline.ts +17 -15
- package/src/components/product-pipeline.ts +93 -11
- package/src/components/product-plan.test.ts +40 -2
- package/src/components/product-plan.ts +331 -45
- package/src/drift-record.test.ts +20 -0
- package/src/drift-record.ts +16 -0
- package/src/floor-table.data.ts +54 -31
- package/src/forge-check/contract.ts +12 -1
- package/src/forge-check/forge-check.test.ts +17 -0
- package/src/forge-check/index.ts +2 -0
- package/src/gate-resume-run.ts +27 -3
- package/src/generated-check.e2e.test.ts +21 -1
- package/src/generated-check.test.ts +66 -0
- package/src/generated-check.ts +51 -10
- package/src/image-pins.ts +31 -0
- package/src/lexicon.ts +11 -0
- package/src/lifecycle/git.test.ts +48 -0
- package/src/lifecycle/git.ts +27 -4
- package/src/lifecycle/publish-npm.ts +31 -1
- package/src/lifecycle/reach-locks.test.ts +87 -0
- package/src/lifecycle/reach-locks.ts +169 -0
- package/src/lifecycle/release-cut.ts +17 -1
- package/src/lifecycle/release-images.test.ts +56 -0
- package/src/lifecycle/release-images.ts +1 -2
- package/src/notify-product.ts +19 -8
- package/src/op/activities/source-release.ts +2 -1
- package/src/op/activities/source-rollback.ts +2 -1
- package/src/op/gate-resume.test.ts +27 -0
- package/src/op/index.ts +10 -0
- package/src/op/op-waves-evidence-jobs.ts +10 -4
- package/src/op/op-waves-notify-words.test.ts +18 -0
- package/src/op/op-waves-render-spec.test.ts +160 -0
- package/src/op/op-waves-render-spec.ts +171 -0
- package/src/op/op-waves-run.ts +2 -1
- package/src/op/op-waves.ts +5 -2
- package/src/op/schedule-overdue.test.ts +43 -0
- package/src/op/schedule-overdue.ts +57 -3
- package/src/op/wave-stop.test.ts +72 -0
- package/src/op/wave-stop.ts +137 -0
- package/src/planned-files.test.ts +80 -0
- package/src/planned-files.ts +134 -0
- package/src/pr-forge-job.test.ts +53 -0
- package/src/pr-forge-job.ts +46 -0
- package/src/pr-loop-narrowed.test.ts +2 -1
- package/src/pr-loop-words.test.ts +2 -1
- package/src/pr-loop.test.ts +1 -2
- package/src/pr-loop.ts +4 -80
- package/src/pr-plan-note.ts +155 -3
- package/src/pr-post-replan.test.ts +144 -0
- package/src/pr-post-subject.test.ts +230 -0
- package/src/pr-post.test.ts +2 -1
- package/src/pr-post.ts +150 -15
- package/src/pr-status.ts +91 -0
- package/src/ref-gate-init.ts +30 -11
- package/src/release-floors.ts +78 -25
- package/src/render-module.ts +73 -0
- package/src/state-migration-record.test.ts +2 -3
- package/src/state-migration.ts +1 -2
- package/src/workspace/ci-green-cli.ts +3 -2
- package/src/workspace/ci-green-workflow.test.ts +32 -1
- package/src/workspace/release-train.ts +2 -1
- package/src/workspace/release-workflow.test.ts +36 -5
- package/src/workspace/release-workflow.ts +10 -7
- package/src/workspace/trust/check-evidence-report.ts +15 -8
- package/src/workspace/trust/check-evidence.test.ts +5 -0
- package/src/workspace/trust/ref-gate-cli.ts +30 -8
- package/src/workspace/trust/ref-gate-pieces.test.ts +46 -1
- package/src/workspace/trust/ref-gate.test.ts +10 -0
- package/src/workspace/workspace-run.ts +2 -1
package/src/pr-post.test.ts
CHANGED
|
@@ -12,7 +12,8 @@ import { afterAll, describe, expect, test, vi } from "vitest";
|
|
|
12
12
|
import type { CommandContext } from "./cli/registry";
|
|
13
13
|
import { parseArgs } from "./cli/parse-args";
|
|
14
14
|
import { postOpenPlanReports, postPlanReport, readPlanReport } from "./pr-post";
|
|
15
|
-
import { prNoteMarker,
|
|
15
|
+
import { prNoteMarker, type PrReport } from "./pr-loop";
|
|
16
|
+
import { prStatusState } from "./pr-status";
|
|
16
17
|
import type { ForgeStatus, PrForge } from "./pr-forge";
|
|
17
18
|
|
|
18
19
|
const FIXTURE = join(import.meta.dirname, "__fixtures__", "pr-loop", "pr-plan.golden.json");
|
package/src/pr-post.ts
CHANGED
|
@@ -32,16 +32,17 @@
|
|
|
32
32
|
import { appendFileSync, existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
33
33
|
import { tmpdir } from "node:os";
|
|
34
34
|
import { join } from "node:path";
|
|
35
|
-
import { prNoteMarker, prStatusContext,
|
|
35
|
+
import { prNoteMarker, prStatusContext, renderPrNote, type PrOverdue, type PrReport } from "./pr-loop";
|
|
36
|
+
import { prStatusDescription, prStatusState } from "./pr-status";
|
|
36
37
|
import { forgePrincipalOf, type PrForge } from "./pr-forge";
|
|
37
|
-
import { GITHUB_COMMENT_LIMIT, GITLAB_NOTE_LIMIT } from "./plan-summary";
|
|
38
|
+
import { fitNote, GITHUB_COMMENT_LIMIT, GITLAB_NOTE_LIMIT } from "./plan-summary";
|
|
38
39
|
import { activeProductWords, commentLine, type CiProductWords } from "./ci-product-words";
|
|
39
40
|
import { controlEdgeFactsFromEnv, remarkCrossStackEdges, type ControlEdgeFacts } from "./control/edges";
|
|
40
41
|
import { CHECK_EVIDENCE_FILE, checkEvidenceNoteLine, openEvidenceFor } from "./workspace/trust/check-evidence-report";
|
|
41
42
|
import { PLAN_RUN_RECORD_FILE, readPlanRunRecord } from "./pr-plan-record";
|
|
42
43
|
import type { OpRunRecordInput } from "./op/runtime";
|
|
43
44
|
import type { RunOrigin } from "./lifecycle/release-ledger";
|
|
44
|
-
import { isPlanNote, planNoteMarker, PR_PLAN_NOTE_CONTRACT, PR_PLAN_NOTE_FILE, PRODUCT_MARKER_BODY, PRODUCT_MARKER_LIMIT, PRODUCT_MARKER_NAME, productMarkerLine, renderPlanNote, type PrPlanNoteHandoff, type PrPlanNoteWords } from "./pr-plan-note";
|
|
45
|
+
import { isPlanNote, PLAN_BODY_LIMIT, PLAN_SUBJECT_LIMIT, planNoteMarker, planSubjectProblem, PR_PLAN_NOTE_CONTRACT, PR_PLAN_NOTE_FILE, PRODUCT_MARKER_BODY, PRODUCT_MARKER_LIMIT, PRODUCT_MARKER_NAME, productMarkerLine, renderPlanNote, sinceLastLine, type PrPlanBodyHandoff, type PrPlanNoteHandoff, type PrPlanNoteWords, type PrPlanSubject } from "./pr-plan-note";
|
|
45
46
|
|
|
46
47
|
/** The plan report's file under the report directory. */
|
|
47
48
|
export const PR_PLAN_REPORT_FILE = "pr-plan.json";
|
|
@@ -107,6 +108,14 @@ export interface PlanPostInput {
|
|
|
107
108
|
* pushes. `keep` returns a warning to say, when there is one.
|
|
108
109
|
*/
|
|
109
110
|
recordRun?: PlanRunRecorder;
|
|
111
|
+
/**
|
|
112
|
+
* The one argument a re-plan was narrowed to (#4963), such as a
|
|
113
|
+
* terragucci root: when the report or the hand-off says the change
|
|
114
|
+
* reaches nothing, the pull request gets a reply that the argument is not
|
|
115
|
+
* affected, and the note and the status stay as they were. Ignored when
|
|
116
|
+
* empty or not one plain word.
|
|
117
|
+
*/
|
|
118
|
+
notAffected?: string;
|
|
110
119
|
}
|
|
111
120
|
|
|
112
121
|
/** How the note job keeps the plan job's run record (#4899). */
|
|
@@ -162,7 +171,7 @@ export function readPlanReport(input: Pick<PlanPostInput, "dir" | "pr" | "head"
|
|
|
162
171
|
* The note for `report`, rendered here, with every `<!--` after the marker
|
|
163
172
|
* line written as `<!--`, so the note carries no hidden marker but its own.
|
|
164
173
|
*/
|
|
165
|
-
export function planNoteFor(report: PrReport, forge: Pick<PrForge, "kind" | "host">, marker: string, baseTip?: string): string {
|
|
174
|
+
export function planNoteFor(report: PrReport, forge: Pick<PrForge, "kind" | "host">, marker: string, baseTip?: string, own?: string): string {
|
|
166
175
|
const note = renderPrNote(report, {
|
|
167
176
|
limit: forge.kind === "gitlab" ? GITLAB_NOTE_LIMIT : GITHUB_COMMENT_LIMIT,
|
|
168
177
|
approver: forgePrincipalOf(forge.kind, forge.host, "<your-login>"),
|
|
@@ -171,7 +180,42 @@ export function planNoteFor(report: PrReport, forge: Pick<PrForge, "kind" | "hos
|
|
|
171
180
|
const rest = (at < 0 ? "" : note.slice(at + 1)).split("<!--").join("<!--");
|
|
172
181
|
// #4628: the tip line is written after the defusing, from the caller's sha, never the report's.
|
|
173
182
|
const tip = baseTip && SHA.test(baseTip) ? `${rest.endsWith("\n") ? "" : "\n"}${prNoteTipMarker(baseTip)}\n` : "";
|
|
174
|
-
|
|
183
|
+
// #4963: the product's own line, already checked, under chant's marker.
|
|
184
|
+
return `${marker}\n${own ? `${own}\n` : ""}${rest}${tip}`;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The product's hidden line for a report or a hand-off (#4931, #4963): from
|
|
189
|
+
* the pipeline's `productMarker` and the file's `marker`, checked against
|
|
190
|
+
* {@link PRODUCT_MARKER_BODY}. Undefined when either is missing or the
|
|
191
|
+
* marker is not plain words.
|
|
192
|
+
*/
|
|
193
|
+
function productLineOf(name: string | undefined, marker: unknown): string | undefined {
|
|
194
|
+
if (name === undefined || !PRODUCT_MARKER_NAME.test(name) || typeof marker !== "string" || marker.length > PRODUCT_MARKER_LIMIT) return undefined;
|
|
195
|
+
if (marker !== "" && !PRODUCT_MARKER_BODY.test(marker)) return undefined;
|
|
196
|
+
return productMarkerLine(name, marker);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** The one plain word a re-plan was narrowed to (#4963), or undefined. */
|
|
200
|
+
function narrowedTo(input: Pick<PlanPostInput, "notAffected">): string | undefined {
|
|
201
|
+
const a = input.notAffected?.trim();
|
|
202
|
+
return a && /^[A-Za-z0-9_.\/@+=,:-]+$/.test(a) ? a : undefined;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The reply for a re-plan narrowed to an argument the change does not
|
|
207
|
+
* reach (#4963), in place of the note and the status, as terragucci's
|
|
208
|
+
* plan-note job replied (plan-note.ts).
|
|
209
|
+
*/
|
|
210
|
+
async function replyNotAffected(input: PlanPostInput, argument: string, state: PlanPostResult["state"], warnings: string[]): Promise<PlanPostResult> {
|
|
211
|
+
const description = `${argument} is not affected by this pull request, so nothing was planned.`;
|
|
212
|
+
try {
|
|
213
|
+
await input.forge.addComment(input.pr, `${activeProductWords().product}: ${description}`);
|
|
214
|
+
} catch (err) {
|
|
215
|
+
warnings.push(`could not reply on #${input.pr}: ${err instanceof Error ? err.message : String(err)}`);
|
|
216
|
+
}
|
|
217
|
+
const recorded = await keepRunRecord(input, warnings);
|
|
218
|
+
return { state, description: cut(description), noted: false, ...(recorded ? { recorded } : {}), warnings };
|
|
175
219
|
}
|
|
176
220
|
|
|
177
221
|
/** The hidden line a note carries with the target branch's commit it was posted against (#4628). */
|
|
@@ -184,6 +228,55 @@ export function prNoteStaleMarker(sha: string): string {
|
|
|
184
228
|
return `<!-- chant-pr-stale:${sha} -->`;
|
|
185
229
|
}
|
|
186
230
|
|
|
231
|
+
/**
|
|
232
|
+
* The hidden line a note keeps its plan's subject in (#4972): base64url of
|
|
233
|
+
* the subject's JSON, `{ id }` alone when its parts would make the line
|
|
234
|
+
* longer than {@link PLAN_SUBJECT_LIMIT}. Undefined when even that is.
|
|
235
|
+
*/
|
|
236
|
+
export function prNoteSubjectMarker(subject: PrPlanSubject): string | undefined {
|
|
237
|
+
const line = (s: PrPlanSubject) => `<!-- chant-pr-subject:${Buffer.from(JSON.stringify(s), "utf8").toString("base64url")} -->`;
|
|
238
|
+
const full = line(subject);
|
|
239
|
+
if (full.length <= PLAN_SUBJECT_LIMIT) return full;
|
|
240
|
+
const bare = line({ id: subject.id });
|
|
241
|
+
return bare.length <= PLAN_SUBJECT_LIMIT ? bare : undefined;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const SUBJECT_LINE = /^<!-- chant-pr-subject:([A-Za-z0-9_-]+) -->$/m;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* The subject a note kept (#4972), checked again: the line was chant's, but
|
|
248
|
+
* what it holds came from an earlier plan job. Undefined when there is none.
|
|
249
|
+
*/
|
|
250
|
+
export function subjectInNote(body: string): PrPlanSubject | undefined {
|
|
251
|
+
const m = SUBJECT_LINE.exec(body.replace(/\r\n/g, "\n"));
|
|
252
|
+
if (!m?.[1] || m[1].length > PLAN_SUBJECT_LIMIT) return undefined;
|
|
253
|
+
try {
|
|
254
|
+
const s = JSON.parse(Buffer.from(m[1], "base64url").toString("utf8")) as unknown;
|
|
255
|
+
return planSubjectProblem(s) === undefined ? (s as PrPlanSubject) : undefined;
|
|
256
|
+
} catch {
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* The line saying what changed since the previous note (#4972): the
|
|
263
|
+
* previous note of the same environment and member is read with the job's
|
|
264
|
+
* token, and its kept subject compared with the hand-off's. Undefined when
|
|
265
|
+
* there is no previous note, it kept no subject, or the id is the same. A
|
|
266
|
+
* forge that refuses the read is a warning.
|
|
267
|
+
*/
|
|
268
|
+
async function sinceLastOf(input: PlanPostInput, subject: PrPlanSubject, words: PrPlanNoteWords | undefined, warnings: string[]): Promise<string | undefined> {
|
|
269
|
+
let found: { body: string } | undefined;
|
|
270
|
+
try {
|
|
271
|
+
found = await input.forge.findComment(input.pr, prNoteMarker(input.env, input.member));
|
|
272
|
+
} catch (err) {
|
|
273
|
+
warnings.push(`could not read the previous note on #${input.pr}, so the note does not say what changed since it: ${err instanceof Error ? err.message : String(err)}`);
|
|
274
|
+
return undefined;
|
|
275
|
+
}
|
|
276
|
+
const previous = found ? subjectInNote(found.body) : undefined;
|
|
277
|
+
return previous ? sinceLastLine(previous, subject, words ?? {}) : undefined;
|
|
278
|
+
}
|
|
279
|
+
|
|
187
280
|
const TIP_LINE = /<!-- chant-pr-tip:([0-9a-f]{40}) -->/;
|
|
188
281
|
const STALE_LINE = /<!-- chant-pr-stale:([0-9a-f]{40}) -->/;
|
|
189
282
|
const STALE_PREFIX = "> Stale: ";
|
|
@@ -221,6 +314,9 @@ export async function postPlanReport(input: PlanPostInput): Promise<PlanPostResu
|
|
|
221
314
|
description = cut(read.refused);
|
|
222
315
|
} else {
|
|
223
316
|
let report = read.report;
|
|
317
|
+
// #4963: a re-plan narrowed to an argument the change does not reach.
|
|
318
|
+
const narrowed = narrowedTo(input);
|
|
319
|
+
if (narrowed && report.status === "nothing" && !failedJob) return replyNotAffected(input, narrowed, "success", warnings);
|
|
224
320
|
if (input.overdue) {
|
|
225
321
|
const { overdue: _forged, ...rest } = report;
|
|
226
322
|
const found = await input.overdue().catch(() => [] as PrOverdue[]);
|
|
@@ -235,7 +331,9 @@ export async function postPlanReport(input: PlanPostInput): Promise<PlanPostResu
|
|
|
235
331
|
state = prStatusState(report);
|
|
236
332
|
description = prStatusDescription(report);
|
|
237
333
|
// A member the change does not reach has nothing to say on the pull request (as pr-plan's own publish).
|
|
238
|
-
|
|
334
|
+
// #4963: the report's own `marker`, under the pipeline's productMarker, as a hand-off's.
|
|
335
|
+
const own = productLineOf((input.noteWords ?? noteWordsFromEnv())?.productMarker, (read.report as { marker?: unknown }).marker);
|
|
336
|
+
if (!(input.member && report.status === "nothing" && !report.overdue?.length && !report.migrations?.length)) note = planNoteFor(report, input.forge, prNoteMarker(input.env, input.member), input.baseTip, own);
|
|
239
337
|
} catch (err) {
|
|
240
338
|
refused = `the plan report does not render: ${err instanceof Error ? err.message : String(err)}`;
|
|
241
339
|
state = "failure";
|
|
@@ -336,7 +434,7 @@ async function postOutcome(
|
|
|
336
434
|
* Read a product's plan note hand-off under `dir` (#4799) and check it is the
|
|
337
435
|
* one the caller ran, as {@link readPlanReport} checks a report.
|
|
338
436
|
*/
|
|
339
|
-
export function readPlanNoteHandoff(input: Pick<PlanPostInput, "dir" | "pr" | "head" | "env" | "member">): { handoff: PrPlanNoteHandoff } | { refused: string } {
|
|
437
|
+
export function readPlanNoteHandoff(input: Pick<PlanPostInput, "dir" | "pr" | "head" | "env" | "member">): { handoff: PrPlanNoteHandoff | PrPlanBodyHandoff } | { refused: string } {
|
|
340
438
|
let doc: unknown;
|
|
341
439
|
try {
|
|
342
440
|
doc = JSON.parse(readFileSync(join(input.dir, PR_PLAN_NOTE_FILE), "utf-8"));
|
|
@@ -353,14 +451,39 @@ export function readPlanNoteHandoff(input: Pick<PlanPostInput, "dir" | "pr" | "h
|
|
|
353
451
|
if ((r.member ?? undefined) !== input.member) return { refused: `the plan note is for ${JSON.stringify(r.member ?? null)}, not ${JSON.stringify(input.member ?? null)}` };
|
|
354
452
|
if (r.state !== "success" && r.state !== "failure" && r.state !== "pending") return { refused: `the plan note's state ${JSON.stringify(r.state)} is not success, failure or pending` };
|
|
355
453
|
if (typeof r.description !== "string") return { refused: "the plan note has no description" };
|
|
356
|
-
|
|
454
|
+
// #4963: the product's own text in place of a plan note.
|
|
455
|
+
if (r.body !== undefined) {
|
|
456
|
+
if (r.note !== undefined) return { refused: "the plan note gives both a note and a body; give one" };
|
|
457
|
+
if (typeof r.body !== "string" || r.body.length > PLAN_BODY_LIMIT) return { refused: `the plan note's body is not text of at most ${PLAN_BODY_LIMIT} characters` };
|
|
458
|
+
} else if (!isPlanNote(r.note) || r.note.head !== r.head || !Array.isArray(r.note.waves) || !Array.isArray(r.note.groups) || !Array.isArray(r.note.named)) {
|
|
357
459
|
return { refused: "the plan note's note is not a plan note for its head" };
|
|
358
460
|
}
|
|
359
461
|
// #4931: the product's hidden line is the change's too, so it holds only plain words.
|
|
360
462
|
if (r.marker !== undefined && (typeof r.marker !== "string" || r.marker.length > PRODUCT_MARKER_LIMIT || (r.marker !== "" && !PRODUCT_MARKER_BODY.test(r.marker)))) {
|
|
361
463
|
return { refused: `the plan note's marker is not words of letters, digits and _.,/@+=:- of at most ${PRODUCT_MARKER_LIMIT} characters` };
|
|
362
464
|
}
|
|
363
|
-
|
|
465
|
+
// #4972: the subject is kept in the note and said back in a later one, so it holds only plain words too.
|
|
466
|
+
const subjectProblem = r.subject !== undefined ? planSubjectProblem(r.subject) : undefined;
|
|
467
|
+
if (subjectProblem) return { refused: `the plan note's subject ${subjectProblem}` };
|
|
468
|
+
return { handoff: doc as PrPlanNoteHandoff | PrPlanBodyHandoff };
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* The note for a hand-off of the product's own text (#4963): chant's
|
|
473
|
+
* marker, the product's line, the body with every `<!--` defused, the
|
|
474
|
+
* notices as quoted lines under it, the tip line, cut to the forge's limit.
|
|
475
|
+
*/
|
|
476
|
+
export function planBodyHandoffNote(handoff: PrPlanBodyHandoff, forge: Pick<PrForge, "kind">, marker: string, noteWords?: PrPlanNoteWords, baseTip?: string, notices: readonly string[] = []): string {
|
|
477
|
+
const limit = forge.kind === "gitlab" ? GITLAB_NOTE_LIMIT : GITHUB_COMMENT_LIMIT;
|
|
478
|
+
const line = productLineOf(noteWords?.productMarker, handoff.marker);
|
|
479
|
+
const head = `${marker}\n${line ? `${line}\n` : ""}`;
|
|
480
|
+
const said = notices.length > 0 ? `\n${notices.map((n) => `> ${n.split("<!--").join("<!--")}`).join("\n")}\n` : "";
|
|
481
|
+
const tip = baseTip && SHA.test(baseTip) ? `${prNoteTipMarker(baseTip)}\n` : "";
|
|
482
|
+
// #4972: the subject, kept for the next note to compare with.
|
|
483
|
+
const kept = handoff.subject ? prNoteSubjectMarker(handoff.subject) : undefined;
|
|
484
|
+
const subject = kept ? `${kept}\n` : "";
|
|
485
|
+
const body = handoff.body.split("<!--").join("<!--").replace(/\n*$/, "\n");
|
|
486
|
+
return `${head}${fitNote(body, { limit: Math.max(0, limit - head.length - said.length - tip.length - subject.length) })}${said}${tip}${subject}`;
|
|
364
487
|
}
|
|
365
488
|
|
|
366
489
|
/** The notices in the file `CHANT_PLAN_NOTE_NOTICES` names (#4931), one a line, or none when unset or unreadable. */
|
|
@@ -394,7 +517,10 @@ function noteWordsFromEnv(): PrPlanNoteWords | undefined {
|
|
|
394
517
|
*/
|
|
395
518
|
export function planNoteHandoffNote(handoff: PrPlanNoteHandoff, forge: Pick<PrForge, "kind">, marker: string, noteWords?: PrPlanNoteWords, baseTip?: string): string {
|
|
396
519
|
const words = activeProductWords();
|
|
397
|
-
|
|
520
|
+
// #4972: the subject, kept for the next note to compare with, within the forge's limit.
|
|
521
|
+
const kept = handoff.subject ? prNoteSubjectMarker(handoff.subject) : undefined;
|
|
522
|
+
const limit = (forge.kind === "gitlab" ? GITLAB_NOTE_LIMIT : GITHUB_COMMENT_LIMIT) - (kept ? kept.length + 1 : 0);
|
|
523
|
+
const rendered = renderPlanNote(handoff.note, { limit, words, ...(noteWords ? { note: noteWords } : {}) });
|
|
398
524
|
let body = rendered.split("<!--").join("<!--");
|
|
399
525
|
const n = handoff.note;
|
|
400
526
|
const previews = n.previews ?? [];
|
|
@@ -404,7 +530,8 @@ export function planNoteHandoffNote(handoff: PrPlanNoteHandoff, forge: Pick<PrFo
|
|
|
404
530
|
// #4931: the product's own line, from the pipeline's name and the hand-off's checked body, under chant's marker.
|
|
405
531
|
const name = noteWords?.productMarker;
|
|
406
532
|
const own = name !== undefined && PRODUCT_MARKER_NAME.test(name) && handoff.marker !== undefined ? `${productMarkerLine(name, handoff.marker)}\n` : "";
|
|
407
|
-
|
|
533
|
+
const subject = kept ? `${body.endsWith("\n") || tip ? "" : "\n"}${kept}\n` : "";
|
|
534
|
+
return `${marker}\n${own}${body}${tip}${subject}`;
|
|
408
535
|
}
|
|
409
536
|
|
|
410
537
|
/** {@link postPlanReport} for a product's plan note hand-off (#4799). */
|
|
@@ -424,14 +551,22 @@ async function postPlanNoteHandoff(input: PlanPostInput): Promise<PlanPostResult
|
|
|
424
551
|
} else {
|
|
425
552
|
state = read.handoff.state;
|
|
426
553
|
description = read.handoff.description;
|
|
554
|
+
const h = read.handoff;
|
|
555
|
+
// #4963: a re-plan narrowed to an argument the change does not reach.
|
|
556
|
+
const narrowed = narrowedTo(input);
|
|
557
|
+
if (narrowed && "note" in h && h.note.nothing === true && !failedJob) return replyNotAffected(input, narrowed, state, warnings);
|
|
427
558
|
// #4931: the overdue Ops (#4289), asked here with the job's token, and the note job's own notices, under the counts.
|
|
428
|
-
const given =
|
|
559
|
+
const given = "note" in h ? (h.note.notices ?? []) : [];
|
|
429
560
|
// An Op the product's own notices already call overdue is not said twice.
|
|
430
561
|
const overdue = input.overdue ? (await input.overdue().catch(() => [] as PrOverdue[])).filter((o) => !given.some((g) => g.includes(`\`${o.op}\``) && g.includes("overdue"))).map((o) => o.message) : [];
|
|
431
|
-
const
|
|
432
|
-
|
|
562
|
+
const noteWords = input.noteWords ?? noteWordsFromEnv();
|
|
563
|
+
// #4972: what changed since the previous note, from the subject it kept, read here with the job's token.
|
|
564
|
+
const since = h.subject ? await sinceLastOf(input, h.subject, noteWords, warnings) : undefined;
|
|
565
|
+
const added = [...(since ? [since] : []), ...overdue, ...(input.notices ?? noticesFromEnv())].filter((n, i, all) => !given.includes(n) && all.indexOf(n) === i);
|
|
433
566
|
try {
|
|
434
|
-
note =
|
|
567
|
+
note = "note" in h
|
|
568
|
+
? planNoteHandoffNote(added.length > 0 ? { ...h, note: { ...h.note, notices: [...given, ...added] } } : h, input.forge, prNoteMarker(input.env, input.member), noteWords, input.baseTip)
|
|
569
|
+
: planBodyHandoffNote(h, input.forge, prNoteMarker(input.env, input.member), noteWords, input.baseTip, added);
|
|
435
570
|
} catch (err) {
|
|
436
571
|
refused = `the plan note does not render: ${err instanceof Error ? err.message : String(err)}`;
|
|
437
572
|
state = "failure";
|
package/src/pr-status.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pull-request loop's commit status (#3183): its description and its
|
|
3
|
+
* state, from the report `chant components pr-plan` and `pr-apply` write.
|
|
4
|
+
*
|
|
5
|
+
* They lived in `./pr-loop.ts` until #4966 moved them here, so the bundle
|
|
6
|
+
* a product builds from `pr-loop.ts` and `pr-forge.ts` (the report, the note
|
|
7
|
+
* and the forge clients, `pr-loop-bundle.test.ts`) keeps room under its
|
|
8
|
+
* ceiling. chant's own handlers post the status; no product reads these.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { activeProductWords, type CiProductWords } from "./ci-product-words";
|
|
12
|
+
import { memberHoleReasons, type PrReport } from "./pr-loop";
|
|
13
|
+
|
|
14
|
+
/** A commit status's description, at most 140 characters (GitHub's limit). */
|
|
15
|
+
export function prStatusDescription(report: PrReport, words: CiProductWords = activeProductWords()): string {
|
|
16
|
+
const n = report.members.length;
|
|
17
|
+
const many = (k: number): string => `${k} ${words.noun[k === 1 ? 0 : 1]}`;
|
|
18
|
+
const sum = report.members.reduce(
|
|
19
|
+
(acc, m) => ({ change: acc.change + m.counts.create + m.counts.update + m.counts.replace, destroy: acc.destroy + m.counts.delete + m.counts.replace }),
|
|
20
|
+
{ change: 0, destroy: 0 },
|
|
21
|
+
);
|
|
22
|
+
const digest = report.digest ? `; plan ${report.digest.replace(/^(?:jcs1-)?sha256:/, "").slice(0, 12)}` : "";
|
|
23
|
+
let text: string;
|
|
24
|
+
switch (report.status) {
|
|
25
|
+
case "nothing":
|
|
26
|
+
text = "nothing to plan";
|
|
27
|
+
break;
|
|
28
|
+
case "planned": {
|
|
29
|
+
const unknown = report.members.filter((m) => memberHoleReasons(report, m.member).length > 0).length;
|
|
30
|
+
// #4626: a narrowed plan says so in its status.
|
|
31
|
+
const narrowed = Object.values(report.narrowed ?? {}).filter((a) => a.length > 0).length;
|
|
32
|
+
text = `${many(n)}${narrowed > 0 ? ` (${narrowed} narrowed with --target)` : ""}: ${sum.change} to change, ${sum.destroy} to destroy or replace${unknown > 0 ? `, ${unknown} with holes` : ""}${digest}`;
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case "plan-failed":
|
|
36
|
+
text = `a ${words.noun[0]} failed to ${words.verbs.plan[0]}${digest}`;
|
|
37
|
+
break;
|
|
38
|
+
case "recorded":
|
|
39
|
+
text = `recorded ${many(n)}: ${report.approval.status === "approved" ? "the approved plan" : report.approval.status === "changed" ? "the plan differs from the approved one" : "no approval for this plan"}${digest}`;
|
|
40
|
+
break;
|
|
41
|
+
case "applied":
|
|
42
|
+
text = `${words.verbs.apply[1]} ${many(n)}${digest}`;
|
|
43
|
+
break;
|
|
44
|
+
case "wave-applied": {
|
|
45
|
+
const last = (report.waves ?? []).filter((w) => w.status === "applied").at(-1);
|
|
46
|
+
text = `applied wave ${last?.wave ?? "?"} of ${report.selection.waves.length}${last ? ` under ${last.approval === "pull-request" ? "the pull request's approval" : `${last.gate}`}` : ""}`;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case "failed":
|
|
50
|
+
text = `apply failed for ${report.members.filter((m) => m.status === "failed").map((m) => m.member).join(", ")}`;
|
|
51
|
+
break;
|
|
52
|
+
case "waiting":
|
|
53
|
+
text = `waiting: ${report.members.filter((m) => m.status === "waiting").map((m) => m.member).join(", ")} planned again after an upstream applied, not approved yet`;
|
|
54
|
+
break;
|
|
55
|
+
case "refused": {
|
|
56
|
+
const waiting = report.waves?.find((w) => w.status === "waiting");
|
|
57
|
+
if (waiting && (report.refusal === "wave-not-approved" || report.refusal === "wave-plan-changed")) {
|
|
58
|
+
text = `wave ${waiting.wave} waits at ${waiting.gate}: ${report.refusal === "wave-plan-changed" ? "its plan changed after its approval" : "its plan moved, approve it"}`;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
if (report.refusal === "earlier-wave") {
|
|
62
|
+
text = "refused: an earlier wave has not applied";
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
if (report.refusal === "requires-unmet" || report.refusal === "before-merge-off") {
|
|
66
|
+
const unmet = (report.beforeMerge?.requires ?? []).filter((r) => !r.passed).map((r) => r.name);
|
|
67
|
+
text = report.refusal === "before-merge-off" ? "refused: this workspace does not apply before merge" : `refused: ${unmet.join(", ") || "a require"} unmet for an apply before merge`;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
if (report.refusal === "policy-denied" || report.refusal === "policy-error") {
|
|
71
|
+
text = report.refusal === "policy-denied" ? `refused: the policy denied the plan (${(report.policy?.rules ?? []).join(", ")})` : "refused: the policy could not be checked";
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
text = `refused: ${report.refusal === "plan-changed" ? "the plan changed after review" : report.refusal === "not-a-reviewer" ? "the approver has not approved the pull request" : report.refusal === "author-approved" ? "the approver wrote the change" : report.refusal === "no-pull-request" ? "no pull request merged this commit" : report.refusal === "locked" ? "another pull request holds a target lock" : "the plan is not approved"}`;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return text.length > 140 ? text.slice(0, 137) + "..." : text;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The commit status state for a report: success, failure, or pending while it waits on approval. */
|
|
82
|
+
export function prStatusState(report: PrReport): "success" | "failure" | "pending" {
|
|
83
|
+
// #4168 decision 1: a merge whose plan differs from the approved one is recorded, and its status fails.
|
|
84
|
+
if (report.status === "recorded") return report.approval.status === "changed" ? "failure" : "success";
|
|
85
|
+
// #4294: a plan the policy denied, with no override, or one it could not check, fails at the plan stage as it would at the apply.
|
|
86
|
+
if (report.status === "planned" && report.policy && (report.policy.result === "error" || (report.policy.result === "denied" && !report.policy.override))) return "failure";
|
|
87
|
+
if (report.status === "planned" || report.status === "applied" || report.status === "wave-applied" || report.status === "nothing") return "success";
|
|
88
|
+
if (report.status === "refused" && (report.refusal === "not-approved" || report.refusal === "wave-not-approved")) return "pending";
|
|
89
|
+
if (report.status === "waiting") return "pending";
|
|
90
|
+
return "failure";
|
|
91
|
+
}
|
package/src/ref-gate-init.ts
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* {@link refGateInitPlan} plans, and writes nothing, so a product folds the
|
|
7
7
|
* files into its own plan and keeps its dry run:
|
|
8
8
|
*
|
|
9
|
-
* - `.chant/trust.json` with a `refs` rule for the branch (#4867)
|
|
9
|
+
* - `.chant/trust.json` with a `refs` rule for the branch (#4867), whose
|
|
10
|
+
* `plan` and `policy` are each target's with `targets` (#4978): created
|
|
10
11
|
* with `"schema": 1` when there is none, the rule added in place when the
|
|
11
12
|
* file has no rule for the branch, left as it is when it has one or does
|
|
12
13
|
* not parse.
|
|
@@ -23,15 +24,17 @@
|
|
|
23
24
|
*/
|
|
24
25
|
|
|
25
26
|
import { spawnSync } from "node:child_process";
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
27
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
28
|
+
import { isAbsolute, join } from "node:path";
|
|
29
|
+
import { writePlannedFiles } from "./planned-files";
|
|
30
|
+
import { EVIDENCE_MEMBER_NAME, targetEvidenceCheck } from "./ci-evidence-jobs";
|
|
28
31
|
import { appendElement, setProperty } from "./workspace/json-edit";
|
|
29
32
|
import { parseJsonText } from "./workspace/jsonc";
|
|
30
33
|
import { REF_CHECK_NAME, TRUST_CONFIG_PATH, trustConfigSchema, type TrustConfig } from "./workspace/trust/policy";
|
|
31
34
|
import { refPatternRegExp, REF_GATE_STATUS } from "./workspace/trust/ref-gate";
|
|
32
35
|
import { REF_GATE_HOOK_MARK, refGateHook } from "./workspace/trust/ref-gate-cli";
|
|
33
36
|
|
|
34
|
-
export { REF_GATE_PIECES_FLOOR } from "./release-floors";
|
|
37
|
+
export { REF_GATE_PIECES_FLOOR, TARGET_SIGNED_CHECKS_FLOOR } from "./release-floors";
|
|
35
38
|
|
|
36
39
|
/** One check the rule requires evidence for, as `refs[].checks[]` holds it. */
|
|
37
40
|
export interface RefGateInitCheck {
|
|
@@ -47,6 +50,13 @@ export interface RefGateInitOptions {
|
|
|
47
50
|
branch?: string;
|
|
48
51
|
/** The checks an update of the branch needs current evidence for. At least one. */
|
|
49
52
|
checks: readonly RefGateInitCheck[];
|
|
53
|
+
/**
|
|
54
|
+
* The product plan's targets (#4978), as `productPlan.targets` names them.
|
|
55
|
+
* A target's note job signs `plan:<target>` and `policy:<target>`, so with
|
|
56
|
+
* targets a check named `plan` or `policy` stands for each target's, with
|
|
57
|
+
* the same action and command, in the order the targets are given.
|
|
58
|
+
*/
|
|
59
|
+
targets?: readonly string[];
|
|
50
60
|
/** The commit status the gate's status job sets. Default `chant/ref-gate`, which the rule then leaves out. */
|
|
51
61
|
status?: string;
|
|
52
62
|
/** Write the `pre-push` hook in this checkout. Default true. */
|
|
@@ -94,11 +104,21 @@ function planned(path: string, content: string, extra: Pick<RefGateInitFile, "mo
|
|
|
94
104
|
return { path, status: before === undefined ? "created" : before === content ? "unchanged" : "updated", content, ...extra };
|
|
95
105
|
}
|
|
96
106
|
|
|
107
|
+
/**
|
|
108
|
+
* The rule's checks (#4978): with `targets`, `plan` and `policy` become each
|
|
109
|
+
* target's `plan:<target>` and `policy:<target>` (`targetEvidenceCheck`),
|
|
110
|
+
* which is what a product plan with targets signs.
|
|
111
|
+
*/
|
|
112
|
+
export function refGateInitChecks(checks: readonly RefGateInitCheck[], targets?: readonly string[]): RefGateInitCheck[] {
|
|
113
|
+
if (!targets || targets.length === 0) return [...checks];
|
|
114
|
+
return checks.flatMap((c) => (c.check === "plan" || c.check === "policy" ? targets.map((t) => ({ ...c, check: targetEvidenceCheck(c.check as "plan" | "policy", t) })) : [c]));
|
|
115
|
+
}
|
|
116
|
+
|
|
97
117
|
/** The `refs` rule for `ref`, with `action` and `status` only where they differ from the defaults. */
|
|
98
118
|
function ruleFor(ref: string, opts: RefGateInitOptions): Record<string, unknown> {
|
|
99
119
|
return {
|
|
100
120
|
ref,
|
|
101
|
-
checks: opts.checks.map((c) => ({ check: c.check, ...(c.action === "warn" ? { action: "warn" } : {}), command: c.command })),
|
|
121
|
+
checks: refGateInitChecks(opts.checks, opts.targets).map((c) => ({ check: c.check, ...(c.action === "warn" ? { action: "warn" } : {}), command: c.command })),
|
|
102
122
|
...(opts.status && opts.status !== REF_GATE_STATUS ? { status: opts.status } : {}),
|
|
103
123
|
};
|
|
104
124
|
}
|
|
@@ -113,6 +133,9 @@ export function refGateInitPlan(repo: string, opts: RefGateInitOptions): RefGate
|
|
|
113
133
|
const ref = `refs/heads/${branch}`;
|
|
114
134
|
if (!branch || /\s|\*/.test(branch)) throw new RefGateInitError(`the branch is one branch name, such as main, not ${JSON.stringify(branch)}`);
|
|
115
135
|
if (opts.checks.length === 0) throw new RefGateInitError("the ref gate's rule needs at least one check");
|
|
136
|
+
for (const t of opts.targets ?? []) {
|
|
137
|
+
if (!EVIDENCE_MEMBER_NAME.test(t)) throw new RefGateInitError(`${JSON.stringify(t)} is not a product plan target's name: letters, digits, - and _`);
|
|
138
|
+
}
|
|
116
139
|
for (const c of opts.checks) {
|
|
117
140
|
if (!REF_CHECK_NAME.test(c.check)) throw new RefGateInitError(`${JSON.stringify(c.check)} is not a check name: letters, digits, . _ : -`);
|
|
118
141
|
if (!c.command.trim()) throw new RefGateInitError(`check ${c.check} needs the command that produces its evidence`);
|
|
@@ -180,10 +203,6 @@ export function refGateInitPlan(repo: string, opts: RefGateInitOptions): RefGate
|
|
|
180
203
|
|
|
181
204
|
/** Write the files of a plan, each directory made and the hook executable. An unchanged file is not touched. */
|
|
182
205
|
export function writeRefGateInit(plan: Pick<RefGateInitPlan, "files">): void {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
mkdirSync(dirname(f.path), { recursive: true });
|
|
186
|
-
writeFileSync(f.path, f.content);
|
|
187
|
-
if (f.mode !== undefined) chmodSync(f.path, f.mode);
|
|
188
|
-
}
|
|
206
|
+
// #4966: chant's one planned-file writer.
|
|
207
|
+
writePlannedFiles(plan.files);
|
|
189
208
|
}
|