@intentius/chant 0.124.77 → 0.124.78
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/__fixtures__/notify-messages/events.d.ts +9 -0
- package/dist/__fixtures__/notify-messages/events.d.ts.map +1 -0
- package/dist/__fixtures__/notify-messages/events.js +21 -0
- package/dist/__fixtures__/product-words.d.ts +14 -0
- package/dist/__fixtures__/product-words.d.ts.map +1 -1
- package/dist/__fixtures__/product-words.js +11 -0
- package/dist/__fixtures__/terragucci-notify.d.ts +66 -0
- package/dist/__fixtures__/terragucci-notify.d.ts.map +1 -0
- package/dist/__fixtures__/terragucci-notify.js +133 -0
- package/dist/action-pins.d.ts +8 -0
- package/dist/action-pins.d.ts.map +1 -1
- package/dist/action-pins.js +9 -0
- package/dist/agent-guard.d.ts.map +1 -1
- package/dist/agent-guard.js +1 -2
- package/dist/ci-commit.d.ts +66 -2
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +148 -19
- package/dist/ci-own-jobs.d.ts.map +1 -1
- package/dist/ci-own-jobs.js +1 -2
- package/dist/ci-product-words.d.ts +18 -4
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +26 -6
- package/dist/ci-product.d.ts +1 -1
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +3 -4
- package/dist/cli/handlers/release.js +4 -4
- package/dist/components/pr-env-components.d.ts.map +1 -1
- package/dist/components/pr-env-components.js +1 -2
- package/dist/config.d.ts +14 -8
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +16 -1
- package/dist/lexicon.d.ts +8 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lexicon.js +9 -0
- package/dist/lifecycle/release-images.d.ts +77 -3
- package/dist/lifecycle/release-images.d.ts.map +1 -1
- package/dist/lifecycle/release-images.js +132 -6
- package/dist/notify-product.d.ts +11 -2
- package/dist/notify-product.d.ts.map +1 -1
- package/dist/notify-product.js +16 -4
- package/dist/notify-relay.d.ts.map +1 -1
- package/dist/notify-relay.js +1 -2
- package/dist/notify.d.ts +36 -4
- package/dist/notify.d.ts.map +1 -1
- package/dist/notify.js +31 -21
- package/dist/notify.schema.json +1 -0
- package/dist/op/activities/review-product.d.ts +111 -0
- package/dist/op/activities/review-product.d.ts.map +1 -0
- package/dist/op/activities/review-product.js +116 -0
- package/dist/policy-engine.d.ts.map +1 -1
- package/dist/policy-engine.js +1 -2
- package/dist/pr-forge-reads.d.ts +124 -0
- package/dist/pr-forge-reads.d.ts.map +1 -0
- package/dist/pr-forge-reads.js +322 -0
- package/dist/pr-forge.d.ts +14 -0
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +21 -13
- package/dist/pr-plan-note.d.ts +293 -0
- package/dist/pr-plan-note.d.ts.map +1 -0
- package/dist/pr-plan-note.js +362 -0
- package/dist/release-floors.d.ts +9 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +9 -1
- package/dist/state-export.d.ts.map +1 -1
- package/dist/state-export.js +1 -2
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +1 -2
- package/dist/state-unlock.d.ts.map +1 -1
- package/dist/state-unlock.js +1 -2
- package/dist/wave-runtime.mjs +271 -271
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +2 -1
- package/package.json +1 -1
- package/src/__fixtures__/notify-messages/events.ts +23 -0
- package/src/__fixtures__/notify-messages/messages.json +50 -0
- package/src/__fixtures__/pr-loop/terragucci-plan.note.golden.md +53 -0
- package/src/__fixtures__/pr-loop/terragucci-plan.note.json +83 -0
- package/src/__fixtures__/product-words.ts +12 -0
- package/src/__fixtures__/review-agent/terragucci-review.json +94 -0
- package/src/__fixtures__/terragucci-notify.ts +170 -0
- package/src/action-pins.test.ts +12 -1
- package/src/action-pins.ts +11 -0
- package/src/agent-guard.test.ts +1 -2
- package/src/agent-guard.ts +1 -2
- package/src/ci-commit.test.ts +163 -0
- package/src/ci-commit.ts +168 -21
- package/src/ci-own-jobs.test.ts +1 -2
- package/src/ci-own-jobs.ts +1 -2
- package/src/ci-product-words.ts +35 -7
- package/src/ci-product.ts +3 -4
- package/src/cli/handlers/build-pr-loop-control.test.ts +1 -2
- package/src/cli/handlers/build-run-group.test.ts +1 -2
- package/src/cli/handlers/release.ts +5 -5
- package/src/components/pr-env-components.test.ts +1 -2
- package/src/components/pr-env-components.ts +1 -2
- package/src/config.ts +23 -3
- package/src/gate-policy-bundle.test.ts +1 -1
- package/src/lexicon.ts +10 -0
- package/src/lifecycle/release-images-dockerfile.test.ts +221 -0
- package/src/lifecycle/release-images.ts +167 -8
- package/src/notify-message-words.test.ts +186 -0
- package/src/notify-product.ts +17 -4
- package/src/notify-relay.ts +1 -2
- package/src/notify.schema.json +1 -0
- package/src/notify.ts +59 -19
- package/src/op/activities/review-product.test.ts +116 -0
- package/src/op/activities/review-product.ts +200 -0
- package/src/op/schedule-overdue.test.ts +26 -0
- package/src/policy-engine.test.ts +1 -2
- package/src/policy-engine.ts +1 -2
- package/src/pr-forge-reads.test.ts +285 -0
- package/src/pr-forge-reads.ts +424 -0
- package/src/pr-forge.ts +30 -16
- package/src/pr-plan-note.test.ts +105 -0
- package/src/pr-plan-note.ts +521 -0
- package/src/release-floors.ts +13 -1
- package/src/state-export.test.ts +1 -2
- package/src/state-export.ts +1 -2
- package/src/state-migration.test.ts +1 -2
- package/src/state-migration.ts +1 -2
- package/src/state-unlock.test.ts +1 -2
- package/src/state-unlock.ts +1 -2
- package/src/workspace/release-workflow.ts +2 -1
|
@@ -21,11 +21,24 @@
|
|
|
21
21
|
* An npm target's `pins` names the file in a package that carries the
|
|
22
22
|
* digests. The publish plan and `chant release verify` read it and refuse a
|
|
23
23
|
* digest the release does not record as an image.
|
|
24
|
+
*
|
|
25
|
+
* An entry may name a Dockerfile instead of a command (#4819): chant runs
|
|
26
|
+
* the reproducible build itself ({@link releaseImageBuildCommand}), a
|
|
27
|
+
* `docker-container` buildx builder writing an OCI archive with timestamps
|
|
28
|
+
* rewritten from `SOURCE_DATE_EPOCH` and no attestations, for every
|
|
29
|
+
* platform. Its `prepare` command (the bundle the image carries, a packed
|
|
30
|
+
* package) runs first with no digests file named, so the image is the same
|
|
31
|
+
* in the cut and the publish job. A product's package build turns the
|
|
32
|
+
* digests file and its `{ name: reference }` into the table it bakes in with
|
|
33
|
+
* {@link releaseImagePins}, and writes the pins file with
|
|
34
|
+
* {@link writeReleaseImagePins}. This module reaches only Node's built-ins at
|
|
35
|
+
* run time, so a product's build script imports it under plain Node.
|
|
24
36
|
*/
|
|
25
37
|
|
|
26
38
|
import { spawnSync } from "node:child_process";
|
|
27
|
-
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
28
|
-
import { dirname, isAbsolute, relative, resolve } from "node:path";
|
|
39
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
40
|
+
import { dirname, isAbsolute, posix, relative, resolve } from "node:path";
|
|
41
|
+
import { NEXT_RELEASE } from "../release-floors";
|
|
29
42
|
import type { PublishDeclaration } from "./publish-declaration";
|
|
30
43
|
import type { Release, ReleaseArtifact } from "./release-store";
|
|
31
44
|
|
|
@@ -35,8 +48,15 @@ export const RELEASE_DIGESTS_ENV = "CHANT_RELEASE_DIGESTS";
|
|
|
35
48
|
/** The first chant with `release.images`, `CHANT_RELEASE_DIGESTS`, `chant release images` and an npm target's `pins` (#4657). Products feature-detect on it. */
|
|
36
49
|
export const RELEASE_IMAGES_FLOOR = "0.124.71";
|
|
37
50
|
|
|
38
|
-
/**
|
|
39
|
-
|
|
51
|
+
/**
|
|
52
|
+
* The first chant whose `release.images` takes a Dockerfile entry, with
|
|
53
|
+
* `releaseImagePins` and `writeReleaseImagePins` for a product's package
|
|
54
|
+
* build (#4819).
|
|
55
|
+
*/
|
|
56
|
+
export const RELEASE_IMAGE_DOCKERFILE_FLOOR = NEXT_RELEASE;
|
|
57
|
+
|
|
58
|
+
/** One image a release builds in its cut with a command of the product's. */
|
|
59
|
+
export interface ReleaseImageBuild {
|
|
40
60
|
/** The image's name: its key in the digests file, and its artifact's `component` in the release. */
|
|
41
61
|
name: string;
|
|
42
62
|
/** The shell command, run in the member's directory, that writes the archive. */
|
|
@@ -45,6 +65,65 @@ export interface ReleaseImageDeclaration {
|
|
|
45
65
|
archive: string;
|
|
46
66
|
}
|
|
47
67
|
|
|
68
|
+
/** One image chant builds from a Dockerfile (#4819). */
|
|
69
|
+
export interface ReleaseImageDockerfile {
|
|
70
|
+
name: string;
|
|
71
|
+
/** The Dockerfile, relative to the member. */
|
|
72
|
+
dockerfile: string;
|
|
73
|
+
/** The build context, relative to the member. Default `.`. */
|
|
74
|
+
context?: string;
|
|
75
|
+
/** The platforms the archive's image index holds. Default {@link RELEASE_IMAGE_PLATFORMS}. */
|
|
76
|
+
platforms?: string[];
|
|
77
|
+
/** Where the archive goes, relative to the member. Default `dist/images/<name>.tar`. */
|
|
78
|
+
archive?: string;
|
|
79
|
+
/** A command run once before the builds, with `CHANT_RELEASE_DIGESTS` unset: what the image copies in, such as the bundle or a packed package. */
|
|
80
|
+
prepare?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** One image a release builds in its cut. */
|
|
84
|
+
export type ReleaseImageDeclaration = ReleaseImageBuild | ReleaseImageDockerfile;
|
|
85
|
+
|
|
86
|
+
/** The platforms a Dockerfile entry builds by default. Building arm64 on amd64 needs QEMU's binfmt handlers. */
|
|
87
|
+
export const RELEASE_IMAGE_PLATFORMS: readonly string[] = ["linux/amd64", "linux/arm64"];
|
|
88
|
+
|
|
89
|
+
/** The buildx builder a Dockerfile entry builds with, created with the `docker-container` driver when missing: the default driver cannot rewrite timestamps in an OCI archive. */
|
|
90
|
+
export const RELEASE_IMAGE_BUILDER = "chant-release";
|
|
91
|
+
|
|
92
|
+
const PLATFORM = /^[a-z0-9]+\/[a-z0-9_]+(?:\/[a-z0-9]+)?$/;
|
|
93
|
+
|
|
94
|
+
/** A word the shell reads as itself. */
|
|
95
|
+
const sh = (s: string): string => (/^[A-Za-z0-9_./:=,@+%-]+$/.test(s) ? s : `'${s.replace(/'/g, "'\\''")}'`);
|
|
96
|
+
|
|
97
|
+
const isDockerfile = (i: ReleaseImageDeclaration): i is ReleaseImageDockerfile => "dockerfile" in i && i.dockerfile !== undefined;
|
|
98
|
+
|
|
99
|
+
const archiveOf = (i: ReleaseImageDeclaration): string => i.archive ?? `dist/images/${i.name}.tar`;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The shell command a Dockerfile entry builds with (#4819), the one
|
|
103
|
+
* terragucci's and plywood's `scripts/release-image.sh` ran: `--no-cache`,
|
|
104
|
+
* no provenance or SBOM in the archive (chant attaches its own), the
|
|
105
|
+
* `SOURCE_DATE_EPOCH` the cut sets passed as a build argument and used to
|
|
106
|
+
* rewrite every timestamp, and every platform in one image index.
|
|
107
|
+
*/
|
|
108
|
+
export function releaseImageBuildCommand(i: ReleaseImageDockerfile): string {
|
|
109
|
+
const archive = archiveOf(i);
|
|
110
|
+
const b = RELEASE_IMAGE_BUILDER;
|
|
111
|
+
return [
|
|
112
|
+
`{ docker buildx inspect ${b} >/dev/null 2>&1 || docker buildx create --name ${b} --driver docker-container >/dev/null; }`,
|
|
113
|
+
`mkdir -p ${sh(posix.dirname(archive))}`,
|
|
114
|
+
[
|
|
115
|
+
`docker buildx build --builder ${b} --no-cache --platform ${sh((i.platforms ?? RELEASE_IMAGE_PLATFORMS).join(","))}`,
|
|
116
|
+
`--provenance=false --sbom=false --build-arg SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH"`,
|
|
117
|
+
`--output ${sh(`type=oci,dest=${archive},rewrite-timestamp=true`)} -f ${sh(i.dockerfile)} ${sh(i.context ?? ".")} >&2`,
|
|
118
|
+
].join(" "),
|
|
119
|
+
].join(" && ");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Each entry as a command and an archive: a Dockerfile entry's command is {@link releaseImageBuildCommand}, its archive the default when it names none. */
|
|
123
|
+
export function resolveReleaseImages(images: readonly ReleaseImageDeclaration[]): ReleaseImageBuild[] {
|
|
124
|
+
return images.map((i) => (isDockerfile(i) ? { name: i.name, build: releaseImageBuildCommand(i), archive: archiveOf(i) } : i));
|
|
125
|
+
}
|
|
126
|
+
|
|
48
127
|
export class ReleaseImageError extends Error {
|
|
49
128
|
constructor(
|
|
50
129
|
readonly code: string,
|
|
@@ -58,15 +137,22 @@ export class ReleaseImageError extends Error {
|
|
|
58
137
|
|
|
59
138
|
const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
|
|
60
139
|
|
|
61
|
-
|
|
140
|
+
const outside = (p: string): boolean => isAbsolute(p) || p.split(/[\\/]/).includes("..");
|
|
141
|
+
|
|
142
|
+
/** Check a member's `release.images`: names valid and unique, one of `build` and `dockerfile`, paths inside the member, platforms of the form os/arch. */
|
|
62
143
|
export function checkReleaseImages(images: readonly ReleaseImageDeclaration[]): void {
|
|
63
144
|
const seen = new Set<string>();
|
|
64
145
|
for (const i of images) {
|
|
65
146
|
if (!NAME.test(i.name)) throw new ReleaseImageError("release-image-name-invalid", `release.images: "${i.name}" is not a name of letters, digits, ".", "_" and "-"`);
|
|
66
147
|
if (seen.has(i.name)) throw new ReleaseImageError("release-image-name-taken", `release.images names "${i.name}" twice`);
|
|
67
148
|
seen.add(i.name);
|
|
68
|
-
if (
|
|
69
|
-
|
|
149
|
+
if (isDockerfile(i) && "build" in i) throw new ReleaseImageError("release-image-invalid", `release.images "${i.name}" names a build command and a Dockerfile; chant builds a Dockerfile itself, so name one`);
|
|
150
|
+
const paths: [string, string | undefined][] = isDockerfile(i) ? [["the archive", archiveOf(i)], ["the Dockerfile", i.dockerfile], ["the context", i.context]] : [["the archive", i.archive]];
|
|
151
|
+
for (const [what, p] of paths) {
|
|
152
|
+
if (p !== undefined && outside(p)) throw new ReleaseImageError("release-image-archive-outside", `release.images "${i.name}": ${what} ${p} is not a path inside the member`);
|
|
153
|
+
}
|
|
154
|
+
if (isDockerfile(i) && i.platforms !== undefined && (i.platforms.length === 0 || !i.platforms.every((p) => PLATFORM.test(p)))) {
|
|
155
|
+
throw new ReleaseImageError("release-image-invalid", `release.images "${i.name}": platforms is a list of os/arch such as linux/amd64, not ${JSON.stringify(i.platforms)}`);
|
|
70
156
|
}
|
|
71
157
|
}
|
|
72
158
|
}
|
|
@@ -100,10 +186,24 @@ export function buildReleaseImages(i: BuildImagesInput): ReleaseArtifact[] {
|
|
|
100
186
|
checkReleaseImages(i.images);
|
|
101
187
|
const run = i.run ?? defaultRun;
|
|
102
188
|
const out: ReleaseArtifact[] = [];
|
|
103
|
-
|
|
189
|
+
const envFor = (): NodeJS.ProcessEnv => {
|
|
104
190
|
const env: NodeJS.ProcessEnv = { ...(i.env ?? process.env), SOURCE_DATE_EPOCH: String(i.sourceDateEpoch) };
|
|
105
191
|
delete env.CHANT_RELEASE_LABEL;
|
|
106
192
|
if (i.label !== null) env.CHANT_RELEASE_LABEL = i.label;
|
|
193
|
+
return env;
|
|
194
|
+
};
|
|
195
|
+
// #4819: each prepare command once, before any build, with no digests file, as the image's contents are built in the cut and the publish job alike.
|
|
196
|
+
const prepared = new Set<string>();
|
|
197
|
+
for (const image of i.images) {
|
|
198
|
+
if (!isDockerfile(image) || !image.prepare || prepared.has(image.prepare)) continue;
|
|
199
|
+
prepared.add(image.prepare);
|
|
200
|
+
const env = envFor();
|
|
201
|
+
delete env[RELEASE_DIGESTS_ENV];
|
|
202
|
+
const status = run(image.prepare, { cwd: i.cwd, env });
|
|
203
|
+
if (status !== 0) throw new ReleaseImageError("release-image-build-failed", `the prepare command of image "${image.name}" exited ${status ?? "with a signal"}: ${image.prepare}`);
|
|
204
|
+
}
|
|
205
|
+
for (const image of resolveReleaseImages(i.images)) {
|
|
206
|
+
const env = envFor();
|
|
107
207
|
const status = run(image.build, { cwd: i.cwd, env });
|
|
108
208
|
if (status !== 0) throw new ReleaseImageError("release-image-build-failed", `the build of image "${image.name}" exited ${status ?? "with a signal"}: ${image.build}`);
|
|
109
209
|
const abs = resolve(i.cwd, image.archive);
|
|
@@ -124,6 +224,65 @@ export function releaseImageDigests(release: Pick<Release, "artifactDigests">, n
|
|
|
124
224
|
return out;
|
|
125
225
|
}
|
|
126
226
|
|
|
227
|
+
// ── a product's package build (#4819) ──────────────────────────────────
|
|
228
|
+
|
|
229
|
+
const SHA256 = /^sha256:[0-9a-f]{64}$/;
|
|
230
|
+
|
|
231
|
+
export interface ReleaseImagePinsInput {
|
|
232
|
+
/** Each image's name in `release.images`, to its reference at this version: `ghcr.io/intentius/plywood-pulumi:0.3.0-pulumi3.272.0`. */
|
|
233
|
+
images: Record<string, string>;
|
|
234
|
+
/** The package's version. A cut's label (`CHANT_RELEASE_LABEL`) must be it. */
|
|
235
|
+
version: string;
|
|
236
|
+
env?: NodeJS.ProcessEnv;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* The digest table a release's package build bakes into its bundle: each
|
|
241
|
+
* reference in `images` to the digest the cut recorded for its name, in
|
|
242
|
+
* `images`' order. Undefined outside a release build (no
|
|
243
|
+
* `CHANT_RELEASE_DIGESTS`), when a pipeline names the images by tag. Refuses
|
|
244
|
+
* a label that is not the version and a name the digests file has no digest
|
|
245
|
+
* for.
|
|
246
|
+
*/
|
|
247
|
+
export function releaseImagePins(i: ReleaseImagePinsInput): Record<string, string> | undefined {
|
|
248
|
+
const env = i.env ?? process.env;
|
|
249
|
+
const file = env[RELEASE_DIGESTS_ENV];
|
|
250
|
+
if (!file) return undefined;
|
|
251
|
+
const label = env.CHANT_RELEASE_LABEL;
|
|
252
|
+
if (label && label !== i.version) {
|
|
253
|
+
throw new ReleaseImageError("release-label-not-version", `the release is labelled ${label}, and the package is at ${i.version}`, `Set the package's version to ${label} on the default branch, then cut the merged commit.`);
|
|
254
|
+
}
|
|
255
|
+
const named = JSON.parse(readFileSync(file, "utf-8")) as Record<string, unknown>;
|
|
256
|
+
const table: Record<string, string> = {};
|
|
257
|
+
for (const [name, reference] of Object.entries(i.images)) {
|
|
258
|
+
const digest = named[name];
|
|
259
|
+
if (typeof digest !== "string" || !SHA256.test(digest)) throw new ReleaseImageError("release-image-digest-missing", `${file} has no digest for the ${name} image, which the release builds`);
|
|
260
|
+
table[reference] = digest;
|
|
261
|
+
}
|
|
262
|
+
return table;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Write the pins file an npm target's `pins` names, once the bundle is
|
|
267
|
+
* built: the table as JSON, after checking that every bundle in `bundles`
|
|
268
|
+
* carries each digest. With no table (not a release build), remove the file,
|
|
269
|
+
* so a package never ships a stale one.
|
|
270
|
+
*/
|
|
271
|
+
export function writeReleaseImagePins(table: Record<string, string> | undefined, o: { out: string; bundles?: readonly string[] }): void {
|
|
272
|
+
if (!table) {
|
|
273
|
+
rmSync(o.out, { force: true });
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
for (const bundle of o.bundles ?? []) {
|
|
277
|
+
const text = readFileSync(bundle, "utf-8");
|
|
278
|
+
for (const [reference, digest] of Object.entries(table)) {
|
|
279
|
+
if (!text.includes(digest)) throw new ReleaseImageError("release-pin-not-bundled", `${bundle} does not carry ${reference}@${digest}`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
mkdirSync(dirname(o.out), { recursive: true });
|
|
283
|
+
writeFileSync(o.out, `${JSON.stringify(table, null, 2)}\n`);
|
|
284
|
+
}
|
|
285
|
+
|
|
127
286
|
/** Write the digests file a package build reads. */
|
|
128
287
|
export function writeReleaseDigests(file: string, digests: Record<string, string>): void {
|
|
129
288
|
mkdirSync(dirname(file), { recursive: true });
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack and Teams messages a product can word (#4818): labels, a drift
|
|
3
|
+
* notice's re-run button, and the relay's name in the Teams reply.
|
|
4
|
+
*
|
|
5
|
+
* Two proofs. With no words, every message is the bytes chant 0.124.77
|
|
6
|
+
* rendered (`__fixtures__/notify-messages/messages.json`). With terragucci's
|
|
7
|
+
* words, chant's messages are the bytes terragucci's own renderers write
|
|
8
|
+
* (`__fixtures__/terragucci-notify.ts`, copied from terragucci), over the
|
|
9
|
+
* notices terragucci's notify tests build.
|
|
10
|
+
*/
|
|
11
|
+
import { describe, expect, test } from "vitest";
|
|
12
|
+
import { makeNotifyEvent, sendNotify, slackMessage, teamsMessage, type NotifyEvent, type NotifyFetch, type NotifyMessageWords } from "./notify";
|
|
13
|
+
import { driftNotifyFields, NOTIFY_MESSAGE_WORDS_FLOOR, productSendOptions } from "./notify-product";
|
|
14
|
+
import { assertProductWords } from "./ci-product-words";
|
|
15
|
+
import { NEXT_RELEASE } from "./release-floors";
|
|
16
|
+
import { NOTIFY_MESSAGE_EVENTS } from "./__fixtures__/notify-messages/events";
|
|
17
|
+
import recorded from "./__fixtures__/notify-messages/messages.json";
|
|
18
|
+
import * as tg from "./__fixtures__/terragucci-notify";
|
|
19
|
+
import schema from "./notify.schema.json";
|
|
20
|
+
import { contract } from "./workspace/__fixtures__/contract-repo";
|
|
21
|
+
|
|
22
|
+
const { expectValid } = contract(schema);
|
|
23
|
+
const NOW = new Date("2026-11-08T12:00:00.000Z");
|
|
24
|
+
const relay = { token: "signed-ref" };
|
|
25
|
+
|
|
26
|
+
describe("a message given no words (#4818)", () => {
|
|
27
|
+
test.each(Object.keys(NOTIFY_MESSAGE_EVENTS))("%s is the bytes chant 0.124.77 wrote, with and without relay buttons", (key) => {
|
|
28
|
+
const e = NOTIFY_MESSAGE_EVENTS[key]!;
|
|
29
|
+
const want = (recorded as Record<string, Record<string, string>>)[key]!;
|
|
30
|
+
for (const words of [undefined, {}]) {
|
|
31
|
+
expect(JSON.stringify(slackMessage(e, undefined, words))).toBe(want.slack);
|
|
32
|
+
expect(JSON.stringify(teamsMessage(e, undefined, words))).toBe(want.teams);
|
|
33
|
+
expect(JSON.stringify(slackMessage(e, relay, words))).toBe(want.slackRelay);
|
|
34
|
+
expect(JSON.stringify(teamsMessage(e, relay, words))).toBe(want.teamsRelay);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("chant's words, and a product's words with no message slot, leave sendNotify's options as they were", () => {
|
|
39
|
+
expect(productSendOptions(assertProductWords({}), { attempts: 1 })).toEqual({ attempts: 1 });
|
|
40
|
+
expect(productSendOptions(assertProductWords({ product: "plywood", noun: ["stack", "stacks"] }))).toEqual({ prefix: "x-plywood" });
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// ── terragucci ───────────────────────────────────────────────────────────
|
|
45
|
+
|
|
46
|
+
/** terragucci's message words, as it would pass them in its CiProductWords' notify slot. */
|
|
47
|
+
const TERRAGUCCI_MESSAGE: NotifyMessageWords = {
|
|
48
|
+
targets: "Roots",
|
|
49
|
+
noTargets: "see the run",
|
|
50
|
+
reason: "Outcome",
|
|
51
|
+
again: "run the wave again",
|
|
52
|
+
wave: "Wave",
|
|
53
|
+
teamsReport: false,
|
|
54
|
+
rerun: { label: "Re-plan", action: "terragucci-replan", block: "terragucci-drift" },
|
|
55
|
+
};
|
|
56
|
+
const words = assertProductWords({ product: "terragucci", noun: ["root", "roots"], notify: { source: "terragucci", wave: "wave {k}", headers: "x-terragucci", message: TERRAGUCCI_MESSAGE } });
|
|
57
|
+
|
|
58
|
+
/** The chat event for a wave notice: what terragucci's messages show, as chant's event fields. */
|
|
59
|
+
function waveEvent(n: tg.WaveNotice): NotifyEvent {
|
|
60
|
+
return makeNotifyEvent(
|
|
61
|
+
{
|
|
62
|
+
source: "terragucci",
|
|
63
|
+
event: n.event,
|
|
64
|
+
summary: tg.summary(n),
|
|
65
|
+
project: n.project,
|
|
66
|
+
wave: { number: n.wave, gate: `wave-${n.wave}` },
|
|
67
|
+
targets: n.roots,
|
|
68
|
+
...(n.digest ? { digest: n.digest } : {}),
|
|
69
|
+
approve: { command: n.approve, ...(n.review ? { review: n.review } : {}) },
|
|
70
|
+
...(n.outcome ? { reason: n.outcome } : {}),
|
|
71
|
+
run: n.run ? { url: n.run } : {},
|
|
72
|
+
...(n.report ? { reportUrl: n.report } : {}),
|
|
73
|
+
},
|
|
74
|
+
{ env: {}, now: NOW },
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The drift event: chant's drift fields under terragucci's words, its headline as the summary, and the Re-plan page. */
|
|
79
|
+
function driftEvent(n: tg.DriftNotice): NotifyEvent {
|
|
80
|
+
const fields = driftNotifyFields(words, { changed: n.roots, failed: n.failed, project: n.project, ...(n.report ? { reportUrl: n.report } : {}) });
|
|
81
|
+
return makeNotifyEvent({ ...fields, summary: tg.driftHeadline(n).slice("terragucci: ".length), ...(n.replan ? { rerunUrl: n.replan } : {}), run: n.run ? { url: n.run } : {} }, { env: {}, now: NOW });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// The notices terragucci's test/notify.test.ts builds (ENV is acme/infra, run 42).
|
|
85
|
+
const RUN = "https://github.com/acme/infra/actions/runs/42";
|
|
86
|
+
const PROJECT = "github.com/acme/infra";
|
|
87
|
+
const waiting: tg.WaveNotice = { event: "waiting", wave: 2, project: PROJECT, roots: ["envs/prod/app", "envs/prod/db"], approve: "npx terragucci approve wave-2 --plan jcs1-sha256:ab", digest: "jcs1-sha256:ab", run: RUN };
|
|
88
|
+
const WAVES: Record<string, tg.WaveNotice> = {
|
|
89
|
+
waiting,
|
|
90
|
+
"waiting with a report": { ...waiting, report: "https://reports.example/acme/42" },
|
|
91
|
+
"under pr-review": { ...waiting, review: { pr: 7, url: "https://github.com/acme/infra/pull/7/files" } },
|
|
92
|
+
"waiting with the relay": { ...waiting, relay: "terragucci" },
|
|
93
|
+
refused: { event: "refused", wave: 3, project: PROJECT, roots: ["envs/prod/app"], approve: "read the plans that moved, then npx terragucci approve wave-3 --plan jcs1-sha256:dd, or revert", outcome: "wave 3 changed after approval: envs/prod/app", run: RUN },
|
|
94
|
+
"failed, no roots": { event: "failed", wave: 1, project: "this project", roots: [], approve: "nothing to approve: the apply failed; read the job log" },
|
|
95
|
+
"failed, policy denied": { event: "failed", wave: 1, project: PROJECT, roots: ["envs/prod/app"], approve: "nothing to approve: the policy denied it; an override command is in the job log", outcome: "policy denied envs/prod/app", run: RUN, report: "https://reports.example/acme/43" },
|
|
96
|
+
};
|
|
97
|
+
const DRIFTS: Record<string, tg.DriftNotice> = {
|
|
98
|
+
"drift with a Re-plan page": { project: PROJECT, roots: ["app"], failed: ["db"], run: RUN, replan: "https://github.com/acme/infra/actions/workflows/terragucci.yml" },
|
|
99
|
+
"drift on GitLab, with a report": { project: "acme/infra", roots: ["app", "net"], failed: [], run: "https://gitlab.com/acme/infra/-/jobs/9", report: "https://reports.example/acme/44", replan: "https://gitlab.com/acme/infra/-/pipeline_schedules" },
|
|
100
|
+
"drift with no Re-plan page": { project: PROJECT, roots: [], failed: ["db"] },
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
describe("terragucci's messages, rendered by chant under its words (#4818)", () => {
|
|
104
|
+
test.each(Object.keys(WAVES))("a wave %s: Slack and Teams are terragucci's bytes", (key) => {
|
|
105
|
+
const n = WAVES[key]!;
|
|
106
|
+
const e = waveEvent(n);
|
|
107
|
+
const message = { ...TERRAGUCCI_MESSAGE, ...(n.relay ? { relayName: n.relay } : {}) };
|
|
108
|
+
expect(JSON.stringify(slackMessage(e, undefined, message))).toBe(JSON.stringify(tg.slackMessage(n)));
|
|
109
|
+
expect(JSON.stringify(teamsMessage(e, undefined, message))).toBe(JSON.stringify(tg.teamsMessage(n)));
|
|
110
|
+
if (n.relay) {
|
|
111
|
+
expect(JSON.stringify(slackMessage(e, relay, message))).toBe(JSON.stringify(tg.slackMessage(n, relay)));
|
|
112
|
+
expect(JSON.stringify(teamsMessage(e, relay, message))).toBe(JSON.stringify(tg.teamsMessage(n, relay)));
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test.each(Object.keys(DRIFTS))("%s: Slack and Teams are terragucci's bytes", (key) => {
|
|
117
|
+
const n = DRIFTS[key]!;
|
|
118
|
+
const e = driftEvent(n);
|
|
119
|
+
expect(JSON.stringify(slackMessage(e, undefined, TERRAGUCCI_MESSAGE))).toBe(JSON.stringify(tg.slackDrift(n)));
|
|
120
|
+
expect(JSON.stringify(teamsMessage(e, undefined, TERRAGUCCI_MESSAGE))).toBe(JSON.stringify(tg.teamsDrift(n)));
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("terragucci's test lines hold: the review line, the relay reply, the Re-plan button", () => {
|
|
124
|
+
const review = slackMessage(waveEvent(WAVES["under pr-review"]!), undefined, TERRAGUCCI_MESSAGE).text.split("\n");
|
|
125
|
+
expect(review[1]).toBe("Review and approve: <https://github.com/acme/infra/pull/7/files|pull request 7>, then run the wave again");
|
|
126
|
+
const card = (teamsMessage(waveEvent(WAVES["waiting with the relay"]!), relay, { ...TERRAGUCCI_MESSAGE, relayName: "terragucci" }) as any).attachments[0].content;
|
|
127
|
+
expect(card.body.at(-1).text).toBe("Approve here: reply @terragucci approve signed-ref. Decline: reply @terragucci decline signed-ref.");
|
|
128
|
+
const n = DRIFTS["drift with a Re-plan page"]!;
|
|
129
|
+
const slack = slackMessage(driftEvent(n), undefined, TERRAGUCCI_MESSAGE);
|
|
130
|
+
expect(slack.text.split("\n")).toEqual(["*terragucci: drift in github.com/acme/infra: 1 root changed outside Terraform, 1 could not be refreshed*", "Drifted: app", "Not refreshed: db", `Run: <${RUN}>`]);
|
|
131
|
+
expect((slack.blocks?.[1] as any).elements).toEqual([{ type: "button", action_id: "terragucci-replan", text: { type: "plain_text", text: "Re-plan" }, url: n.replan }]);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("sendNotify posts terragucci's drift bodies with the words and no render of its own", async () => {
|
|
135
|
+
const n = DRIFTS["drift with a Re-plan page"]!;
|
|
136
|
+
const posted: Record<string, string> = {};
|
|
137
|
+
const fetch: NotifyFetch = async (url, init) => {
|
|
138
|
+
posted[url] = init.body;
|
|
139
|
+
return { ok: true, status: 200 };
|
|
140
|
+
};
|
|
141
|
+
const env = { S: "https://hooks.slack.test/a", T: "https://teams.test/b" };
|
|
142
|
+
const out = await sendNotify({ slack: "S", teams: "T" }, driftEvent(n), productSendOptions(words, { env, fetch, attempts: 1 }));
|
|
143
|
+
expect(out.map((d) => d.ok)).toEqual([true, true]);
|
|
144
|
+
expect(posted[env.S]).toBe(JSON.stringify(tg.slackDrift(n)));
|
|
145
|
+
expect(posted[env.T]).toBe(JSON.stringify(tg.teamsDrift(n)));
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("sendNotify names the relay in the Teams reply from its message options", async () => {
|
|
149
|
+
const n = WAVES["waiting with the relay"]!;
|
|
150
|
+
const posted: string[] = [];
|
|
151
|
+
const fetch: NotifyFetch = async (_url, init) => {
|
|
152
|
+
posted.push(init.body);
|
|
153
|
+
return { ok: true, status: 200 };
|
|
154
|
+
};
|
|
155
|
+
const options = productSendOptions(words, { env: { T: "https://teams.test/b", RK: "k" }, fetch, attempts: 1, message: { relayName: "terragucci" } });
|
|
156
|
+
await sendNotify({ teams: "T", relay: "RK" }, waveEvent(n), options);
|
|
157
|
+
const card = JSON.parse(posted[0]!).attachments[0].content;
|
|
158
|
+
expect(card.body.at(-1).text).toMatch(/^Approve here: reply @terragucci approve \S+\. Decline: reply @terragucci decline \S+\.$/);
|
|
159
|
+
expect(card.body[1].facts[0]).toEqual({ title: "Wave", value: "2" });
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("chant's own words for the re-run button and the relay (#4818)", () => {
|
|
164
|
+
const drift = NOTIFY_MESSAGE_EVENTS.drift!;
|
|
165
|
+
const e = { ...drift, rerunUrl: "https://github.com/acme/db/actions/workflows/drift.yml" };
|
|
166
|
+
|
|
167
|
+
test("a re-run page gives a Slack button and a Teams action before the run's", () => {
|
|
168
|
+
const slack = slackMessage(e);
|
|
169
|
+
expect(slack.blocks?.[1]).toEqual({ type: "actions", elements: [{ type: "button", action_id: "chant-rerun", text: { type: "plain_text", text: "Run again" }, url: e.rerunUrl }] });
|
|
170
|
+
const card = (teamsMessage(e) as any).attachments[0].content;
|
|
171
|
+
expect(card.actions).toEqual([
|
|
172
|
+
{ type: "Action.OpenUrl", title: "Run again", url: e.rerunUrl },
|
|
173
|
+
{ type: "Action.OpenUrl", title: "Open the run", url: drift.run!.url },
|
|
174
|
+
]);
|
|
175
|
+
expectValid(JSON.parse(JSON.stringify(e)));
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("the relay's name turns the Teams fact into the full replies", () => {
|
|
179
|
+
const waitingEvent = NOTIFY_MESSAGE_EVENTS.waiting!;
|
|
180
|
+
const card = (teamsMessage(waitingEvent, relay, { relayName: "chant-relay" }) as any).attachments[0].content;
|
|
181
|
+
expect(card.body[1].facts.map((f: { title: string }) => f.title)).not.toContain("Approve in chat");
|
|
182
|
+
expect(card.body[2]).toEqual({ type: "TextBlock", wrap: true, text: "Approve here: reply @chant-relay approve signed-ref. Decline: reply @chant-relay decline signed-ref." });
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("the floor names the next release", () => expect(NOTIFY_MESSAGE_WORDS_FLOOR).toBe(NEXT_RELEASE));
|
|
186
|
+
});
|
package/src/notify-product.ts
CHANGED
|
@@ -14,6 +14,15 @@
|
|
|
14
14
|
|
|
15
15
|
import { CHANT_WORDS, isChantWords, type CiProductNotifyWords, type CiProductWords } from "./ci-product-words";
|
|
16
16
|
import type { NotifyFields, SendNotifyOptions } from "./notify";
|
|
17
|
+
import { NEXT_RELEASE } from "./release-floors";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The first chant whose Slack and Teams messages take a product's words, a
|
|
21
|
+
* drift event's `rerunUrl` and the relay's name (#4818): `notify.message` in
|
|
22
|
+
* the words, `message` in sendNotify's options, and the third argument of
|
|
23
|
+
* `slackMessage` and `teamsMessage`.
|
|
24
|
+
*/
|
|
25
|
+
export const NOTIFY_MESSAGE_WORDS_FLOOR = NEXT_RELEASE;
|
|
17
26
|
|
|
18
27
|
/** The notify slots of `words`, chant's when a caller built words before #4610. */
|
|
19
28
|
export function productNotifyWords(words: CiProductWords): CiProductNotifyWords {
|
|
@@ -26,12 +35,16 @@ export function productNotifySource(words: CiProductWords): string {
|
|
|
26
35
|
}
|
|
27
36
|
|
|
28
37
|
/**
|
|
29
|
-
* `options` with the product's header prefix, unless the caller names one
|
|
30
|
-
*
|
|
38
|
+
* `options` with the product's header prefix, unless the caller names one,
|
|
39
|
+
* and its message words (`notify.message`, #4818) under the caller's
|
|
40
|
+
* `message`. chant's own words with no message words leave `options` as they
|
|
41
|
+
* are, so chant sends `x-chant`.
|
|
31
42
|
*/
|
|
32
43
|
export function productSendOptions(words: CiProductWords, options: SendNotifyOptions = {}): SendNotifyOptions {
|
|
33
|
-
|
|
34
|
-
|
|
44
|
+
const own = productNotifyWords(words);
|
|
45
|
+
const out = own.message ? { ...options, message: { ...own.message, ...options.message } } : options;
|
|
46
|
+
if (options.prefix !== undefined || isChantWords(words)) return out;
|
|
47
|
+
return { ...out, prefix: own.headers };
|
|
35
48
|
}
|
|
36
49
|
|
|
37
50
|
/** What a drift notice concerns. */
|
package/src/notify-relay.ts
CHANGED
|
@@ -47,7 +47,6 @@ import { createServer, type IncomingMessage, type Server } from "node:http";
|
|
|
47
47
|
import type { CiProductWords } from "./ci-product-words";
|
|
48
48
|
import type { GatedRequest } from "./lifecycle/gated-request-digest";
|
|
49
49
|
import { readRelayToken, RELAY_APPROVE_ACTION, RELAY_DECLINE_ACTION, type RelayRef } from "./notify";
|
|
50
|
-
import { NEXT_RELEASE } from "./release-floors";
|
|
51
50
|
|
|
52
51
|
/**
|
|
53
52
|
* The first chant whose relay answers a gate's decision point and whose
|
|
@@ -65,7 +64,7 @@ export const NOTIFY_RELAY_POINTS_FLOOR = "0.124.72";
|
|
|
65
64
|
* (#4759). A product whose relay container ran its own entrypoint for these
|
|
66
65
|
* feature-detects on it.
|
|
67
66
|
*/
|
|
68
|
-
export const NOTIFY_RELAY_CLONE_FLOOR =
|
|
67
|
+
export const NOTIFY_RELAY_CLONE_FLOOR = "0.124.77";
|
|
69
68
|
|
|
70
69
|
/** The relay's settings, by environment variable. */
|
|
71
70
|
export const RELAY_ENV = {
|
package/src/notify.schema.json
CHANGED
|
@@ -89,6 +89,7 @@
|
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
91
|
"reportUrl": { "type": "string" },
|
|
92
|
+
"rerunUrl": { "type": "string", "description": "On drift (#4818): the page where a person runs the check again, which the Slack and Teams messages open from a button." },
|
|
92
93
|
"detail": { "type": "object", "description": "The product's own record of the outcome, carried whole (terragucci.outcome/v1)." }
|
|
93
94
|
},
|
|
94
95
|
"allOf": [
|
package/src/notify.ts
CHANGED
|
@@ -102,6 +102,8 @@ export interface NotifyEvent {
|
|
|
102
102
|
run?: NotifyRun;
|
|
103
103
|
/** A report page for the run. */
|
|
104
104
|
reportUrl?: string;
|
|
105
|
+
/** On `drift` (#4818): the page where a person runs the check again, which the chat messages open from a button. */
|
|
106
|
+
rerunUrl?: string;
|
|
105
107
|
/** The product's own record of the outcome, carried whole for programs that know it. */
|
|
106
108
|
detail?: Record<string, unknown>;
|
|
107
109
|
}
|
|
@@ -205,15 +207,41 @@ export function notifyHeadline(e: NotifyEvent): string {
|
|
|
205
207
|
return `${e.source}: ${what} ${HEADLINE[e.event]}`;
|
|
206
208
|
}
|
|
207
209
|
|
|
210
|
+
/**
|
|
211
|
+
* A product's words in the Slack and Teams messages (#4818). Each slot left
|
|
212
|
+
* out keeps chant's, so a message given none is as before.
|
|
213
|
+
*/
|
|
214
|
+
export interface NotifyMessageWords {
|
|
215
|
+
/** The targets' label. Default `Targets`. */
|
|
216
|
+
targets?: string;
|
|
217
|
+
/** The targets' value when the event names none. Default: no line. */
|
|
218
|
+
noTargets?: string;
|
|
219
|
+
/** The reason's label. Default `Reason`. */
|
|
220
|
+
reason?: string;
|
|
221
|
+
/** What a person does after the review: `run it again`. */
|
|
222
|
+
again?: string;
|
|
223
|
+
/** The label of a Teams fact giving the wave's number. Default: no fact. */
|
|
224
|
+
wave?: string;
|
|
225
|
+
/** `false` leaves the report link out of the Teams card. */
|
|
226
|
+
teamsReport?: boolean;
|
|
227
|
+
/** The re-run button: its label (`Run again`), and the Slack action id (`chant-rerun`) and block id (none). */
|
|
228
|
+
rerun?: { label?: string; action?: string; block?: string };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** The words, and the relay's name: a Teams outgoing webhook reads only a message that mentions it, so with the name the card says the whole reply (#4818). */
|
|
232
|
+
export interface NotifyMessageOptions extends NotifyMessageWords {
|
|
233
|
+
relayName?: string;
|
|
234
|
+
}
|
|
235
|
+
|
|
208
236
|
/** The label and value lines both chat messages show, in order. */
|
|
209
|
-
function facts(e: NotifyEvent): { title: string; value: string; link?: string }[] {
|
|
237
|
+
function facts(e: NotifyEvent, w: NotifyMessageWords): { title: string; value: string; link?: string }[] {
|
|
210
238
|
const out: { title: string; value: string; link?: string }[] = [];
|
|
211
|
-
if (e.approve?.review) out.push({ title: "Review and approve", value: `pull request ${e.approve.review.pr}, then run it again`, link: e.approve.review.url });
|
|
239
|
+
if (e.approve?.review) out.push({ title: "Review and approve", value: `pull request ${e.approve.review.pr}, then ${w.again ?? "run it again"}`, link: e.approve.review.url });
|
|
212
240
|
if (e.drift) {
|
|
213
241
|
if (e.drift.changed.length > 0) out.push({ title: "Drifted", value: e.drift.changed.join(", ") });
|
|
214
242
|
if (e.drift.missing?.length) out.push({ title: "Missing", value: e.drift.missing.join(", ") });
|
|
215
243
|
if (e.drift.failed?.length) out.push({ title: "Not refreshed", value: e.drift.failed.join(", ") });
|
|
216
|
-
} else if (e.targets.length > 0) out.push({ title: "Targets", value: e.targets.join(", ") });
|
|
244
|
+
} else if (e.targets.length > 0 || w.noTargets) out.push({ title: w.targets ?? "Targets", value: e.targets.join(", ") || w.noTargets! });
|
|
217
245
|
if (e.ci) {
|
|
218
246
|
out.push({ title: "Commit", value: `${e.ci.commit.slice(0, 12)} on ${e.ci.branch}` });
|
|
219
247
|
if (e.ci.phase) out.push({ title: "Phase", value: e.ci.failedRun ? `${e.ci.phase}: ${e.ci.failedRun.name} ${e.ci.failedRun.conclusion ?? ""}`.trimEnd() : e.ci.phase });
|
|
@@ -223,7 +251,7 @@ function facts(e: NotifyEvent): { title: string; value: string; link?: string }[
|
|
|
223
251
|
}
|
|
224
252
|
if (e.digest) out.push({ title: "Digest", value: e.digest });
|
|
225
253
|
if (e.approve) out.push({ title: e.approve.review ? "Or approve" : "Approve", value: e.approve.command });
|
|
226
|
-
if (e.reason) out.push({ title: "Reason", value: e.reason });
|
|
254
|
+
if (e.reason) out.push({ title: w.reason ?? "Reason", value: e.reason });
|
|
227
255
|
if (e.run?.url) out.push({ title: "Run", value: e.run.url, link: e.run.url });
|
|
228
256
|
if (e.reportUrl) out.push({ title: "Report", value: e.reportUrl, link: e.reportUrl });
|
|
229
257
|
return out;
|
|
@@ -290,18 +318,20 @@ export interface RelayButtons {
|
|
|
290
318
|
token: string;
|
|
291
319
|
}
|
|
292
320
|
|
|
293
|
-
/** A Slack incoming webhook's body: one mrkdwn text, with the approve command as code and the links as links. With `relay`, Approve and Decline buttons (#4611). */
|
|
294
|
-
export function slackMessage(e: NotifyEvent, relay?: RelayButtons): { text: string; blocks?: unknown[] } {
|
|
321
|
+
/** A Slack incoming webhook's body: one mrkdwn text, with the approve command as code and the links as links. With `relay`, Approve and Decline buttons (#4611); with `rerunUrl`, a button that opens it (#4818). */
|
|
322
|
+
export function slackMessage(e: NotifyEvent, relay?: RelayButtons, w: NotifyMessageOptions = {}): { text: string; blocks?: unknown[] } {
|
|
295
323
|
const lines = [`*${notifyHeadline(e)}*`];
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
324
|
+
const r = w.rerun ?? {};
|
|
325
|
+
for (const f of facts(e, w)) {
|
|
326
|
+
if (f.title === "Review and approve") lines.push(`${f.title}: <${f.link}|${f.value.replace(", then", ">, then")}`);
|
|
327
|
+
else if (/^(Or a|A)pprove$|^Digest$/.test(f.title)) lines.push(`${f.title}: \`${f.value}\``);
|
|
299
328
|
else if (f.link) lines.push(`${f.title}: <${f.link}>`);
|
|
300
329
|
else lines.push(`${f.title}: ${f.value}`);
|
|
301
330
|
}
|
|
302
331
|
const text = lines.join("\n");
|
|
303
|
-
|
|
304
|
-
|
|
332
|
+
const blocks: unknown[] = relay ? [slackRelayActions(relay)] : [];
|
|
333
|
+
if (e.rerunUrl) blocks.push({ type: "actions", block_id: r.block, elements: [{ type: "button", action_id: r.action ?? "chant-rerun", text: { type: "plain_text", text: r.label ?? "Run again" }, url: e.rerunUrl }] });
|
|
334
|
+
return blocks.length ? { text, blocks: [{ type: "section", text: { type: "mrkdwn", text } }, ...blocks] } : { text };
|
|
305
335
|
}
|
|
306
336
|
|
|
307
337
|
/**
|
|
@@ -319,12 +349,19 @@ export function teamsRelayReply(relay: RelayButtons, action: "approve" | "declin
|
|
|
319
349
|
return `${action} ${relay.token}`;
|
|
320
350
|
}
|
|
321
351
|
|
|
322
|
-
/** A Teams incoming webhook's body (a Workflows webhook): one Adaptive Card, with buttons that open the review page and the run. With `relay`, the reply that approves through the relay (#4611). */
|
|
323
|
-
export function teamsMessage(e: NotifyEvent, relay?: RelayButtons): Record<string, unknown> {
|
|
324
|
-
const
|
|
352
|
+
/** A Teams incoming webhook's body (a Workflows webhook): one Adaptive Card, with buttons that open the review page, the re-run page (#4818) and the run. With `relay`, the reply that approves through the relay (#4611), in full when `w.relayName` names it. */
|
|
353
|
+
export function teamsMessage(e: NotifyEvent, relay?: RelayButtons, w: NotifyMessageOptions = {}): Record<string, unknown> {
|
|
354
|
+
const at = w.relayName && `reply @${w.relayName} `;
|
|
355
|
+
const all = [
|
|
356
|
+
...(w.wave && e.wave ? [{ title: w.wave, value: `${e.wave.number}` }] : []),
|
|
357
|
+
...facts(e, w).filter((f) => w.teamsReport !== false || f.title !== "Report"),
|
|
358
|
+
...(relay && !at ? [{ title: "Approve in chat", value: `mention the relay and reply: ${teamsRelayReply(relay)}` }] : []),
|
|
359
|
+
];
|
|
360
|
+
const open = (title: string, url: string) => ({ type: "Action.OpenUrl", title, url });
|
|
325
361
|
const actions = [
|
|
326
|
-
...(e.approve?.review ? [
|
|
327
|
-
...(e.
|
|
362
|
+
...(e.approve?.review ? [open("Review and approve", e.approve.review.url)] : []),
|
|
363
|
+
...(e.rerunUrl ? [open(w.rerun?.label ?? "Run again", e.rerunUrl)] : []),
|
|
364
|
+
...(e.run?.url ? [open("Open the run", e.run.url)] : []),
|
|
328
365
|
];
|
|
329
366
|
return {
|
|
330
367
|
type: "message",
|
|
@@ -339,6 +376,7 @@ export function teamsMessage(e: NotifyEvent, relay?: RelayButtons): Record<strin
|
|
|
339
376
|
body: [
|
|
340
377
|
{ type: "TextBlock", text: notifyHeadline(e), weight: "Bolder", wrap: true },
|
|
341
378
|
{ type: "FactSet", facts: all.map((f) => ({ title: f.title, value: f.link && f.title === "Review and approve" ? `${f.value}: ${f.link}` : f.value })) },
|
|
379
|
+
...(relay && at ? [{ type: "TextBlock", wrap: true, text: `Approve here: ${at}approve ${relay.token}. Decline: ${at}decline ${relay.token}.` }] : []),
|
|
342
380
|
],
|
|
343
381
|
...(actions.length > 0 ? { actions } : {}),
|
|
344
382
|
},
|
|
@@ -449,6 +487,8 @@ export interface SendNotifyOptions {
|
|
|
449
487
|
* {@link slackRelayActions} and {@link teamsRelayReply}.
|
|
450
488
|
*/
|
|
451
489
|
render?: { slack?: (e: NotifyEvent, relay?: RelayButtons) => unknown; teams?: (e: NotifyEvent, relay?: RelayButtons) => unknown };
|
|
490
|
+
/** The product's words and the relay's name for chant's own Slack and Teams bodies (#4818). */
|
|
491
|
+
message?: NotifyMessageOptions;
|
|
452
492
|
/** Seconds since the epoch, for the signature's timestamp. Default: the clock. */
|
|
453
493
|
now?: number;
|
|
454
494
|
}
|
|
@@ -523,7 +563,7 @@ export async function sendNotify(config: NotifyConfig | undefined, event: Notify
|
|
|
523
563
|
await deliver("webhook", config.webhook, () => {
|
|
524
564
|
const key = config.key ? env[config.key] : undefined;
|
|
525
565
|
if (!key) return `${config.key ?? "the key variable"} is not set, and an event is never sent unsigned`;
|
|
526
|
-
return webhookRequest(event, key, {
|
|
566
|
+
return webhookRequest(event, key, { now: options.now, prefix: options.prefix || undefined, userAgent: options.userAgent || undefined });
|
|
527
567
|
});
|
|
528
568
|
}
|
|
529
569
|
// #4611: a waiting event's buttons, when the relay's key is set.
|
|
@@ -531,7 +571,7 @@ export async function sendNotify(config: NotifyConfig | undefined, event: Notify
|
|
|
531
571
|
const relayKey = config.relay ? env[config.relay] : undefined;
|
|
532
572
|
if (config.relay && ref && !relayKey) log(`notify: ${config.relay} is not set, so the message carries no relay buttons`);
|
|
533
573
|
const buttons = ref && relayKey ? { token: relayToken(relayKey, ref) } : undefined;
|
|
534
|
-
if (config.slack) await deliver("slack", config.slack, () => json(options.render?.slack ? options.render.slack(event, buttons) : slackMessage(event, buttons)));
|
|
535
|
-
if (config.teams) await deliver("teams", config.teams, () => json(options.render?.teams ? options.render.teams(event, buttons) : teamsMessage(event, buttons)));
|
|
574
|
+
if (config.slack) await deliver("slack", config.slack, () => json(options.render?.slack ? options.render.slack(event, buttons) : slackMessage(event, buttons, options.message)));
|
|
575
|
+
if (config.teams) await deliver("teams", config.teams, () => json(options.render?.teams ? options.render.teams(event, buttons) : teamsMessage(event, buttons, options.message)));
|
|
536
576
|
return out;
|
|
537
577
|
}
|