@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
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The forge reads beside the clients (#4809), driven through a recording
|
|
3
|
+
* `fetch`: the calls each makes on GitHub, Forgejo and GitLab, and what each
|
|
4
|
+
* reads back.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, expect, test } from "vitest";
|
|
8
|
+
import { ForgeApiError, type ForgeFetch } from "./pr-forge";
|
|
9
|
+
import { forgejoReads, forgeReadsFor, githubReads, gitlabReads } from "./pr-forge-reads";
|
|
10
|
+
|
|
11
|
+
interface Call {
|
|
12
|
+
method: string;
|
|
13
|
+
url: string;
|
|
14
|
+
headers: Record<string, string>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A fake forge: `routes` maps `METHOD path-without-query` (optionally `?page=N`) to a response body, or a status. */
|
|
18
|
+
function fakeFetch(routes: Record<string, unknown>): { fetch: ForgeFetch; calls: Call[] } {
|
|
19
|
+
const calls: Call[] = [];
|
|
20
|
+
const fetch: ForgeFetch = async (url, init) => {
|
|
21
|
+
calls.push({ method: init.method, url, headers: init.headers });
|
|
22
|
+
const u = new URL(url);
|
|
23
|
+
const key = `${init.method} ${u.pathname}`;
|
|
24
|
+
const page = Number(u.searchParams.get("page") ?? "1");
|
|
25
|
+
const found = routes[`${key}?page=${page}`] ?? routes[key];
|
|
26
|
+
if (found === undefined) return { ok: false, status: 404, text: async () => '{"message":"Not Found"}' };
|
|
27
|
+
if (typeof found === "number") return { ok: false, status: found, text: async () => "" };
|
|
28
|
+
return { ok: true, status: 200, text: async () => JSON.stringify(found) };
|
|
29
|
+
};
|
|
30
|
+
return { fetch, calls };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const SHA = "a".repeat(40);
|
|
34
|
+
const MERGED = "m".repeat(40);
|
|
35
|
+
const urls = (calls: Call[]) => calls.map((c) => `${c.method} ${c.url}`);
|
|
36
|
+
|
|
37
|
+
describe("github", () => {
|
|
38
|
+
const opts = { apiBase: "https://api.github.com", repo: "acme/infra", token: "t0k" };
|
|
39
|
+
|
|
40
|
+
test("names the token's user", async () => {
|
|
41
|
+
const { fetch, calls } = fakeFetch({ "GET /user": { login: "tg-bot", id: 7 } });
|
|
42
|
+
expect(await githubReads({ ...opts, fetch }).tokenUser()).toEqual({ login: "tg-bot", id: 7 });
|
|
43
|
+
expect(urls(calls)).toEqual(["GET https://api.github.com/user"]);
|
|
44
|
+
expect(calls[0]!.headers.Authorization).toBe("Bearer t0k");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("reads a merged pull request's author, URL and merge commit, and undefined for a missing one", async () => {
|
|
48
|
+
const { fetch } = fakeFetch({
|
|
49
|
+
"GET /repos/acme/infra/pulls/12": {
|
|
50
|
+
number: 12,
|
|
51
|
+
title: "t",
|
|
52
|
+
body: "b",
|
|
53
|
+
state: "closed",
|
|
54
|
+
merged: true,
|
|
55
|
+
merge_commit_sha: MERGED,
|
|
56
|
+
html_url: "https://github.com/acme/infra/pull/12",
|
|
57
|
+
user: { login: "alice" },
|
|
58
|
+
head: { ref: "feat", sha: SHA, repo: { full_name: "acme/infra" } },
|
|
59
|
+
base: { ref: "main" },
|
|
60
|
+
updated_at: "2026-11-08T00:00:00Z",
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
const reads = githubReads({ ...opts, fetch });
|
|
64
|
+
expect(await reads.pullRequest(12)).toEqual({
|
|
65
|
+
number: 12,
|
|
66
|
+
title: "t",
|
|
67
|
+
body: "b",
|
|
68
|
+
state: "merged",
|
|
69
|
+
head: "feat",
|
|
70
|
+
headSha: SHA,
|
|
71
|
+
base: "main",
|
|
72
|
+
author: "alice",
|
|
73
|
+
url: "https://github.com/acme/infra/pull/12",
|
|
74
|
+
sameRepo: true,
|
|
75
|
+
mergeCommit: MERGED,
|
|
76
|
+
updated: "2026-11-08T00:00:00Z",
|
|
77
|
+
});
|
|
78
|
+
expect(await reads.pullRequest(13)).toBeUndefined();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("finds the pull requests from a branch in any state, newest first, and filters the head server-side", async () => {
|
|
82
|
+
const { fetch, calls } = fakeFetch({
|
|
83
|
+
"GET /repos/acme/infra/pulls": [
|
|
84
|
+
{ number: 3, state: "closed", head: { ref: "wave/1" } },
|
|
85
|
+
{ number: 9, state: "open", head: { ref: "wave/1" } },
|
|
86
|
+
{ number: 5, state: "open", head: { ref: "wave/1", repo: { full_name: "fork/infra" } } },
|
|
87
|
+
],
|
|
88
|
+
});
|
|
89
|
+
const got = await githubReads({ ...opts, fetch }).pullRequestsFrom("wave/1");
|
|
90
|
+
expect(got.map((p) => [p.number, p.state])).toEqual([
|
|
91
|
+
[9, "open"],
|
|
92
|
+
[3, "closed"],
|
|
93
|
+
]);
|
|
94
|
+
expect(urls(calls)).toEqual(["GET https://api.github.com/repos/acme/infra/pulls?state=all&head=acme%3Awave%2F1&per_page=100&page=1"]);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("lists the pull requests whose head starts with a prefix, newest update first, up to the limit", async () => {
|
|
98
|
+
const page1 = Array.from({ length: 100 }, (_, i) => ({ number: 1000 - i, state: "closed", head: { ref: i % 2 ? "other" : `rollout/${i}` } }));
|
|
99
|
+
const { fetch, calls } = fakeFetch({
|
|
100
|
+
"GET /repos/acme/infra/pulls?page=1": page1,
|
|
101
|
+
"GET /repos/acme/infra/pulls?page=2": [{ number: 1, state: "open", head: { ref: "rollout/late" } }],
|
|
102
|
+
});
|
|
103
|
+
const got = await githubReads({ ...opts, fetch }).pullRequestsFrom("rollout/", { prefix: true, limit: 100 });
|
|
104
|
+
expect(got).toHaveLength(50);
|
|
105
|
+
expect(got[0]!.head).toBe("rollout/0");
|
|
106
|
+
expect(urls(calls)).toEqual(["GET https://api.github.com/repos/acme/infra/pulls?state=all&sort=updated&direction=desc&per_page=100&page=1"]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("reads every comment with its author, across pages", async () => {
|
|
110
|
+
const page1 = Array.from({ length: 100 }, (_, i) => ({ id: i + 1, body: `c${i}`, user: { login: "bob", id: 2 } }));
|
|
111
|
+
const { fetch } = fakeFetch({
|
|
112
|
+
"GET /repos/acme/infra/issues/12/comments?page=1": page1,
|
|
113
|
+
"GET /repos/acme/infra/issues/12/comments?page=2": [{ id: 500, body: "marker", user: { login: "tg-bot", id: 7 }, created_at: "2026-11-08T00:00:00Z" }],
|
|
114
|
+
});
|
|
115
|
+
const notes = await githubReads({ ...opts, fetch }).pullRequestNotes(12);
|
|
116
|
+
expect(notes).toHaveLength(101);
|
|
117
|
+
expect(notes.at(-1)).toEqual({ id: 500, body: "marker", author: "tg-bot", authorId: 7, system: false, created: "2026-11-08T00:00:00Z" });
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("reads the newest check run per name", async () => {
|
|
121
|
+
const { fetch, calls } = fakeFetch({
|
|
122
|
+
[`GET /repos/acme/infra/commits/${SHA}/check-runs`]: {
|
|
123
|
+
total_count: 3,
|
|
124
|
+
check_runs: [
|
|
125
|
+
{ id: 1, name: "apply/net", status: "completed", conclusion: "failure" },
|
|
126
|
+
{ id: 4, name: "apply/net", status: "completed", conclusion: "success" },
|
|
127
|
+
{ id: 2, name: "lint", status: "in_progress", conclusion: null },
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
expect(await githubReads({ ...opts, fetch }).checkRuns(SHA)).toEqual([
|
|
132
|
+
{ id: 4, name: "apply/net", status: "completed", conclusion: "success" },
|
|
133
|
+
{ id: 2, name: "lint", status: "in_progress" },
|
|
134
|
+
]);
|
|
135
|
+
expect(urls(calls)).toEqual([`GET https://api.github.com/repos/acme/infra/commits/${SHA}/check-runs?per_page=100&page=1`]);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("reads a pull request's commits with their authors and committers", async () => {
|
|
139
|
+
const { fetch } = fakeFetch({
|
|
140
|
+
"GET /repos/acme/infra/pulls/12/commits": [
|
|
141
|
+
{
|
|
142
|
+
sha: SHA,
|
|
143
|
+
commit: { message: "fix\n\nRequested-by: carol", author: { name: "Al", email: "al@x.io" }, committer: { name: "GitHub", email: "noreply@github.com" } },
|
|
144
|
+
author: { login: "alice" },
|
|
145
|
+
committer: { login: "web-flow" },
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
});
|
|
149
|
+
expect(await githubReads({ ...opts, fetch }).pullRequestCommits(12)).toEqual([
|
|
150
|
+
{ sha: SHA, message: "fix\n\nRequested-by: carol", author: { name: "Al", email: "al@x.io", login: "alice" }, committer: { name: "GitHub", email: "noreply@github.com", login: "web-flow" } },
|
|
151
|
+
]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("names a collaborator's permission level, and undefined for a stranger", async () => {
|
|
155
|
+
const { fetch } = fakeFetch({ "GET /repos/acme/infra/collaborators/alice/permission": { permission: "triage" } });
|
|
156
|
+
const reads = githubReads({ ...opts, fetch });
|
|
157
|
+
expect(await reads.permission("alice")).toBe("triage");
|
|
158
|
+
expect(await reads.permission("mallory")).toBeUndefined();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("lists every open pull request, into any base", async () => {
|
|
162
|
+
const { fetch, calls } = fakeFetch({
|
|
163
|
+
"GET /repos/acme/infra/pulls": [
|
|
164
|
+
{ number: 8, user: { login: "bob" }, head: { ref: "b", sha: SHA, repo: { full_name: "bob/infra" } }, base: { ref: "release", sha: MERGED } },
|
|
165
|
+
{ number: 4, user: { login: "al" }, head: { ref: "a", sha: SHA }, base: { ref: "main" } },
|
|
166
|
+
],
|
|
167
|
+
});
|
|
168
|
+
expect(await githubReads({ ...opts, fetch }).openPullRequests()).toEqual([
|
|
169
|
+
{ number: 4, head: "a", headSha: SHA, base: "main", author: "al", fork: false },
|
|
170
|
+
{ number: 8, head: "b", headSha: SHA, base: "release", baseSha: MERGED, author: "bob", fork: true },
|
|
171
|
+
]);
|
|
172
|
+
expect(urls(calls)).toEqual(["GET https://api.github.com/repos/acme/infra/pulls?state=open&per_page=100&page=1"]);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("a forge error other than 404 throws a ForgeApiError", async () => {
|
|
176
|
+
const { fetch } = fakeFetch({ "GET /repos/acme/infra/pulls/12": 500 });
|
|
177
|
+
await expect(githubReads({ ...opts, fetch }).pullRequest(12)).rejects.toBeInstanceOf(ForgeApiError);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe("forgejo", () => {
|
|
182
|
+
const opts = { apiBase: "https://code.acme.io/api/v1", repo: "acme/infra", token: "t0k", host: "code.acme.io" };
|
|
183
|
+
|
|
184
|
+
test("matches a branch's pull requests over pages, with token auth", async () => {
|
|
185
|
+
const page1 = Array.from({ length: 50 }, (_, i) => ({ number: 100 + i, state: "closed", head: { ref: `x${i}` } }));
|
|
186
|
+
const { fetch, calls } = fakeFetch({
|
|
187
|
+
"GET /api/v1/repos/acme/infra/pulls?page=1": page1,
|
|
188
|
+
"GET /api/v1/repos/acme/infra/pulls?page=2": [{ number: 7, state: "closed", merged: true, merge_commit_sha: MERGED, head: { ref: "wave/1" } }],
|
|
189
|
+
});
|
|
190
|
+
const got = await forgejoReads({ ...opts, fetch }).pullRequestsFrom("wave/1");
|
|
191
|
+
expect(got.map((p) => [p.number, p.state, p.mergeCommit])).toEqual([[7, "merged", MERGED]]);
|
|
192
|
+
expect(urls(calls)).toEqual([
|
|
193
|
+
"GET https://code.acme.io/api/v1/repos/acme/infra/pulls?state=all&sort=recentupdate&limit=50&page=1",
|
|
194
|
+
"GET https://code.acme.io/api/v1/repos/acme/infra/pulls?state=all&sort=recentupdate&limit=50&page=2",
|
|
195
|
+
]);
|
|
196
|
+
expect(calls[0]!.headers.Authorization).toBe("token t0k");
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test("an empty repository's 404 list is no pull request", async () => {
|
|
200
|
+
const { fetch } = fakeFetch({ "GET /api/v1/repos/acme/infra": { empty: true } });
|
|
201
|
+
expect(await forgejoReads({ ...opts, fetch }).pullRequestsFrom("wave/", { prefix: true })).toEqual([]);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("has no check runs", async () => {
|
|
205
|
+
const { fetch, calls } = fakeFetch({});
|
|
206
|
+
expect(await forgejoReads({ ...opts, fetch }).checkRuns(SHA)).toEqual([]);
|
|
207
|
+
expect(calls).toEqual([]);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
describe("gitlab", () => {
|
|
212
|
+
const opts = { apiBase: "https://gitlab.com/api/v4", project: "acme/infra", token: "glpat" };
|
|
213
|
+
const P = "/api/v4/projects/acme%2Finfra";
|
|
214
|
+
|
|
215
|
+
test("names the token's user by username and id", async () => {
|
|
216
|
+
const { fetch, calls } = fakeFetch({ "GET /api/v4/user": { username: "project_1_bot", id: 41 } });
|
|
217
|
+
expect(await gitlabReads({ ...opts, fetch }).tokenUser()).toEqual({ login: "project_1_bot", id: 41 });
|
|
218
|
+
expect(calls[0]!.headers["PRIVATE-TOKEN"]).toBe("glpat");
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("reads a merge request, its merge commit falling back to squash and then head", async () => {
|
|
222
|
+
const mr = { iid: 5, title: "t", description: "d", state: "merged", sha: SHA, source_branch: "feat", target_branch: "main", web_url: "https://gitlab.com/acme/infra/-/merge_requests/5", author: { username: "alice" }, source_project_id: 1, target_project_id: 1 };
|
|
223
|
+
const { fetch } = fakeFetch({ [`GET ${P}/merge_requests/5`]: { ...mr, merge_commit_sha: null, squash_commit_sha: null } });
|
|
224
|
+
expect(await gitlabReads({ ...opts, fetch }).pullRequest(5)).toMatchObject({ number: 5, state: "merged", author: "alice", url: mr.web_url, mergeCommit: SHA, sameRepo: true });
|
|
225
|
+
const squashed = fakeFetch({ [`GET ${P}/merge_requests/5`]: { ...mr, squash_commit_sha: MERGED } });
|
|
226
|
+
expect((await gitlabReads({ ...opts, fetch: squashed.fetch }).pullRequest(5))?.mergeCommit).toBe(MERGED);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test("finds the merge requests from a branch in any state, a fork's left out", async () => {
|
|
230
|
+
const { fetch, calls } = fakeFetch({
|
|
231
|
+
[`GET ${P}/merge_requests`]: [
|
|
232
|
+
{ iid: 2, state: "opened", source_branch: "wave/1", source_project_id: 1, target_project_id: 1 },
|
|
233
|
+
{ iid: 3, state: "opened", source_branch: "wave/1", source_project_id: 9, target_project_id: 1 },
|
|
234
|
+
{ iid: 1, state: "closed", source_branch: "wave/1" },
|
|
235
|
+
],
|
|
236
|
+
});
|
|
237
|
+
expect((await gitlabReads({ ...opts, fetch }).pullRequestsFrom("wave/1")).map((m) => [m.number, m.state])).toEqual([
|
|
238
|
+
[2, "open"],
|
|
239
|
+
[1, "closed"],
|
|
240
|
+
]);
|
|
241
|
+
expect(urls(calls)).toEqual([`GET https://gitlab.com${P}/merge_requests?state=all&source_branch=wave%2F1&order_by=updated_at&sort=desc&per_page=100&page=1`]);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test("reads every note, system notes marked", async () => {
|
|
245
|
+
const { fetch, calls } = fakeFetch({
|
|
246
|
+
[`GET ${P}/merge_requests/5/notes`]: [
|
|
247
|
+
{ id: 1, body: "approved this merge request", system: true, author: { username: "project_1_bot", id: 41 } },
|
|
248
|
+
{ id: 2, body: "<!-- marker -->", system: false, author: { username: "project_1_bot", id: 41 } },
|
|
249
|
+
],
|
|
250
|
+
});
|
|
251
|
+
const notes = await gitlabReads({ ...opts, fetch }).pullRequestNotes(5);
|
|
252
|
+
expect(notes.map((n) => [n.id, n.system, n.authorId])).toEqual([
|
|
253
|
+
[1, true, 41],
|
|
254
|
+
[2, false, 41],
|
|
255
|
+
]);
|
|
256
|
+
expect(urls(calls)).toEqual([`GET https://gitlab.com${P}/merge_requests/5/notes?sort=asc&order_by=created_at&per_page=100&page=1`]);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test("reads a merge request's commits", async () => {
|
|
260
|
+
const { fetch } = fakeFetch({ [`GET ${P}/merge_requests/5/commits`]: [{ id: SHA, message: "m", author_name: "Al", author_email: "al@x.io", committer_email: "c@x.io" }] });
|
|
261
|
+
expect(await gitlabReads({ ...opts, fetch }).pullRequestCommits(5)).toEqual([{ sha: SHA, message: "m", author: { name: "Al", email: "al@x.io" }, committer: { email: "c@x.io" } }]);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test("names a member's role by the access level, and undefined for a stranger", async () => {
|
|
265
|
+
const { fetch } = fakeFetch({ "GET /api/v4/users": [{ id: 3, username: "alice" }], [`GET ${P}/members/all/3`]: { access_level: 30 } });
|
|
266
|
+
expect(await gitlabReads({ ...opts, fetch }).permission("alice")).toBe("developer");
|
|
267
|
+
const none = fakeFetch({ "GET /api/v4/users": [] });
|
|
268
|
+
expect(await gitlabReads({ ...opts, fetch: none.fetch }).permission("mallory")).toBeUndefined();
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test("lists every open merge request, into any target", async () => {
|
|
272
|
+
const { fetch } = fakeFetch({
|
|
273
|
+
[`GET ${P}/merge_requests`]: [{ iid: 4, source_branch: "a", sha: SHA, target_branch: "release", author: { username: "al" }, diff_refs: { base_sha: MERGED }, source_project_id: 1, target_project_id: 1 }],
|
|
274
|
+
});
|
|
275
|
+
expect(await gitlabReads({ ...opts, fetch }).openPullRequests()).toEqual([{ number: 4, head: "a", headSha: SHA, base: "release", baseSha: MERGED, author: "al", fork: false }]);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
test("forgeReadsFor builds the reads for a target", async () => {
|
|
280
|
+
const { fetch, calls } = fakeFetch({ "GET /api/v4/user": { username: "bot", id: 1 } });
|
|
281
|
+
const reads = forgeReadsFor({ kind: "gitlab", apiBase: "https://gitlab.com/api/v4", repo: "42", host: "gitlab.com", token: "cj", tokenSource: "CI_JOB_TOKEN", tokenHeader: "JOB-TOKEN" }, fetch);
|
|
282
|
+
expect(reads.kind).toBe("gitlab");
|
|
283
|
+
expect(await reads.tokenUser()).toEqual({ login: "bot", id: 1 });
|
|
284
|
+
expect(calls[0]!.headers["JOB-TOKEN"]).toBe("cj");
|
|
285
|
+
});
|