@intentius/sql-yodeler 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/apply-steps/index.d.ts +73 -21
- package/dist/apply-steps/index.js +171 -49
- package/dist/apply-steps/index.js.map +1 -1
- package/dist/approval-mode/index.d.ts +7 -0
- package/dist/approval-mode/index.js +10 -3
- package/dist/approval-mode/index.js.map +1 -1
- package/dist/chant/apply.d.ts +15 -3
- package/dist/chant/apply.js +22 -3
- package/dist/chant/apply.js.map +1 -1
- package/dist/ci/render.d.ts +7 -2
- package/dist/ci/render.js +13 -3
- package/dist/ci/render.js.map +1 -1
- package/dist/commands/apply.d.ts +2 -0
- package/dist/commands/apply.js +196 -87
- package/dist/commands/apply.js.map +1 -1
- package/dist/commands/approve.d.ts +51 -1
- package/dist/commands/approve.js +177 -14
- package/dist/commands/approve.js.map +1 -1
- package/dist/commands/cleanup.d.ts +1 -0
- package/dist/commands/cleanup.js +11 -7
- package/dist/commands/cleanup.js.map +1 -1
- package/dist/commands/create.d.ts +31 -0
- package/dist/commands/create.js +171 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/drift.js +8 -8
- package/dist/commands/drift.js.map +1 -1
- package/dist/commands/emulator.d.ts +17 -0
- package/dist/commands/emulator.js +78 -0
- package/dist/commands/emulator.js.map +1 -0
- package/dist/commands/index.js +4 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/init.js +7 -5
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/override.js +46 -22
- package/dist/commands/override.js.map +1 -1
- package/dist/commands/plan.js +20 -20
- package/dist/commands/plan.js.map +1 -1
- package/dist/commands/revert.js +10 -7
- package/dist/commands/revert.js.map +1 -1
- package/dist/config/define.d.ts +5 -5
- package/dist/mcp/tools.d.ts +2 -2
- package/dist/mcp/tools.js +7 -5
- package/dist/mcp/tools.js.map +1 -1
- package/dist/notify/index.d.ts +30 -95
- package/dist/notify/index.js +50 -153
- package/dist/notify/index.js.map +1 -1
- package/dist/notify/verify.d.ts +17 -31
- package/dist/notify/verify.js +16 -47
- package/dist/notify/verify.js.map +1 -1
- package/dist/pr/forge.d.ts +33 -38
- package/dist/pr/forge.js +74 -97
- package/dist/pr/forge.js.map +1 -1
- package/dist/pr/issue.d.ts +16 -33
- package/dist/pr/issue.js +17 -88
- package/dist/pr/issue.js.map +1 -1
- package/dist/pr/model.d.ts +5 -3
- package/dist/pr/model.js +12 -6
- package/dist/pr/model.js.map +1 -1
- package/dist/pr/render.js +7 -6
- package/dist/pr/render.js.map +1 -1
- package/dist/pr/tenants.js +2 -2
- package/dist/pr/tenants.js.map +1 -1
- package/dist/release/index.d.ts +63 -0
- package/dist/release/index.js +122 -0
- package/dist/release/index.js.map +1 -0
- package/dist/report/audit.d.ts +18 -19
- package/dist/report/audit.js +57 -27
- package/dist/report/audit.js.map +1 -1
- package/dist/report/model.js +18 -5
- package/dist/report/model.js.map +1 -1
- package/dist/tenants/wave.d.ts +9 -3
- package/dist/tenants/wave.js +4 -5
- package/dist/tenants/wave.js.map +1 -1
- package/dist/versioned/approval.js +1 -1
- package/dist/versioned/approval.js.map +1 -1
- package/dist/versioned/policy.d.ts +44 -24
- package/dist/versioned/policy.js +70 -37
- package/dist/versioned/policy.js.map +1 -1
- package/dist/waves/index.d.ts +9 -13
- package/dist/waves/index.js +12 -36
- package/dist/waves/index.js.map +1 -1
- package/package.json +7 -7
- package/schemas/apply.schema.json +2 -0
- package/schemas/cleanup.schema.json +1 -0
- package/schemas/event.schema.json +218 -25
- package/schemas/init.schema.json +1 -0
- package/schemas/plan.schema.json +3 -1
- package/schemas/revert.schema.json +2 -1
- package/dist/pr/comment.d.ts +0 -32
- package/dist/pr/comment.js +0 -99
- package/dist/pr/comment.js.map +0 -1
package/dist/notify/verify.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* node:crypto
|
|
2
|
+
* Checking a yodel webhook event (#61), over chant's notify-verify (#211).
|
|
3
|
+
* It needs only node:crypto and chant's compiled notify-verify, so a
|
|
4
|
+
* receiver can import it alone, in plain Node:
|
|
4
5
|
*
|
|
5
6
|
* ```ts
|
|
6
7
|
* import { verifyWebhook } from "@intentius/sql-yodeler/webhook";
|
|
@@ -15,57 +16,25 @@
|
|
|
15
16
|
* epoch), a dot, and the request body exactly as sent. It travels as
|
|
16
17
|
* `x-yodel-signature: sha256=<hex>`. Signing the timestamp with the body
|
|
17
18
|
* lets a receiver refuse a delivery replayed later; {@link verifyWebhook}
|
|
18
|
-
* refuses one
|
|
19
|
+
* refuses one more than five minutes from now by default. This is chant's
|
|
20
|
+
* scheme under yodel's header names, so a receiver written for an earlier
|
|
21
|
+
* release keeps verifying.
|
|
19
22
|
*/
|
|
20
|
-
import {
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
export const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export const
|
|
27
|
-
|
|
28
|
-
export
|
|
29
|
-
return `sha256=${createHmac("sha256", key).update(`${String(timestamp)}.${body}`, "utf8").digest("hex")}`;
|
|
30
|
-
}
|
|
31
|
-
function header(headers, name) {
|
|
32
|
-
if (typeof headers.get === "function")
|
|
33
|
-
return headers.get(name) ?? undefined;
|
|
34
|
-
for (const [k, v] of Object.entries(headers)) {
|
|
35
|
-
if (k.toLowerCase() !== name)
|
|
36
|
-
continue;
|
|
37
|
-
return Array.isArray(v) ? v[0] : v;
|
|
38
|
-
}
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
23
|
+
import { verifyWebhook as chantVerify, webhookHeaderNames } from "@intentius/chant/notify-verify";
|
|
24
|
+
export { DEFAULT_TOLERANCE_SECONDS, signWebhook } from "@intentius/chant/notify-verify";
|
|
25
|
+
/** The prefix of yodel's webhook header names. */
|
|
26
|
+
export const HEADER_PREFIX = "x-yodel";
|
|
27
|
+
const names = webhookHeaderNames(HEADER_PREFIX);
|
|
28
|
+
export const SIGNATURE_HEADER = names.signature;
|
|
29
|
+
export const TIMESTAMP_HEADER = names.timestamp;
|
|
30
|
+
export const EVENT_HEADER = names.event;
|
|
31
|
+
export const DELIVERY_HEADER = names.delivery;
|
|
41
32
|
/**
|
|
42
33
|
* Whether a delivery was signed with `key` and is recent: the signature
|
|
43
34
|
* header matches (compared in constant time) and the timestamp is within the
|
|
44
35
|
* tolerance either side of now. On success, the parsed event.
|
|
45
36
|
*/
|
|
46
37
|
export function verifyWebhook(input) {
|
|
47
|
-
|
|
48
|
-
return { ok: false, reason: "no key to verify with" };
|
|
49
|
-
const body = typeof input.body === "string" ? input.body : Buffer.from(input.body).toString("utf8");
|
|
50
|
-
const signature = header(input.headers, SIGNATURE_HEADER);
|
|
51
|
-
const timestamp = header(input.headers, TIMESTAMP_HEADER);
|
|
52
|
-
if (!signature)
|
|
53
|
-
return { ok: false, reason: `no ${SIGNATURE_HEADER} header` };
|
|
54
|
-
if (!timestamp || !/^\d+$/.test(timestamp))
|
|
55
|
-
return { ok: false, reason: `no ${TIMESTAMP_HEADER} header, or not a number of seconds` };
|
|
56
|
-
const expected = Buffer.from(signWebhook(input.key, timestamp, body));
|
|
57
|
-
const given = Buffer.from(signature);
|
|
58
|
-
if (given.length !== expected.length || !timingSafeEqual(given, expected))
|
|
59
|
-
return { ok: false, reason: "the signature does not match" };
|
|
60
|
-
const now = input.now ?? Math.floor(Date.now() / 1000);
|
|
61
|
-
const tolerance = input.toleranceSeconds ?? DEFAULT_TOLERANCE_SECONDS;
|
|
62
|
-
if (Math.abs(now - Number(timestamp)) > tolerance)
|
|
63
|
-
return { ok: false, reason: `the timestamp is more than ${String(tolerance)}s from now` };
|
|
64
|
-
try {
|
|
65
|
-
return { ok: true, event: JSON.parse(body) };
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
return { ok: false, reason: "the body is not JSON" };
|
|
69
|
-
}
|
|
38
|
+
return chantVerify({ ...input, prefix: HEADER_PREFIX });
|
|
70
39
|
}
|
|
71
40
|
//# sourceMappingURL=verify.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../../src/notify/verify.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../../src/notify/verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,aAAa,IAAI,WAAW,EAAE,kBAAkB,EAAqD,MAAM,gCAAgC,CAAC;AAErJ,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAGxF,kDAAkD;AAClD,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AAEvC,MAAM,KAAK,GAAG,kBAAkB,CAAC,aAAa,CAAC,CAAC;AAChD,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,SAAS,CAAC;AAChD,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,SAAS,CAAC;AAChD,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC;AACxC,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC,QAAQ,CAAC;AAK9C;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAkB;IAC9C,OAAO,WAAW,CAAC,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;AAC1D,CAAC"}
|
package/dist/pr/forge.d.ts
CHANGED
|
@@ -1,40 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Where `yodel plan <env> --comment`
|
|
3
|
-
*
|
|
4
|
-
* overridden by a
|
|
2
|
+
* Where `yodel plan <env> --comment` and `yodel drift <env> --issue` post:
|
|
3
|
+
* chant's forge client (`@intentius/chant/pr-forge`, #210) for the CI job's
|
|
4
|
+
* forge, repository, pull (merge) request and token, each overridden by a
|
|
5
|
+
* flag. chant reads the job's environment and makes every REST call; yodel
|
|
6
|
+
* keeps the flags and the bodies.
|
|
5
7
|
*
|
|
6
8
|
* - GitHub Actions: `GITHUB_ACTIONS=true`. `GITHUB_REPOSITORY`, the PR number
|
|
7
|
-
* from the event payload (`GITHUB_EVENT_PATH
|
|
8
|
-
* `
|
|
9
|
-
* https://api.github.com), token `GITHUB_TOKEN`.
|
|
9
|
+
* from the event payload (`GITHUB_EVENT_PATH`) or `refs/pull/<n>/merge` in
|
|
10
|
+
* `GITHUB_REF`, `GITHUB_API_URL` (default https://api.github.com).
|
|
10
11
|
* - GitLab CI: `GITLAB_CI=true`. `CI_API_V4_URL`, `CI_PROJECT_ID`,
|
|
11
|
-
* `CI_MERGE_REQUEST_IID` (a merge request pipeline)
|
|
12
|
-
* (a project or personal access token with `api` scope: `CI_JOB_TOKEN`
|
|
13
|
-
* cannot write merge request notes).
|
|
12
|
+
* `CI_MERGE_REQUEST_IID` (a merge request pipeline).
|
|
14
13
|
* - Forgejo Actions: `FORGEJO_ACTIONS=true` (runner 7 and later), or
|
|
15
14
|
* `GITEA_ACTIONS=true`, or a GitHub-style job whose API URL ends in
|
|
16
|
-
* `/api/v1`. `
|
|
17
|
-
* `
|
|
18
|
-
* `GITHUB_API_URL` (else `<server>/api/v1`), token `FORGEJO_TOKEN` /
|
|
19
|
-
* `GITHUB_TOKEN`.
|
|
15
|
+
* `/api/v1`. The `FORGEJO_*` variables before the `GITHUB_*` ones, and
|
|
16
|
+
* `<server>/api/v1` when no API URL is set.
|
|
20
17
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
18
|
+
* The token is the first set of chant's `FORGE_TOKEN_ORDER`:
|
|
19
|
+
* `CHANT_GITHUB_TOKEN`, `GH_TOKEN`, `GITHUB_TOKEN` on GitHub;
|
|
20
|
+
* `CHANT_FORGEJO_TOKEN`, `FORGEJO_TOKEN`, `GH_TOKEN`, `GITHUB_TOKEN` on
|
|
21
|
+
* Forgejo; `CHANT_GITLAB_TOKEN`, `GITLAB_TOKEN`, `CI_JOB_TOKEN` on GitLab
|
|
22
|
+
* (`CI_JOB_TOKEN` cannot write merge request notes or issues: name a project
|
|
23
|
+
* access token with `api` scope). `--token-env <NAME>` names the one
|
|
24
|
+
* variable to read instead; the token itself is never a flag, never printed
|
|
25
|
+
* and never put in an error.
|
|
23
26
|
*/
|
|
24
|
-
|
|
27
|
+
import type { ForgeFetch, ForgeKind, ForgeTarget, PrForge } from "@intentius/chant/pr-forge";
|
|
28
|
+
export type { ForgeKind, ForgeTarget, PrForge };
|
|
25
29
|
export declare const FORGES: readonly ForgeKind[];
|
|
26
|
-
export interface ForgeTarget {
|
|
27
|
-
forge: ForgeKind;
|
|
28
|
-
/** `owner/name` (GitHub, Forgejo), or the project id or path (GitLab). */
|
|
29
|
-
repo: string;
|
|
30
|
-
/** The PR number (GitHub, Forgejo) or MR iid (GitLab). */
|
|
31
|
-
pr: number;
|
|
32
|
-
/** The REST API's base, e.g. https://api.github.com, https://gitlab.com/api/v4, https://codeberg.org/api/v1. */
|
|
33
|
-
apiUrl: string;
|
|
34
|
-
token: string;
|
|
35
|
-
/** The variable the token came from, for messages. */
|
|
36
|
-
tokenEnv: string;
|
|
37
|
-
}
|
|
38
30
|
export interface ForgeFlags {
|
|
39
31
|
forge?: string | undefined;
|
|
40
32
|
repo?: string | undefined;
|
|
@@ -42,13 +34,16 @@ export interface ForgeFlags {
|
|
|
42
34
|
apiUrl?: string | undefined;
|
|
43
35
|
tokenEnv?: string | undefined;
|
|
44
36
|
}
|
|
45
|
-
/**
|
|
46
|
-
export
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
37
|
+
/** A forge to post to: chant's client, and the target it was made for. */
|
|
38
|
+
export interface Forge {
|
|
39
|
+
target: ForgeTarget;
|
|
40
|
+
client: PrForge;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* chant's forge client for `--comment` (`withPr`: the pull request too) or
|
|
44
|
+
* `--issue`, from flags and the environment, or a YodelError saying what is
|
|
45
|
+
* missing. `what` names the option, for messages.
|
|
46
|
+
*/
|
|
47
|
+
export declare function resolveForge(flags: ForgeFlags, env: NodeJS.ProcessEnv, what: "--comment" | "--issue", fetchImpl?: ForgeFetch): Promise<Forge>;
|
|
48
|
+
/** `github acme/db`, for messages. */
|
|
49
|
+
export declare const describeForge: (t: ForgeTarget) => string;
|
package/dist/pr/forge.js
CHANGED
|
@@ -1,119 +1,96 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Where `yodel plan <env> --comment`
|
|
3
|
-
*
|
|
4
|
-
* overridden by a
|
|
2
|
+
* Where `yodel plan <env> --comment` and `yodel drift <env> --issue` post:
|
|
3
|
+
* chant's forge client (`@intentius/chant/pr-forge`, #210) for the CI job's
|
|
4
|
+
* forge, repository, pull (merge) request and token, each overridden by a
|
|
5
|
+
* flag. chant reads the job's environment and makes every REST call; yodel
|
|
6
|
+
* keeps the flags and the bodies.
|
|
5
7
|
*
|
|
6
8
|
* - GitHub Actions: `GITHUB_ACTIONS=true`. `GITHUB_REPOSITORY`, the PR number
|
|
7
|
-
* from the event payload (`GITHUB_EVENT_PATH
|
|
8
|
-
* `
|
|
9
|
-
* https://api.github.com), token `GITHUB_TOKEN`.
|
|
9
|
+
* from the event payload (`GITHUB_EVENT_PATH`) or `refs/pull/<n>/merge` in
|
|
10
|
+
* `GITHUB_REF`, `GITHUB_API_URL` (default https://api.github.com).
|
|
10
11
|
* - GitLab CI: `GITLAB_CI=true`. `CI_API_V4_URL`, `CI_PROJECT_ID`,
|
|
11
|
-
* `CI_MERGE_REQUEST_IID` (a merge request pipeline)
|
|
12
|
-
* (a project or personal access token with `api` scope: `CI_JOB_TOKEN`
|
|
13
|
-
* cannot write merge request notes).
|
|
12
|
+
* `CI_MERGE_REQUEST_IID` (a merge request pipeline).
|
|
14
13
|
* - Forgejo Actions: `FORGEJO_ACTIONS=true` (runner 7 and later), or
|
|
15
14
|
* `GITEA_ACTIONS=true`, or a GitHub-style job whose API URL ends in
|
|
16
|
-
* `/api/v1`. `
|
|
17
|
-
* `
|
|
18
|
-
* `GITHUB_API_URL` (else `<server>/api/v1`), token `FORGEJO_TOKEN` /
|
|
19
|
-
* `GITHUB_TOKEN`.
|
|
15
|
+
* `/api/v1`. The `FORGEJO_*` variables before the `GITHUB_*` ones, and
|
|
16
|
+
* `<server>/api/v1` when no API URL is set.
|
|
20
17
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
18
|
+
* The token is the first set of chant's `FORGE_TOKEN_ORDER`:
|
|
19
|
+
* `CHANT_GITHUB_TOKEN`, `GH_TOKEN`, `GITHUB_TOKEN` on GitHub;
|
|
20
|
+
* `CHANT_FORGEJO_TOKEN`, `FORGEJO_TOKEN`, `GH_TOKEN`, `GITHUB_TOKEN` on
|
|
21
|
+
* Forgejo; `CHANT_GITLAB_TOKEN`, `GITLAB_TOKEN`, `CI_JOB_TOKEN` on GitLab
|
|
22
|
+
* (`CI_JOB_TOKEN` cannot write merge request notes or issues: name a project
|
|
23
|
+
* access token with `api` scope). `--token-env <NAME>` names the one
|
|
24
|
+
* variable to read instead; the token itself is never a flag, never printed
|
|
25
|
+
* and never put in an error.
|
|
23
26
|
*/
|
|
24
|
-
import { readFileSync } from "node:fs";
|
|
25
27
|
import { YodelError } from "../project.js";
|
|
26
28
|
export const FORGES = ["github", "gitlab", "forgejo"];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
/** The PR number from a GitHub-style event payload, or from the ref. */
|
|
39
|
-
export function prFromEvent(eventPath, ref) {
|
|
40
|
-
if (eventPath) {
|
|
41
|
-
try {
|
|
42
|
-
const event = JSON.parse(readFileSync(eventPath, "utf8"));
|
|
43
|
-
const n = event.pull_request?.number ?? (event.issue?.pull_request ? event.issue.number : undefined) ?? (event.pull_request ? event.number : undefined);
|
|
44
|
-
if (typeof n === "number" && Number.isInteger(n) && n > 0)
|
|
45
|
-
return n;
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
// Unreadable payload: fall back to the ref.
|
|
29
|
+
/**
|
|
30
|
+
* The job's environment with the flags written in as the variables chant
|
|
31
|
+
* reads, so a flag wins over what the job carries: `--repo`, `--pr` and
|
|
32
|
+
* `--api-url` stand in for the job's repository, pull request and API.
|
|
33
|
+
*/
|
|
34
|
+
function withFlags(kind, flags, env) {
|
|
35
|
+
const out = { ...env };
|
|
36
|
+
if (kind === "gitlab") {
|
|
37
|
+
if (flags.repo !== undefined) {
|
|
38
|
+
out.CI_MERGE_REQUEST_PROJECT_ID = flags.repo;
|
|
39
|
+
out.CI_PROJECT_ID = flags.repo;
|
|
49
40
|
}
|
|
41
|
+
if (flags.pr !== undefined)
|
|
42
|
+
out.CI_MERGE_REQUEST_IID = flags.pr;
|
|
43
|
+
if (flags.apiUrl !== undefined)
|
|
44
|
+
out.CI_API_V4_URL = flags.apiUrl;
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
// A Forgejo job reads FORGEJO_* before GITHUB_*, so a flag sets both.
|
|
48
|
+
const set = (name, value) => {
|
|
49
|
+
out[`GITHUB_${name}`] = value;
|
|
50
|
+
out[`FORGEJO_${name}`] = value;
|
|
51
|
+
};
|
|
52
|
+
if (flags.repo !== undefined)
|
|
53
|
+
set("REPOSITORY", flags.repo);
|
|
54
|
+
if (flags.apiUrl !== undefined)
|
|
55
|
+
set("API_URL", flags.apiUrl);
|
|
56
|
+
if (flags.pr !== undefined) {
|
|
57
|
+
// The event payload names the pull request before the ref does.
|
|
58
|
+
set("EVENT_PATH", undefined);
|
|
59
|
+
set("REF", `refs/pull/${flags.pr}/merge`);
|
|
50
60
|
}
|
|
51
|
-
|
|
52
|
-
return m ? Number(m[1]) : undefined;
|
|
61
|
+
return out;
|
|
53
62
|
}
|
|
54
|
-
const DEFAULT_TOKEN_ENV = {
|
|
55
|
-
github: ["GITHUB_TOKEN"],
|
|
56
|
-
gitlab: ["GITLAB_TOKEN"],
|
|
57
|
-
forgejo: ["FORGEJO_TOKEN", "GITHUB_TOKEN"],
|
|
58
|
-
};
|
|
59
63
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
64
|
+
* chant's forge client for `--comment` (`withPr`: the pull request too) or
|
|
65
|
+
* `--issue`, from flags and the environment, or a YodelError saying what is
|
|
66
|
+
* missing. `what` names the option, for messages.
|
|
63
67
|
*/
|
|
64
|
-
function
|
|
68
|
+
export async function resolveForge(flags, env, what, fetchImpl) {
|
|
69
|
+
const withPr = what === "--comment";
|
|
65
70
|
if (flags.forge !== undefined && !FORGES.includes(flags.forge))
|
|
66
71
|
throw new YodelError(`--forge must be one of ${FORGES.join(", ")}, got ${JSON.stringify(flags.forge)}`);
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
if (flags.pr !== undefined && !/^[1-9]\d*$/.test(flags.pr))
|
|
73
|
+
throw new YodelError(`--pr must be a pull request number, got ${JSON.stringify(flags.pr)}`);
|
|
74
|
+
const { detectForge, forgeTargetFromEnv, forgeClient, ForgeEnvironmentError } = await import("@intentius/chant/pr-forge");
|
|
75
|
+
const kind = flags.forge ?? detectForge(env);
|
|
76
|
+
if (!kind)
|
|
69
77
|
throw new YodelError(`${what} cannot tell the forge: not a GitHub Actions, GitLab CI or Forgejo Actions job; pass --forge github|gitlab|forgejo with --repo${withPr ? ", --pr" : ""} and --api-url`);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
let apiUrl = flags.apiUrl;
|
|
74
|
-
if (forge === "gitlab") {
|
|
75
|
-
repo ??= pick("CI_PROJECT_ID", "CI_PROJECT_PATH");
|
|
76
|
-
pr ??= pick("CI_MERGE_REQUEST_IID") !== undefined ? Number(pick("CI_MERGE_REQUEST_IID")) : undefined;
|
|
77
|
-
apiUrl ??= pick("CI_API_V4_URL");
|
|
78
|
+
let target;
|
|
79
|
+
try {
|
|
80
|
+
target = forgeTargetFromEnv(withFlags(kind, flags, env), { kind, requirePr: withPr, ...(flags.tokenEnv ? { tokenEnv: flags.tokenEnv } : {}) });
|
|
78
81
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
apiUrl = `${server.replace(/\/+$/, "")}/api/v1`;
|
|
89
|
-
}
|
|
90
|
-
if (!apiUrl && forge === "github")
|
|
91
|
-
apiUrl = "https://api.github.com";
|
|
92
|
-
}
|
|
93
|
-
const missing = [];
|
|
94
|
-
if (!repo)
|
|
95
|
-
missing.push(forge === "gitlab" ? "the project (--repo, or CI_PROJECT_ID)" : "the repository (--repo owner/name, or GITHUB_REPOSITORY)");
|
|
96
|
-
if (withPr && (pr === undefined || !Number.isInteger(pr) || pr <= 0)) {
|
|
97
|
-
missing.push(forge === "gitlab" ? "the merge request (--pr, or CI_MERGE_REQUEST_IID in a merge request pipeline)" : "the pull request (--pr, or a pull_request event)");
|
|
82
|
+
catch (e) {
|
|
83
|
+
if (!(e instanceof ForgeEnvironmentError))
|
|
84
|
+
throw e;
|
|
85
|
+
const token = e.missing.some((m) => m.startsWith("a token"));
|
|
86
|
+
const hints = [
|
|
87
|
+
...(e.missing.some((m) => !m.startsWith("a token")) ? [`outside CI pass ${withPr ? "--repo, --pr and --api-url" : "--repo and --api-url"}`] : []),
|
|
88
|
+
...(token && !flags.tokenEnv ? ["name another token variable with --token-env"] : []),
|
|
89
|
+
];
|
|
90
|
+
throw new YodelError(`${what} on ${kind} needs ${e.missing.join(", ")}${hints.length ? `; ${hints.join("; ")}` : ""}`);
|
|
98
91
|
}
|
|
99
|
-
|
|
100
|
-
missing.push(forge === "gitlab" ? "the API URL (--api-url, or CI_API_V4_URL)" : "the API URL (--api-url, or FORGEJO_API_URL / GITHUB_API_URL)");
|
|
101
|
-
const names = flags.tokenEnv ? [flags.tokenEnv] : DEFAULT_TOKEN_ENV[forge];
|
|
102
|
-
const tokenEnv = names.find((n) => env[n]) ?? names[0] ?? "";
|
|
103
|
-
const token = env[tokenEnv] ?? "";
|
|
104
|
-
if (!token)
|
|
105
|
-
missing.push(`a token (${names.join(" or ")} is not set${flags.tokenEnv ? "" : "; name another variable with --token-env"})`);
|
|
106
|
-
if (missing.length > 0)
|
|
107
|
-
throw new YodelError(`${what} on ${forge} needs ${missing.join(", ")}`);
|
|
108
|
-
const base = { forge, repo: repo, apiUrl: apiUrl.replace(/\/+$/, ""), token, tokenEnv };
|
|
109
|
-
return withPr ? { ...base, pr: pr } : base;
|
|
110
|
-
}
|
|
111
|
-
/** Resolves the target from flags and the environment, or says what is missing. */
|
|
112
|
-
export function resolveForgeTarget(flags, env) {
|
|
113
|
-
return resolve(flags, env, "--comment", true);
|
|
114
|
-
}
|
|
115
|
-
/** The repository a job writes to (`yodel drift --issue`), from flags and the environment, or says what is missing. */
|
|
116
|
-
export function resolveForgeRepo(flags, env, what = "--issue") {
|
|
117
|
-
return resolve(flags, env, what, false);
|
|
92
|
+
return { target, client: forgeClient(target, fetchImpl) };
|
|
118
93
|
}
|
|
94
|
+
/** `github acme/db`, for messages. */
|
|
95
|
+
export const describeForge = (t) => `${t.kind} ${t.repo}`;
|
|
119
96
|
//# sourceMappingURL=forge.js.map
|
package/dist/pr/forge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forge.js","sourceRoot":"","sources":["../../src/pr/forge.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"forge.js","sourceRoot":"","sources":["../../src/pr/forge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,MAAM,CAAC,MAAM,MAAM,GAAyB,CAAC,QAAQ,EAAE,QAAQ,EAAE,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AE,CAAC"}
|
package/dist/pr/issue.d.ts
CHANGED
|
@@ -1,37 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The drift watch's tracking issue (#49): one open issue per project and
|
|
3
3
|
* environment, found by its marker, opened when drift is found, updated
|
|
4
|
-
* while it lasts, and closed, with a comment, when it is gone.
|
|
5
|
-
*
|
|
4
|
+
* while it lasts, and closed, with a comment, when it is gone. chant's
|
|
5
|
+
* `trackIssue` (#210) finds and writes it on each forge; yodel says what
|
|
6
|
+
* the run found.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* PUT {api}/projects/{id}/issues/{iid} description, or state_event close
|
|
12
|
-
* POST {api}/projects/{id}/issues/{iid}/notes
|
|
13
|
-
* Forgejo as GitHub, under /api/v1, with type=issues and limit
|
|
14
|
-
*
|
|
15
|
-
* The client lists only open issues, so a closed one is never reopened:
|
|
16
|
-
* drift found again after a close opens a new issue.
|
|
8
|
+
* Only open issues are read, so a closed one is never reopened: drift found
|
|
9
|
+
* again after a close opens a new issue. The issue counts as current while
|
|
10
|
+
* its title is the same and its body carries the drift's fingerprint, so a
|
|
11
|
+
* body that names a new run does not edit it on every scheduled run.
|
|
17
12
|
*/
|
|
18
|
-
import type {
|
|
19
|
-
export interface ForgeIssue {
|
|
20
|
-
number: number;
|
|
21
|
-
title: string;
|
|
22
|
-
body: string;
|
|
23
|
-
url?: string | undefined;
|
|
24
|
-
}
|
|
25
|
-
export interface IssueClient {
|
|
26
|
-
/** The open issues (not pull requests). */
|
|
27
|
-
open(): Promise<ForgeIssue[]>;
|
|
28
|
-
create(title: string, body: string): Promise<ForgeIssue>;
|
|
29
|
-
update(n: number, title: string, body: string): Promise<ForgeIssue>;
|
|
30
|
-
/** Comments `comment` on the issue, then closes it. */
|
|
31
|
-
close(n: number, comment: string): Promise<void>;
|
|
32
|
-
}
|
|
33
|
-
type Fetch = typeof fetch;
|
|
34
|
-
export declare function issueClient(t: ForgeRepo, f?: Fetch): IssueClient;
|
|
13
|
+
import type { PrForge } from "@intentius/chant/pr-forge";
|
|
35
14
|
/**
|
|
36
15
|
* The marker an environment's tracking issue carries, so the next run finds
|
|
37
16
|
* it. Keyed by the project's directory in its repository (`.` at the root),
|
|
@@ -53,16 +32,20 @@ export type DriftOutcome = {
|
|
|
53
32
|
kind: "unknown";
|
|
54
33
|
why: string;
|
|
55
34
|
};
|
|
35
|
+
/** The tracking issue a run touched. */
|
|
36
|
+
export interface TrackedIssue {
|
|
37
|
+
number: number;
|
|
38
|
+
url?: string | undefined;
|
|
39
|
+
}
|
|
56
40
|
export type IssueAction = {
|
|
57
41
|
action: "opened" | "updated" | "unchanged" | "closed";
|
|
58
|
-
issue:
|
|
42
|
+
issue: TrackedIssue;
|
|
59
43
|
} | {
|
|
60
44
|
action: "none";
|
|
61
45
|
} | {
|
|
62
46
|
action: "left";
|
|
63
47
|
why: string;
|
|
64
|
-
issue?:
|
|
48
|
+
issue?: TrackedIssue;
|
|
65
49
|
};
|
|
66
50
|
/** Brings the environment's tracking issue in line with the outcome; see the module comment. */
|
|
67
|
-
export declare function trackDrift(
|
|
68
|
-
export {};
|
|
51
|
+
export declare function trackDrift(forge: Pick<PrForge, "trackIssue">, marker: string, outcome: DriftOutcome): Promise<IssueAction>;
|
package/dist/pr/issue.js
CHANGED
|
@@ -1,81 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The drift watch's tracking issue (#49): one open issue per project and
|
|
3
3
|
* environment, found by its marker, opened when drift is found, updated
|
|
4
|
-
* while it lasts, and closed, with a comment, when it is gone.
|
|
5
|
-
*
|
|
4
|
+
* while it lasts, and closed, with a comment, when it is gone. chant's
|
|
5
|
+
* `trackIssue` (#210) finds and writes it on each forge; yodel says what
|
|
6
|
+
* the run found.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* PUT {api}/projects/{id}/issues/{iid} description, or state_event close
|
|
12
|
-
* POST {api}/projects/{id}/issues/{iid}/notes
|
|
13
|
-
* Forgejo as GitHub, under /api/v1, with type=issues and limit
|
|
14
|
-
*
|
|
15
|
-
* The client lists only open issues, so a closed one is never reopened:
|
|
16
|
-
* drift found again after a close opens a new issue.
|
|
8
|
+
* Only open issues are read, so a closed one is never reopened: drift found
|
|
9
|
+
* again after a close opens a new issue. The issue counts as current while
|
|
10
|
+
* its title is the same and its body carries the drift's fingerprint, so a
|
|
11
|
+
* body that names a new run does not edit it on every scheduled run.
|
|
17
12
|
*/
|
|
18
|
-
import { YodelError } from "../project.js";
|
|
19
|
-
const PAGE = 100;
|
|
20
|
-
const MAX_PAGES = 20;
|
|
21
|
-
const repoPath = (repo) => repo.split("/").map(encodeURIComponent).join("/");
|
|
22
|
-
export function issueClient(t, f = fetch) {
|
|
23
|
-
const gitlab = t.forge === "gitlab";
|
|
24
|
-
const headers = gitlab
|
|
25
|
-
? { "PRIVATE-TOKEN": t.token, Accept: "application/json" }
|
|
26
|
-
: t.forge === "forgejo"
|
|
27
|
-
? { Authorization: `token ${t.token}`, Accept: "application/json" }
|
|
28
|
-
: { Authorization: `Bearer ${t.token}`, Accept: "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28" };
|
|
29
|
-
const base = gitlab ? `${t.apiUrl}/projects/${encodeURIComponent(t.repo)}/issues` : `${t.apiUrl}/repos/${repoPath(t.repo)}/issues`;
|
|
30
|
-
const call = async (method, url, body) => {
|
|
31
|
-
let res;
|
|
32
|
-
try {
|
|
33
|
-
res = await f(url, { method, headers: { ...headers, ...(body ? { "Content-Type": "application/json" } : {}) }, ...(body ? { body: JSON.stringify(body) } : {}) });
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
throw new YodelError(`${t.forge}: ${method} ${url} failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
37
|
-
}
|
|
38
|
-
const text = await res.text();
|
|
39
|
-
if (!res.ok)
|
|
40
|
-
throw new YodelError(`${t.forge}: ${method} ${url} answered ${String(res.status)}: ${text.slice(0, 300).replaceAll(t.token, "[token]")}`);
|
|
41
|
-
return text ? JSON.parse(text) : {};
|
|
42
|
-
};
|
|
43
|
-
const toIssue = (r) => ({
|
|
44
|
-
number: Number(gitlab ? r.iid : r.number),
|
|
45
|
-
title: typeof r.title === "string" ? r.title : "",
|
|
46
|
-
body: typeof (gitlab ? r.description : r.body) === "string" ? String(gitlab ? r.description : r.body) : "",
|
|
47
|
-
url: typeof r.html_url === "string" ? r.html_url : typeof r.web_url === "string" ? r.web_url : undefined,
|
|
48
|
-
});
|
|
49
|
-
const list = (page) => gitlab
|
|
50
|
-
? `${base}?state=opened&per_page=${String(PAGE)}&page=${String(page)}`
|
|
51
|
-
: t.forge === "forgejo"
|
|
52
|
-
? `${base}?state=open&type=issues&limit=${String(PAGE)}&page=${String(page)}`
|
|
53
|
-
: `${base}?state=open&per_page=${String(PAGE)}&page=${String(page)}`;
|
|
54
|
-
return {
|
|
55
|
-
async open() {
|
|
56
|
-
const all = [];
|
|
57
|
-
for (let page = 1; page <= MAX_PAGES; page++) {
|
|
58
|
-
const got = (await call("GET", list(page)));
|
|
59
|
-
if (!Array.isArray(got))
|
|
60
|
-
throw new YodelError(`${t.forge}: listing issues did not return a list`);
|
|
61
|
-
all.push(...got.filter((r) => r.pull_request === undefined || r.pull_request === null).map(toIssue));
|
|
62
|
-
if (got.length < PAGE)
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
return all;
|
|
66
|
-
},
|
|
67
|
-
async create(title, body) {
|
|
68
|
-
return toIssue((await call("POST", base, gitlab ? { title, description: body } : { title, body })));
|
|
69
|
-
},
|
|
70
|
-
async update(n, title, body) {
|
|
71
|
-
return toIssue((await call(gitlab ? "PUT" : "PATCH", `${base}/${String(n)}`, gitlab ? { title, description: body } : { title, body })));
|
|
72
|
-
},
|
|
73
|
-
async close(n, comment) {
|
|
74
|
-
await call("POST", `${base}/${String(n)}/${gitlab ? "notes" : "comments"}`, { body: comment });
|
|
75
|
-
await call(gitlab ? "PUT" : "PATCH", `${base}/${String(n)}`, gitlab ? { state_event: "close" } : { state: "closed" });
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
13
|
/**
|
|
80
14
|
* The marker an environment's tracking issue carries, so the next run finds
|
|
81
15
|
* it. Keyed by the project's directory in its repository (`.` at the root),
|
|
@@ -86,22 +20,17 @@ export function driftIssueMarker(project, environment) {
|
|
|
86
20
|
return `<!-- yodel:drift project=${clean(project || ".")} env=${clean(environment)} -->`;
|
|
87
21
|
}
|
|
88
22
|
/** Brings the environment's tracking issue in line with the outcome; see the module comment. */
|
|
89
|
-
export async function trackDrift(
|
|
90
|
-
const
|
|
91
|
-
const
|
|
23
|
+
export async function trackDrift(forge, marker, outcome) {
|
|
24
|
+
const finding = outcome.kind === "drift" ? { title: outcome.title, body: `${marker}\n${outcome.body}` } : null;
|
|
25
|
+
const r = await forge.trackIssue(marker, finding, {
|
|
26
|
+
...(outcome.kind === "drift" ? { sameWhen: outcome.fingerprint } : {}),
|
|
27
|
+
...(outcome.kind === "clean" ? { closeOnClear: true, clearComment: outcome.comment } : {}),
|
|
28
|
+
});
|
|
29
|
+
const issue = r.number !== undefined ? { number: r.number, ...(r.url ? { url: r.url } : {}) } : undefined;
|
|
92
30
|
if (outcome.kind === "unknown")
|
|
93
31
|
return { action: "left", why: outcome.why, ...(issue ? { issue } : {}) };
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
await client.close(issue.number, outcome.comment);
|
|
98
|
-
return { action: "closed", issue };
|
|
99
|
-
}
|
|
100
|
-
const body = `${marker}\n${outcome.body}`;
|
|
101
|
-
if (!issue)
|
|
102
|
-
return { action: "opened", issue: await client.create(outcome.title, body) };
|
|
103
|
-
if (issue.body.includes(outcome.fingerprint) && issue.title === outcome.title)
|
|
104
|
-
return { action: "unchanged", issue };
|
|
105
|
-
return { action: "updated", issue: await client.update(issue.number, outcome.title, body) };
|
|
32
|
+
if (r.action === "none" || r.action === "left" || !issue)
|
|
33
|
+
return { action: "none" };
|
|
34
|
+
return { action: r.action, issue };
|
|
106
35
|
}
|
|
107
36
|
//# sourceMappingURL=issue.js.map
|