@leitwerk-dev/github 0.0.0-bootstrap.0 → 0.2.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.
Files changed (48) hide show
  1. package/README.md +139 -1
  2. package/dist/LICENSE +13 -0
  3. package/dist/authorization.d.ts +16 -0
  4. package/dist/authorization.d.ts.map +1 -0
  5. package/dist/binding.d.ts +5 -0
  6. package/dist/binding.d.ts.map +1 -0
  7. package/dist/capability.d.ts +11 -0
  8. package/dist/capability.d.ts.map +1 -0
  9. package/dist/chunk-6X3F3VHK.js +344 -0
  10. package/dist/chunk-6X3F3VHK.js.map +1 -0
  11. package/dist/client.d.ts +200 -0
  12. package/dist/client.d.ts.map +1 -0
  13. package/dist/external.d.ts +150 -0
  14. package/dist/external.d.ts.map +1 -0
  15. package/dist/index.d.ts +20 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +790 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/issue-provider.d.ts +8 -0
  20. package/dist/issue-provider.d.ts.map +1 -0
  21. package/dist/issue-watcher.d.ts +31 -0
  22. package/dist/issue-watcher.d.ts.map +1 -0
  23. package/dist/poll-report.d.ts +22 -0
  24. package/dist/poll-report.d.ts.map +1 -0
  25. package/dist/provider.d.ts +8 -0
  26. package/dist/provider.d.ts.map +1 -0
  27. package/dist/testing/tool-fixture.d.ts +45 -0
  28. package/dist/testing/tool-fixture.d.ts.map +1 -0
  29. package/dist/testing.d.ts +145 -0
  30. package/dist/testing.d.ts.map +1 -0
  31. package/dist/testing.js +322 -0
  32. package/dist/testing.js.map +1 -0
  33. package/dist/tools.d.ts +4 -0
  34. package/dist/tools.d.ts.map +1 -0
  35. package/package.json +54 -14
  36. package/src/authorization.ts +62 -0
  37. package/src/binding.ts +7 -0
  38. package/src/capability.ts +16 -0
  39. package/src/client.ts +526 -0
  40. package/src/external.ts +192 -0
  41. package/src/index.ts +65 -0
  42. package/src/issue-provider.ts +278 -0
  43. package/src/issue-watcher.ts +45 -0
  44. package/src/poll-report.ts +47 -0
  45. package/src/provider.ts +216 -0
  46. package/src/testing/tool-fixture.ts +126 -0
  47. package/src/testing.ts +466 -0
  48. package/src/tools.ts +287 -0
@@ -0,0 +1,126 @@
1
+ import type { IntegrationToolExecutionContext } from "@leitwerk-dev/process-sdk";
2
+ import { createInMemoryExternalWriteLog, createToolCollector } from "@leitwerk-dev/test-support";
3
+ import type { GitHubClientLike } from "../capability.js";
4
+ import type { GitHubPullRequest } from "../client.js";
5
+ import { registerGitHubTools } from "../tools.js";
6
+
7
+ export function toolContext(id = "p"): IntegrationToolExecutionContext {
8
+ return {
9
+ process: { id, paramsJson: "{}" },
10
+ project: {
11
+ instanceId: id,
12
+ workBranch: "feature",
13
+ baseBranch: "main",
14
+ metadata: { github: { owner: "team", repo: "one", profile: "first" } },
15
+ },
16
+ idempotencyKey: "retained-pr-key",
17
+ signal: new AbortController().signal,
18
+ } as unknown as IntegrationToolExecutionContext;
19
+ }
20
+
21
+ export const pullRequestArgs = {
22
+ projectKey: "one",
23
+ owner: "attacker",
24
+ repo: "two",
25
+ profile: "other",
26
+ title: "A change",
27
+ body: "Review",
28
+ head: "feature",
29
+ base: "main",
30
+ };
31
+
32
+ /** Stateful provider boundary, with no Git, filesystem, or network. Unexpected calls fail closed. */
33
+ export function toolFixture() {
34
+ const pulls: GitHubPullRequest[] = [];
35
+ const comments: Array<{ body: string }> = [];
36
+ const requests: Array<{ method: string; owner: string; repo: string }> = [];
37
+ const profiles: string[] = [];
38
+ const failure = { create: "none" as "none" | "before" | "after", comment: false };
39
+ const record = (method: string, owner: string, repo: string) =>
40
+ requests.push({ method, owner, repo });
41
+ const methods = {
42
+ profile: { apiBaseUrl: "https://github.invalid", token: "fake", botLogin: "bot" },
43
+ async listPullRequests(owner, repo) {
44
+ record("list", owner, repo);
45
+ return structuredClone(pulls);
46
+ },
47
+ async createPullRequest(owner, repo, input) {
48
+ record("create", owner, repo);
49
+ if (failure.create === "before") throw new Error("create rejected");
50
+ const pr: GitHubPullRequest = {
51
+ number: pulls.length + 1,
52
+ title: input.title,
53
+ body: input.body,
54
+ state: "open",
55
+ merged: false,
56
+ merge_commit_sha: null,
57
+ html_url: "https://github.invalid/team/one/pull/1",
58
+ head: { ref: input.head, sha: "feature-sha" },
59
+ base: { ref: input.base, sha: "base-sha" },
60
+ };
61
+ pulls.push(pr);
62
+ if (failure.create === "after") throw new Error("response lost");
63
+ return structuredClone(pr);
64
+ },
65
+ async listIssueComments(owner, repo) {
66
+ record("comments", owner, repo);
67
+ return structuredClone(comments);
68
+ },
69
+ async addIssueComment(owner, repo, _number, body) {
70
+ record("comment", owner, repo);
71
+ comments.push({ body });
72
+ if (failure.comment) throw new Error("response lost");
73
+ return {};
74
+ },
75
+ async getPullRequest(owner, repo, number) {
76
+ record("get", owner, repo);
77
+ const pr = pulls.find((p) => p.number === number);
78
+ if (!pr) throw new Error("Unknown PR");
79
+ return structuredClone(pr);
80
+ },
81
+ async updatePullRequest(owner, repo, number, patch) {
82
+ record("update", owner, repo);
83
+ const pr = pulls.find((p) => p.number === number);
84
+ if (!pr) throw new Error("Unknown PR");
85
+ Object.assign(pr, patch);
86
+ return structuredClone(pr);
87
+ },
88
+ } satisfies Pick<
89
+ GitHubClientLike,
90
+ | "profile"
91
+ | "listPullRequests"
92
+ | "createPullRequest"
93
+ | "listIssueComments"
94
+ | "addIssueComment"
95
+ | "updatePullRequest"
96
+ | "getPullRequest"
97
+ >;
98
+ const client = new Proxy(methods, {
99
+ get(target, key) {
100
+ if (!(key in target)) throw new Error(`Unexpected provider access: ${String(key)}`);
101
+ return Reflect.get(target, key);
102
+ },
103
+ }) as unknown as GitHubClientLike;
104
+ const writes = createInMemoryExternalWriteLog();
105
+ const { api, tools } = createToolCollector(writes);
106
+ registerGitHubTools(api, {
107
+ client(profile) {
108
+ profiles.push(profile);
109
+ return client;
110
+ },
111
+ });
112
+ return {
113
+ pulls,
114
+ comments,
115
+ requests,
116
+ profiles,
117
+ failure,
118
+ writes,
119
+ tools,
120
+ execute(name: string, args: Record<string, unknown>, ctx = toolContext()) {
121
+ const tool = tools.get(name);
122
+ if (!tool) throw new Error(`Missing tool ${name}`);
123
+ return tool.execute(ctx, args);
124
+ },
125
+ };
126
+ }
package/src/testing.ts ADDED
@@ -0,0 +1,466 @@
1
+ import { LocalForgeStore, type LocalRepositorySeed } from "@leitwerk-dev/test-support/local-git";
2
+ import { actionableFeedback, authorizedTrigger } from "./authorization.js";
3
+ import type { GitHubClientLike } from "./capability.js";
4
+ import type {
5
+ GitHubCheckSummary,
6
+ GitHubFeedbackItem,
7
+ GitHubIssue,
8
+ GitHubLabelEvent,
9
+ GitHubProfile,
10
+ GitHubPullRequest,
11
+ GitHubRelease,
12
+ } from "./client.js";
13
+ import { assertGitHubRepository } from "./client.js";
14
+
15
+ /** @public */
16
+ interface LocalGitHubRepository {
17
+ /** @public */
18
+ repository: ReturnType<LocalGitHubAdapter["newRepository"]>;
19
+ /** @public */
20
+ issues: GitHubIssue[];
21
+ /** @public */
22
+ pulls: GitHubPullRequest[];
23
+ /** @public */
24
+ comments: Record<string, Array<ReturnType<LocalGitHubAdapter["newComment"]>>>;
25
+ /** @public */
26
+ feedback: Record<string, GitHubFeedbackItem[]>;
27
+ /** @public */
28
+ checks: Record<string, GitHubCheckSummary>;
29
+ /** @public */
30
+ releases: GitHubRelease[];
31
+ /** @public */
32
+ assets: Record<string, string>;
33
+ /** @public */
34
+ labels: Array<{
35
+ /** @internal */
36
+ id: number;
37
+ /** @internal */
38
+ name: string;
39
+ }>;
40
+ /** @public */
41
+ labelEvents: Record<string, GitHubLabelEvent[]>;
42
+ /** @public */
43
+ reactions: Record<
44
+ string,
45
+ Array<{
46
+ /** @internal */
47
+ id: number;
48
+ /** @internal */
49
+ content: string;
50
+ /** @internal */
51
+ user: {
52
+ /** @internal */
53
+ login: string;
54
+ };
55
+ }>
56
+ >;
57
+ /** @public */
58
+ feedbackEditors: Record<string, string | null>;
59
+ }
60
+ /** @public */
61
+ export interface LocalGitHubState {
62
+ /** @public */
63
+ version: 1;
64
+ /** @public */
65
+ sequence: number;
66
+ /** @public */
67
+ repositories: LocalGitHubRepository[];
68
+ /** @public */
69
+ failAfterPullRequestWrite: boolean;
70
+ /** @public */
71
+ members: string[];
72
+ /** @public */
73
+ failAfterWrite: string | null;
74
+ }
75
+ /** @public */
76
+ interface LocalGitHubOptions {
77
+ /** @public */
78
+ root: string;
79
+ /** @public */
80
+ baseUrl: string;
81
+ /** @public */
82
+ now?: () => number;
83
+ /** @public */
84
+ nextId?: () => number;
85
+ /** @public */
86
+ seeds?: LocalRepositorySeed[];
87
+ /** @public */
88
+ allowedOrganization?: string;
89
+ }
90
+
91
+ /** Persistent local GitHub with actual commit ancestry and configurable release assets. @public */
92
+ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalGitHubOptions> {
93
+ /** @public */
94
+ constructor(options: LocalGitHubOptions) {
95
+ super(options, "github.json", {
96
+ version: 1,
97
+ sequence: 0,
98
+ repositories: [],
99
+ failAfterPullRequestWrite: false,
100
+ members: [],
101
+ failAfterWrite: null,
102
+ });
103
+ this.state.members ??= [];
104
+ this.state.failAfterWrite ??= null;
105
+ for (const r of this.state.repositories) {
106
+ r.labels ??= [];
107
+ r.labelEvents ??= {};
108
+ r.reactions ??= {};
109
+ r.feedbackEditors ??= {};
110
+ }
111
+ for (const seed of options.seeds ?? []) this.seed(seed);
112
+ }
113
+ /** @public */
114
+ repo(owner: string, name: string) {
115
+ const repo = this.state.repositories.find((r) => r.repository.full_name === `${owner}/${name}`);
116
+ if (!repo) throw new Error("Unknown local GitHub repository");
117
+ return repo;
118
+ }
119
+ /** @public */
120
+ seed(seed: LocalRepositorySeed) {
121
+ const existing = this.state.repositories.find(
122
+ (r) => r.repository.full_name === `${seed.owner}/${seed.name}`,
123
+ );
124
+ if (existing) return existing;
125
+ const repo: LocalGitHubRepository = {
126
+ repository: this.newRepository(seed),
127
+ issues: [],
128
+ pulls: [],
129
+ comments: {},
130
+ feedback: {},
131
+ checks: {},
132
+ releases: [],
133
+ assets: {},
134
+ labels: [],
135
+ labelEvents: {},
136
+ reactions: {},
137
+ feedbackEditors: {},
138
+ };
139
+ this.state.repositories.push(repo);
140
+ this.save();
141
+ return repo;
142
+ }
143
+ /** @public */
144
+ setChecks(repo: LocalGitHubRepository, summary: GitHubCheckSummary) {
145
+ this.git.head(repo.repository.ssh_url, summary.headSha);
146
+ repo.checks[summary.headSha] = structuredClone(summary);
147
+ this.save();
148
+ }
149
+ /** @public */
150
+ publishRelease(
151
+ repo: LocalGitHubRepository,
152
+ input: {
153
+ /** @public */
154
+ tag: string;
155
+ /** @public */
156
+ ref: string;
157
+ /** @public */
158
+ assets: Record<string, string>;
159
+ /** @internal */
160
+ draft?: boolean;
161
+ /** @internal */
162
+ prerelease?: boolean;
163
+ },
164
+ ) {
165
+ const commit = this.git.head(repo.repository.ssh_url, input.ref);
166
+ this.git.run(repo.repository.ssh_url, ["check-ref-format", `refs/tags/${input.tag}`]);
167
+ this.git.run(repo.repository.ssh_url, ["tag", "--", input.tag, commit]);
168
+ const id = this.id();
169
+ const release: GitHubRelease = {
170
+ id,
171
+ tag_name: input.tag,
172
+ target_commitish: commit,
173
+ draft: input.draft ?? false,
174
+ prerelease: input.prerelease ?? false,
175
+ html_url: `${this.options.baseUrl}/__local`,
176
+ assets: Object.entries(input.assets).map(([name, contents]) => {
177
+ const url = `${this.options.baseUrl}/__local/assets/${this.id()}`;
178
+ repo.assets[url] = contents;
179
+ return { name, url, browser_download_url: url };
180
+ }),
181
+ };
182
+ repo.releases.unshift(release);
183
+ this.save();
184
+ return release;
185
+ }
186
+ /** @public */
187
+ override newRepository(seed: LocalRepositorySeed) {
188
+ return {
189
+ ...super.newRepository(seed),
190
+ /** @public */
191
+ archived: false,
192
+ /** @public */
193
+ has_issues: true,
194
+ };
195
+ }
196
+ /** @public */
197
+ setMembership(login: string, member: boolean) {
198
+ this.state.members = this.state.members.filter(
199
+ (value) => value.toLowerCase() !== login.toLowerCase(),
200
+ );
201
+ if (member) this.state.members.push(login);
202
+ this.save();
203
+ }
204
+ /** @public */
205
+ failNextResponse(operation: "comment" | "reply" | "reaction" | "issue" | "label") {
206
+ this.state.failAfterWrite = operation;
207
+ this.save();
208
+ }
209
+ private lostResponse(operation: string) {
210
+ if (this.state.failAfterWrite !== operation) return;
211
+ this.state.failAfterWrite = null;
212
+ this.save();
213
+ throw new Error(`Local GitHub: response lost after ${operation} write`);
214
+ }
215
+ /** @public */
216
+ createIssue(
217
+ repo: LocalGitHubRepository,
218
+ input: {
219
+ /** @public */
220
+ title: string;
221
+ /** @public */
222
+ body?: string;
223
+ /** @public */
224
+ author?: string;
225
+ },
226
+ ) {
227
+ const number = this.id();
228
+ const issue: GitHubIssue = {
229
+ number,
230
+ title: input.title,
231
+ body: input.body ?? "",
232
+ state: "open",
233
+ html_url: `${this.options.baseUrl}/__local#issue-${number}`,
234
+ updated_at: this.timestamp(),
235
+ user: { login: input.author ?? "developer" },
236
+ labels: [],
237
+ };
238
+ repo.issues.push(issue);
239
+ this.save();
240
+ return issue;
241
+ }
242
+ /** @public */
243
+ setIssueLabel(
244
+ repo: LocalGitHubRepository,
245
+ number: number,
246
+ name: string,
247
+ actor: string,
248
+ present = true,
249
+ ) {
250
+ const issue = repo.issues.find((value) => value.number === number);
251
+ if (!issue) throw new Error("Unknown local GitHub issue");
252
+ issue.labels = issue.labels.filter((label) => label.name !== name);
253
+ if (present) issue.labels.push({ id: this.id(), name });
254
+ const event: GitHubLabelEvent = {
255
+ id: this.id(),
256
+ event: present ? "labeled" : "unlabeled",
257
+ label: { name },
258
+ actor: { login: actor },
259
+ };
260
+ repo.labelEvents[number] ??= [];
261
+ repo.labelEvents[number].push(event);
262
+ issue.updated_at = this.timestamp();
263
+ this.save();
264
+ return event;
265
+ }
266
+ /** @public */
267
+ editFeedback(
268
+ repo: LocalGitHubRepository,
269
+ number: number,
270
+ kind: GitHubFeedbackItem["kind"],
271
+ id: number,
272
+ body: string,
273
+ editor: string | null,
274
+ ) {
275
+ const item = repo.feedback[number]?.find((value) => value.kind === kind && value.id === id);
276
+ if (!item) throw new Error("Unknown local GitHub feedback");
277
+ item.body = body;
278
+ item.createdAt = this.timestamp();
279
+ repo.feedbackEditors[`${kind}:${id}`] = editor;
280
+ this.save();
281
+ }
282
+
283
+ /** @public */
284
+ client(): GitHubClientLike {
285
+ const profile: GitHubProfile = {
286
+ apiBaseUrl: this.options.baseUrl,
287
+ token: "",
288
+ botLogin: "leitwerk-bot",
289
+ ...(this.options.allowedOrganization
290
+ ? { allowedOrganization: this.options.allowedOrganization }
291
+ : {}),
292
+ };
293
+ const repo = (owner: string, name: string) => {
294
+ assertGitHubRepository(profile, owner, name);
295
+ return this.repo(owner, name);
296
+ };
297
+ const client: GitHubClientLike = {
298
+ profile,
299
+ listRepositories: async () =>
300
+ this.state.repositories
301
+ .map((r) => ({ ...r.repository, archived: false, has_issues: true }))
302
+ .filter(
303
+ (r) =>
304
+ !profile.allowedOrganization ||
305
+ r.owner.login.toLowerCase() === profile.allowedOrganization.toLowerCase(),
306
+ ),
307
+ listOpenIssues: async (owner, name) =>
308
+ structuredClone(repo(owner, name).issues.filter((i) => i.state === "open")),
309
+ listIssueEvents: async (owner, name, number) =>
310
+ structuredClone(repo(owner, name).labelEvents[number] ?? []),
311
+ isOrganizationMember: async (login) =>
312
+ !profile.allowedOrganization ||
313
+ this.state.members.some((member) => member.toLowerCase() === login.toLowerCase()),
314
+ authorizedTrigger: async (owner, name, number, trigger, done) =>
315
+ authorizedTrigger(client, owner, name, number, trigger, done),
316
+ resolveGitIdentity: async (name) => ({
317
+ provider: "github",
318
+ profile: name,
319
+ login: profile.botLogin,
320
+ name: "Sandbox Developer",
321
+ email: "developer@sandbox.invalid",
322
+ }),
323
+ listLabels: async (owner, name) => structuredClone(repo(owner, name).labels),
324
+ createLabel: async (owner, name, labelName) => {
325
+ const r = repo(owner, name);
326
+ let label = r.labels.find((value) => value.name === labelName);
327
+ if (!label) {
328
+ label = { id: this.id(), name: labelName };
329
+ r.labels.push(label);
330
+ this.save();
331
+ this.lostResponse("label");
332
+ }
333
+ return structuredClone(label);
334
+ },
335
+ ensureLabel: async (owner, name, labelName) => {
336
+ const label = repo(owner, name).labels.find((value) => value.name === labelName);
337
+ return label ? structuredClone(label) : client.createLabel(owner, name, labelName);
338
+ },
339
+ updateIssue: async (owner, name, number, patch) => {
340
+ const issue = repo(owner, name).issues.find((i) => i.number === number);
341
+ if (!issue) throw new Error("Unknown local GitHub issue");
342
+ for (const key of ["title", "body", "state"] as const)
343
+ if (typeof patch[key] === "string") issue[key] = patch[key];
344
+ if (Array.isArray(patch.labels))
345
+ issue.labels = patch.labels.map((value) => ({ id: this.id(), name: String(value) }));
346
+ issue.updated_at = this.timestamp();
347
+ this.save();
348
+ this.lostResponse("issue");
349
+ return structuredClone(issue);
350
+ },
351
+ listFeedbackReactions: async (owner, name, kind, id) =>
352
+ structuredClone(repo(owner, name).reactions[`${kind}:${id}`] ?? []),
353
+ addFeedbackReaction: async (owner, name, kind, id) => {
354
+ if (!["conversation", "inline"].includes(kind))
355
+ throw new Error("Reviews do not support reactions");
356
+ const r = repo(owner, name);
357
+ r.reactions[`${kind}:${id}`] ??= [];
358
+ const reactions = r.reactions[`${kind}:${id}`];
359
+ let reaction = reactions.find(
360
+ (r) => r.content === "eyes" && r.user.login === profile.botLogin,
361
+ );
362
+ if (!reaction) {
363
+ reaction = { id: this.id(), content: "eyes", user: { login: profile.botLogin } };
364
+ reactions.push(reaction);
365
+ this.save();
366
+ this.lostResponse("reaction");
367
+ }
368
+ return structuredClone(reaction);
369
+ },
370
+ listFeedbackReplies: async (owner, name, number, kind) =>
371
+ kind === "inline"
372
+ ? structuredClone(
373
+ (repo(owner, name).feedback[number] ?? [])
374
+ .filter((f) => f.kind === "inline")
375
+ .map((f) => ({ ...f })),
376
+ )
377
+ : client.listIssueComments(owner, name, number),
378
+ replyFeedback: async (owner, name, number, kind, id, body) => {
379
+ if (kind !== "inline") return client.addIssueComment(owner, name, number, body);
380
+ const value = this.addFeedback(repo(owner, name), number, {
381
+ kind: "inline",
382
+ body,
383
+ author: profile.botLogin,
384
+ });
385
+ Object.assign(value, { in_reply_to_id: id });
386
+ this.save();
387
+ this.lostResponse("reply");
388
+ return structuredClone(value);
389
+ },
390
+ listActionablePullRequestFeedback: async (owner, name, number, signal) =>
391
+ actionableFeedback(
392
+ client,
393
+ await client.listPullRequestFeedback(owner, name, number, signal),
394
+ ),
395
+ getIssue: async (owner, name, number) => {
396
+ const issue = repo(owner, name).issues.find((i) => i.number === number);
397
+ if (!issue) throw new Error("Unknown local GitHub issue");
398
+ return structuredClone(issue);
399
+ },
400
+ getCommit: async (owner, name, ref) => ({
401
+ sha: this.git.head(repo(owner, name).repository.ssh_url, ref),
402
+ }),
403
+ isAncestor: async (owner, name, ancestor, descendant) =>
404
+ this.git.isAncestor(repo(owner, name).repository.ssh_url, ancestor, descendant),
405
+ listIssueComments: async (owner, name, number) =>
406
+ structuredClone(repo(owner, name).comments[number] ?? []),
407
+ addIssueComment: async (owner, name, number, body) => {
408
+ const r = repo(owner, name);
409
+ if (!r.pulls.some((p) => p.number === number) && !r.issues.some((i) => i.number === number))
410
+ throw new Error("Unknown local GitHub issue or PR");
411
+ const value = this.newComment(body);
412
+ r.comments[number] ??= [];
413
+ r.comments[number].push(value);
414
+ this.save();
415
+ this.lostResponse("comment");
416
+ return structuredClone(value);
417
+ },
418
+ createPullRequest: async (owner, name, input) => {
419
+ const r = repo(owner, name);
420
+ const pr = this.newPullRequest(r, input);
421
+ r.pulls.push(pr);
422
+ const fail = this.state.failAfterPullRequestWrite;
423
+ this.state.failAfterPullRequestWrite = false;
424
+ this.save();
425
+ if (fail) throw new Error("Local GitHub: response lost after PR creation");
426
+ return this.refresh(r, pr);
427
+ },
428
+ ...this.pullRequestClient(repo, "Unknown local GitHub pull request"),
429
+ listPullRequestFeedback: async (owner, name, number) =>
430
+ structuredClone([
431
+ ...(repo(owner, name).feedback[number] ?? []).filter((item) => {
432
+ if (!profile.allowedOrganization) return true;
433
+ const editor = repo(owner, name).feedbackEditors[`${item.kind}:${item.id}`];
434
+ return (
435
+ editor === undefined ||
436
+ (editor !== null &&
437
+ this.state.members.some((m) => m.toLowerCase() === editor.toLowerCase()))
438
+ );
439
+ }),
440
+ ...(repo(owner, name).comments[number] ?? []).map((c) => ({
441
+ kind: "conversation" as const,
442
+ id: c.id,
443
+ body: c.body,
444
+ author: c.user.login,
445
+ createdAt: c.created_at,
446
+ })),
447
+ ]),
448
+ getCheckSummary: async (owner, name, sha) =>
449
+ structuredClone(
450
+ repo(owner, name).checks[sha] ?? {
451
+ headSha: sha,
452
+ status: "pending",
453
+ total: 0,
454
+ failed: [],
455
+ },
456
+ ),
457
+ listReleases: async (owner, name) => structuredClone(repo(owner, name).releases),
458
+ downloadReleaseAsset: async (asset) => {
459
+ for (const r of this.state.repositories)
460
+ if (r.assets[asset.url] !== undefined) return r.assets[asset.url];
461
+ throw new Error("Unknown local GitHub release asset");
462
+ },
463
+ };
464
+ return client;
465
+ }
466
+ }