@theholocron/github-client 1.58.0-alpha.3 → 1.58.0-alpha.31
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 +6 -1
- package/dist/index.d.mts +403 -1
- package/dist/index.mjs +154 -6
- package/package.json +18 -18
package/README.md
CHANGED
|
@@ -32,6 +32,11 @@ await client.topics.setTopics("owner/name", ["cli", "nodejs"]);
|
|
|
32
32
|
// Git plumbing (blobs, trees, commits, refs, PRs)
|
|
33
33
|
const ref = await client.git.getRef("owner/name", "main");
|
|
34
34
|
const blob = await client.git.createBlob("owner/name", "file contents");
|
|
35
|
+
|
|
36
|
+
// List a directory; a 404 is an empty list. `recursive` descends into nested directories
|
|
37
|
+
// (one request each) and returns a flat list of full paths.
|
|
38
|
+
const entries = await client.git.listDirectory("owner/name", ".holocron", { recursive: true });
|
|
39
|
+
// [{ name, path, type: "file" | "dir" | "symlink" | "submodule", size, sha }]
|
|
35
40
|
```
|
|
36
41
|
|
|
37
42
|
## Namespaces
|
|
@@ -50,7 +55,7 @@ const blob = await client.git.createBlob("owner/name", "file contents");
|
|
|
50
55
|
| `labels` | `listLabels`, `createLabel`, `updateLabel`, `deleteLabel` |
|
|
51
56
|
| `topics` | `setTopics` |
|
|
52
57
|
| `properties` | `setProperties` |
|
|
53
|
-
| `git` | `getRef`, `getCommit`, `getTree`, `getContents`, `putContents`, `createBlob`, `createTree`, `createCommit`, `createRef`, `updateRef`, `createPull`
|
|
58
|
+
| `git` | `getRef`, `getCommit`, `getTree`, `getContents`, `listDirectory`, `putContents`, `createBlob`, `createTree`, `createCommit`, `createRef`, `updateRef`, `createPull` |
|
|
54
59
|
| `checks` | `createCheckRun` |
|
|
55
60
|
|
|
56
61
|
GitHub accepts at most 50 annotations per check-run request. Slice with the
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
import "@theholocron/http-client";
|
|
2
2
|
import { ErrorSink, Logger } from "@theholocron/observability/core";
|
|
3
|
+
/**
|
|
4
|
+
* GitHub's GraphQL API has exactly one endpoint (`POST /graphql`, always) —
|
|
5
|
+
* unlike REST's per-resource paths, there's nothing here for `createRestClient()`
|
|
6
|
+
* to route on. Reused anyway for the transport it already gets right (auth
|
|
7
|
+
* header, JSON body/parsing, network-failure wrapping into `ProviderApiError`
|
|
8
|
+
* with `status: 0`) — only the response-shape difference needs handling on
|
|
9
|
+
* top: GraphQL always answers `200 OK`, even for a query error, with the
|
|
10
|
+
* error(s) in the response body's own `errors` array rather than the HTTP
|
|
11
|
+
* status. `createRestClient()`'s own `!res.ok` branch never fires for a
|
|
12
|
+
* GraphQL error — this wrapper's the one place that translates a 200 with a
|
|
13
|
+
* populated `errors` array into a thrown `ProviderApiError`, matching the
|
|
14
|
+
* REST client's own error-throwing contract so callers don't need to know
|
|
15
|
+
* which transport they're talking to.
|
|
16
|
+
*/
|
|
17
|
+
interface GraphQLClient {
|
|
18
|
+
/**
|
|
19
|
+
* Sends one query or mutation to `POST /graphql` and returns its `data`. Throws a `ProviderApiError` (status `200`, with the
|
|
20
|
+
* response's `errors` array) when GitHub answers with errors, and the transport's own `ProviderApiError` for a network or HTTP failure.
|
|
21
|
+
*/
|
|
22
|
+
query<T>(document: string, variables?: Record<string, unknown>): Promise<T>;
|
|
23
|
+
}
|
|
24
|
+
/** Options for creating a GitHub client. */
|
|
3
25
|
interface GitHubClientOptions {
|
|
26
|
+
/** The token sent as the bearer credential. */
|
|
4
27
|
token: string;
|
|
28
|
+
/** The GitHub API base URL; defaults to `https://api.github.com`. */
|
|
5
29
|
baseUrl?: string;
|
|
30
|
+
/** The `fetch` implementation to use; defaults to the global `fetch`. */
|
|
6
31
|
fetch?: typeof fetch;
|
|
7
32
|
/** Structured logger for request/response diagnostics. Defaults to a no-op. */
|
|
8
33
|
logger?: Logger;
|
|
@@ -16,8 +41,11 @@ interface GitHubBranch {
|
|
|
16
41
|
sha: string;
|
|
17
42
|
};
|
|
18
43
|
}
|
|
44
|
+
/** The lifecycle state of a check run. */
|
|
19
45
|
type CheckRunStatus = "queued" | "in_progress" | "completed";
|
|
46
|
+
/** The final result of a completed check run. */
|
|
20
47
|
type CheckRunConclusion = "success" | "failure" | "neutral" | "cancelled" | "timed_out" | "action_required" | "skipped";
|
|
48
|
+
/** The severity of a check run annotation. */
|
|
21
49
|
type CheckRunAnnotationLevel = "notice" | "warning" | "failure";
|
|
22
50
|
/**
|
|
23
51
|
* GitHub's cap on `output.annotations` per `createCheckRun()` /
|
|
@@ -26,15 +54,19 @@ type CheckRunAnnotationLevel = "notice" | "warning" | "failure";
|
|
|
26
54
|
* do for you; slice with it rather than hardcoding the number.
|
|
27
55
|
*/
|
|
28
56
|
export declare const MAX_CHECK_RUN_ANNOTATIONS = 50;
|
|
57
|
+
/** One inline annotation attached to a check run's output, anchored to a file and line range. */
|
|
29
58
|
interface CheckRunAnnotation {
|
|
30
59
|
/** File path relative to the repo root. */
|
|
31
60
|
path: string;
|
|
32
61
|
/** 1-indexed. */
|
|
33
62
|
start_line: number;
|
|
63
|
+
/** 1-indexed last line of the annotated range. */
|
|
34
64
|
end_line: number;
|
|
35
65
|
/** Only valid when `start_line === end_line`. */
|
|
36
66
|
start_column?: number;
|
|
67
|
+
/** Column of the end of the range; only valid when `start_line === end_line`. */
|
|
37
68
|
end_column?: number;
|
|
69
|
+
/** Severity of the annotation. */
|
|
38
70
|
annotation_level: CheckRunAnnotationLevel;
|
|
39
71
|
/** Max 64KB. */
|
|
40
72
|
message: string;
|
|
@@ -43,9 +75,13 @@ interface CheckRunAnnotation {
|
|
|
43
75
|
/** Max 64KB. */
|
|
44
76
|
raw_details?: string;
|
|
45
77
|
}
|
|
78
|
+
/** The title, summary and optional annotations shown on a check run. */
|
|
46
79
|
interface CheckRunOutput {
|
|
80
|
+
/** The output's title. */
|
|
47
81
|
title: string;
|
|
82
|
+
/** The output's summary, rendered as Markdown. */
|
|
48
83
|
summary: string;
|
|
84
|
+
/** Longer details text, rendered as Markdown. */
|
|
49
85
|
text?: string;
|
|
50
86
|
/**
|
|
51
87
|
* Inline PR annotations — up to {@link MAX_CHECK_RUN_ANNOTATIONS} per
|
|
@@ -54,7 +90,9 @@ interface CheckRunOutput {
|
|
|
54
90
|
*/
|
|
55
91
|
annotations?: CheckRunAnnotation[];
|
|
56
92
|
}
|
|
93
|
+
/** The body of a `createCheckRun()` request. */
|
|
57
94
|
interface CreateCheckRunInput {
|
|
95
|
+
/** The check run's name, as shown in the checks list. */
|
|
58
96
|
name: string;
|
|
59
97
|
/** The commit SHA the check run attaches to. */
|
|
60
98
|
head_sha: string;
|
|
@@ -62,30 +100,48 @@ interface CreateCheckRunInput {
|
|
|
62
100
|
status?: CheckRunStatus;
|
|
63
101
|
/** Required when `status` is `"completed"`. */
|
|
64
102
|
conclusion?: CheckRunConclusion;
|
|
103
|
+
/** The title, summary and annotations to show on the check run. */
|
|
65
104
|
output?: CheckRunOutput;
|
|
66
105
|
/** URL for the "Details" link on the check run. GitHub defaults to the check suite's own summary page when omitted. */
|
|
67
106
|
details_url?: string;
|
|
68
107
|
}
|
|
108
|
+
/** A check run as GitHub returns it, with only the fields this client reads. */
|
|
69
109
|
interface GitHubCheckRun {
|
|
110
|
+
/** The check run's numeric id. */
|
|
70
111
|
id: number;
|
|
112
|
+
/** The check run's name. */
|
|
71
113
|
name: string;
|
|
114
|
+
/** The commit SHA the check run is attached to. */
|
|
72
115
|
head_sha: string;
|
|
116
|
+
/** The check run's current lifecycle state. */
|
|
73
117
|
status: CheckRunStatus;
|
|
118
|
+
/** The check run's result, or `null` until it is completed. */
|
|
74
119
|
conclusion: CheckRunConclusion | null;
|
|
120
|
+
/** The URL of the check run's page on GitHub. */
|
|
75
121
|
html_url: string;
|
|
122
|
+
/** The check's own "Details" link, when it set one. */
|
|
123
|
+
details_url?: string | null;
|
|
76
124
|
}
|
|
125
|
+
/** The body of an `updateCheckRun()` request; every field is optional. */
|
|
77
126
|
interface UpdateCheckRunInput {
|
|
127
|
+
/** The lifecycle state to move the check run to. */
|
|
78
128
|
status?: CheckRunStatus;
|
|
79
129
|
/** Required when `status` is `"completed"`. */
|
|
80
130
|
conclusion?: CheckRunConclusion;
|
|
131
|
+
/** The title, summary and annotations to set on the check run. */
|
|
81
132
|
output?: CheckRunOutput;
|
|
82
133
|
/** URL for the "Details" link on the check run. */
|
|
83
134
|
details_url?: string;
|
|
84
135
|
}
|
|
136
|
+
/** A deployment environment of a repository and its protection settings. */
|
|
85
137
|
interface GitHubEnvironment {
|
|
138
|
+
/** The environment's name. */
|
|
86
139
|
name: string;
|
|
140
|
+
/** Minutes to wait before a job that targets the environment may proceed. */
|
|
87
141
|
wait_timer?: number;
|
|
142
|
+
/** Whether the user who triggered a deployment may also approve it. */
|
|
88
143
|
prevent_self_review?: boolean;
|
|
144
|
+
/** The protection rules on the environment; each has a `type` and, for required reviewers, the reviewers. */
|
|
89
145
|
protection_rules?: Array<{
|
|
90
146
|
type: string;
|
|
91
147
|
reviewers?: Array<{
|
|
@@ -96,52 +152,107 @@ interface GitHubEnvironment {
|
|
|
96
152
|
}>;
|
|
97
153
|
}>;
|
|
98
154
|
}
|
|
155
|
+
/** A git reference (such as a branch) and the object it points at. */
|
|
99
156
|
interface GitRef {
|
|
157
|
+
/** The object the reference points at. */
|
|
100
158
|
object: {
|
|
159
|
+
/** The object's SHA. */
|
|
101
160
|
sha: string;
|
|
161
|
+
/** The object's type, e.g. `commit`. */
|
|
102
162
|
type: string;
|
|
163
|
+
/** The API URL of the object. */
|
|
103
164
|
url: string;
|
|
104
165
|
};
|
|
166
|
+
/** The full reference name, e.g. `refs/heads/main`. */
|
|
105
167
|
ref: string;
|
|
168
|
+
/** The API URL of the reference. */
|
|
106
169
|
url: string;
|
|
107
170
|
}
|
|
171
|
+
/** A git commit, with only the fields this client reads. */
|
|
108
172
|
interface GitCommit {
|
|
173
|
+
/** The commit's SHA. */
|
|
109
174
|
sha: string;
|
|
175
|
+
/** The tree the commit points at. */
|
|
110
176
|
tree: {
|
|
177
|
+
/** The tree's SHA. */
|
|
111
178
|
sha: string;
|
|
179
|
+
/** The API URL of the tree. */
|
|
112
180
|
url: string;
|
|
113
181
|
};
|
|
114
182
|
}
|
|
183
|
+
/** One entry of a git tree. */
|
|
115
184
|
interface GitTreeItem {
|
|
185
|
+
/** The entry's path within the tree. */
|
|
116
186
|
path: string;
|
|
187
|
+
/** The entry's object SHA. */
|
|
117
188
|
sha: string;
|
|
189
|
+
/** The kind of object the entry points at, e.g. `blob` or `tree`. */
|
|
118
190
|
type: string;
|
|
191
|
+
/** The entry's file mode, e.g. `100644`. */
|
|
119
192
|
mode?: string;
|
|
193
|
+
/** The blob's size in bytes; absent for trees. */
|
|
120
194
|
size?: number;
|
|
121
195
|
}
|
|
196
|
+
/** A git tree as GitHub returns it. */
|
|
122
197
|
interface GitTree {
|
|
198
|
+
/** The tree's SHA. */
|
|
123
199
|
sha: string;
|
|
200
|
+
/** The entries of the tree. */
|
|
124
201
|
tree: GitTreeItem[];
|
|
202
|
+
/** Whether GitHub cut the entry list short because the tree was too large. */
|
|
125
203
|
truncated: boolean;
|
|
126
204
|
}
|
|
205
|
+
/** A file's contents as the contents API returns them. */
|
|
127
206
|
interface GitContents {
|
|
207
|
+
/** The file content, encoded as named by `encoding`. */
|
|
128
208
|
content: string;
|
|
209
|
+
/** The encoding of `content`, normally `base64`. */
|
|
129
210
|
encoding: string;
|
|
211
|
+
/** The file's blob SHA. */
|
|
130
212
|
sha: string;
|
|
213
|
+
/** The file's name. */
|
|
131
214
|
name: string;
|
|
215
|
+
/** The file's path in the repository. */
|
|
132
216
|
path: string;
|
|
133
217
|
}
|
|
218
|
+
/** One entry of a directory listing from the contents API. */
|
|
219
|
+
interface GitDirectoryEntry {
|
|
220
|
+
/** The entry's name, without its directory. */
|
|
221
|
+
name: string;
|
|
222
|
+
/** The entry's path from the repository root, e.g. `.holocron/notifications.ts`. */
|
|
223
|
+
path: string;
|
|
224
|
+
/** What the entry is; `dir` entries are listed, and descended into only when `recursive` is set. */
|
|
225
|
+
type: "file" | "dir" | "symlink" | "submodule";
|
|
226
|
+
/** The size in bytes; GitHub reports `0` for directories and submodules. */
|
|
227
|
+
size: number;
|
|
228
|
+
/** The entry's object SHA. */
|
|
229
|
+
sha: string;
|
|
230
|
+
}
|
|
231
|
+
/** Options for `listDirectory()`. */
|
|
232
|
+
interface ListDirectoryOptions {
|
|
233
|
+
/** A branch, tag or commit SHA; defaults to the repo's default branch. */
|
|
234
|
+
ref?: string;
|
|
235
|
+
/** Also list the contents of every nested directory, as one flat list of full paths. Defaults to `false`. */
|
|
236
|
+
recursive?: boolean;
|
|
237
|
+
}
|
|
134
238
|
/** What `git.putContents` returns: the file's new blob sha (the `sha` to pass next time) and the commit it made. */
|
|
135
239
|
interface PutContentsResult {
|
|
240
|
+
/** The file written: its path and its new blob SHA. */
|
|
136
241
|
content: {
|
|
242
|
+
/** The file's new blob SHA. */
|
|
137
243
|
sha: string;
|
|
244
|
+
/** The file's path. */
|
|
138
245
|
path: string;
|
|
139
246
|
};
|
|
247
|
+
/** The commit that was made. */
|
|
140
248
|
commit: {
|
|
249
|
+
/** The new commit's SHA. */
|
|
141
250
|
sha: string;
|
|
142
251
|
};
|
|
143
252
|
}
|
|
253
|
+
/** The body of a `putContents()` request. */
|
|
144
254
|
interface PutContentsInput {
|
|
255
|
+
/** The commit message. */
|
|
145
256
|
message: string;
|
|
146
257
|
/** The new file text (UTF-8); the client encodes it. */
|
|
147
258
|
content: string;
|
|
@@ -154,93 +265,183 @@ interface PutContentsInput {
|
|
|
154
265
|
/** Defaults to the repo's default branch. */
|
|
155
266
|
branch?: string;
|
|
156
267
|
}
|
|
268
|
+
/** A git blob created in the repository. */
|
|
157
269
|
interface GitBlob {
|
|
270
|
+
/** The blob's SHA. */
|
|
158
271
|
sha: string;
|
|
272
|
+
/** The API URL of the blob. */
|
|
159
273
|
url: string;
|
|
160
274
|
}
|
|
275
|
+
/** A pull request as returned when one is created, with only the fields this client reads. */
|
|
161
276
|
interface GitPull {
|
|
277
|
+
/** The pull request's number. */
|
|
162
278
|
number: number;
|
|
279
|
+
/** The URL of the pull request's page on GitHub. */
|
|
163
280
|
html_url: string;
|
|
281
|
+
/** The pull request's title. */
|
|
164
282
|
title: string;
|
|
165
283
|
}
|
|
284
|
+
/** The body of a `createPull()` request. */
|
|
166
285
|
interface CreatePullInput {
|
|
286
|
+
/** The pull request's title. */
|
|
167
287
|
title: string;
|
|
288
|
+
/** The branch the changes come from. */
|
|
168
289
|
head: string;
|
|
290
|
+
/** The branch the changes are to be merged into. */
|
|
169
291
|
base: string;
|
|
292
|
+
/** The pull request's description. */
|
|
170
293
|
body?: string;
|
|
171
294
|
}
|
|
295
|
+
/** An issue as GitHub returns it, with only the fields this client reads. */
|
|
172
296
|
interface GitHubIssue {
|
|
297
|
+
/** The issue's numeric id. */
|
|
173
298
|
id: number;
|
|
299
|
+
/** The issue's number within its repository. */
|
|
174
300
|
number: number;
|
|
301
|
+
/** The issue's title. */
|
|
175
302
|
title: string;
|
|
303
|
+
/** The issue's description; `null` or absent when empty. */
|
|
176
304
|
body?: string | null;
|
|
305
|
+
/** Whether the issue is open or closed. */
|
|
177
306
|
state: "open" | "closed";
|
|
307
|
+
/** The labels on the issue. */
|
|
178
308
|
labels: Array<{
|
|
179
309
|
name: string;
|
|
180
310
|
}>;
|
|
311
|
+
/** The user the issue is assigned to, or `null` when unassigned. */
|
|
181
312
|
assignee: {
|
|
182
313
|
login: string;
|
|
183
314
|
name?: string | null;
|
|
184
315
|
email?: string | null;
|
|
185
316
|
} | null;
|
|
317
|
+
/** When the issue was last updated, as an ISO 8601 timestamp. */
|
|
186
318
|
updated_at: string;
|
|
319
|
+
/** The URL of the issue's page on GitHub. */
|
|
187
320
|
html_url: string;
|
|
321
|
+
/** When the issue was created, as an ISO 8601 timestamp. */
|
|
322
|
+
created_at?: string;
|
|
323
|
+
/** The milestone the issue belongs to, or `null` when none. */
|
|
324
|
+
milestone?: {
|
|
325
|
+
number: number;
|
|
326
|
+
title: string;
|
|
327
|
+
} | null;
|
|
328
|
+
/** The issue's GraphQL node id. */
|
|
329
|
+
node_id?: string;
|
|
330
|
+
/** Set when the item is a pull request; GitHub's issues API returns pull requests too. */
|
|
188
331
|
pull_request?: unknown;
|
|
189
332
|
}
|
|
333
|
+
/** A milestone, with only the fields this client reads. */
|
|
190
334
|
interface GitHubMilestone {
|
|
335
|
+
/** The milestone's number. */
|
|
191
336
|
number: number;
|
|
337
|
+
/** The milestone's title. */
|
|
192
338
|
title: string;
|
|
193
339
|
}
|
|
340
|
+
/** A comment on an issue, with only the fields this client reads. */
|
|
341
|
+
interface GitHubIssueComment {
|
|
342
|
+
/** The comment's text. */
|
|
343
|
+
body: string;
|
|
344
|
+
/** When it was written, as an ISO 8601 timestamp. */
|
|
345
|
+
created_at: string;
|
|
346
|
+
/** Who wrote it. */
|
|
347
|
+
user: {
|
|
348
|
+
login: string;
|
|
349
|
+
} | null;
|
|
350
|
+
}
|
|
351
|
+
/** Filters for listing issues. */
|
|
194
352
|
interface IssueSearchParams {
|
|
353
|
+
/** The page to read, from 1. */
|
|
354
|
+
page?: number;
|
|
355
|
+
/** A milestone number, `*` for any or `none`. */
|
|
356
|
+
milestone?: string;
|
|
357
|
+
/** Which issues to list by state; GitHub defaults to `open`. */
|
|
195
358
|
state?: "open" | "closed" | "all";
|
|
359
|
+
/** The field to sort by, passed through to GitHub. */
|
|
196
360
|
sort?: string;
|
|
361
|
+
/** The sort direction, passed through to GitHub. */
|
|
197
362
|
direction?: string;
|
|
363
|
+
/** The number of issues per page. */
|
|
198
364
|
per_page?: number;
|
|
365
|
+
/** Which issues to list by relation to the user, passed through to GitHub. */
|
|
199
366
|
filter?: string;
|
|
367
|
+
/** Limit to issues assigned to this login. */
|
|
200
368
|
assignee?: string;
|
|
201
369
|
}
|
|
370
|
+
/** A repository label. */
|
|
202
371
|
interface GitHubLabel {
|
|
372
|
+
/** The label's name. */
|
|
203
373
|
name: string;
|
|
374
|
+
/** The label's color as a hex code without the leading `#`. */
|
|
204
375
|
color: string;
|
|
376
|
+
/** The label's description, or `null` when it has none. */
|
|
205
377
|
description: string | null;
|
|
206
378
|
}
|
|
379
|
+
/** How a Pages site is built: by a workflow or from a branch. */
|
|
207
380
|
type PagesBuildType = "workflow" | "legacy";
|
|
381
|
+
/** The status of a Pages build. */
|
|
208
382
|
type PagesBuildStatus = "built" | "building" | "errored" | "unknown";
|
|
383
|
+
/** A repository's GitHub Pages site configuration. */
|
|
209
384
|
interface GitHubPages {
|
|
385
|
+
/** The latest build's status, or `null` when there is none. */
|
|
210
386
|
status: PagesBuildStatus | null;
|
|
387
|
+
/** How the site is built, or `null` when unknown. */
|
|
211
388
|
build_type: PagesBuildType | null;
|
|
389
|
+
/** The branch and folder the site is published from, for a legacy build. */
|
|
212
390
|
source?: {
|
|
391
|
+
/** The branch the site is published from. */
|
|
213
392
|
branch: string;
|
|
393
|
+
/** The folder on the branch, `/` or `/docs`. */
|
|
214
394
|
path: string;
|
|
215
395
|
};
|
|
396
|
+
/** Whether HTTPS is enforced for the site. */
|
|
216
397
|
https_enforced: boolean;
|
|
398
|
+
/** The site's custom domain, or `null` when it has none. */
|
|
217
399
|
custom_domain: string | null;
|
|
218
400
|
}
|
|
401
|
+
/** The body of a Pages creation request. */
|
|
219
402
|
interface CreatePagesPayload {
|
|
403
|
+
/** How the site is built. */
|
|
220
404
|
build_type: PagesBuildType;
|
|
221
405
|
/** Required when build_type is "legacy". */
|
|
222
406
|
source?: {
|
|
407
|
+
/** The branch the site is published from. */
|
|
223
408
|
branch: string;
|
|
409
|
+
/** The folder on the branch, `/` or `/docs`. */
|
|
224
410
|
path: string;
|
|
225
411
|
};
|
|
226
412
|
}
|
|
413
|
+
/** The body of a Pages update request; every field is optional. */
|
|
227
414
|
interface UpdatePagesPayload {
|
|
415
|
+
/** How the site is built. */
|
|
228
416
|
build_type?: PagesBuildType;
|
|
417
|
+
/** The branch and folder to publish from. */
|
|
229
418
|
source?: {
|
|
419
|
+
/** The branch the site is published from. */
|
|
230
420
|
branch: string;
|
|
421
|
+
/** The folder on the branch, `/` or `/docs`. */
|
|
231
422
|
path: string;
|
|
232
423
|
};
|
|
424
|
+
/** The custom domain, or `null` to remove it. */
|
|
233
425
|
cname?: string | null;
|
|
426
|
+
/** Whether to enforce HTTPS. */
|
|
234
427
|
https_enforced?: boolean;
|
|
235
428
|
}
|
|
236
429
|
/** One custom property of an organization, as its schema defines it. */
|
|
237
430
|
interface OrgProperty {
|
|
431
|
+
/** The property's name. */
|
|
238
432
|
property_name: string;
|
|
239
433
|
/** `string`, `single_select`, `multi_select`, `true_false` or `url`. */
|
|
240
434
|
value_type: string;
|
|
435
|
+
/** Whether a repository must set the property. */
|
|
241
436
|
required?: boolean;
|
|
242
437
|
/** The values a `single_select` or `multi_select` property accepts; `null` for any other type. */
|
|
243
438
|
allowed_values?: string[] | null;
|
|
439
|
+
/** The value a repository gets when it sets none, or `null`. */
|
|
440
|
+
default_value?: string | string[] | null;
|
|
441
|
+
/** A line saying what the property is for, or `null`. */
|
|
442
|
+
description?: string | null;
|
|
443
|
+
/** Who may edit the property's value on a repository: `org_actors` or `org_and_repo_actors`, or `null`. */
|
|
444
|
+
values_editable_by?: string | null;
|
|
244
445
|
}
|
|
245
446
|
/** One custom property value set on a repository. */
|
|
246
447
|
interface RepoPropertyValue {
|
|
@@ -249,11 +450,19 @@ interface RepoPropertyValue {
|
|
|
249
450
|
/** A string, a string array for `multi_select`, or `null` when unset. */
|
|
250
451
|
value: string | string[] | null;
|
|
251
452
|
}
|
|
453
|
+
/** A pull request as GitHub returns it, with only the fields this client reads. */
|
|
252
454
|
interface GitHubPullRequest {
|
|
455
|
+
/** The pull request's number. */
|
|
253
456
|
number: number;
|
|
457
|
+
/** The pull request's title. */
|
|
254
458
|
title: string;
|
|
459
|
+
/** The pull request's description, as written (markdown); `null` when it has none. */
|
|
460
|
+
body?: string | null;
|
|
461
|
+
/** Whether the pull request is open or closed. */
|
|
255
462
|
state: "open" | "closed";
|
|
463
|
+
/** When the pull request was merged as an ISO 8601 timestamp, or `null` if it was not merged. */
|
|
256
464
|
merged_at: string | null;
|
|
465
|
+
/** The URL of the pull request's page on GitHub. */
|
|
257
466
|
html_url: string;
|
|
258
467
|
/** The head branch: its name and the commit it pointed at when the PR was read. */
|
|
259
468
|
head: {
|
|
@@ -262,6 +471,40 @@ interface GitHubPullRequest {
|
|
|
262
471
|
/** The head commit. */
|
|
263
472
|
sha: string;
|
|
264
473
|
};
|
|
474
|
+
/** Whether the pull request is a draft. */
|
|
475
|
+
draft?: boolean;
|
|
476
|
+
/** When the pull request was opened, as an ISO 8601 timestamp. */
|
|
477
|
+
created_at?: string;
|
|
478
|
+
/** The author. */
|
|
479
|
+
user?: {
|
|
480
|
+
/** The author's login. */
|
|
481
|
+
login: string;
|
|
482
|
+
/** The account type: `User` or `Bot` (Dependabot is a `Bot`). */
|
|
483
|
+
type: string;
|
|
484
|
+
};
|
|
485
|
+
/** Who merged it; `null` for a pull request that is not merged. */
|
|
486
|
+
merged_by?: {
|
|
487
|
+
login: string;
|
|
488
|
+
} | null;
|
|
489
|
+
/** The base branch. */
|
|
490
|
+
base?: {
|
|
491
|
+
/** The base branch's name, e.g. `alpha`. */
|
|
492
|
+
ref: string;
|
|
493
|
+
};
|
|
494
|
+
/** The people whose review is still asked for. */
|
|
495
|
+
requested_reviewers?: {
|
|
496
|
+
login: string;
|
|
497
|
+
}[];
|
|
498
|
+
/** Lines added, as the single-pull-request endpoint returns it (the list endpoint omits it). */
|
|
499
|
+
additions?: number;
|
|
500
|
+
/** Lines removed; see `additions`. */
|
|
501
|
+
deletions?: number;
|
|
502
|
+
/** Files changed; see `additions`. */
|
|
503
|
+
changed_files?: number;
|
|
504
|
+
/** Whether it merges cleanly; `null` while GitHub is still working it out. */
|
|
505
|
+
mergeable?: boolean | null;
|
|
506
|
+
/** `dirty` means it conflicts with its base; see `mergeable`. */
|
|
507
|
+
mergeable_state?: string;
|
|
265
508
|
}
|
|
266
509
|
/** A commit's name/email as git itself recorded it — `commit.author`/`commit.committer`, distinct from the GitHub-account `author` below (a commit can carry any email, linked to a GitHub account or not). */
|
|
267
510
|
interface GitHubCommitIdentity {
|
|
@@ -270,10 +513,15 @@ interface GitHubCommitIdentity {
|
|
|
270
513
|
}
|
|
271
514
|
/** One commit as returned by `GET /pulls/{pull_number}/commits` — only the fields any known consumer needs. */
|
|
272
515
|
interface GitHubPullRequestCommit {
|
|
516
|
+
/** The commit's SHA. */
|
|
273
517
|
sha: string;
|
|
518
|
+
/** The commit's message and git identities. */
|
|
274
519
|
commit: {
|
|
520
|
+
/** The commit message. */
|
|
275
521
|
message: string;
|
|
522
|
+
/** The commit's author, as git recorded it. */
|
|
276
523
|
author: GitHubCommitIdentity;
|
|
524
|
+
/** The commit's committer, as git recorded it. */
|
|
277
525
|
committer: GitHubCommitIdentity;
|
|
278
526
|
};
|
|
279
527
|
/** The commit's linked GitHub account, when GitHub can associate one — `null` for a commit email with no linked account. `type: "Bot"` identifies an app-authored commit (e.g. Dependabot, a prior Sentinel auto-fix-commit). */
|
|
@@ -288,7 +536,9 @@ interface GitHubPullRequestCommit {
|
|
|
288
536
|
}
|
|
289
537
|
/** One file as returned by `GET /pulls/{pull_number}/files` — only the fields any known consumer needs. */
|
|
290
538
|
interface GitHubPullRequestFile {
|
|
539
|
+
/** The file's path in the repository. */
|
|
291
540
|
filename: string;
|
|
541
|
+
/** How the pull request changes the file. */
|
|
292
542
|
status: "added" | "removed" | "modified" | "renamed" | "copied" | "changed" | "unchanged";
|
|
293
543
|
/** Set only when `status === "renamed"`. */
|
|
294
544
|
previous_filename?: string;
|
|
@@ -308,8 +558,10 @@ interface CreateReviewComment {
|
|
|
308
558
|
line: number;
|
|
309
559
|
/** Almost always `"RIGHT"` (the PR's own new content) — `"LEFT"` targets the base/pre-PR version instead. */
|
|
310
560
|
side: "LEFT" | "RIGHT";
|
|
561
|
+
/** The comment text. */
|
|
311
562
|
body: string;
|
|
312
563
|
}
|
|
564
|
+
/** The body of a review creation request. */
|
|
313
565
|
interface CreateReviewInput {
|
|
314
566
|
/** The PR's head SHA the review attaches to. */
|
|
315
567
|
commit_id: string;
|
|
@@ -322,12 +574,23 @@ interface CreateReviewInput {
|
|
|
322
574
|
* required-approval counts and dismissal.
|
|
323
575
|
*/
|
|
324
576
|
event: "COMMENT" | "REQUEST_CHANGES" | "APPROVE";
|
|
577
|
+
/** Inline comments to post with the review. */
|
|
325
578
|
comments?: CreateReviewComment[];
|
|
326
579
|
}
|
|
327
580
|
/** `POST /pulls/{pull_number}/reviews`'s response — only the fields any known consumer needs. */
|
|
328
581
|
interface GitHubPullRequestReview {
|
|
582
|
+
/** The review's numeric id. */
|
|
329
583
|
id: number;
|
|
584
|
+
/** The URL of the review on GitHub. */
|
|
330
585
|
html_url: string;
|
|
586
|
+
/** `APPROVED`, `CHANGES_REQUESTED`, `COMMENTED`, `DISMISSED` or `PENDING`; set on a review read back. */
|
|
587
|
+
state?: string;
|
|
588
|
+
/** The reviewer; set on a review read back. */
|
|
589
|
+
user?: {
|
|
590
|
+
login: string;
|
|
591
|
+
} | null;
|
|
592
|
+
/** The review's summary text (markdown); set on a review read back, and `null` or empty when it has none. */
|
|
593
|
+
body?: string | null;
|
|
331
594
|
}
|
|
332
595
|
/**
|
|
333
596
|
* One review thread — GraphQL-only (`resolveReviewThread`, the mutation
|
|
@@ -337,7 +600,9 @@ interface GitHubPullRequestReview {
|
|
|
337
600
|
* never compare it against a REST-sourced ID.
|
|
338
601
|
*/
|
|
339
602
|
interface ReviewThread {
|
|
603
|
+
/** The thread's GraphQL node id. */
|
|
340
604
|
id: string;
|
|
605
|
+
/** Whether the thread is resolved. */
|
|
341
606
|
isResolved: boolean;
|
|
342
607
|
/** The thread's first comment's author login (e.g. `"the-holocron-sentinel[bot]"`) — `undefined` if GitHub ever returns a thread with no comments, which shouldn't happen in practice. Callers filter on this before resolving anything, so a bot never touches a human reviewer's own thread. */
|
|
343
608
|
authorLogin: string | undefined;
|
|
@@ -355,9 +620,16 @@ interface ReviewThread {
|
|
|
355
620
|
*/
|
|
356
621
|
body: string | undefined;
|
|
357
622
|
}
|
|
623
|
+
/** A repository as GitHub returns it, with only the fields this client reads. */
|
|
358
624
|
interface GitHubRepo {
|
|
625
|
+
/** The repository's numeric id, which organization secrets and variables name their readers by. */
|
|
626
|
+
id: number;
|
|
627
|
+
/** The name of the repository's default branch. */
|
|
359
628
|
default_branch: string;
|
|
629
|
+
/** The repository's `owner/name`. */
|
|
360
630
|
full_name: string;
|
|
631
|
+
/** Whether the repository is archived (read-only). */
|
|
632
|
+
archived?: boolean;
|
|
361
633
|
/** The repository description. */
|
|
362
634
|
description?: string | null;
|
|
363
635
|
/** The repository homepage URL. */
|
|
@@ -389,13 +661,20 @@ interface GitHubRepo {
|
|
|
389
661
|
status: string;
|
|
390
662
|
} | undefined> | null;
|
|
391
663
|
}
|
|
664
|
+
/** A file's contents as the contents API returns them. */
|
|
392
665
|
interface GitHubContents {
|
|
666
|
+
/** The file content, encoded as named by `encoding`. */
|
|
393
667
|
content: string;
|
|
668
|
+
/** The encoding of `content`, normally `base64`. */
|
|
394
669
|
encoding: string;
|
|
395
670
|
}
|
|
671
|
+
/** A repository ruleset in summary form. */
|
|
396
672
|
interface GitHubRuleset {
|
|
673
|
+
/** The ruleset's numeric id. */
|
|
397
674
|
id: number;
|
|
675
|
+
/** The ruleset's name. */
|
|
398
676
|
name: string;
|
|
677
|
+
/** How the ruleset is enforced, e.g. `active`, `evaluate` or `disabled`. */
|
|
399
678
|
enforcement: string;
|
|
400
679
|
}
|
|
401
680
|
/** One ruleset in full, as `GET /repos/{repo}/rulesets/{id}` returns it. */
|
|
@@ -408,6 +687,7 @@ interface GitHubRulesetDetail extends GitHubRuleset {
|
|
|
408
687
|
parameters?: Record<string, unknown>;
|
|
409
688
|
}>;
|
|
410
689
|
}
|
|
690
|
+
/** Where a secret lives: the repository, one of its environments, or an organization. */
|
|
411
691
|
type SecretScope = {
|
|
412
692
|
kind: "repo";
|
|
413
693
|
} | {
|
|
@@ -417,14 +697,30 @@ type SecretScope = {
|
|
|
417
697
|
kind: "organization";
|
|
418
698
|
org: string;
|
|
419
699
|
};
|
|
700
|
+
/** A public key used to encrypt a secret before it is sent. */
|
|
420
701
|
interface GitHubPublicKey {
|
|
702
|
+
/** The key's id, sent back with the encrypted secret. */
|
|
421
703
|
key_id: string;
|
|
704
|
+
/** The Base64-encoded public key. */
|
|
422
705
|
key: string;
|
|
423
706
|
}
|
|
707
|
+
/** Who can read an organization secret: every repository, every private one, or the ones listed. */
|
|
708
|
+
type OrgSecretVisibility = "all" | "private" | "selected";
|
|
709
|
+
/** An organization secret as the list returns it: its name and who can read it (never its value). */
|
|
710
|
+
interface OrgSecretInfo {
|
|
711
|
+
/** The secret's name. */
|
|
712
|
+
name: string;
|
|
713
|
+
/** Who can read it. */
|
|
714
|
+
visibility: OrgSecretVisibility;
|
|
715
|
+
}
|
|
716
|
+
/** The workflow run that a code scanning setup started. */
|
|
424
717
|
interface CodeScanningSetupResult {
|
|
718
|
+
/** The id of the workflow run. */
|
|
425
719
|
run_id: number;
|
|
720
|
+
/** The URL of the workflow run. */
|
|
426
721
|
run_url: string;
|
|
427
722
|
}
|
|
723
|
+
/** A permission level a team can hold on a repository. */
|
|
428
724
|
type TeamPermission = "pull" | "triage" | "push" | "maintain" | "admin";
|
|
429
725
|
/** A team with access to a repository, and the permission it has there. */
|
|
430
726
|
interface RepoTeam {
|
|
@@ -435,10 +731,14 @@ interface RepoTeam {
|
|
|
435
731
|
}
|
|
436
732
|
/** A member of a team, as GitHub lists it. `id` is the numeric user id, which survives a rename; `login` does not. */
|
|
437
733
|
interface TeamMember {
|
|
734
|
+
/** The member's numeric user id. */
|
|
438
735
|
id: number;
|
|
736
|
+
/** The member's login. */
|
|
439
737
|
login: string;
|
|
738
|
+
/** The kind of account, e.g. `User`. */
|
|
440
739
|
type?: string;
|
|
441
740
|
}
|
|
741
|
+
/** Where a variable lives: the repository, one of its environments, or an organization. */
|
|
442
742
|
type VariableScope = {
|
|
443
743
|
kind: "repo";
|
|
444
744
|
} | {
|
|
@@ -455,14 +755,20 @@ type VariableScope = {
|
|
|
455
755
|
type VariableVisibility = "all" | "private" | "selected";
|
|
456
756
|
/** A GitHub Actions variable. Unlike a secret its value is readable, so a reconcile can tell whether it differs. */
|
|
457
757
|
interface GitHubVariable {
|
|
758
|
+
/** The variable's name. */
|
|
458
759
|
name: string;
|
|
760
|
+
/** The variable's value. */
|
|
459
761
|
value: string;
|
|
460
762
|
/** Present on organization variables only. */
|
|
461
763
|
visibility?: VariableVisibility;
|
|
462
764
|
}
|
|
765
|
+
/** The authenticated user, with only the fields this client reads. */
|
|
463
766
|
interface GitHubUser {
|
|
767
|
+
/** The user's login. */
|
|
464
768
|
login: string;
|
|
769
|
+
/** The user's display name, or `null` when not set. */
|
|
465
770
|
name: string | null;
|
|
771
|
+
/** The user's public email, or `null` when not set. */
|
|
466
772
|
email: string | null;
|
|
467
773
|
}
|
|
468
774
|
/** The authenticated user and, for a token that expires, when. */
|
|
@@ -477,30 +783,48 @@ interface GitHubUserWithExpiry {
|
|
|
477
783
|
* ISO 8601, or `undefined` when the header is missing or is not a date.
|
|
478
784
|
*/
|
|
479
785
|
export declare function parseTokenExpiration(header: string | null): string | undefined;
|
|
786
|
+
/** A workflow run as GitHub returns it, with only the fields this client reads. */
|
|
480
787
|
interface GitHubWorkflowRun {
|
|
788
|
+
/** The run's numeric id. */
|
|
481
789
|
id: number;
|
|
790
|
+
/** The workflow's name, or `null` when unnamed. */
|
|
482
791
|
name: string | null;
|
|
792
|
+
/** The run's display title. */
|
|
483
793
|
display_title: string;
|
|
794
|
+
/** The branch the run was triggered on. */
|
|
484
795
|
head_branch: string;
|
|
796
|
+
/** The commit SHA the run was triggered on. */
|
|
485
797
|
head_sha: string;
|
|
798
|
+
/** The run's status, e.g. `queued`, `in_progress` or `completed`. */
|
|
486
799
|
status: string;
|
|
800
|
+
/** The run's result once completed, or `null` before. */
|
|
487
801
|
conclusion: string | null;
|
|
802
|
+
/** The URL of the run's page on GitHub. */
|
|
488
803
|
html_url: string;
|
|
804
|
+
/** When the run was created, as an ISO 8601 timestamp. */
|
|
489
805
|
created_at: string;
|
|
806
|
+
/** When the run was last updated, as an ISO 8601 timestamp. */
|
|
490
807
|
updated_at: string;
|
|
491
808
|
}
|
|
809
|
+
/** Filters for listing workflow runs. */
|
|
492
810
|
interface WorkflowRunFilter {
|
|
811
|
+
/** Only runs on this branch. */
|
|
493
812
|
branch?: string;
|
|
813
|
+
/** The maximum number of runs to return. */
|
|
494
814
|
limit?: number;
|
|
815
|
+
/** Only runs with this status. */
|
|
495
816
|
status?: string;
|
|
496
817
|
}
|
|
818
|
+
/** The credentials identifying a GitHub App: its id and private key. */
|
|
497
819
|
interface GitHubAppCredentials {
|
|
498
820
|
/** The App's numeric id (not the client id). */
|
|
499
821
|
appId: string;
|
|
500
822
|
/** PEM-encoded RSA private key — PKCS#1 (GitHub's default download format) or PKCS#8, either works. */
|
|
501
823
|
privateKey: string;
|
|
502
824
|
}
|
|
825
|
+
/** A short-lived installation access token and when it expires. */
|
|
503
826
|
interface InstallationAccessToken {
|
|
827
|
+
/** The installation access token, used as a bearer token for the REST API. */
|
|
504
828
|
token: string;
|
|
505
829
|
/** ISO 8601 — installation tokens are short-lived, about an hour. */
|
|
506
830
|
expiresAt: string;
|
|
@@ -520,6 +844,41 @@ export declare function createAppJWT(creds: GitHubAppCredentials, now?: number):
|
|
|
520
844
|
export declare function getInstallationAccessToken(creds: GitHubAppCredentials, installationId: number, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<InstallationAccessToken>;
|
|
521
845
|
/** The whole flow in one call — an already-authenticated `GitHubClient` scoped to one installation. */
|
|
522
846
|
export declare function createInstallationClient(creds: GitHubAppCredentials, installationId: number, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubClient>;
|
|
847
|
+
/** The account an App or one of its installations belongs to. */
|
|
848
|
+
interface GitHubAppAccount {
|
|
849
|
+
/** The user or organization login. */
|
|
850
|
+
login: string;
|
|
851
|
+
/** `User` or `Organization` (GitHub also reports `Enterprise` for an enterprise-owned App). */
|
|
852
|
+
type: string;
|
|
853
|
+
}
|
|
854
|
+
/** An App as `GET /app` reports it. */
|
|
855
|
+
interface GitHubApp {
|
|
856
|
+
/** The App's URL name, as in `github.com/apps/<slug>`. */
|
|
857
|
+
slug: string;
|
|
858
|
+
/** The App's display name. */
|
|
859
|
+
name: string;
|
|
860
|
+
/** Who owns the App: decides which settings page its permissions live on. */
|
|
861
|
+
owner: GitHubAppAccount | null;
|
|
862
|
+
/** The permissions the App asks for now: name to `read`, `write` or `admin`. */
|
|
863
|
+
permissions: Record<string, string>;
|
|
864
|
+
/** The webhook events the App is subscribed to now. */
|
|
865
|
+
events: string[];
|
|
866
|
+
}
|
|
867
|
+
/** One installation of an App as `GET /app/installations` reports it. */
|
|
868
|
+
interface GitHubAppInstallation {
|
|
869
|
+
/** The installation id. */
|
|
870
|
+
id: number;
|
|
871
|
+
/** The account the App is installed on. */
|
|
872
|
+
account: GitHubAppAccount | null;
|
|
873
|
+
/** What this installation has accepted: it lags the App's own list until an owner accepts a new request. */
|
|
874
|
+
permissions: Record<string, string>;
|
|
875
|
+
/** The events delivered to this installation. */
|
|
876
|
+
events: string[];
|
|
877
|
+
}
|
|
878
|
+
/** The App this JWT identifies: its slug, owner and the permissions and events it asks for now. */
|
|
879
|
+
export declare function getApp(creds: GitHubAppCredentials, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubApp>;
|
|
880
|
+
/** Every installation of the App this JWT identifies, with what each has accepted. Reads all pages. */
|
|
881
|
+
export declare function listAppInstallations(creds: GitHubAppCredentials, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubAppInstallation[]>;
|
|
523
882
|
/**
|
|
524
883
|
* GitHub's own webhook mechanics — signature verification and header/
|
|
525
884
|
* payload shapes. Pure functions, no REST call, no auth token: these
|
|
@@ -550,6 +909,7 @@ export declare function verifyGitHubWebhookSignature(input: {
|
|
|
550
909
|
signature: string | undefined;
|
|
551
910
|
secret: string;
|
|
552
911
|
}): boolean;
|
|
912
|
+
/** The three GitHub webhook headers a consumer needs. */
|
|
553
913
|
interface GitHubWebhookHeaders {
|
|
554
914
|
/** `X-GitHub-Event` — the event category, e.g. `"push"`, `"pull_request"`. */
|
|
555
915
|
event: string | undefined;
|
|
@@ -560,31 +920,62 @@ interface GitHubWebhookHeaders {
|
|
|
560
920
|
}
|
|
561
921
|
/** Extracts GitHub's three webhook headers, case-insensitively (Node's raw headers may arrive lower-cased, or as an array when a header repeats). */
|
|
562
922
|
export declare function parseGitHubWebhookHeaders(headers: Record<string, string | string[] | undefined>): GitHubWebhookHeaders;
|
|
923
|
+
/** The payload of an `installation` webhook delivery. */
|
|
563
924
|
interface GitHubInstallationWebhookPayload {
|
|
925
|
+
/** What happened to the installation, e.g. `created` or `deleted`. */
|
|
564
926
|
action: string;
|
|
927
|
+
/** The installation the delivery is about. */
|
|
565
928
|
installation: {
|
|
929
|
+
/** The installation id. */
|
|
566
930
|
id: number;
|
|
567
931
|
};
|
|
568
932
|
}
|
|
933
|
+
/** The payload of a `push` webhook delivery. */
|
|
569
934
|
interface GitHubPushWebhookPayload {
|
|
935
|
+
/** The full name of the pushed ref, e.g. `refs/heads/main`. */
|
|
570
936
|
ref: string;
|
|
937
|
+
/** The installation the delivery is about, when sent. */
|
|
571
938
|
installation?: {
|
|
939
|
+
/** The installation id. */
|
|
572
940
|
id: number;
|
|
573
941
|
};
|
|
942
|
+
/** The repository that was pushed to. */
|
|
574
943
|
repository: {
|
|
944
|
+
/** The repository's owner/name. */
|
|
575
945
|
full_name: string;
|
|
946
|
+
/** The name of the default branch. */
|
|
576
947
|
default_branch: string;
|
|
577
948
|
};
|
|
578
949
|
}
|
|
950
|
+
/** The payload of a `pull_request` webhook delivery. */
|
|
579
951
|
interface GitHubPullRequestWebhookPayload {
|
|
952
|
+
/** What happened to the pull request, e.g. `opened` or `closed`. */
|
|
580
953
|
action: string;
|
|
954
|
+
/** For an `edited` action, the fields that changed (each holds the previous value); absent for other actions. */
|
|
955
|
+
changes?: {
|
|
956
|
+
/** Present when the title was edited. */
|
|
957
|
+
title?: {
|
|
958
|
+
/** The title before the edit. */
|
|
959
|
+
from: string;
|
|
960
|
+
};
|
|
961
|
+
/** Present when the description was edited. */
|
|
962
|
+
body?: {
|
|
963
|
+
/** The description before the edit; `null` when it was empty. */
|
|
964
|
+
from: string | null;
|
|
965
|
+
};
|
|
966
|
+
};
|
|
967
|
+
/** The installation the delivery is about, when sent. */
|
|
581
968
|
installation?: {
|
|
969
|
+
/** The installation id. */
|
|
582
970
|
id: number;
|
|
583
971
|
};
|
|
972
|
+
/** The repository the pull request belongs to. */
|
|
584
973
|
repository: {
|
|
974
|
+
/** The repository's owner/name. */
|
|
585
975
|
full_name: string;
|
|
586
976
|
};
|
|
587
977
|
}
|
|
978
|
+
/** Creates a GitHub client with a group of methods per API area (branches, pulls, issues, secrets and so on), backed by one REST client and one GraphQL client built from the same options. */
|
|
588
979
|
export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
589
980
|
branches: {
|
|
590
981
|
protectBranch: (repo: string, branch: string, payload: Record<string, unknown>) => Promise<void>;
|
|
@@ -592,6 +983,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
592
983
|
removeBranch: (repo: string, branch: string) => Promise<void>;
|
|
593
984
|
};
|
|
594
985
|
checks: {
|
|
986
|
+
listCheckRunsForRef: (repo: string, ref: string) => Promise<GitHubCheckRun[]>;
|
|
595
987
|
createCheckRun: (repo: string, input: CreateCheckRunInput) => Promise<GitHubCheckRun>;
|
|
596
988
|
updateCheckRun: (repo: string, checkRunId: number, input: UpdateCheckRunInput) => Promise<GitHubCheckRun>;
|
|
597
989
|
};
|
|
@@ -605,6 +997,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
605
997
|
getCommit: (repo: string, sha: string) => Promise<GitCommit>;
|
|
606
998
|
getTree: (repo: string, sha: string, recursive?: boolean) => Promise<GitTree>;
|
|
607
999
|
getContents: (repo: string, path: string, ref?: string) => Promise<GitContents>;
|
|
1000
|
+
listDirectory: (repo: string, path: string, options?: ListDirectoryOptions) => Promise<GitDirectoryEntry[]>;
|
|
608
1001
|
putContents: (repo: string, path: string, input: PutContentsInput) => Promise<PutContentsResult>;
|
|
609
1002
|
createBlob: (repo: string, content: string, encoding?: string) => Promise<GitBlob>;
|
|
610
1003
|
createTree: (repo: string, tree: Array<{
|
|
@@ -618,6 +1011,8 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
618
1011
|
updateRef: (repo: string, ref: string, sha: string, force?: boolean) => Promise<GitRef>;
|
|
619
1012
|
createPull: (repo: string, input: CreatePullInput) => Promise<GitPull>;
|
|
620
1013
|
};
|
|
1014
|
+
/** The GraphQL client, for the callers whose API (Projects v2) has no REST form. */
|
|
1015
|
+
graphql: GraphQLClient;
|
|
621
1016
|
issues: {
|
|
622
1017
|
listIssues: (repo: string, params?: IssueSearchParams) => Promise<GitHubIssue[]>;
|
|
623
1018
|
getIssue: (repo: string, number: number) => Promise<GitHubIssue>;
|
|
@@ -626,6 +1021,8 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
626
1021
|
addLabels: (repo: string, number: number, labels: string[]) => Promise<void>;
|
|
627
1022
|
removeLabel: (repo: string, number: number, label: string) => Promise<void>;
|
|
628
1023
|
createComment: (repo: string, number: number, body: string) => Promise<void>;
|
|
1024
|
+
listComments: (repo: string, number: number) => Promise<GitHubIssueComment[]>;
|
|
1025
|
+
createMilestone: (repo: string, title: string) => Promise<GitHubMilestone>;
|
|
629
1026
|
listMilestones: (repo: string, params?: {
|
|
630
1027
|
state?: "open" | "closed" | "all";
|
|
631
1028
|
}) => Promise<GitHubMilestone[]>;
|
|
@@ -651,6 +1048,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
651
1048
|
properties: {
|
|
652
1049
|
getValues: (repo: string) => Promise<RepoPropertyValue[]>;
|
|
653
1050
|
orgSchema: (org: string) => Promise<OrgProperty[]>;
|
|
1051
|
+
setOrgProperty: (org: string, property: OrgProperty) => Promise<OrgProperty>;
|
|
654
1052
|
setProperties: (repo: string, values: Record<string, string | string[]>) => Promise<void>;
|
|
655
1053
|
};
|
|
656
1054
|
pulls: {
|
|
@@ -658,6 +1056,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
658
1056
|
listPullRequests: (repo: string, state: "open" | "closed") => Promise<GitHubPullRequest[]>;
|
|
659
1057
|
listCommits: (repo: string, number: number) => Promise<GitHubPullRequestCommit[]>;
|
|
660
1058
|
listFiles: (repo: string, number: number) => Promise<GitHubPullRequestFile[]>;
|
|
1059
|
+
listReviews: (repo: string, number: number) => Promise<GitHubPullRequestReview[]>;
|
|
661
1060
|
createReview: (repo: string, number: number, input: CreateReviewInput) => Promise<GitHubPullRequestReview>;
|
|
662
1061
|
listReviewThreads: (repo: string, number: number) => Promise<ReviewThread[]>;
|
|
663
1062
|
resolveReviewThread: (threadId: string) => Promise<void>;
|
|
@@ -675,6 +1074,8 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
675
1074
|
};
|
|
676
1075
|
secrets: {
|
|
677
1076
|
listSecrets: (repo: string, scope: SecretScope) => Promise<string[]>;
|
|
1077
|
+
listOrgSecretInfo: (org: string) => Promise<OrgSecretInfo[]>;
|
|
1078
|
+
listSelectedRepositories: (org: string, name: string) => Promise<string[]>;
|
|
678
1079
|
getPublicKey: (repo: string, scope: SecretScope) => Promise<GitHubPublicKey>;
|
|
679
1080
|
putSecret: (repo: string, scope: SecretScope, name: string, body: Record<string, unknown>) => Promise<void>;
|
|
680
1081
|
deleteSecret: (repo: string, scope: SecretScope, name: string) => Promise<void>;
|
|
@@ -717,5 +1118,6 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
717
1118
|
createWorkflowDispatch: (repo: string, workflowFile: string, ref: string, inputs?: Record<string, string>) => Promise<void>;
|
|
718
1119
|
};
|
|
719
1120
|
};
|
|
1121
|
+
/** The client returned by `createGitHubClient()`: one group of methods per GitHub API area. */
|
|
720
1122
|
export type GitHubClient = ReturnType<typeof createGitHubClient>;
|
|
721
|
-
export type { CheckRunAnnotation, CheckRunAnnotationLevel, CheckRunConclusion, CheckRunOutput, CheckRunStatus, CodeScanningSetupResult, CreateCheckRunInput, CreatePagesPayload, CreatePullInput, CreateReviewComment, CreateReviewInput, GitBlob, GitCommit, GitContents, GitHubAppCredentials, GitHubCheckRun, GitHubClientOptions, GitHubContents, GitHubEnvironment, GitHubInstallationWebhookPayload, GitHubIssue, GitHubLabel, GitHubMilestone, GitHubPages, GitHubPublicKey, GitHubPullRequest, GitHubPullRequestCommit, GitHubPullRequestFile, GitHubPullRequestReview, GitHubPullRequestWebhookPayload, GitHubPushWebhookPayload, GitHubRepo, GitHubRuleset, GitHubRulesetDetail, GitHubUser, GitHubUserWithExpiry, GitHubVariable, GitHubWebhookHeaders, GitHubWorkflowRun, GitPull, GitRef, GitTree, GitTreeItem, InstallationAccessToken, IssueSearchParams, OrgProperty, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, RepoPropertyValue, RepoTeam, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdatePagesPayload, VariableScope, VariableVisibility, WorkflowRunFilter };
|
|
1123
|
+
export type { CheckRunAnnotation, CheckRunAnnotationLevel, CheckRunConclusion, CheckRunOutput, CheckRunStatus, CodeScanningSetupResult, CreateCheckRunInput, CreatePagesPayload, CreatePullInput, CreateReviewComment, CreateReviewInput, GitBlob, GitCommit, GitContents, GitDirectoryEntry, GitHubApp, GitHubAppAccount, GitHubAppCredentials, GitHubAppInstallation, GitHubCheckRun, GitHubClientOptions, GitHubContents, GitHubEnvironment, GitHubInstallationWebhookPayload, GitHubIssue, GitHubIssueComment, GitHubLabel, GitHubMilestone, GitHubPages, GitHubPublicKey, GitHubPullRequest, GitHubPullRequestCommit, GitHubPullRequestFile, GitHubPullRequestReview, GitHubPullRequestWebhookPayload, GitHubPushWebhookPayload, GitHubRepo, GitHubRuleset, GitHubRulesetDetail, GitHubUser, GitHubUserWithExpiry, GitHubVariable, GitHubWebhookHeaders, GitHubWorkflowRun, GitPull, GitRef, GitTree, GitTreeItem, GraphQLClient, InstallationAccessToken, IssueSearchParams, ListDirectoryOptions, OrgProperty, OrgSecretInfo, OrgSecretVisibility, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, RepoPropertyValue, RepoTeam, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdatePagesPayload, VariableScope, VariableVisibility, WorkflowRunFilter };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ProviderApiError, createRestClient } from "@theholocron/http-client";
|
|
2
2
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
3
3
|
// src/graphql/graphql.ts
|
|
4
|
+
/** A {@link GraphQLClient} for GitHub's GraphQL API, built on the shared REST transport. */
|
|
4
5
|
function createGitHubGraphQLClient(config) {
|
|
5
6
|
const rest = createRestClient({
|
|
6
7
|
baseUrl: config.baseUrl ?? "https://api.github.com",
|
|
@@ -107,8 +108,21 @@ function branches(rest) {
|
|
|
107
108
|
* do for you; slice with it rather than hardcoding the number.
|
|
108
109
|
*/
|
|
109
110
|
const MAX_CHECK_RUN_ANNOTATIONS = 50;
|
|
111
|
+
/** Page size and the most pages {@link checks}`.listCheckRunsForRef` reads: 100 a page over 10 pages, so 1,000 check runs. */
|
|
112
|
+
const CHECK_RUN_PAGE_SIZE = 100;
|
|
113
|
+
const CHECK_RUN_MAX_PAGES = 10;
|
|
110
114
|
function checks(rest) {
|
|
111
115
|
return {
|
|
116
|
+
/** Every check run on a commit, read a page at a time until a page comes back short. */
|
|
117
|
+
listCheckRunsForRef: async (repo, ref) => {
|
|
118
|
+
const all = [];
|
|
119
|
+
for (let page = 1; page <= CHECK_RUN_MAX_PAGES; page++) {
|
|
120
|
+
const batch = await rest.request(`${repoBase(repo)}/commits/${ref}/check-runs?per_page=${CHECK_RUN_PAGE_SIZE}&page=${page}`);
|
|
121
|
+
all.push(...batch.check_runs);
|
|
122
|
+
if (batch.check_runs.length < CHECK_RUN_PAGE_SIZE) break;
|
|
123
|
+
}
|
|
124
|
+
return all;
|
|
125
|
+
},
|
|
112
126
|
createCheckRun: (repo, input) => rest.request(`${repoBase(repo)}/check-runs`, {
|
|
113
127
|
method: "POST",
|
|
114
128
|
body: input
|
|
@@ -150,6 +164,36 @@ function git(rest) {
|
|
|
150
164
|
*/
|
|
151
165
|
getContents: (repo, path, ref) => rest.request(`${repoBase(repo)}/contents/${path}`, ref ? { query: { ref } } : void 0),
|
|
152
166
|
/**
|
|
167
|
+
* Lists the directory at `path` through the contents API (`GET /repos/:repo/contents/:path`, which
|
|
168
|
+
* answers an array for a directory). A 404 (no such directory) is an empty list, not an error; any
|
|
169
|
+
* other failure is the usual `ProviderApiError`. One request lists one level: with
|
|
170
|
+
* `recursive: true` it makes one more request per nested directory and returns a flat list of
|
|
171
|
+
* full paths (directories included). A `path` that is a file, not a directory, throws.
|
|
172
|
+
*/
|
|
173
|
+
listDirectory: async (repo, path, options = {}) => {
|
|
174
|
+
const list = async (at) => {
|
|
175
|
+
let body;
|
|
176
|
+
try {
|
|
177
|
+
body = await rest.request(`${repoBase(repo)}/contents/${filePath(at)}`, options.ref ? { query: { ref: options.ref } } : void 0);
|
|
178
|
+
} catch (err) {
|
|
179
|
+
if (err instanceof ProviderApiError && err.status === 404) return [];
|
|
180
|
+
throw err;
|
|
181
|
+
}
|
|
182
|
+
if (!Array.isArray(body)) throw new Error(`${repo}:${at} is a file, not a directory`);
|
|
183
|
+
const entries = body.map(({ name, path: p, type, size, sha }) => ({
|
|
184
|
+
name,
|
|
185
|
+
path: p,
|
|
186
|
+
type,
|
|
187
|
+
size,
|
|
188
|
+
sha
|
|
189
|
+
}));
|
|
190
|
+
if (!options.recursive) return entries;
|
|
191
|
+
const nested = await Promise.all(entries.filter((e) => e.type === "dir").map((e) => list(e.path)));
|
|
192
|
+
return [...entries, ...nested.flat()];
|
|
193
|
+
};
|
|
194
|
+
return list(path.replace(/^\/+|\/+$/g, ""));
|
|
195
|
+
},
|
|
196
|
+
/**
|
|
153
197
|
* `PUT /repos/:repo/contents/:path` — creates or updates one file in a single commit. Pass `sha` when
|
|
154
198
|
* updating so a concurrent change is refused (409) and not silently overwritten.
|
|
155
199
|
*/
|
|
@@ -215,6 +259,8 @@ function issues(rest) {
|
|
|
215
259
|
if (params.per_page) qs.set("per_page", String(params.per_page));
|
|
216
260
|
if (params.filter) qs.set("filter", params.filter);
|
|
217
261
|
if (params.assignee) qs.set("assignee", params.assignee);
|
|
262
|
+
if (params.page) qs.set("page", String(params.page));
|
|
263
|
+
if (params.milestone) qs.set("milestone", params.milestone);
|
|
218
264
|
const q = qs.toString();
|
|
219
265
|
const path = q ? `${repoBase(repo)}/issues?${q}` : `${repoBase(repo)}/issues`;
|
|
220
266
|
return rest.request(path);
|
|
@@ -237,6 +283,18 @@ function issues(rest) {
|
|
|
237
283
|
method: "POST",
|
|
238
284
|
body: { body }
|
|
239
285
|
}),
|
|
286
|
+
listComments: async (repo, number) => {
|
|
287
|
+
const all = [];
|
|
288
|
+
for (let page = 1;; page++) {
|
|
289
|
+
const batch = await rest.request(`${repoBase(repo)}/issues/${number}/comments?per_page=100&page=${page}`);
|
|
290
|
+
all.push(...batch);
|
|
291
|
+
if (batch.length < 100) return all;
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
createMilestone: (repo, title) => rest.request(`${repoBase(repo)}/milestones`, {
|
|
295
|
+
method: "POST",
|
|
296
|
+
body: { title }
|
|
297
|
+
}),
|
|
240
298
|
listMilestones: (repo, params = {}) => {
|
|
241
299
|
const qs = new URLSearchParams({ per_page: "100" });
|
|
242
300
|
if (params.state) qs.set("state", params.state);
|
|
@@ -301,6 +359,19 @@ function properties(rest) {
|
|
|
301
359
|
*/
|
|
302
360
|
orgSchema: (org) => rest.request(`/orgs/${segment(org)}/properties/schema`),
|
|
303
361
|
/**
|
|
362
|
+
* Creates or replaces one custom property definition of the organization. GitHub replaces the whole definition,
|
|
363
|
+
* so send back every field the property already has (`orgSchema` has them); a field left out is reset.
|
|
364
|
+
* The token needs write access to the organization's custom properties (`Custom properties: admin`).
|
|
365
|
+
*/
|
|
366
|
+
setOrgProperty: (org, property) => {
|
|
367
|
+
const { property_name, ...definition } = property;
|
|
368
|
+
const body = Object.fromEntries(Object.entries(definition).filter(([, v]) => v !== void 0));
|
|
369
|
+
return rest.request(`/orgs/${segment(org)}/properties/schema/${segment(property_name)}`, {
|
|
370
|
+
method: "PUT",
|
|
371
|
+
body
|
|
372
|
+
});
|
|
373
|
+
},
|
|
374
|
+
/**
|
|
304
375
|
* `value` is a plain string for `string`/`single_select`/`true_false`
|
|
305
376
|
* custom properties, or a string array for `multi_select` ones —
|
|
306
377
|
* GitHub's own PATCH body accepts either per property. A single-string
|
|
@@ -353,6 +424,9 @@ const RESOLVE_REVIEW_THREAD_MUTATION = `
|
|
|
353
424
|
/** Page size and the most pages {@link pulls}`.listPullRequests` reads: 100 a page (GitHub's maximum) over 100 pages, so 10,000 pull requests. */
|
|
354
425
|
const PULL_REQUEST_PAGE_SIZE = 100;
|
|
355
426
|
const PULL_REQUEST_MAX_PAGES = 100;
|
|
427
|
+
/** Page size and the most pages {@link pulls}`.listFiles` reads: 100 a page over 30 pages, the 3000 files GitHub serves. */
|
|
428
|
+
const FILE_PAGE_SIZE = 100;
|
|
429
|
+
const FILE_MAX_PAGES = 30;
|
|
356
430
|
function pulls(rest, graphql) {
|
|
357
431
|
return {
|
|
358
432
|
getPullRequest: (repo, number) => rest.request(`${repoBase(repo)}/pulls/${number}`),
|
|
@@ -377,12 +451,20 @@ function pulls(rest, graphql) {
|
|
|
377
451
|
*/
|
|
378
452
|
listCommits: (repo, number) => rest.request(`${repoBase(repo)}/pulls/${number}/commits?per_page=100`),
|
|
379
453
|
/**
|
|
380
|
-
* A PR's own changed files
|
|
381
|
-
*
|
|
382
|
-
* files (GitHub caps this endpoint at 3000 regardless of pagination)
|
|
383
|
-
* is an edge case no consumer here needs to paginate for today.
|
|
454
|
+
* A PR's own changed files, read a page at a time until a page comes back short. GitHub serves at most
|
|
455
|
+
* 3000 files from this endpoint, so a larger PR is cut at that cap.
|
|
384
456
|
*/
|
|
385
|
-
listFiles: (repo, number) =>
|
|
457
|
+
listFiles: async (repo, number) => {
|
|
458
|
+
const all = [];
|
|
459
|
+
for (let page = 1; page <= FILE_MAX_PAGES; page++) {
|
|
460
|
+
const batch = await rest.request(`${repoBase(repo)}/pulls/${number}/files?per_page=${FILE_PAGE_SIZE}&page=${page}`);
|
|
461
|
+
all.push(...batch);
|
|
462
|
+
if (batch.length < FILE_PAGE_SIZE) break;
|
|
463
|
+
}
|
|
464
|
+
return all;
|
|
465
|
+
},
|
|
466
|
+
/** A PR's reviews, oldest first. `per_page=100` covers every real PR in this org. */
|
|
467
|
+
listReviews: (repo, number) => rest.request(`${repoBase(repo)}/pulls/${number}/reviews?per_page=100`),
|
|
386
468
|
/**
|
|
387
469
|
* Submits a review in one call — GitHub has no separate "create draft,
|
|
388
470
|
* then submit" step when `event` is provided directly (the multi-step
|
|
@@ -456,6 +538,13 @@ function scopeBase$1(repo, scope) {
|
|
|
456
538
|
function secrets(rest) {
|
|
457
539
|
return {
|
|
458
540
|
listSecrets: (repo, scope) => rest.request(`${scopeBase$1(repo, scope)}/secrets`).then((r) => r.secrets.map((s) => s.name)),
|
|
541
|
+
/** The organization's secrets with their visibility, names only (first 100). */
|
|
542
|
+
listOrgSecretInfo: (org) => rest.request(`/orgs/${org}/actions/secrets?per_page=100`).then((r) => r.secrets.map((s) => ({
|
|
543
|
+
name: s.name,
|
|
544
|
+
visibility: s.visibility
|
|
545
|
+
}))),
|
|
546
|
+
/** The names of the repositories that can read one organization secret of visibility `selected` (first 100). */
|
|
547
|
+
listSelectedRepositories: (org, name) => rest.request(`/orgs/${org}/actions/secrets/${name}/repositories?per_page=100`).then((r) => r.repositories.map((repo) => repo.name)),
|
|
459
548
|
getPublicKey: (repo, scope) => rest.request(`${scopeBase$1(repo, scope)}/secrets/public-key`),
|
|
460
549
|
putSecret: (repo, scope, name, body) => rest.request(`${scopeBase$1(repo, scope)}/secrets/${name}`, {
|
|
461
550
|
method: "PUT",
|
|
@@ -845,6 +934,62 @@ async function createInstallationClient(creds, installationId, opts = {}) {
|
|
|
845
934
|
fetch: opts.fetch
|
|
846
935
|
});
|
|
847
936
|
}
|
|
937
|
+
// src/app-info/app-info.ts
|
|
938
|
+
/**
|
|
939
|
+
* What a GitHub App is right now, read with the App's own JWT (`GET /app`, `GET /app/installations`). GitHub has no
|
|
940
|
+
* endpoint that changes an existing App's permissions or event subscriptions, so these reads are how a caller
|
|
941
|
+
* checks the settings page was done by hand.
|
|
942
|
+
*
|
|
943
|
+
* https://docs.github.com/en/rest/apps/apps#get-the-authenticated-app
|
|
944
|
+
* https://docs.github.com/en/rest/apps/apps#list-installations-for-the-authenticated-app
|
|
945
|
+
*/
|
|
946
|
+
const PAGE_SIZE = 100;
|
|
947
|
+
const account = (value) => {
|
|
948
|
+
const { login, type } = value ?? {};
|
|
949
|
+
return typeof login === "string" ? {
|
|
950
|
+
login,
|
|
951
|
+
type: typeof type === "string" ? type : ""
|
|
952
|
+
} : null;
|
|
953
|
+
};
|
|
954
|
+
async function appGet(creds, path, opts) {
|
|
955
|
+
const jwt = await createAppJWT(creds);
|
|
956
|
+
const baseUrl = opts.baseUrl ?? "https://api.github.com";
|
|
957
|
+
const res = await (opts.fetch ?? globalThis.fetch)(`${baseUrl}${path}`, { headers: {
|
|
958
|
+
authorization: `Bearer ${jwt}`,
|
|
959
|
+
accept: "application/vnd.github+json",
|
|
960
|
+
"x-github-api-version": "2022-11-28"
|
|
961
|
+
} });
|
|
962
|
+
if (!res.ok) {
|
|
963
|
+
const body = await res.text().catch(() => "");
|
|
964
|
+
throw new ProviderApiError(`GitHub GET ${path} → ${res.status}`, res.status, body);
|
|
965
|
+
}
|
|
966
|
+
return res.json();
|
|
967
|
+
}
|
|
968
|
+
/** The App this JWT identifies: its slug, owner and the permissions and events it asks for now. */
|
|
969
|
+
async function getApp(creds, opts = {}) {
|
|
970
|
+
const raw = await appGet(creds, "/app", opts);
|
|
971
|
+
return {
|
|
972
|
+
slug: String(raw.slug),
|
|
973
|
+
name: String(raw.name),
|
|
974
|
+
owner: account(raw.owner),
|
|
975
|
+
permissions: raw.permissions ?? {},
|
|
976
|
+
events: raw.events ?? []
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
/** Every installation of the App this JWT identifies, with what each has accepted. Reads all pages. */
|
|
980
|
+
async function listAppInstallations(creds, opts = {}) {
|
|
981
|
+
const installations = [];
|
|
982
|
+
for (let page = 1;; page++) {
|
|
983
|
+
const raws = await appGet(creds, `/app/installations?per_page=${PAGE_SIZE}&page=${page}`, opts);
|
|
984
|
+
for (const raw of raws) installations.push({
|
|
985
|
+
id: Number(raw.id),
|
|
986
|
+
account: account(raw.account),
|
|
987
|
+
permissions: raw.permissions ?? {},
|
|
988
|
+
events: raw.events ?? []
|
|
989
|
+
});
|
|
990
|
+
if (raws.length < PAGE_SIZE) return installations;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
848
993
|
// src/webhooks/webhooks.ts
|
|
849
994
|
/**
|
|
850
995
|
* GitHub's own webhook mechanics — signature verification and header/
|
|
@@ -891,6 +1036,7 @@ function parseGitHubWebhookHeaders(headers) {
|
|
|
891
1036
|
};
|
|
892
1037
|
}
|
|
893
1038
|
// src/index.ts
|
|
1039
|
+
/** Creates a GitHub client with a group of methods per API area (branches, pulls, issues, secrets and so on), backed by one REST client and one GraphQL client built from the same options. */
|
|
894
1040
|
function createGitHubClient(opts) {
|
|
895
1041
|
const rest = createGitHubRestClient(opts);
|
|
896
1042
|
const graphql = createGitHubGraphQLApiClient(opts);
|
|
@@ -899,6 +1045,8 @@ function createGitHubClient(opts) {
|
|
|
899
1045
|
checks: checks(rest),
|
|
900
1046
|
environments: environments(rest),
|
|
901
1047
|
git: git(rest),
|
|
1048
|
+
/** The GraphQL client, for the callers whose API (Projects v2) has no REST form. */
|
|
1049
|
+
graphql,
|
|
902
1050
|
issues: issues(rest),
|
|
903
1051
|
labels: labels(rest),
|
|
904
1052
|
pages: pages(rest),
|
|
@@ -915,4 +1063,4 @@ function createGitHubClient(opts) {
|
|
|
915
1063
|
workflows: workflows(rest)
|
|
916
1064
|
};
|
|
917
1065
|
}
|
|
918
|
-
export { MAX_CHECK_RUN_ANNOTATIONS, createAppJWT, createGitHubClient, createInstallationClient, getInstallationAccessToken, parseGitHubWebhookHeaders, parseTokenExpiration, verifyGitHubWebhookSignature };
|
|
1066
|
+
export { MAX_CHECK_RUN_ANNOTATIONS, createAppJWT, createGitHubClient, createInstallationClient, getApp, getInstallationAccessToken, listAppInstallations, parseGitHubWebhookHeaders, parseTokenExpiration, verifyGitHubWebhookSignature };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/github-client",
|
|
3
|
-
"version": "1.58.0-alpha.
|
|
3
|
+
"version": "1.58.0-alpha.31",
|
|
4
4
|
"description": "A TypeScript client for the GitHub REST API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github",
|
|
@@ -32,23 +32,23 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@theholocron/http-client": "^1.58.0-alpha.
|
|
36
|
-
"@theholocron/observability": "^0.
|
|
35
|
+
"@theholocron/http-client": "^1.58.0-alpha.31",
|
|
36
|
+
"@theholocron/observability": "^0.7.0-alpha.4"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^26",
|
|
40
|
-
"@vitest/coverage-v8": "^5.0
|
|
41
|
-
"@vitest/eslint-plugin": "^1.6.
|
|
42
|
-
"eslint": "^10.
|
|
43
|
-
"eslint-plugin-n": "^18.
|
|
44
|
-
"globals": "^17.
|
|
45
|
-
"tsdown": "^0.23.
|
|
40
|
+
"@vitest/coverage-v8": "^5.1.0",
|
|
41
|
+
"@vitest/eslint-plugin": "^1.6.28",
|
|
42
|
+
"eslint": "^10.14.0",
|
|
43
|
+
"eslint-plugin-n": "^18.5.0",
|
|
44
|
+
"globals": "^17.14.0",
|
|
45
|
+
"tsdown": "^0.23.5",
|
|
46
46
|
"typescript": "^5.9.3",
|
|
47
|
-
"vitest": "^5.0
|
|
48
|
-
"@theholocron/eslint-config": "^8.9.0-alpha.
|
|
49
|
-
"@theholocron/
|
|
50
|
-
"@theholocron/
|
|
51
|
-
"@theholocron/vitest-config": "^8.9.0-alpha.
|
|
47
|
+
"vitest": "^5.1.0",
|
|
48
|
+
"@theholocron/eslint-config": "^8.9.0-alpha.17",
|
|
49
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.17",
|
|
50
|
+
"@theholocron/tsconfig": "^8.9.0-alpha.17",
|
|
51
|
+
"@theholocron/vitest-config": "^8.9.0-alpha.17"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=22.0.0"
|
|
@@ -57,10 +57,10 @@
|
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
|
-
"
|
|
61
|
-
"
|
|
60
|
+
"build": "tsdown && node ../scripts/check-bundle-size.mjs",
|
|
61
|
+
"lint:code": "eslint .",
|
|
62
|
+
"test:unit": "vitest run --coverage",
|
|
62
63
|
"test:watch": "vitest",
|
|
63
|
-
"
|
|
64
|
-
"verification.unitTests": "vitest run"
|
|
64
|
+
"typecheck": "tsc --noEmit"
|
|
65
65
|
}
|
|
66
66
|
}
|