@notation/factory-github 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,316 @@
1
+ import {
2
+ type AuthorCheck,
3
+ type Channel,
4
+ type ChannelContext,
5
+ deriveKey,
6
+ hmacHex,
7
+ timingSafeEqual,
8
+ } from "@notation/factory/router";
9
+ import type { AuthorSet } from "../implementations/selectors.ts";
10
+ import { appJwt } from "./app-jwt.ts";
11
+ import { comment, readDir, repoToken, sourceChanges, writeCheck as writeRepoCheck, writeStatus as writeRepoStatus } from "./repos.ts";
12
+
13
+ /** The webhook secret of the App with id `appId`, which the router derives from the root key. */
14
+ export const webhookSecret = (rootKey: string, appId: string) =>
15
+ deriveKey(rootKey, `github:webhook:${appId}`);
16
+
17
+ /** Checks GitHub's `X-Hub-Signature-256` header against the raw request body. */
18
+ export const verifySignature = async (
19
+ secret: string,
20
+ body: Uint8Array<ArrayBuffer>,
21
+ header: string | null,
22
+ ) => {
23
+ if (!header?.startsWith("sha256=")) return false;
24
+ return timingSafeEqual(header.slice(7), await hmacHex(secret, body));
25
+ };
26
+
27
+ /** The names of what a GitHub channel reads from its context. */
28
+ export const CHANNEL_SECRETS = { rootKey: "ROOT_KEY", privateKey: "PRIVATE_KEY" } as const;
29
+ export const CHANNEL_VALUES = { appId: "APP_ID" } as const;
30
+
31
+ /** Someone who posted to a thread. `bot` is set for an App or another bot account. */
32
+ export type Author = { login: string; association: string; bot: boolean };
33
+
34
+ /** The parts of an issue or comment event that selectors read. */
35
+ export type GithubEvent = {
36
+ action: string;
37
+ /** The author of the comment, or of the issue. */
38
+ author: Author;
39
+ /** For a comment, the issue's author, whose opening post the prompt also quotes. */
40
+ opener?: Author;
41
+ body: string;
42
+ /** The body before an edit. The same as `body` when an edit didn't change it. */
43
+ before: string;
44
+ labels: string[];
45
+ };
46
+
47
+ type Post = {
48
+ body?: string | null;
49
+ user?: { login: string; type?: string };
50
+ author_association?: string;
51
+ };
52
+
53
+ const authorOf = (post: Post): Author => ({
54
+ login: post.user?.login ?? "",
55
+ association: post.author_association ?? "",
56
+ bot: post.user?.type === "Bot",
57
+ });
58
+
59
+ const parse = (event: string, payload: any): GithubEvent | undefined => {
60
+ const post: Post | undefined =
61
+ event === "issue_comment"
62
+ ? payload.comment
63
+ : event === "issues"
64
+ ? payload.issue
65
+ : undefined;
66
+ if (!post || typeof payload.action !== "string") return undefined;
67
+ const body = post.body ?? "";
68
+ return {
69
+ action: payload.action,
70
+ author: authorOf(post),
71
+ ...(event === "issue_comment" && payload.issue && { opener: authorOf(payload.issue) }),
72
+ body,
73
+ before: payload.changes?.body?.from ?? body,
74
+ labels: (payload.issue?.labels ?? []).map((l: { name: string }) => l.name),
75
+ };
76
+ };
77
+
78
+ /** The parts of an issue or comment payload that worktree functions and prompts read. */
79
+ const eventPayload = (payload: any) => ({
80
+ action: payload.action,
81
+ issue: payload.issue && {
82
+ number: payload.issue.number,
83
+ title: payload.issue.title,
84
+ body: payload.issue.body,
85
+ labels: (payload.issue.labels ?? []).map((l: { name: string }) => ({ name: l.name })),
86
+ user: { login: payload.issue.user?.login },
87
+ ...(payload.issue.pull_request && { pull_request: { url: payload.issue.pull_request.url } }),
88
+ },
89
+ ...(payload.comment && {
90
+ comment: { id: payload.comment.id, body: payload.comment.body, user: { login: payload.comment.user?.login } },
91
+ }),
92
+ repository: { full_name: payload.repository?.full_name, default_branch: payload.repository?.default_branch },
93
+ sender: { login: payload.sender?.login },
94
+ });
95
+
96
+ type Payload = ReturnType<typeof eventPayload>;
97
+
98
+ /** Where a run's replies go: an issue or a pull request. */
99
+ export type Thread = { repo: string; issue: number };
100
+
101
+ /** The prompt for a run that an issue or a comment started. */
102
+ export const prompt = (event: string, payload: Payload) => {
103
+ const { issue, comment, repository } = payload;
104
+ const kind = issue.pull_request ? "pull request" : "issue";
105
+ const lines = [
106
+ `You're working in ${repository.full_name}, on ${kind} #${issue.number}: ${issue.title}`,
107
+ "",
108
+ ];
109
+ if (event === "issue_comment") {
110
+ lines.push(
111
+ `@${issue.user.login} opened it with:`,
112
+ issue.body ?? "",
113
+ "",
114
+ `@${comment!.user.login} commented:`,
115
+ comment!.body,
116
+ );
117
+ } else {
118
+ lines.push(`@${issue.user.login} ${payload.action} it with:`, issue.body ?? "");
119
+ }
120
+ lines.push(
121
+ "",
122
+ `Your final message is posted as a comment on the ${kind}. The gh CLI is signed in for ${repository.full_name}.`,
123
+ );
124
+ return lines.join("\n");
125
+ };
126
+
127
+ /** Author associations that mean the person has write access to the repo. */
128
+ const WRITE_ACCESS = new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
129
+
130
+ const escapeRegExp = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
131
+
132
+ /**
133
+ * Whether `body` mentions `mention` as GitHub would: case-insensitively, and
134
+ * not as part of a longer name or an email address (`@claudette`,
135
+ * `me@claude.ai`).
136
+ */
137
+ export const mentions = (body: string, mention: string) =>
138
+ new RegExp(`(?<![\\w@.-])${escapeRegExp(mention)}(?![\\w-])`, "i").test(body);
139
+
140
+ type Selector = {
141
+ actions: string[];
142
+ mention?: string;
143
+ labels?: string[];
144
+ from: AuthorSet | AuthorSet[];
145
+ };
146
+
147
+ const selects = (selector: Selector, event: GithubEvent) => {
148
+ if (!selector.actions.includes(event.action)) return false;
149
+ if (selector.labels?.some((l) => !event.labels.includes(l))) return false;
150
+ if (selector.mention) {
151
+ if (!mentions(event.body, selector.mention)) return false;
152
+ // An edit matches only if it newly adds the mention.
153
+ if (event.action === "edited" && mentions(event.before, selector.mention)) {
154
+ return false;
155
+ }
156
+ }
157
+ return true;
158
+ };
159
+
160
+ const checkOne = (sets: AuthorSet[], author: Author): AuthorCheck => {
161
+ if (author.bot) return { result: "denied" };
162
+ const allowed = sets.some((s) =>
163
+ s.kind === "user"
164
+ ? s.login.toLowerCase() === author.login.toLowerCase()
165
+ : s.kind === "collaborators" && WRITE_ACCESS.has(author.association),
166
+ );
167
+ if (allowed) return { result: "allowed" };
168
+ const teams = sets.filter((s) => s.kind === "team");
169
+ return teams.length ? { result: "check", sets: teams } : { result: "denied" };
170
+ };
171
+
172
+ /**
173
+ * Whether the event's author may start a run. A comment's prompt also
174
+ * quotes the issue's opening post, so the issue's author must match `from`
175
+ * too. Bots never match.
176
+ */
177
+ const checkAuthor = (from: Selector["from"], { author, opener }: GithubEvent): AuthorCheck => {
178
+ const sets = Array.isArray(from) ? from : [from];
179
+ const checks = [author, ...(opener ? [opener] : [])].map((a) => checkOne(sets, a));
180
+ if (checks.some((c) => c.result === "denied")) return { result: "denied" };
181
+ const pending = checks.find((c) => c.result === "check");
182
+ return pending ?? { result: "allowed" };
183
+ };
184
+
185
+ /** One GitHub App's webhook. A delivery's scope is its repo. */
186
+ export const channel = (ctx: ChannelContext): Channel<GithubEvent> => {
187
+ const appId = ctx.value(CHANNEL_VALUES.appId);
188
+ const rootKey = () => ctx.secret(CHANNEL_SECRETS.rootKey);
189
+ const auth = async () => ({ appId, privateKey: await ctx.secret(CHANNEL_SECRETS.privateKey) });
190
+ return {
191
+ async receive(request) {
192
+ const target = request.headers.get("x-github-hook-installation-target-id");
193
+ if (target !== appId) {
194
+ return { status: "rejected", reason: `delivery for App ${target}, not ${appId}` };
195
+ }
196
+
197
+ const body = new Uint8Array(await request.arrayBuffer());
198
+ const secret = await webhookSecret(await rootKey(), appId);
199
+ const signature = request.headers.get("x-hub-signature-256");
200
+ if (!(await verifySignature(secret, body, signature))) {
201
+ return { status: "rejected", reason: "bad signature" };
202
+ }
203
+
204
+ const event = request.headers.get("x-github-event") ?? "";
205
+ const payload = JSON.parse(new TextDecoder().decode(body));
206
+ const changes = sourceChanges(event, payload);
207
+ if (changes?.length) return { status: "source", changes };
208
+ const repo: string | undefined = payload.repository?.full_name;
209
+ const data = parse(event, payload);
210
+ if (!repo || !data) return { status: "ignored", reason: event };
211
+ // The App's own replies would otherwise start runs.
212
+ const post = event === "issue_comment" ? payload.comment : payload.issue;
213
+ if (String(post?.performed_via_github_app?.id ?? "") === appId) {
214
+ return { status: "ignored", reason: "posted by this App" };
215
+ }
216
+ return {
217
+ status: "accepted",
218
+ delivery: {
219
+ id: request.headers.get("x-github-delivery") ?? "",
220
+ scope: repo,
221
+ repo,
222
+ event,
223
+ data,
224
+ payload: eventPayload(payload),
225
+ },
226
+ };
227
+ },
228
+
229
+ match(selector, delivery) {
230
+ const s = selector as Selector;
231
+ return selects(s, delivery.data)
232
+ ? checkAuthor(s.from, delivery.data)
233
+ : undefined;
234
+ },
235
+
236
+ async sync(url) {
237
+ await setWebhookConfig({
238
+ appId,
239
+ privateKey: await ctx.secret(CHANNEL_SECRETS.privateKey),
240
+ rootKey: await rootKey(),
241
+ url,
242
+ });
243
+ },
244
+
245
+ async read(repo, dir, ref) {
246
+ return readDir(await auth(), repo, dir, ref);
247
+ },
248
+
249
+ async writeStatus(repo, status) {
250
+ await writeRepoStatus(await auth(), repo, status);
251
+ },
252
+
253
+ async writeCheck(repo, ref, check) {
254
+ await writeRepoCheck(await auth(), repo, ref, check);
255
+ },
256
+
257
+ conversation(delivery) {
258
+ const payload = delivery.payload as Payload;
259
+ const thread: Thread = { repo: delivery.repo, issue: payload.issue.number };
260
+ return {
261
+ id: `github:${thread.repo}#${thread.issue}`.toLowerCase(),
262
+ prompt: prompt(delivery.event, payload),
263
+ thread,
264
+ };
265
+ },
266
+
267
+ async reply(thread, text) {
268
+ const { repo, issue } = thread as Thread;
269
+ await comment(await auth(), repo, issue, text);
270
+ },
271
+
272
+ async token(repo, permissions) {
273
+ return repoToken(await auth(), repo, permissions);
274
+ },
275
+ };
276
+ };
277
+
278
+ const GITHUB_API = "https://api.github.com";
279
+
280
+ /**
281
+ * Sets the App's webhook to `url`, with the webhook secret derived from the
282
+ * root key. It authenticates as the App with its private key.
283
+ */
284
+ const setWebhookConfig = async ({
285
+ appId,
286
+ privateKey,
287
+ rootKey,
288
+ url,
289
+ }: {
290
+ appId: string;
291
+ privateKey: string;
292
+ rootKey: string;
293
+ url: string;
294
+ }) => {
295
+ const response = await fetch(`${GITHUB_API}/app/hook/config`, {
296
+ method: "PATCH",
297
+ headers: {
298
+ Accept: "application/vnd.github+json",
299
+ Authorization: `Bearer ${await appJwt(appId, privateKey)}`,
300
+ "Content-Type": "application/json",
301
+ "User-Agent": "notation-factory-router",
302
+ "X-GitHub-Api-Version": "2022-11-28",
303
+ },
304
+ body: JSON.stringify({
305
+ url,
306
+ content_type: "json",
307
+ insecure_ssl: "0",
308
+ secret: await webhookSecret(rootKey, appId),
309
+ }),
310
+ });
311
+ if (!response.ok) {
312
+ throw new Error(
313
+ `GitHub PATCH /app/hook/config for App ${appId} failed with status ${response.status}: ${await response.text()}`,
314
+ );
315
+ }
316
+ };
@@ -0,0 +1,44 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import { sourceChanges } from "./repos.ts";
4
+
5
+ const repository = { full_name: "acme/api", default_branch: "main" };
6
+
7
+ test("a push to the default branch changes the repo at the pushed commit", () => {
8
+ assert.deepEqual(sourceChanges("push", { ref: "refs/heads/main", after: "abc", repository }), [
9
+ { repo: "acme/api", ref: "abc" },
10
+ ]);
11
+ });
12
+
13
+ test("a push to another branch, or a deleted default branch, changes nothing", () => {
14
+ assert.equal(sourceChanges("push", { ref: "refs/heads/feature", after: "abc", repository }), undefined);
15
+ assert.equal(sourceChanges("push", { ref: "refs/heads/main", deleted: true, repository }), undefined);
16
+ });
17
+
18
+ test("an install adds its repos, and an uninstall removes them", () => {
19
+ const repositories = [{ full_name: "acme/api" }, { full_name: "acme/web" }];
20
+ assert.deepEqual(sourceChanges("installation", { action: "created", repositories }), [
21
+ { repo: "acme/api" },
22
+ { repo: "acme/web" },
23
+ ]);
24
+ assert.deepEqual(sourceChanges("installation", { action: "deleted", repositories }), [
25
+ { repo: "acme/api", removed: true },
26
+ { repo: "acme/web", removed: true },
27
+ ]);
28
+ assert.equal(sourceChanges("installation", { action: "new_permissions_accepted", repositories }), undefined);
29
+ });
30
+
31
+ test("repos added to and removed from an install change", () => {
32
+ assert.deepEqual(
33
+ sourceChanges("installation_repositories", {
34
+ action: "added",
35
+ repositories_added: [{ full_name: "acme/api" }],
36
+ repositories_removed: [{ full_name: "acme/old" }],
37
+ }),
38
+ [{ repo: "acme/api" }, { repo: "acme/old", removed: true }],
39
+ );
40
+ });
41
+
42
+ test("other events change nothing", () => {
43
+ assert.equal(sourceChanges("issue_comment", { action: "created", repository }), undefined);
44
+ });
@@ -0,0 +1,202 @@
1
+ import type { BuildCheck, FactoryStatus, SourceChange, SourceFiles } from "@notation/factory/router";
2
+ import { appJwt } from "./app-jwt.ts";
3
+
4
+ const GITHUB_API = "https://api.github.com";
5
+
6
+ /** The most files, and the largest file, that `readDir` reads. */
7
+ const MAX_FILES = 200;
8
+ const MAX_FILE_BYTES = 512 * 1024;
9
+
10
+ /** GitHub's limit on an Actions variable's value is 48 KB, so long errors are cut. */
11
+ const MAX_ERROR_CHARS = 8000;
12
+
13
+ export type AppAuth = { appId: string; privateKey: string };
14
+
15
+ const github = async (
16
+ method: string,
17
+ path: string,
18
+ token: string,
19
+ { body, accept = "application/vnd.github+json" }: { body?: unknown; accept?: string } = {},
20
+ ) => {
21
+ const response = await fetch(`${GITHUB_API}${path}`, {
22
+ method,
23
+ headers: {
24
+ Accept: accept,
25
+ Authorization: `Bearer ${token}`,
26
+ "User-Agent": "notation-factory-router",
27
+ "X-GitHub-Api-Version": "2022-11-28",
28
+ ...(body === undefined ? {} : { "Content-Type": "application/json" }),
29
+ },
30
+ body: body === undefined ? undefined : JSON.stringify(body),
31
+ });
32
+ return response;
33
+ };
34
+
35
+ const ok = async (response: Response, what: string) => {
36
+ if (!response.ok) {
37
+ throw new Error(`GitHub ${what} failed with status ${response.status}: ${await response.text()}`);
38
+ }
39
+ return response;
40
+ };
41
+
42
+ /** An installation token for `repo` alone, with only `permissions`. */
43
+ export const repoToken = async (
44
+ { appId, privateKey }: AppAuth,
45
+ repo: string,
46
+ permissions: Record<string, "read" | "write">,
47
+ ) => {
48
+ const jwt = await appJwt(appId, privateKey);
49
+ const installation = (await (
50
+ await ok(await github("GET", `/repos/${repo}/installation`, jwt), `GET /repos/${repo}/installation`)
51
+ ).json()) as { id: number };
52
+ const { token } = (await (
53
+ await ok(
54
+ await github("POST", `/app/installations/${installation.id}/access_tokens`, jwt, {
55
+ body: { repositories: [repo.split("/")[1]], permissions },
56
+ }),
57
+ `POST /app/installations/${installation.id}/access_tokens`,
58
+ )
59
+ ).json()) as { token: string };
60
+ return token;
61
+ };
62
+
63
+ /**
64
+ * The files under `dir` in `repo` at `ref`, or at the default branch's head:
65
+ * 1. Resolves the ref to a commit and its tree.
66
+ * 2. Lists the tree, and keeps the files under `dir`.
67
+ * 3. Reads each file as text.
68
+ */
69
+ export const readDir = async (
70
+ auth: AppAuth,
71
+ repo: string,
72
+ dir: string,
73
+ ref?: string,
74
+ ): Promise<SourceFiles> => {
75
+ const token = await repoToken(auth, repo, { contents: "read" });
76
+ const branch =
77
+ ref ??
78
+ ((await (await ok(await github("GET", `/repos/${repo}`, token), `GET /repos/${repo}`)).json()) as {
79
+ default_branch: string;
80
+ }).default_branch;
81
+ const commit = (await (
82
+ await ok(await github("GET", `/repos/${repo}/commits/${encodeURIComponent(branch)}`, token), `GET /repos/${repo}/commits/${branch}`)
83
+ ).json()) as { sha: string; commit: { tree: { sha: string } } };
84
+ const tree = (await (
85
+ await ok(
86
+ await github("GET", `/repos/${repo}/git/trees/${commit.commit.tree.sha}?recursive=1`, token),
87
+ `GET /repos/${repo}/git/trees`,
88
+ )
89
+ ).json()) as { truncated: boolean; tree: { path: string; type: string; sha: string; size?: number }[] };
90
+ const prefix = `${dir}/`;
91
+ const blobs = tree.tree.filter((e) => e.type === "blob" && e.path.startsWith(prefix));
92
+ if (tree.truncated && blobs.length === 0) {
93
+ throw new Error(`${repo}'s tree is too large for GitHub to list in one response.`);
94
+ }
95
+ if (blobs.length > MAX_FILES) {
96
+ throw new Error(`${repo} has ${blobs.length} files in ${dir}/. The most the hub reads is ${MAX_FILES}.`);
97
+ }
98
+ const files: Record<string, string> = {};
99
+ for (const blob of blobs) {
100
+ if ((blob.size ?? 0) > MAX_FILE_BYTES) {
101
+ throw new Error(`${blob.path} is larger than ${MAX_FILE_BYTES / 1024} KB.`);
102
+ }
103
+ const response = await ok(
104
+ await github("GET", `/repos/${repo}/git/blobs/${blob.sha}`, token, { accept: "application/vnd.github.raw+json" }),
105
+ `GET /repos/${repo}/git/blobs/${blob.sha}`,
106
+ );
107
+ files[blob.path.slice(prefix.length)] = await response.text();
108
+ }
109
+ return { ref: commit.sha, files };
110
+ };
111
+
112
+ const STATUS_VARIABLE = "FACTORY_STATUS";
113
+
114
+ /** Writes `status` to the repo's `FACTORY_STATUS` Actions variable, as JSON. */
115
+ export const writeStatus = async (auth: AppAuth, repo: string, status: FactoryStatus) => {
116
+ const token = await repoToken(auth, repo, { actions_variables: "write" });
117
+ const value = JSON.stringify({
118
+ ...status,
119
+ ...(status.error ? { error: status.error.slice(0, MAX_ERROR_CHARS) } : {}),
120
+ });
121
+ const updated = await github("PATCH", `/repos/${repo}/actions/variables/${STATUS_VARIABLE}`, token, {
122
+ body: { name: STATUS_VARIABLE, value },
123
+ });
124
+ if (updated.status !== 404) return void (await ok(updated, `PATCH ${STATUS_VARIABLE} on ${repo}`));
125
+ await ok(
126
+ await github("POST", `/repos/${repo}/actions/variables`, token, { body: { name: STATUS_VARIABLE, value } }),
127
+ `POST ${STATUS_VARIABLE} on ${repo}`,
128
+ );
129
+ };
130
+
131
+ /**
132
+ * Creates or updates the App's check run named `check.name` on commit `ref`.
133
+ * A finished check gets the conclusion of its state.
134
+ */
135
+ export const writeCheck = async (auth: AppAuth, repo: string, ref: string, check: BuildCheck) => {
136
+ const token = await repoToken(auth, repo, { checks: "write" });
137
+ const listed = (await (
138
+ await ok(
139
+ await github("GET", `/repos/${repo}/commits/${ref}/check-runs?check_name=${encodeURIComponent(check.name)}&app_id=${auth.appId}`, token),
140
+ `GET /repos/${repo}/commits/${ref}/check-runs`,
141
+ )
142
+ ).json()) as { check_runs: { id: number }[] };
143
+ const done = check.state !== "queued" && check.state !== "in_progress";
144
+ const body = {
145
+ name: check.name,
146
+ head_sha: ref,
147
+ status: done ? "completed" : check.state,
148
+ ...(done && { conclusion: check.state }),
149
+ ...(check.url && { details_url: check.url }),
150
+ ...(check.summary && { output: { title: check.name, summary: check.summary } }),
151
+ };
152
+ const [run] = listed.check_runs;
153
+ if (run) {
154
+ await ok(await github("PATCH", `/repos/${repo}/check-runs/${run.id}`, token, { body }), `PATCH /repos/${repo}/check-runs/${run.id}`);
155
+ } else {
156
+ await ok(await github("POST", `/repos/${repo}/check-runs`, token, { body }), `POST /repos/${repo}/check-runs`);
157
+ }
158
+ };
159
+
160
+ /** GitHub's limit on a comment's body. */
161
+ const MAX_COMMENT_CHARS = 65536;
162
+
163
+ /** Comments `body` on an issue or a pull request, as the App. */
164
+ export const comment = async (auth: AppAuth, repo: string, issue: number, body: string) => {
165
+ const token = await repoToken(auth, repo, { issues: "write" });
166
+ const text = body.length > MAX_COMMENT_CHARS ? `${body.slice(0, MAX_COMMENT_CHARS - 20)}\n\n…(cut)` : body;
167
+ await ok(
168
+ await github("POST", `/repos/${repo}/issues/${issue}/comments`, token, { body: { body: text } }),
169
+ `POST /repos/${repo}/issues/${issue}/comments`,
170
+ );
171
+ };
172
+
173
+ const fullNames = (repos: { full_name: string }[] | undefined) => (repos ?? []).map((r) => r.full_name);
174
+
175
+ /**
176
+ * The repos whose outposts a delivery changes:
177
+ * - a push to the default branch, at the pushed commit
178
+ * - an install or unsuspend, and repos added to an install, at the default branch
179
+ * - an uninstall or suspend, and repos removed from an install, which the hub can no longer read
180
+ */
181
+ export const sourceChanges = (event: string, payload: any): SourceChange[] | undefined => {
182
+ if (event === "push") {
183
+ const repo = payload.repository;
184
+ if (!repo || payload.deleted || payload.ref !== `refs/heads/${repo.default_branch}`) return undefined;
185
+ return [{ repo: repo.full_name, ref: payload.after }];
186
+ }
187
+ if (event === "installation") {
188
+ const repos = fullNames(payload.repositories);
189
+ if (payload.action === "created" || payload.action === "unsuspend") return repos.map((repo) => ({ repo }));
190
+ if (payload.action === "deleted" || payload.action === "suspend") {
191
+ return repos.map((repo) => ({ repo, removed: true }));
192
+ }
193
+ return undefined;
194
+ }
195
+ if (event === "installation_repositories") {
196
+ return [
197
+ ...fullNames(payload.repositories_added).map((repo) => ({ repo })),
198
+ ...fullNames(payload.repositories_removed).map((repo) => ({ repo, removed: true })),
199
+ ];
200
+ }
201
+ return undefined;
202
+ };
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.