@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.
- package/README.md +139 -1
- package/dist/LICENSE +13 -0
- package/dist/authorization.d.ts +16 -0
- package/dist/authorization.d.ts.map +1 -0
- package/dist/binding.d.ts +5 -0
- package/dist/binding.d.ts.map +1 -0
- package/dist/capability.d.ts +11 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/chunk-6X3F3VHK.js +344 -0
- package/dist/chunk-6X3F3VHK.js.map +1 -0
- package/dist/client.d.ts +200 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/external.d.ts +150 -0
- package/dist/external.d.ts.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +790 -0
- package/dist/index.js.map +1 -0
- package/dist/issue-provider.d.ts +8 -0
- package/dist/issue-provider.d.ts.map +1 -0
- package/dist/issue-watcher.d.ts +31 -0
- package/dist/issue-watcher.d.ts.map +1 -0
- package/dist/poll-report.d.ts +22 -0
- package/dist/poll-report.d.ts.map +1 -0
- package/dist/provider.d.ts +8 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/testing/tool-fixture.d.ts +45 -0
- package/dist/testing/tool-fixture.d.ts.map +1 -0
- package/dist/testing.d.ts +145 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +322 -0
- package/dist/testing.js.map +1 -0
- package/dist/tools.d.ts +4 -0
- package/dist/tools.d.ts.map +1 -0
- package/package.json +54 -14
- package/src/authorization.ts +62 -0
- package/src/binding.ts +7 -0
- package/src/capability.ts +16 -0
- package/src/client.ts +526 -0
- package/src/external.ts +192 -0
- package/src/index.ts +65 -0
- package/src/issue-provider.ts +278 -0
- package/src/issue-watcher.ts +45 -0
- package/src/poll-report.ts +47 -0
- package/src/provider.ts +216 -0
- package/src/testing/tool-fixture.ts +126 -0
- package/src/testing.ts +466 -0
- package/src/tools.ts +287 -0
package/dist/testing.js
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import {
|
|
2
|
+
actionableFeedback,
|
|
3
|
+
assertGitHubRepository,
|
|
4
|
+
authorizedTrigger
|
|
5
|
+
} from "./chunk-6X3F3VHK.js";
|
|
6
|
+
|
|
7
|
+
// src/testing.ts
|
|
8
|
+
import { LocalForgeStore } from "@leitwerk-dev/test-support/local-git";
|
|
9
|
+
var LocalGitHubAdapter = class extends LocalForgeStore {
|
|
10
|
+
/** @public */
|
|
11
|
+
constructor(options) {
|
|
12
|
+
super(options, "github.json", {
|
|
13
|
+
version: 1,
|
|
14
|
+
sequence: 0,
|
|
15
|
+
repositories: [],
|
|
16
|
+
failAfterPullRequestWrite: false,
|
|
17
|
+
members: [],
|
|
18
|
+
failAfterWrite: null
|
|
19
|
+
});
|
|
20
|
+
this.state.members ??= [];
|
|
21
|
+
this.state.failAfterWrite ??= null;
|
|
22
|
+
for (const r of this.state.repositories) {
|
|
23
|
+
r.labels ??= [];
|
|
24
|
+
r.labelEvents ??= {};
|
|
25
|
+
r.reactions ??= {};
|
|
26
|
+
r.feedbackEditors ??= {};
|
|
27
|
+
}
|
|
28
|
+
for (const seed of options.seeds ?? []) this.seed(seed);
|
|
29
|
+
}
|
|
30
|
+
/** @public */
|
|
31
|
+
repo(owner, name) {
|
|
32
|
+
const repo = this.state.repositories.find((r) => r.repository.full_name === `${owner}/${name}`);
|
|
33
|
+
if (!repo) throw new Error("Unknown local GitHub repository");
|
|
34
|
+
return repo;
|
|
35
|
+
}
|
|
36
|
+
/** @public */
|
|
37
|
+
seed(seed) {
|
|
38
|
+
const existing = this.state.repositories.find(
|
|
39
|
+
(r) => r.repository.full_name === `${seed.owner}/${seed.name}`
|
|
40
|
+
);
|
|
41
|
+
if (existing) return existing;
|
|
42
|
+
const repo = {
|
|
43
|
+
repository: this.newRepository(seed),
|
|
44
|
+
issues: [],
|
|
45
|
+
pulls: [],
|
|
46
|
+
comments: {},
|
|
47
|
+
feedback: {},
|
|
48
|
+
checks: {},
|
|
49
|
+
releases: [],
|
|
50
|
+
assets: {},
|
|
51
|
+
labels: [],
|
|
52
|
+
labelEvents: {},
|
|
53
|
+
reactions: {},
|
|
54
|
+
feedbackEditors: {}
|
|
55
|
+
};
|
|
56
|
+
this.state.repositories.push(repo);
|
|
57
|
+
this.save();
|
|
58
|
+
return repo;
|
|
59
|
+
}
|
|
60
|
+
/** @public */
|
|
61
|
+
setChecks(repo, summary) {
|
|
62
|
+
this.git.head(repo.repository.ssh_url, summary.headSha);
|
|
63
|
+
repo.checks[summary.headSha] = structuredClone(summary);
|
|
64
|
+
this.save();
|
|
65
|
+
}
|
|
66
|
+
/** @public */
|
|
67
|
+
publishRelease(repo, input) {
|
|
68
|
+
const commit = this.git.head(repo.repository.ssh_url, input.ref);
|
|
69
|
+
this.git.run(repo.repository.ssh_url, ["check-ref-format", `refs/tags/${input.tag}`]);
|
|
70
|
+
this.git.run(repo.repository.ssh_url, ["tag", "--", input.tag, commit]);
|
|
71
|
+
const id = this.id();
|
|
72
|
+
const release = {
|
|
73
|
+
id,
|
|
74
|
+
tag_name: input.tag,
|
|
75
|
+
target_commitish: commit,
|
|
76
|
+
draft: input.draft ?? false,
|
|
77
|
+
prerelease: input.prerelease ?? false,
|
|
78
|
+
html_url: `${this.options.baseUrl}/__local`,
|
|
79
|
+
assets: Object.entries(input.assets).map(([name, contents]) => {
|
|
80
|
+
const url = `${this.options.baseUrl}/__local/assets/${this.id()}`;
|
|
81
|
+
repo.assets[url] = contents;
|
|
82
|
+
return { name, url, browser_download_url: url };
|
|
83
|
+
})
|
|
84
|
+
};
|
|
85
|
+
repo.releases.unshift(release);
|
|
86
|
+
this.save();
|
|
87
|
+
return release;
|
|
88
|
+
}
|
|
89
|
+
/** @public */
|
|
90
|
+
newRepository(seed) {
|
|
91
|
+
return {
|
|
92
|
+
...super.newRepository(seed),
|
|
93
|
+
/** @public */
|
|
94
|
+
archived: false,
|
|
95
|
+
/** @public */
|
|
96
|
+
has_issues: true
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** @public */
|
|
100
|
+
setMembership(login, member) {
|
|
101
|
+
this.state.members = this.state.members.filter(
|
|
102
|
+
(value) => value.toLowerCase() !== login.toLowerCase()
|
|
103
|
+
);
|
|
104
|
+
if (member) this.state.members.push(login);
|
|
105
|
+
this.save();
|
|
106
|
+
}
|
|
107
|
+
/** @public */
|
|
108
|
+
failNextResponse(operation) {
|
|
109
|
+
this.state.failAfterWrite = operation;
|
|
110
|
+
this.save();
|
|
111
|
+
}
|
|
112
|
+
lostResponse(operation) {
|
|
113
|
+
if (this.state.failAfterWrite !== operation) return;
|
|
114
|
+
this.state.failAfterWrite = null;
|
|
115
|
+
this.save();
|
|
116
|
+
throw new Error(`Local GitHub: response lost after ${operation} write`);
|
|
117
|
+
}
|
|
118
|
+
/** @public */
|
|
119
|
+
createIssue(repo, input) {
|
|
120
|
+
const number = this.id();
|
|
121
|
+
const issue = {
|
|
122
|
+
number,
|
|
123
|
+
title: input.title,
|
|
124
|
+
body: input.body ?? "",
|
|
125
|
+
state: "open",
|
|
126
|
+
html_url: `${this.options.baseUrl}/__local#issue-${number}`,
|
|
127
|
+
updated_at: this.timestamp(),
|
|
128
|
+
user: { login: input.author ?? "developer" },
|
|
129
|
+
labels: []
|
|
130
|
+
};
|
|
131
|
+
repo.issues.push(issue);
|
|
132
|
+
this.save();
|
|
133
|
+
return issue;
|
|
134
|
+
}
|
|
135
|
+
/** @public */
|
|
136
|
+
setIssueLabel(repo, number, name, actor, present = true) {
|
|
137
|
+
const issue = repo.issues.find((value) => value.number === number);
|
|
138
|
+
if (!issue) throw new Error("Unknown local GitHub issue");
|
|
139
|
+
issue.labels = issue.labels.filter((label) => label.name !== name);
|
|
140
|
+
if (present) issue.labels.push({ id: this.id(), name });
|
|
141
|
+
const event = {
|
|
142
|
+
id: this.id(),
|
|
143
|
+
event: present ? "labeled" : "unlabeled",
|
|
144
|
+
label: { name },
|
|
145
|
+
actor: { login: actor }
|
|
146
|
+
};
|
|
147
|
+
repo.labelEvents[number] ??= [];
|
|
148
|
+
repo.labelEvents[number].push(event);
|
|
149
|
+
issue.updated_at = this.timestamp();
|
|
150
|
+
this.save();
|
|
151
|
+
return event;
|
|
152
|
+
}
|
|
153
|
+
/** @public */
|
|
154
|
+
editFeedback(repo, number, kind, id, body, editor) {
|
|
155
|
+
const item = repo.feedback[number]?.find((value) => value.kind === kind && value.id === id);
|
|
156
|
+
if (!item) throw new Error("Unknown local GitHub feedback");
|
|
157
|
+
item.body = body;
|
|
158
|
+
item.createdAt = this.timestamp();
|
|
159
|
+
repo.feedbackEditors[`${kind}:${id}`] = editor;
|
|
160
|
+
this.save();
|
|
161
|
+
}
|
|
162
|
+
/** @public */
|
|
163
|
+
client() {
|
|
164
|
+
const profile = {
|
|
165
|
+
apiBaseUrl: this.options.baseUrl,
|
|
166
|
+
token: "",
|
|
167
|
+
botLogin: "leitwerk-bot",
|
|
168
|
+
...this.options.allowedOrganization ? { allowedOrganization: this.options.allowedOrganization } : {}
|
|
169
|
+
};
|
|
170
|
+
const repo = (owner, name) => {
|
|
171
|
+
assertGitHubRepository(profile, owner, name);
|
|
172
|
+
return this.repo(owner, name);
|
|
173
|
+
};
|
|
174
|
+
const client = {
|
|
175
|
+
profile,
|
|
176
|
+
listRepositories: async () => this.state.repositories.map((r) => ({ ...r.repository, archived: false, has_issues: true })).filter(
|
|
177
|
+
(r) => !profile.allowedOrganization || r.owner.login.toLowerCase() === profile.allowedOrganization.toLowerCase()
|
|
178
|
+
),
|
|
179
|
+
listOpenIssues: async (owner, name) => structuredClone(repo(owner, name).issues.filter((i) => i.state === "open")),
|
|
180
|
+
listIssueEvents: async (owner, name, number) => structuredClone(repo(owner, name).labelEvents[number] ?? []),
|
|
181
|
+
isOrganizationMember: async (login) => !profile.allowedOrganization || this.state.members.some((member) => member.toLowerCase() === login.toLowerCase()),
|
|
182
|
+
authorizedTrigger: async (owner, name, number, trigger, done) => authorizedTrigger(client, owner, name, number, trigger, done),
|
|
183
|
+
resolveGitIdentity: async (name) => ({
|
|
184
|
+
provider: "github",
|
|
185
|
+
profile: name,
|
|
186
|
+
login: profile.botLogin,
|
|
187
|
+
name: "Sandbox Developer",
|
|
188
|
+
email: "developer@sandbox.invalid"
|
|
189
|
+
}),
|
|
190
|
+
listLabels: async (owner, name) => structuredClone(repo(owner, name).labels),
|
|
191
|
+
createLabel: async (owner, name, labelName) => {
|
|
192
|
+
const r = repo(owner, name);
|
|
193
|
+
let label = r.labels.find((value) => value.name === labelName);
|
|
194
|
+
if (!label) {
|
|
195
|
+
label = { id: this.id(), name: labelName };
|
|
196
|
+
r.labels.push(label);
|
|
197
|
+
this.save();
|
|
198
|
+
this.lostResponse("label");
|
|
199
|
+
}
|
|
200
|
+
return structuredClone(label);
|
|
201
|
+
},
|
|
202
|
+
ensureLabel: async (owner, name, labelName) => {
|
|
203
|
+
const label = repo(owner, name).labels.find((value) => value.name === labelName);
|
|
204
|
+
return label ? structuredClone(label) : client.createLabel(owner, name, labelName);
|
|
205
|
+
},
|
|
206
|
+
updateIssue: async (owner, name, number, patch) => {
|
|
207
|
+
const issue = repo(owner, name).issues.find((i) => i.number === number);
|
|
208
|
+
if (!issue) throw new Error("Unknown local GitHub issue");
|
|
209
|
+
for (const key of ["title", "body", "state"])
|
|
210
|
+
if (typeof patch[key] === "string") issue[key] = patch[key];
|
|
211
|
+
if (Array.isArray(patch.labels))
|
|
212
|
+
issue.labels = patch.labels.map((value) => ({ id: this.id(), name: String(value) }));
|
|
213
|
+
issue.updated_at = this.timestamp();
|
|
214
|
+
this.save();
|
|
215
|
+
this.lostResponse("issue");
|
|
216
|
+
return structuredClone(issue);
|
|
217
|
+
},
|
|
218
|
+
listFeedbackReactions: async (owner, name, kind, id) => structuredClone(repo(owner, name).reactions[`${kind}:${id}`] ?? []),
|
|
219
|
+
addFeedbackReaction: async (owner, name, kind, id) => {
|
|
220
|
+
if (!["conversation", "inline"].includes(kind))
|
|
221
|
+
throw new Error("Reviews do not support reactions");
|
|
222
|
+
const r = repo(owner, name);
|
|
223
|
+
r.reactions[`${kind}:${id}`] ??= [];
|
|
224
|
+
const reactions = r.reactions[`${kind}:${id}`];
|
|
225
|
+
let reaction = reactions.find(
|
|
226
|
+
(r2) => r2.content === "eyes" && r2.user.login === profile.botLogin
|
|
227
|
+
);
|
|
228
|
+
if (!reaction) {
|
|
229
|
+
reaction = { id: this.id(), content: "eyes", user: { login: profile.botLogin } };
|
|
230
|
+
reactions.push(reaction);
|
|
231
|
+
this.save();
|
|
232
|
+
this.lostResponse("reaction");
|
|
233
|
+
}
|
|
234
|
+
return structuredClone(reaction);
|
|
235
|
+
},
|
|
236
|
+
listFeedbackReplies: async (owner, name, number, kind) => kind === "inline" ? structuredClone(
|
|
237
|
+
(repo(owner, name).feedback[number] ?? []).filter((f) => f.kind === "inline").map((f) => ({ ...f }))
|
|
238
|
+
) : client.listIssueComments(owner, name, number),
|
|
239
|
+
replyFeedback: async (owner, name, number, kind, id, body) => {
|
|
240
|
+
if (kind !== "inline") return client.addIssueComment(owner, name, number, body);
|
|
241
|
+
const value = this.addFeedback(repo(owner, name), number, {
|
|
242
|
+
kind: "inline",
|
|
243
|
+
body,
|
|
244
|
+
author: profile.botLogin
|
|
245
|
+
});
|
|
246
|
+
Object.assign(value, { in_reply_to_id: id });
|
|
247
|
+
this.save();
|
|
248
|
+
this.lostResponse("reply");
|
|
249
|
+
return structuredClone(value);
|
|
250
|
+
},
|
|
251
|
+
listActionablePullRequestFeedback: async (owner, name, number, signal) => actionableFeedback(
|
|
252
|
+
client,
|
|
253
|
+
await client.listPullRequestFeedback(owner, name, number, signal)
|
|
254
|
+
),
|
|
255
|
+
getIssue: async (owner, name, number) => {
|
|
256
|
+
const issue = repo(owner, name).issues.find((i) => i.number === number);
|
|
257
|
+
if (!issue) throw new Error("Unknown local GitHub issue");
|
|
258
|
+
return structuredClone(issue);
|
|
259
|
+
},
|
|
260
|
+
getCommit: async (owner, name, ref) => ({
|
|
261
|
+
sha: this.git.head(repo(owner, name).repository.ssh_url, ref)
|
|
262
|
+
}),
|
|
263
|
+
isAncestor: async (owner, name, ancestor, descendant) => this.git.isAncestor(repo(owner, name).repository.ssh_url, ancestor, descendant),
|
|
264
|
+
listIssueComments: async (owner, name, number) => structuredClone(repo(owner, name).comments[number] ?? []),
|
|
265
|
+
addIssueComment: async (owner, name, number, body) => {
|
|
266
|
+
const r = repo(owner, name);
|
|
267
|
+
if (!r.pulls.some((p) => p.number === number) && !r.issues.some((i) => i.number === number))
|
|
268
|
+
throw new Error("Unknown local GitHub issue or PR");
|
|
269
|
+
const value = this.newComment(body);
|
|
270
|
+
r.comments[number] ??= [];
|
|
271
|
+
r.comments[number].push(value);
|
|
272
|
+
this.save();
|
|
273
|
+
this.lostResponse("comment");
|
|
274
|
+
return structuredClone(value);
|
|
275
|
+
},
|
|
276
|
+
createPullRequest: async (owner, name, input) => {
|
|
277
|
+
const r = repo(owner, name);
|
|
278
|
+
const pr = this.newPullRequest(r, input);
|
|
279
|
+
r.pulls.push(pr);
|
|
280
|
+
const fail = this.state.failAfterPullRequestWrite;
|
|
281
|
+
this.state.failAfterPullRequestWrite = false;
|
|
282
|
+
this.save();
|
|
283
|
+
if (fail) throw new Error("Local GitHub: response lost after PR creation");
|
|
284
|
+
return this.refresh(r, pr);
|
|
285
|
+
},
|
|
286
|
+
...this.pullRequestClient(repo, "Unknown local GitHub pull request"),
|
|
287
|
+
listPullRequestFeedback: async (owner, name, number) => structuredClone([
|
|
288
|
+
...(repo(owner, name).feedback[number] ?? []).filter((item) => {
|
|
289
|
+
if (!profile.allowedOrganization) return true;
|
|
290
|
+
const editor = repo(owner, name).feedbackEditors[`${item.kind}:${item.id}`];
|
|
291
|
+
return editor === void 0 || editor !== null && this.state.members.some((m) => m.toLowerCase() === editor.toLowerCase());
|
|
292
|
+
}),
|
|
293
|
+
...(repo(owner, name).comments[number] ?? []).map((c) => ({
|
|
294
|
+
kind: "conversation",
|
|
295
|
+
id: c.id,
|
|
296
|
+
body: c.body,
|
|
297
|
+
author: c.user.login,
|
|
298
|
+
createdAt: c.created_at
|
|
299
|
+
}))
|
|
300
|
+
]),
|
|
301
|
+
getCheckSummary: async (owner, name, sha) => structuredClone(
|
|
302
|
+
repo(owner, name).checks[sha] ?? {
|
|
303
|
+
headSha: sha,
|
|
304
|
+
status: "pending",
|
|
305
|
+
total: 0,
|
|
306
|
+
failed: []
|
|
307
|
+
}
|
|
308
|
+
),
|
|
309
|
+
listReleases: async (owner, name) => structuredClone(repo(owner, name).releases),
|
|
310
|
+
downloadReleaseAsset: async (asset) => {
|
|
311
|
+
for (const r of this.state.repositories)
|
|
312
|
+
if (r.assets[asset.url] !== void 0) return r.assets[asset.url];
|
|
313
|
+
throw new Error("Unknown local GitHub release asset");
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
return client;
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
export {
|
|
320
|
+
LocalGitHubAdapter
|
|
321
|
+
};
|
|
322
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/testing.ts"],"sourcesContent":["import { LocalForgeStore, type LocalRepositorySeed } from \"@leitwerk-dev/test-support/local-git\";\nimport { actionableFeedback, authorizedTrigger } from \"./authorization.js\";\nimport type { GitHubClientLike } from \"./capability.js\";\nimport type {\n\tGitHubCheckSummary,\n\tGitHubFeedbackItem,\n\tGitHubIssue,\n\tGitHubLabelEvent,\n\tGitHubProfile,\n\tGitHubPullRequest,\n\tGitHubRelease,\n} from \"./client.js\";\nimport { assertGitHubRepository } from \"./client.js\";\n\n/** @public */\ninterface LocalGitHubRepository {\n\t/** @public */\n\trepository: ReturnType<LocalGitHubAdapter[\"newRepository\"]>;\n\t/** @public */\n\tissues: GitHubIssue[];\n\t/** @public */\n\tpulls: GitHubPullRequest[];\n\t/** @public */\n\tcomments: Record<string, Array<ReturnType<LocalGitHubAdapter[\"newComment\"]>>>;\n\t/** @public */\n\tfeedback: Record<string, GitHubFeedbackItem[]>;\n\t/** @public */\n\tchecks: Record<string, GitHubCheckSummary>;\n\t/** @public */\n\treleases: GitHubRelease[];\n\t/** @public */\n\tassets: Record<string, string>;\n\t/** @public */\n\tlabels: Array<{\n\t\t/** @internal */\n\t\tid: number;\n\t\t/** @internal */\n\t\tname: string;\n\t}>;\n\t/** @public */\n\tlabelEvents: Record<string, GitHubLabelEvent[]>;\n\t/** @public */\n\treactions: Record<\n\t\tstring,\n\t\tArray<{\n\t\t\t/** @internal */\n\t\t\tid: number;\n\t\t\t/** @internal */\n\t\t\tcontent: string;\n\t\t\t/** @internal */\n\t\t\tuser: {\n\t\t\t\t/** @internal */\n\t\t\t\tlogin: string;\n\t\t\t};\n\t\t}>\n\t>;\n\t/** @public */\n\tfeedbackEditors: Record<string, string | null>;\n}\n/** @public */\nexport interface LocalGitHubState {\n\t/** @public */\n\tversion: 1;\n\t/** @public */\n\tsequence: number;\n\t/** @public */\n\trepositories: LocalGitHubRepository[];\n\t/** @public */\n\tfailAfterPullRequestWrite: boolean;\n\t/** @public */\n\tmembers: string[];\n\t/** @public */\n\tfailAfterWrite: string | null;\n}\n/** @public */\ninterface LocalGitHubOptions {\n\t/** @public */\n\troot: string;\n\t/** @public */\n\tbaseUrl: string;\n\t/** @public */\n\tnow?: () => number;\n\t/** @public */\n\tnextId?: () => number;\n\t/** @public */\n\tseeds?: LocalRepositorySeed[];\n\t/** @public */\n\tallowedOrganization?: string;\n}\n\n/** Persistent local GitHub with actual commit ancestry and configurable release assets. @public */\nexport class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalGitHubOptions> {\n\t/** @public */\n\tconstructor(options: LocalGitHubOptions) {\n\t\tsuper(options, \"github.json\", {\n\t\t\tversion: 1,\n\t\t\tsequence: 0,\n\t\t\trepositories: [],\n\t\t\tfailAfterPullRequestWrite: false,\n\t\t\tmembers: [],\n\t\t\tfailAfterWrite: null,\n\t\t});\n\t\tthis.state.members ??= [];\n\t\tthis.state.failAfterWrite ??= null;\n\t\tfor (const r of this.state.repositories) {\n\t\t\tr.labels ??= [];\n\t\t\tr.labelEvents ??= {};\n\t\t\tr.reactions ??= {};\n\t\t\tr.feedbackEditors ??= {};\n\t\t}\n\t\tfor (const seed of options.seeds ?? []) this.seed(seed);\n\t}\n\t/** @public */\n\trepo(owner: string, name: string) {\n\t\tconst repo = this.state.repositories.find((r) => r.repository.full_name === `${owner}/${name}`);\n\t\tif (!repo) throw new Error(\"Unknown local GitHub repository\");\n\t\treturn repo;\n\t}\n\t/** @public */\n\tseed(seed: LocalRepositorySeed) {\n\t\tconst existing = this.state.repositories.find(\n\t\t\t(r) => r.repository.full_name === `${seed.owner}/${seed.name}`,\n\t\t);\n\t\tif (existing) return existing;\n\t\tconst repo: LocalGitHubRepository = {\n\t\t\trepository: this.newRepository(seed),\n\t\t\tissues: [],\n\t\t\tpulls: [],\n\t\t\tcomments: {},\n\t\t\tfeedback: {},\n\t\t\tchecks: {},\n\t\t\treleases: [],\n\t\t\tassets: {},\n\t\t\tlabels: [],\n\t\t\tlabelEvents: {},\n\t\t\treactions: {},\n\t\t\tfeedbackEditors: {},\n\t\t};\n\t\tthis.state.repositories.push(repo);\n\t\tthis.save();\n\t\treturn repo;\n\t}\n\t/** @public */\n\tsetChecks(repo: LocalGitHubRepository, summary: GitHubCheckSummary) {\n\t\tthis.git.head(repo.repository.ssh_url, summary.headSha);\n\t\trepo.checks[summary.headSha] = structuredClone(summary);\n\t\tthis.save();\n\t}\n\t/** @public */\n\tpublishRelease(\n\t\trepo: LocalGitHubRepository,\n\t\tinput: {\n\t\t\t/** @public */\n\t\t\ttag: string;\n\t\t\t/** @public */\n\t\t\tref: string;\n\t\t\t/** @public */\n\t\t\tassets: Record<string, string>;\n\t\t\t/** @internal */\n\t\t\tdraft?: boolean;\n\t\t\t/** @internal */\n\t\t\tprerelease?: boolean;\n\t\t},\n\t) {\n\t\tconst commit = this.git.head(repo.repository.ssh_url, input.ref);\n\t\tthis.git.run(repo.repository.ssh_url, [\"check-ref-format\", `refs/tags/${input.tag}`]);\n\t\tthis.git.run(repo.repository.ssh_url, [\"tag\", \"--\", input.tag, commit]);\n\t\tconst id = this.id();\n\t\tconst release: GitHubRelease = {\n\t\t\tid,\n\t\t\ttag_name: input.tag,\n\t\t\ttarget_commitish: commit,\n\t\t\tdraft: input.draft ?? false,\n\t\t\tprerelease: input.prerelease ?? false,\n\t\t\thtml_url: `${this.options.baseUrl}/__local`,\n\t\t\tassets: Object.entries(input.assets).map(([name, contents]) => {\n\t\t\t\tconst url = `${this.options.baseUrl}/__local/assets/${this.id()}`;\n\t\t\t\trepo.assets[url] = contents;\n\t\t\t\treturn { name, url, browser_download_url: url };\n\t\t\t}),\n\t\t};\n\t\trepo.releases.unshift(release);\n\t\tthis.save();\n\t\treturn release;\n\t}\n\t/** @public */\n\toverride newRepository(seed: LocalRepositorySeed) {\n\t\treturn {\n\t\t\t...super.newRepository(seed),\n\t\t\t/** @public */\n\t\t\tarchived: false,\n\t\t\t/** @public */\n\t\t\thas_issues: true,\n\t\t};\n\t}\n\t/** @public */\n\tsetMembership(login: string, member: boolean) {\n\t\tthis.state.members = this.state.members.filter(\n\t\t\t(value) => value.toLowerCase() !== login.toLowerCase(),\n\t\t);\n\t\tif (member) this.state.members.push(login);\n\t\tthis.save();\n\t}\n\t/** @public */\n\tfailNextResponse(operation: \"comment\" | \"reply\" | \"reaction\" | \"issue\" | \"label\") {\n\t\tthis.state.failAfterWrite = operation;\n\t\tthis.save();\n\t}\n\tprivate lostResponse(operation: string) {\n\t\tif (this.state.failAfterWrite !== operation) return;\n\t\tthis.state.failAfterWrite = null;\n\t\tthis.save();\n\t\tthrow new Error(`Local GitHub: response lost after ${operation} write`);\n\t}\n\t/** @public */\n\tcreateIssue(\n\t\trepo: LocalGitHubRepository,\n\t\tinput: {\n\t\t\t/** @public */\n\t\t\ttitle: string;\n\t\t\t/** @public */\n\t\t\tbody?: string;\n\t\t\t/** @public */\n\t\t\tauthor?: string;\n\t\t},\n\t) {\n\t\tconst number = this.id();\n\t\tconst issue: GitHubIssue = {\n\t\t\tnumber,\n\t\t\ttitle: input.title,\n\t\t\tbody: input.body ?? \"\",\n\t\t\tstate: \"open\",\n\t\t\thtml_url: `${this.options.baseUrl}/__local#issue-${number}`,\n\t\t\tupdated_at: this.timestamp(),\n\t\t\tuser: { login: input.author ?? \"developer\" },\n\t\t\tlabels: [],\n\t\t};\n\t\trepo.issues.push(issue);\n\t\tthis.save();\n\t\treturn issue;\n\t}\n\t/** @public */\n\tsetIssueLabel(\n\t\trepo: LocalGitHubRepository,\n\t\tnumber: number,\n\t\tname: string,\n\t\tactor: string,\n\t\tpresent = true,\n\t) {\n\t\tconst issue = repo.issues.find((value) => value.number === number);\n\t\tif (!issue) throw new Error(\"Unknown local GitHub issue\");\n\t\tissue.labels = issue.labels.filter((label) => label.name !== name);\n\t\tif (present) issue.labels.push({ id: this.id(), name });\n\t\tconst event: GitHubLabelEvent = {\n\t\t\tid: this.id(),\n\t\t\tevent: present ? \"labeled\" : \"unlabeled\",\n\t\t\tlabel: { name },\n\t\t\tactor: { login: actor },\n\t\t};\n\t\trepo.labelEvents[number] ??= [];\n\t\trepo.labelEvents[number].push(event);\n\t\tissue.updated_at = this.timestamp();\n\t\tthis.save();\n\t\treturn event;\n\t}\n\t/** @public */\n\teditFeedback(\n\t\trepo: LocalGitHubRepository,\n\t\tnumber: number,\n\t\tkind: GitHubFeedbackItem[\"kind\"],\n\t\tid: number,\n\t\tbody: string,\n\t\teditor: string | null,\n\t) {\n\t\tconst item = repo.feedback[number]?.find((value) => value.kind === kind && value.id === id);\n\t\tif (!item) throw new Error(\"Unknown local GitHub feedback\");\n\t\titem.body = body;\n\t\titem.createdAt = this.timestamp();\n\t\trepo.feedbackEditors[`${kind}:${id}`] = editor;\n\t\tthis.save();\n\t}\n\n\t/** @public */\n\tclient(): GitHubClientLike {\n\t\tconst profile: GitHubProfile = {\n\t\t\tapiBaseUrl: this.options.baseUrl,\n\t\t\ttoken: \"\",\n\t\t\tbotLogin: \"leitwerk-bot\",\n\t\t\t...(this.options.allowedOrganization\n\t\t\t\t? { allowedOrganization: this.options.allowedOrganization }\n\t\t\t\t: {}),\n\t\t};\n\t\tconst repo = (owner: string, name: string) => {\n\t\t\tassertGitHubRepository(profile, owner, name);\n\t\t\treturn this.repo(owner, name);\n\t\t};\n\t\tconst client: GitHubClientLike = {\n\t\t\tprofile,\n\t\t\tlistRepositories: async () =>\n\t\t\t\tthis.state.repositories\n\t\t\t\t\t.map((r) => ({ ...r.repository, archived: false, has_issues: true }))\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t(r) =>\n\t\t\t\t\t\t\t!profile.allowedOrganization ||\n\t\t\t\t\t\t\tr.owner.login.toLowerCase() === profile.allowedOrganization.toLowerCase(),\n\t\t\t\t\t),\n\t\t\tlistOpenIssues: async (owner, name) =>\n\t\t\t\tstructuredClone(repo(owner, name).issues.filter((i) => i.state === \"open\")),\n\t\t\tlistIssueEvents: async (owner, name, number) =>\n\t\t\t\tstructuredClone(repo(owner, name).labelEvents[number] ?? []),\n\t\t\tisOrganizationMember: async (login) =>\n\t\t\t\t!profile.allowedOrganization ||\n\t\t\t\tthis.state.members.some((member) => member.toLowerCase() === login.toLowerCase()),\n\t\t\tauthorizedTrigger: async (owner, name, number, trigger, done) =>\n\t\t\t\tauthorizedTrigger(client, owner, name, number, trigger, done),\n\t\t\tresolveGitIdentity: async (name) => ({\n\t\t\t\tprovider: \"github\",\n\t\t\t\tprofile: name,\n\t\t\t\tlogin: profile.botLogin,\n\t\t\t\tname: \"Sandbox Developer\",\n\t\t\t\temail: \"developer@sandbox.invalid\",\n\t\t\t}),\n\t\t\tlistLabels: async (owner, name) => structuredClone(repo(owner, name).labels),\n\t\t\tcreateLabel: async (owner, name, labelName) => {\n\t\t\t\tconst r = repo(owner, name);\n\t\t\t\tlet label = r.labels.find((value) => value.name === labelName);\n\t\t\t\tif (!label) {\n\t\t\t\t\tlabel = { id: this.id(), name: labelName };\n\t\t\t\t\tr.labels.push(label);\n\t\t\t\t\tthis.save();\n\t\t\t\t\tthis.lostResponse(\"label\");\n\t\t\t\t}\n\t\t\t\treturn structuredClone(label);\n\t\t\t},\n\t\t\tensureLabel: async (owner, name, labelName) => {\n\t\t\t\tconst label = repo(owner, name).labels.find((value) => value.name === labelName);\n\t\t\t\treturn label ? structuredClone(label) : client.createLabel(owner, name, labelName);\n\t\t\t},\n\t\t\tupdateIssue: async (owner, name, number, patch) => {\n\t\t\t\tconst issue = repo(owner, name).issues.find((i) => i.number === number);\n\t\t\t\tif (!issue) throw new Error(\"Unknown local GitHub issue\");\n\t\t\t\tfor (const key of [\"title\", \"body\", \"state\"] as const)\n\t\t\t\t\tif (typeof patch[key] === \"string\") issue[key] = patch[key];\n\t\t\t\tif (Array.isArray(patch.labels))\n\t\t\t\t\tissue.labels = patch.labels.map((value) => ({ id: this.id(), name: String(value) }));\n\t\t\t\tissue.updated_at = this.timestamp();\n\t\t\t\tthis.save();\n\t\t\t\tthis.lostResponse(\"issue\");\n\t\t\t\treturn structuredClone(issue);\n\t\t\t},\n\t\t\tlistFeedbackReactions: async (owner, name, kind, id) =>\n\t\t\t\tstructuredClone(repo(owner, name).reactions[`${kind}:${id}`] ?? []),\n\t\t\taddFeedbackReaction: async (owner, name, kind, id) => {\n\t\t\t\tif (![\"conversation\", \"inline\"].includes(kind))\n\t\t\t\t\tthrow new Error(\"Reviews do not support reactions\");\n\t\t\t\tconst r = repo(owner, name);\n\t\t\t\tr.reactions[`${kind}:${id}`] ??= [];\n\t\t\t\tconst reactions = r.reactions[`${kind}:${id}`];\n\t\t\t\tlet reaction = reactions.find(\n\t\t\t\t\t(r) => r.content === \"eyes\" && r.user.login === profile.botLogin,\n\t\t\t\t);\n\t\t\t\tif (!reaction) {\n\t\t\t\t\treaction = { id: this.id(), content: \"eyes\", user: { login: profile.botLogin } };\n\t\t\t\t\treactions.push(reaction);\n\t\t\t\t\tthis.save();\n\t\t\t\t\tthis.lostResponse(\"reaction\");\n\t\t\t\t}\n\t\t\t\treturn structuredClone(reaction);\n\t\t\t},\n\t\t\tlistFeedbackReplies: async (owner, name, number, kind) =>\n\t\t\t\tkind === \"inline\"\n\t\t\t\t\t? structuredClone(\n\t\t\t\t\t\t\t(repo(owner, name).feedback[number] ?? [])\n\t\t\t\t\t\t\t\t.filter((f) => f.kind === \"inline\")\n\t\t\t\t\t\t\t\t.map((f) => ({ ...f })),\n\t\t\t\t\t\t)\n\t\t\t\t\t: client.listIssueComments(owner, name, number),\n\t\t\treplyFeedback: async (owner, name, number, kind, id, body) => {\n\t\t\t\tif (kind !== \"inline\") return client.addIssueComment(owner, name, number, body);\n\t\t\t\tconst value = this.addFeedback(repo(owner, name), number, {\n\t\t\t\t\tkind: \"inline\",\n\t\t\t\t\tbody,\n\t\t\t\t\tauthor: profile.botLogin,\n\t\t\t\t});\n\t\t\t\tObject.assign(value, { in_reply_to_id: id });\n\t\t\t\tthis.save();\n\t\t\t\tthis.lostResponse(\"reply\");\n\t\t\t\treturn structuredClone(value);\n\t\t\t},\n\t\t\tlistActionablePullRequestFeedback: async (owner, name, number, signal) =>\n\t\t\t\tactionableFeedback(\n\t\t\t\t\tclient,\n\t\t\t\t\tawait client.listPullRequestFeedback(owner, name, number, signal),\n\t\t\t\t),\n\t\t\tgetIssue: async (owner, name, number) => {\n\t\t\t\tconst issue = repo(owner, name).issues.find((i) => i.number === number);\n\t\t\t\tif (!issue) throw new Error(\"Unknown local GitHub issue\");\n\t\t\t\treturn structuredClone(issue);\n\t\t\t},\n\t\t\tgetCommit: async (owner, name, ref) => ({\n\t\t\t\tsha: this.git.head(repo(owner, name).repository.ssh_url, ref),\n\t\t\t}),\n\t\t\tisAncestor: async (owner, name, ancestor, descendant) =>\n\t\t\t\tthis.git.isAncestor(repo(owner, name).repository.ssh_url, ancestor, descendant),\n\t\t\tlistIssueComments: async (owner, name, number) =>\n\t\t\t\tstructuredClone(repo(owner, name).comments[number] ?? []),\n\t\t\taddIssueComment: async (owner, name, number, body) => {\n\t\t\t\tconst r = repo(owner, name);\n\t\t\t\tif (!r.pulls.some((p) => p.number === number) && !r.issues.some((i) => i.number === number))\n\t\t\t\t\tthrow new Error(\"Unknown local GitHub issue or PR\");\n\t\t\t\tconst value = this.newComment(body);\n\t\t\t\tr.comments[number] ??= [];\n\t\t\t\tr.comments[number].push(value);\n\t\t\t\tthis.save();\n\t\t\t\tthis.lostResponse(\"comment\");\n\t\t\t\treturn structuredClone(value);\n\t\t\t},\n\t\t\tcreatePullRequest: async (owner, name, input) => {\n\t\t\t\tconst r = repo(owner, name);\n\t\t\t\tconst pr = this.newPullRequest(r, input);\n\t\t\t\tr.pulls.push(pr);\n\t\t\t\tconst fail = this.state.failAfterPullRequestWrite;\n\t\t\t\tthis.state.failAfterPullRequestWrite = false;\n\t\t\t\tthis.save();\n\t\t\t\tif (fail) throw new Error(\"Local GitHub: response lost after PR creation\");\n\t\t\t\treturn this.refresh(r, pr);\n\t\t\t},\n\t\t\t...this.pullRequestClient(repo, \"Unknown local GitHub pull request\"),\n\t\t\tlistPullRequestFeedback: async (owner, name, number) =>\n\t\t\t\tstructuredClone([\n\t\t\t\t\t...(repo(owner, name).feedback[number] ?? []).filter((item) => {\n\t\t\t\t\t\tif (!profile.allowedOrganization) return true;\n\t\t\t\t\t\tconst editor = repo(owner, name).feedbackEditors[`${item.kind}:${item.id}`];\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\teditor === undefined ||\n\t\t\t\t\t\t\t(editor !== null &&\n\t\t\t\t\t\t\t\tthis.state.members.some((m) => m.toLowerCase() === editor.toLowerCase()))\n\t\t\t\t\t\t);\n\t\t\t\t\t}),\n\t\t\t\t\t...(repo(owner, name).comments[number] ?? []).map((c) => ({\n\t\t\t\t\t\tkind: \"conversation\" as const,\n\t\t\t\t\t\tid: c.id,\n\t\t\t\t\t\tbody: c.body,\n\t\t\t\t\t\tauthor: c.user.login,\n\t\t\t\t\t\tcreatedAt: c.created_at,\n\t\t\t\t\t})),\n\t\t\t\t]),\n\t\t\tgetCheckSummary: async (owner, name, sha) =>\n\t\t\t\tstructuredClone(\n\t\t\t\t\trepo(owner, name).checks[sha] ?? {\n\t\t\t\t\t\theadSha: sha,\n\t\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\t\ttotal: 0,\n\t\t\t\t\t\tfailed: [],\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\tlistReleases: async (owner, name) => structuredClone(repo(owner, name).releases),\n\t\t\tdownloadReleaseAsset: async (asset) => {\n\t\t\t\tfor (const r of this.state.repositories)\n\t\t\t\t\tif (r.assets[asset.url] !== undefined) return r.assets[asset.url];\n\t\t\t\tthrow new Error(\"Unknown local GitHub release asset\");\n\t\t\t},\n\t\t};\n\t\treturn client;\n\t}\n}\n"],"mappings":";;;;;;;AAAA,SAAS,uBAAiD;AA2FnD,IAAM,qBAAN,cAAiC,gBAAsD;AAAA;AAAA,EAE7F,YAAY,SAA6B;AACxC,UAAM,SAAS,eAAe;AAAA,MAC7B,SAAS;AAAA,MACT,UAAU;AAAA,MACV,cAAc,CAAC;AAAA,MACf,2BAA2B;AAAA,MAC3B,SAAS,CAAC;AAAA,MACV,gBAAgB;AAAA,IACjB,CAAC;AACD,SAAK,MAAM,YAAY,CAAC;AACxB,SAAK,MAAM,mBAAmB;AAC9B,eAAW,KAAK,KAAK,MAAM,cAAc;AACxC,QAAE,WAAW,CAAC;AACd,QAAE,gBAAgB,CAAC;AACnB,QAAE,cAAc,CAAC;AACjB,QAAE,oBAAoB,CAAC;AAAA,IACxB;AACA,eAAW,QAAQ,QAAQ,SAAS,CAAC,EAAG,MAAK,KAAK,IAAI;AAAA,EACvD;AAAA;AAAA,EAEA,KAAK,OAAe,MAAc;AACjC,UAAM,OAAO,KAAK,MAAM,aAAa,KAAK,CAAC,MAAM,EAAE,WAAW,cAAc,GAAG,KAAK,IAAI,IAAI,EAAE;AAC9F,QAAI,CAAC,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,IAAI,EAAE,QAAQ;AAAA,MAC/E,sBAAsB,OAAO,UAAU;AACtC,mBAAW,KAAK,KAAK,MAAM;AAC1B,cAAI,EAAE,OAAO,MAAM,GAAG,MAAM,OAAW,QAAO,EAAE,OAAO,MAAM,GAAG;AACjE,cAAM,IAAI,MAAM,oCAAoC;AAAA,MACrD;AAAA,IACD;AACA,WAAO;AAAA,EACR;AACD;","names":["r"]}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type ServerExtensionAPI } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import type { GitHubIntegration } from "./capability.js";
|
|
3
|
+
export declare function registerGitHubTools(api: ServerExtensionAPI, integration: GitHubIntegration): void;
|
|
4
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,KAAK,kBAAkB,EAEvB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAKzD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,kBAAkB,EAAE,WAAW,EAAE,iBAAiB,QA8Q1F"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,56 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
"name": "@leitwerk-dev/github",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"leitwerk": {
|
|
6
|
+
"extension": {
|
|
7
|
+
"source": "./src/index.ts",
|
|
8
|
+
"import": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"discover": false
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"source": "./src/index.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./testing": {
|
|
19
|
+
"source": "./src/testing.ts",
|
|
20
|
+
"import": "./dist/testing.js",
|
|
21
|
+
"types": "./dist/testing.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup && tsc -p tsconfig.tsup.json --emitDeclarationOnly"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@leitwerk-dev/domain": "0.2.1",
|
|
29
|
+
"@leitwerk-dev/process-sdk": "0.2.1",
|
|
30
|
+
"@leitwerk-dev/watcher-utils": "0.2.1",
|
|
31
|
+
"@leitwerk-dev/repository-rebase": "0.2.1",
|
|
32
|
+
"@leitwerk-dev/test-support": "0.2.1"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsup": "^8.5.1",
|
|
36
|
+
"@types/node": "^26.2.0"
|
|
37
|
+
},
|
|
38
|
+
"license": "Apache-2.0",
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=26 <27"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist/**",
|
|
47
|
+
"src/**",
|
|
48
|
+
"!dist/**/*.test.*",
|
|
49
|
+
"!src/**/*.test.ts"
|
|
50
|
+
],
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/leitwerk-dev/leitwerk.git",
|
|
54
|
+
"directory": "extensions/github"
|
|
55
|
+
}
|
|
16
56
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { GitHubClient, GitHubFeedbackItem, GitHubIssue } from "./client.js";
|
|
2
|
+
|
|
3
|
+
type MembershipClient = Pick<GitHubClient, "profile" | "isOrganizationMember">;
|
|
4
|
+
|
|
5
|
+
export async function authorizedTrigger(
|
|
6
|
+
client: MembershipClient & Pick<GitHubClient, "getIssue" | "listIssueEvents">,
|
|
7
|
+
owner: string,
|
|
8
|
+
repo: string,
|
|
9
|
+
number: number,
|
|
10
|
+
trigger: string,
|
|
11
|
+
done: string,
|
|
12
|
+
) {
|
|
13
|
+
if (
|
|
14
|
+
client.profile.allowedOrganization &&
|
|
15
|
+
owner.toLowerCase() !== client.profile.allowedOrganization.toLowerCase()
|
|
16
|
+
)
|
|
17
|
+
return null;
|
|
18
|
+
const issue = (await client.getIssue(owner, repo, number)) as GitHubIssue & {
|
|
19
|
+
/** @internal */
|
|
20
|
+
pull_request?: unknown;
|
|
21
|
+
};
|
|
22
|
+
if (
|
|
23
|
+
issue.pull_request ||
|
|
24
|
+
issue.state !== "open" ||
|
|
25
|
+
!issue.labels.some((label) => label.name === trigger) ||
|
|
26
|
+
issue.labels.some((label) => label.name === done)
|
|
27
|
+
)
|
|
28
|
+
return null;
|
|
29
|
+
const last = (await client.listIssueEvents(owner, repo, number))
|
|
30
|
+
.filter(
|
|
31
|
+
(event) =>
|
|
32
|
+
(event.event === "labeled" || event.event === "unlabeled") && event.label?.name === trigger,
|
|
33
|
+
)
|
|
34
|
+
.sort((a, b) => b.id - a.id)[0];
|
|
35
|
+
if (
|
|
36
|
+
last?.event !== "labeled" ||
|
|
37
|
+
!last.actor?.login ||
|
|
38
|
+
!(await client.isOrganizationMember(last.actor.login))
|
|
39
|
+
)
|
|
40
|
+
return null;
|
|
41
|
+
return {
|
|
42
|
+
/** @internal */
|
|
43
|
+
issue,
|
|
44
|
+
/** @internal */
|
|
45
|
+
actor: last.actor.login,
|
|
46
|
+
/** @internal */
|
|
47
|
+
eventId: last.id,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function actionableFeedback(client: MembershipClient, feedback: GitHubFeedbackItem[]) {
|
|
52
|
+
const authorized: GitHubFeedbackItem[] = [];
|
|
53
|
+
for (const item of feedback) {
|
|
54
|
+
if (
|
|
55
|
+
item.author.toLowerCase() === client.profile.botLogin.toLowerCase() ||
|
|
56
|
+
item.body.includes("<!-- leitwerk-write:")
|
|
57
|
+
)
|
|
58
|
+
continue;
|
|
59
|
+
if (await client.isOrganizationMember(item.author)) authorized.push(item);
|
|
60
|
+
}
|
|
61
|
+
return authorized;
|
|
62
|
+
}
|
package/src/binding.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { resolveRepositoryProjectBinding } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
|
|
3
|
+
export type { RepositoryProjectBinding as GitHubProjectBinding } from "@leitwerk-dev/process-sdk";
|
|
4
|
+
/** @public */
|
|
5
|
+
export const resolveGitHubProjectBinding = (
|
|
6
|
+
ctx: Parameters<typeof resolveRepositoryProjectBinding>[0],
|
|
7
|
+
) => resolveRepositoryProjectBinding(ctx, "github");
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createCapabilityToken } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import type { GitHubClient } from "./client.js";
|
|
3
|
+
|
|
4
|
+
/** Public contract shared by HTTP and local adapters. @public */
|
|
5
|
+
export type GitHubClientLike = Pick<GitHubClient, keyof GitHubClient>;
|
|
6
|
+
|
|
7
|
+
/** @public */
|
|
8
|
+
export interface GitHubIntegration {
|
|
9
|
+
/** @public */
|
|
10
|
+
client(profile: string): GitHubClientLike;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** @public */
|
|
14
|
+
export const githubIntegration = createCapabilityToken<GitHubIntegration>(
|
|
15
|
+
"@leitwerk-private/github.integration",
|
|
16
|
+
);
|