@theholocron/github-client 1.58.0-alpha.1 → 1.58.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +322 -2
- package/dist/index.mjs +49 -2
- package/package.json +16 -16
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
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
|
+
query<T>(document: string, variables?: Record<string, unknown>): Promise<T>;
|
|
19
|
+
}
|
|
20
|
+
/** Options for creating a GitHub client. */
|
|
3
21
|
interface GitHubClientOptions {
|
|
22
|
+
/** The token sent as the bearer credential. */
|
|
4
23
|
token: string;
|
|
24
|
+
/** The GitHub API base URL; defaults to `https://api.github.com`. */
|
|
5
25
|
baseUrl?: string;
|
|
26
|
+
/** The `fetch` implementation to use; defaults to the global `fetch`. */
|
|
6
27
|
fetch?: typeof fetch;
|
|
7
28
|
/** Structured logger for request/response diagnostics. Defaults to a no-op. */
|
|
8
29
|
logger?: Logger;
|
|
@@ -16,8 +37,11 @@ interface GitHubBranch {
|
|
|
16
37
|
sha: string;
|
|
17
38
|
};
|
|
18
39
|
}
|
|
40
|
+
/** The lifecycle state of a check run. */
|
|
19
41
|
type CheckRunStatus = "queued" | "in_progress" | "completed";
|
|
42
|
+
/** The final result of a completed check run. */
|
|
20
43
|
type CheckRunConclusion = "success" | "failure" | "neutral" | "cancelled" | "timed_out" | "action_required" | "skipped";
|
|
44
|
+
/** The severity of a check run annotation. */
|
|
21
45
|
type CheckRunAnnotationLevel = "notice" | "warning" | "failure";
|
|
22
46
|
/**
|
|
23
47
|
* GitHub's cap on `output.annotations` per `createCheckRun()` /
|
|
@@ -26,15 +50,19 @@ type CheckRunAnnotationLevel = "notice" | "warning" | "failure";
|
|
|
26
50
|
* do for you; slice with it rather than hardcoding the number.
|
|
27
51
|
*/
|
|
28
52
|
export declare const MAX_CHECK_RUN_ANNOTATIONS = 50;
|
|
53
|
+
/** One inline annotation attached to a check run's output, anchored to a file and line range. */
|
|
29
54
|
interface CheckRunAnnotation {
|
|
30
55
|
/** File path relative to the repo root. */
|
|
31
56
|
path: string;
|
|
32
57
|
/** 1-indexed. */
|
|
33
58
|
start_line: number;
|
|
59
|
+
/** 1-indexed last line of the annotated range. */
|
|
34
60
|
end_line: number;
|
|
35
61
|
/** Only valid when `start_line === end_line`. */
|
|
36
62
|
start_column?: number;
|
|
63
|
+
/** Column of the end of the range; only valid when `start_line === end_line`. */
|
|
37
64
|
end_column?: number;
|
|
65
|
+
/** Severity of the annotation. */
|
|
38
66
|
annotation_level: CheckRunAnnotationLevel;
|
|
39
67
|
/** Max 64KB. */
|
|
40
68
|
message: string;
|
|
@@ -43,9 +71,13 @@ interface CheckRunAnnotation {
|
|
|
43
71
|
/** Max 64KB. */
|
|
44
72
|
raw_details?: string;
|
|
45
73
|
}
|
|
74
|
+
/** The title, summary and optional annotations shown on a check run. */
|
|
46
75
|
interface CheckRunOutput {
|
|
76
|
+
/** The output's title. */
|
|
47
77
|
title: string;
|
|
78
|
+
/** The output's summary, rendered as Markdown. */
|
|
48
79
|
summary: string;
|
|
80
|
+
/** Longer details text, rendered as Markdown. */
|
|
49
81
|
text?: string;
|
|
50
82
|
/**
|
|
51
83
|
* Inline PR annotations — up to {@link MAX_CHECK_RUN_ANNOTATIONS} per
|
|
@@ -54,7 +86,9 @@ interface CheckRunOutput {
|
|
|
54
86
|
*/
|
|
55
87
|
annotations?: CheckRunAnnotation[];
|
|
56
88
|
}
|
|
89
|
+
/** The body of a `createCheckRun()` request. */
|
|
57
90
|
interface CreateCheckRunInput {
|
|
91
|
+
/** The check run's name, as shown in the checks list. */
|
|
58
92
|
name: string;
|
|
59
93
|
/** The commit SHA the check run attaches to. */
|
|
60
94
|
head_sha: string;
|
|
@@ -62,30 +96,46 @@ interface CreateCheckRunInput {
|
|
|
62
96
|
status?: CheckRunStatus;
|
|
63
97
|
/** Required when `status` is `"completed"`. */
|
|
64
98
|
conclusion?: CheckRunConclusion;
|
|
99
|
+
/** The title, summary and annotations to show on the check run. */
|
|
65
100
|
output?: CheckRunOutput;
|
|
66
101
|
/** URL for the "Details" link on the check run. GitHub defaults to the check suite's own summary page when omitted. */
|
|
67
102
|
details_url?: string;
|
|
68
103
|
}
|
|
104
|
+
/** A check run as GitHub returns it, with only the fields this client reads. */
|
|
69
105
|
interface GitHubCheckRun {
|
|
106
|
+
/** The check run's numeric id. */
|
|
70
107
|
id: number;
|
|
108
|
+
/** The check run's name. */
|
|
71
109
|
name: string;
|
|
110
|
+
/** The commit SHA the check run is attached to. */
|
|
72
111
|
head_sha: string;
|
|
112
|
+
/** The check run's current lifecycle state. */
|
|
73
113
|
status: CheckRunStatus;
|
|
114
|
+
/** The check run's result, or `null` until it is completed. */
|
|
74
115
|
conclusion: CheckRunConclusion | null;
|
|
116
|
+
/** The URL of the check run's page on GitHub. */
|
|
75
117
|
html_url: string;
|
|
76
118
|
}
|
|
119
|
+
/** The body of an `updateCheckRun()` request; every field is optional. */
|
|
77
120
|
interface UpdateCheckRunInput {
|
|
121
|
+
/** The lifecycle state to move the check run to. */
|
|
78
122
|
status?: CheckRunStatus;
|
|
79
123
|
/** Required when `status` is `"completed"`. */
|
|
80
124
|
conclusion?: CheckRunConclusion;
|
|
125
|
+
/** The title, summary and annotations to set on the check run. */
|
|
81
126
|
output?: CheckRunOutput;
|
|
82
127
|
/** URL for the "Details" link on the check run. */
|
|
83
128
|
details_url?: string;
|
|
84
129
|
}
|
|
130
|
+
/** A deployment environment of a repository and its protection settings. */
|
|
85
131
|
interface GitHubEnvironment {
|
|
132
|
+
/** The environment's name. */
|
|
86
133
|
name: string;
|
|
134
|
+
/** Minutes to wait before a job that targets the environment may proceed. */
|
|
87
135
|
wait_timer?: number;
|
|
136
|
+
/** Whether the user who triggered a deployment may also approve it. */
|
|
88
137
|
prevent_self_review?: boolean;
|
|
138
|
+
/** The protection rules on the environment; each has a `type` and, for required reviewers, the reviewers. */
|
|
89
139
|
protection_rules?: Array<{
|
|
90
140
|
type: string;
|
|
91
141
|
reviewers?: Array<{
|
|
@@ -96,52 +146,87 @@ interface GitHubEnvironment {
|
|
|
96
146
|
}>;
|
|
97
147
|
}>;
|
|
98
148
|
}
|
|
149
|
+
/** A git reference (such as a branch) and the object it points at. */
|
|
99
150
|
interface GitRef {
|
|
151
|
+
/** The object the reference points at. */
|
|
100
152
|
object: {
|
|
153
|
+
/** The object's SHA. */
|
|
101
154
|
sha: string;
|
|
155
|
+
/** The object's type, e.g. `commit`. */
|
|
102
156
|
type: string;
|
|
157
|
+
/** The API URL of the object. */
|
|
103
158
|
url: string;
|
|
104
159
|
};
|
|
160
|
+
/** The full reference name, e.g. `refs/heads/main`. */
|
|
105
161
|
ref: string;
|
|
162
|
+
/** The API URL of the reference. */
|
|
106
163
|
url: string;
|
|
107
164
|
}
|
|
165
|
+
/** A git commit, with only the fields this client reads. */
|
|
108
166
|
interface GitCommit {
|
|
167
|
+
/** The commit's SHA. */
|
|
109
168
|
sha: string;
|
|
169
|
+
/** The tree the commit points at. */
|
|
110
170
|
tree: {
|
|
171
|
+
/** The tree's SHA. */
|
|
111
172
|
sha: string;
|
|
173
|
+
/** The API URL of the tree. */
|
|
112
174
|
url: string;
|
|
113
175
|
};
|
|
114
176
|
}
|
|
177
|
+
/** One entry of a git tree. */
|
|
115
178
|
interface GitTreeItem {
|
|
179
|
+
/** The entry's path within the tree. */
|
|
116
180
|
path: string;
|
|
181
|
+
/** The entry's object SHA. */
|
|
117
182
|
sha: string;
|
|
183
|
+
/** The kind of object the entry points at, e.g. `blob` or `tree`. */
|
|
118
184
|
type: string;
|
|
185
|
+
/** The entry's file mode, e.g. `100644`. */
|
|
119
186
|
mode?: string;
|
|
187
|
+
/** The blob's size in bytes; absent for trees. */
|
|
120
188
|
size?: number;
|
|
121
189
|
}
|
|
190
|
+
/** A git tree as GitHub returns it. */
|
|
122
191
|
interface GitTree {
|
|
192
|
+
/** The tree's SHA. */
|
|
123
193
|
sha: string;
|
|
194
|
+
/** The entries of the tree. */
|
|
124
195
|
tree: GitTreeItem[];
|
|
196
|
+
/** Whether GitHub cut the entry list short because the tree was too large. */
|
|
125
197
|
truncated: boolean;
|
|
126
198
|
}
|
|
199
|
+
/** A file's contents as the contents API returns them. */
|
|
127
200
|
interface GitContents {
|
|
201
|
+
/** The file content, encoded as named by `encoding`. */
|
|
128
202
|
content: string;
|
|
203
|
+
/** The encoding of `content`, normally `base64`. */
|
|
129
204
|
encoding: string;
|
|
205
|
+
/** The file's blob SHA. */
|
|
130
206
|
sha: string;
|
|
207
|
+
/** The file's name. */
|
|
131
208
|
name: string;
|
|
209
|
+
/** The file's path in the repository. */
|
|
132
210
|
path: string;
|
|
133
211
|
}
|
|
134
212
|
/** What `git.putContents` returns: the file's new blob sha (the `sha` to pass next time) and the commit it made. */
|
|
135
213
|
interface PutContentsResult {
|
|
214
|
+
/** The file written: its path and its new blob SHA. */
|
|
136
215
|
content: {
|
|
216
|
+
/** The file's new blob SHA. */
|
|
137
217
|
sha: string;
|
|
218
|
+
/** The file's path. */
|
|
138
219
|
path: string;
|
|
139
220
|
};
|
|
221
|
+
/** The commit that was made. */
|
|
140
222
|
commit: {
|
|
223
|
+
/** The new commit's SHA. */
|
|
141
224
|
sha: string;
|
|
142
225
|
};
|
|
143
226
|
}
|
|
227
|
+
/** The body of a `putContents()` request. */
|
|
144
228
|
interface PutContentsInput {
|
|
229
|
+
/** The commit message. */
|
|
145
230
|
message: string;
|
|
146
231
|
/** The new file text (UTF-8); the client encodes it. */
|
|
147
232
|
content: string;
|
|
@@ -154,99 +239,172 @@ interface PutContentsInput {
|
|
|
154
239
|
/** Defaults to the repo's default branch. */
|
|
155
240
|
branch?: string;
|
|
156
241
|
}
|
|
242
|
+
/** A git blob created in the repository. */
|
|
157
243
|
interface GitBlob {
|
|
244
|
+
/** The blob's SHA. */
|
|
158
245
|
sha: string;
|
|
246
|
+
/** The API URL of the blob. */
|
|
159
247
|
url: string;
|
|
160
248
|
}
|
|
249
|
+
/** A pull request as returned when one is created, with only the fields this client reads. */
|
|
161
250
|
interface GitPull {
|
|
251
|
+
/** The pull request's number. */
|
|
162
252
|
number: number;
|
|
253
|
+
/** The URL of the pull request's page on GitHub. */
|
|
163
254
|
html_url: string;
|
|
255
|
+
/** The pull request's title. */
|
|
164
256
|
title: string;
|
|
165
257
|
}
|
|
258
|
+
/** The body of a `createPull()` request. */
|
|
166
259
|
interface CreatePullInput {
|
|
260
|
+
/** The pull request's title. */
|
|
167
261
|
title: string;
|
|
262
|
+
/** The branch the changes come from. */
|
|
168
263
|
head: string;
|
|
264
|
+
/** The branch the changes are to be merged into. */
|
|
169
265
|
base: string;
|
|
266
|
+
/** The pull request's description. */
|
|
170
267
|
body?: string;
|
|
171
268
|
}
|
|
269
|
+
/** An issue as GitHub returns it, with only the fields this client reads. */
|
|
172
270
|
interface GitHubIssue {
|
|
271
|
+
/** The issue's numeric id. */
|
|
173
272
|
id: number;
|
|
273
|
+
/** The issue's number within its repository. */
|
|
174
274
|
number: number;
|
|
275
|
+
/** The issue's title. */
|
|
175
276
|
title: string;
|
|
277
|
+
/** The issue's description; `null` or absent when empty. */
|
|
176
278
|
body?: string | null;
|
|
279
|
+
/** Whether the issue is open or closed. */
|
|
177
280
|
state: "open" | "closed";
|
|
281
|
+
/** The labels on the issue. */
|
|
178
282
|
labels: Array<{
|
|
179
283
|
name: string;
|
|
180
284
|
}>;
|
|
285
|
+
/** The user the issue is assigned to, or `null` when unassigned. */
|
|
181
286
|
assignee: {
|
|
182
287
|
login: string;
|
|
183
288
|
name?: string | null;
|
|
184
289
|
email?: string | null;
|
|
185
290
|
} | null;
|
|
291
|
+
/** When the issue was last updated, as an ISO 8601 timestamp. */
|
|
186
292
|
updated_at: string;
|
|
293
|
+
/** The URL of the issue's page on GitHub. */
|
|
187
294
|
html_url: string;
|
|
295
|
+
/** Set when the item is a pull request; GitHub's issues API returns pull requests too. */
|
|
188
296
|
pull_request?: unknown;
|
|
189
297
|
}
|
|
298
|
+
/** A milestone, with only the fields this client reads. */
|
|
190
299
|
interface GitHubMilestone {
|
|
300
|
+
/** The milestone's number. */
|
|
191
301
|
number: number;
|
|
302
|
+
/** The milestone's title. */
|
|
192
303
|
title: string;
|
|
193
304
|
}
|
|
305
|
+
/** Filters for listing issues. */
|
|
194
306
|
interface IssueSearchParams {
|
|
307
|
+
/** Which issues to list by state; GitHub defaults to `open`. */
|
|
195
308
|
state?: "open" | "closed" | "all";
|
|
309
|
+
/** The field to sort by, passed through to GitHub. */
|
|
196
310
|
sort?: string;
|
|
311
|
+
/** The sort direction, passed through to GitHub. */
|
|
197
312
|
direction?: string;
|
|
313
|
+
/** The number of issues per page. */
|
|
198
314
|
per_page?: number;
|
|
315
|
+
/** Which issues to list by relation to the user, passed through to GitHub. */
|
|
199
316
|
filter?: string;
|
|
317
|
+
/** Limit to issues assigned to this login. */
|
|
200
318
|
assignee?: string;
|
|
201
319
|
}
|
|
320
|
+
/** A repository label. */
|
|
202
321
|
interface GitHubLabel {
|
|
322
|
+
/** The label's name. */
|
|
203
323
|
name: string;
|
|
324
|
+
/** The label's color as a hex code without the leading `#`. */
|
|
204
325
|
color: string;
|
|
326
|
+
/** The label's description, or `null` when it has none. */
|
|
205
327
|
description: string | null;
|
|
206
328
|
}
|
|
329
|
+
/** How a Pages site is built: by a workflow or from a branch. */
|
|
207
330
|
type PagesBuildType = "workflow" | "legacy";
|
|
331
|
+
/** The status of a Pages build. */
|
|
208
332
|
type PagesBuildStatus = "built" | "building" | "errored" | "unknown";
|
|
333
|
+
/** A repository's GitHub Pages site configuration. */
|
|
209
334
|
interface GitHubPages {
|
|
335
|
+
/** The latest build's status, or `null` when there is none. */
|
|
210
336
|
status: PagesBuildStatus | null;
|
|
337
|
+
/** How the site is built, or `null` when unknown. */
|
|
211
338
|
build_type: PagesBuildType | null;
|
|
339
|
+
/** The branch and folder the site is published from, for a legacy build. */
|
|
212
340
|
source?: {
|
|
341
|
+
/** The branch the site is published from. */
|
|
213
342
|
branch: string;
|
|
343
|
+
/** The folder on the branch, `/` or `/docs`. */
|
|
214
344
|
path: string;
|
|
215
345
|
};
|
|
346
|
+
/** Whether HTTPS is enforced for the site. */
|
|
216
347
|
https_enforced: boolean;
|
|
348
|
+
/** The site's custom domain, or `null` when it has none. */
|
|
217
349
|
custom_domain: string | null;
|
|
218
350
|
}
|
|
351
|
+
/** The body of a Pages creation request. */
|
|
219
352
|
interface CreatePagesPayload {
|
|
353
|
+
/** How the site is built. */
|
|
220
354
|
build_type: PagesBuildType;
|
|
221
355
|
/** Required when build_type is "legacy". */
|
|
222
356
|
source?: {
|
|
357
|
+
/** The branch the site is published from. */
|
|
223
358
|
branch: string;
|
|
359
|
+
/** The folder on the branch, `/` or `/docs`. */
|
|
224
360
|
path: string;
|
|
225
361
|
};
|
|
226
362
|
}
|
|
363
|
+
/** The body of a Pages update request; every field is optional. */
|
|
227
364
|
interface UpdatePagesPayload {
|
|
365
|
+
/** How the site is built. */
|
|
228
366
|
build_type?: PagesBuildType;
|
|
367
|
+
/** The branch and folder to publish from. */
|
|
229
368
|
source?: {
|
|
369
|
+
/** The branch the site is published from. */
|
|
230
370
|
branch: string;
|
|
371
|
+
/** The folder on the branch, `/` or `/docs`. */
|
|
231
372
|
path: string;
|
|
232
373
|
};
|
|
374
|
+
/** The custom domain, or `null` to remove it. */
|
|
233
375
|
cname?: string | null;
|
|
376
|
+
/** Whether to enforce HTTPS. */
|
|
234
377
|
https_enforced?: boolean;
|
|
235
378
|
}
|
|
236
379
|
/** One custom property of an organization, as its schema defines it. */
|
|
237
380
|
interface OrgProperty {
|
|
381
|
+
/** The property's name. */
|
|
238
382
|
property_name: string;
|
|
239
383
|
/** `string`, `single_select`, `multi_select`, `true_false` or `url`. */
|
|
240
384
|
value_type: string;
|
|
385
|
+
/** Whether a repository must set the property. */
|
|
241
386
|
required?: boolean;
|
|
242
387
|
/** The values a `single_select` or `multi_select` property accepts; `null` for any other type. */
|
|
243
388
|
allowed_values?: string[] | null;
|
|
244
389
|
}
|
|
390
|
+
/** One custom property value set on a repository. */
|
|
391
|
+
interface RepoPropertyValue {
|
|
392
|
+
/** The property's name. */
|
|
393
|
+
property_name: string;
|
|
394
|
+
/** A string, a string array for `multi_select`, or `null` when unset. */
|
|
395
|
+
value: string | string[] | null;
|
|
396
|
+
}
|
|
397
|
+
/** A pull request as GitHub returns it, with only the fields this client reads. */
|
|
245
398
|
interface GitHubPullRequest {
|
|
399
|
+
/** The pull request's number. */
|
|
246
400
|
number: number;
|
|
401
|
+
/** The pull request's title. */
|
|
247
402
|
title: string;
|
|
403
|
+
/** Whether the pull request is open or closed. */
|
|
248
404
|
state: "open" | "closed";
|
|
405
|
+
/** When the pull request was merged as an ISO 8601 timestamp, or `null` if it was not merged. */
|
|
249
406
|
merged_at: string | null;
|
|
407
|
+
/** The URL of the pull request's page on GitHub. */
|
|
250
408
|
html_url: string;
|
|
251
409
|
/** The head branch: its name and the commit it pointed at when the PR was read. */
|
|
252
410
|
head: {
|
|
@@ -263,10 +421,15 @@ interface GitHubCommitIdentity {
|
|
|
263
421
|
}
|
|
264
422
|
/** One commit as returned by `GET /pulls/{pull_number}/commits` — only the fields any known consumer needs. */
|
|
265
423
|
interface GitHubPullRequestCommit {
|
|
424
|
+
/** The commit's SHA. */
|
|
266
425
|
sha: string;
|
|
426
|
+
/** The commit's message and git identities. */
|
|
267
427
|
commit: {
|
|
428
|
+
/** The commit message. */
|
|
268
429
|
message: string;
|
|
430
|
+
/** The commit's author, as git recorded it. */
|
|
269
431
|
author: GitHubCommitIdentity;
|
|
432
|
+
/** The commit's committer, as git recorded it. */
|
|
270
433
|
committer: GitHubCommitIdentity;
|
|
271
434
|
};
|
|
272
435
|
/** 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). */
|
|
@@ -281,7 +444,9 @@ interface GitHubPullRequestCommit {
|
|
|
281
444
|
}
|
|
282
445
|
/** One file as returned by `GET /pulls/{pull_number}/files` — only the fields any known consumer needs. */
|
|
283
446
|
interface GitHubPullRequestFile {
|
|
447
|
+
/** The file's path in the repository. */
|
|
284
448
|
filename: string;
|
|
449
|
+
/** How the pull request changes the file. */
|
|
285
450
|
status: "added" | "removed" | "modified" | "renamed" | "copied" | "changed" | "unchanged";
|
|
286
451
|
/** Set only when `status === "renamed"`. */
|
|
287
452
|
previous_filename?: string;
|
|
@@ -301,8 +466,10 @@ interface CreateReviewComment {
|
|
|
301
466
|
line: number;
|
|
302
467
|
/** Almost always `"RIGHT"` (the PR's own new content) — `"LEFT"` targets the base/pre-PR version instead. */
|
|
303
468
|
side: "LEFT" | "RIGHT";
|
|
469
|
+
/** The comment text. */
|
|
304
470
|
body: string;
|
|
305
471
|
}
|
|
472
|
+
/** The body of a review creation request. */
|
|
306
473
|
interface CreateReviewInput {
|
|
307
474
|
/** The PR's head SHA the review attaches to. */
|
|
308
475
|
commit_id: string;
|
|
@@ -315,11 +482,14 @@ interface CreateReviewInput {
|
|
|
315
482
|
* required-approval counts and dismissal.
|
|
316
483
|
*/
|
|
317
484
|
event: "COMMENT" | "REQUEST_CHANGES" | "APPROVE";
|
|
485
|
+
/** Inline comments to post with the review. */
|
|
318
486
|
comments?: CreateReviewComment[];
|
|
319
487
|
}
|
|
320
488
|
/** `POST /pulls/{pull_number}/reviews`'s response — only the fields any known consumer needs. */
|
|
321
489
|
interface GitHubPullRequestReview {
|
|
490
|
+
/** The review's numeric id. */
|
|
322
491
|
id: number;
|
|
492
|
+
/** The URL of the review on GitHub. */
|
|
323
493
|
html_url: string;
|
|
324
494
|
}
|
|
325
495
|
/**
|
|
@@ -330,7 +500,9 @@ interface GitHubPullRequestReview {
|
|
|
330
500
|
* never compare it against a REST-sourced ID.
|
|
331
501
|
*/
|
|
332
502
|
interface ReviewThread {
|
|
503
|
+
/** The thread's GraphQL node id. */
|
|
333
504
|
id: string;
|
|
505
|
+
/** Whether the thread is resolved. */
|
|
334
506
|
isResolved: boolean;
|
|
335
507
|
/** 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. */
|
|
336
508
|
authorLogin: string | undefined;
|
|
@@ -348,19 +520,70 @@ interface ReviewThread {
|
|
|
348
520
|
*/
|
|
349
521
|
body: string | undefined;
|
|
350
522
|
}
|
|
523
|
+
/** A repository as GitHub returns it, with only the fields this client reads. */
|
|
351
524
|
interface GitHubRepo {
|
|
525
|
+
/** The name of the repository's default branch. */
|
|
352
526
|
default_branch: string;
|
|
527
|
+
/** The repository's `owner/name`. */
|
|
353
528
|
full_name: string;
|
|
354
|
-
|
|
529
|
+
/** The repository description. */
|
|
530
|
+
description?: string | null;
|
|
531
|
+
/** The repository homepage URL. */
|
|
532
|
+
homepage?: string | null;
|
|
533
|
+
/** The topics set on the repository. */
|
|
534
|
+
topics?: string[];
|
|
535
|
+
/** Whether squash merging is allowed. */
|
|
536
|
+
allow_squash_merge?: boolean;
|
|
537
|
+
/** Whether merge commits are allowed. */
|
|
538
|
+
allow_merge_commit?: boolean;
|
|
539
|
+
/** Whether rebase merging is allowed. */
|
|
540
|
+
allow_rebase_merge?: boolean;
|
|
541
|
+
/** Whether auto-merge is allowed. */
|
|
542
|
+
allow_auto_merge?: boolean;
|
|
543
|
+
/** Whether a pull request branch can be updated from its base. */
|
|
544
|
+
allow_update_branch?: boolean;
|
|
545
|
+
/** Whether a merged pull request's branch is deleted. */
|
|
546
|
+
delete_branch_on_merge?: boolean;
|
|
547
|
+
/** Whether issues are enabled. */
|
|
548
|
+
has_issues?: boolean;
|
|
549
|
+
/** Whether discussions are enabled. */
|
|
550
|
+
has_discussions?: boolean;
|
|
551
|
+
/** Whether projects are enabled. */
|
|
552
|
+
has_projects?: boolean;
|
|
553
|
+
/** Whether the wiki is enabled. */
|
|
554
|
+
has_wiki?: boolean;
|
|
555
|
+
/** Each feature's `status` (`enabled` / `disabled`). Only an admin token sees it; absent for the rest. */
|
|
556
|
+
security_and_analysis?: Record<string, {
|
|
557
|
+
status: string;
|
|
558
|
+
} | undefined> | null;
|
|
559
|
+
}
|
|
560
|
+
/** A file's contents as the contents API returns them. */
|
|
355
561
|
interface GitHubContents {
|
|
562
|
+
/** The file content, encoded as named by `encoding`. */
|
|
356
563
|
content: string;
|
|
564
|
+
/** The encoding of `content`, normally `base64`. */
|
|
357
565
|
encoding: string;
|
|
358
566
|
}
|
|
567
|
+
/** A repository ruleset in summary form. */
|
|
359
568
|
interface GitHubRuleset {
|
|
569
|
+
/** The ruleset's numeric id. */
|
|
360
570
|
id: number;
|
|
571
|
+
/** The ruleset's name. */
|
|
361
572
|
name: string;
|
|
573
|
+
/** How the ruleset is enforced, e.g. `active`, `evaluate` or `disabled`. */
|
|
362
574
|
enforcement: string;
|
|
363
575
|
}
|
|
576
|
+
/** One ruleset in full, as `GET /repos/{repo}/rulesets/{id}` returns it. */
|
|
577
|
+
interface GitHubRulesetDetail extends GitHubRuleset {
|
|
578
|
+
/** What the ruleset applies to, e.g. `branch`. */
|
|
579
|
+
target?: string;
|
|
580
|
+
/** Each rule has a `type`; some carry `parameters`. */
|
|
581
|
+
rules?: Array<{
|
|
582
|
+
type: string;
|
|
583
|
+
parameters?: Record<string, unknown>;
|
|
584
|
+
}>;
|
|
585
|
+
}
|
|
586
|
+
/** Where a secret lives: the repository, one of its environments, or an organization. */
|
|
364
587
|
type SecretScope = {
|
|
365
588
|
kind: "repo";
|
|
366
589
|
} | {
|
|
@@ -370,21 +593,39 @@ type SecretScope = {
|
|
|
370
593
|
kind: "organization";
|
|
371
594
|
org: string;
|
|
372
595
|
};
|
|
596
|
+
/** A public key used to encrypt a secret before it is sent. */
|
|
373
597
|
interface GitHubPublicKey {
|
|
598
|
+
/** The key's id, sent back with the encrypted secret. */
|
|
374
599
|
key_id: string;
|
|
600
|
+
/** The Base64-encoded public key. */
|
|
375
601
|
key: string;
|
|
376
602
|
}
|
|
603
|
+
/** The workflow run that a code scanning setup started. */
|
|
377
604
|
interface CodeScanningSetupResult {
|
|
605
|
+
/** The id of the workflow run. */
|
|
378
606
|
run_id: number;
|
|
607
|
+
/** The URL of the workflow run. */
|
|
379
608
|
run_url: string;
|
|
380
609
|
}
|
|
610
|
+
/** A permission level a team can hold on a repository. */
|
|
381
611
|
type TeamPermission = "pull" | "triage" | "push" | "maintain" | "admin";
|
|
612
|
+
/** A team with access to a repository, and the permission it has there. */
|
|
613
|
+
interface RepoTeam {
|
|
614
|
+
/** The team's slug. */
|
|
615
|
+
slug: string;
|
|
616
|
+
/** The team's permission on the repository. */
|
|
617
|
+
permission: TeamPermission;
|
|
618
|
+
}
|
|
382
619
|
/** A member of a team, as GitHub lists it. `id` is the numeric user id, which survives a rename; `login` does not. */
|
|
383
620
|
interface TeamMember {
|
|
621
|
+
/** The member's numeric user id. */
|
|
384
622
|
id: number;
|
|
623
|
+
/** The member's login. */
|
|
385
624
|
login: string;
|
|
625
|
+
/** The kind of account, e.g. `User`. */
|
|
386
626
|
type?: string;
|
|
387
627
|
}
|
|
628
|
+
/** Where a variable lives: the repository, one of its environments, or an organization. */
|
|
388
629
|
type VariableScope = {
|
|
389
630
|
kind: "repo";
|
|
390
631
|
} | {
|
|
@@ -401,40 +642,76 @@ type VariableScope = {
|
|
|
401
642
|
type VariableVisibility = "all" | "private" | "selected";
|
|
402
643
|
/** A GitHub Actions variable. Unlike a secret its value is readable, so a reconcile can tell whether it differs. */
|
|
403
644
|
interface GitHubVariable {
|
|
645
|
+
/** The variable's name. */
|
|
404
646
|
name: string;
|
|
647
|
+
/** The variable's value. */
|
|
405
648
|
value: string;
|
|
406
649
|
/** Present on organization variables only. */
|
|
407
650
|
visibility?: VariableVisibility;
|
|
408
651
|
}
|
|
652
|
+
/** The authenticated user, with only the fields this client reads. */
|
|
409
653
|
interface GitHubUser {
|
|
654
|
+
/** The user's login. */
|
|
410
655
|
login: string;
|
|
656
|
+
/** The user's display name, or `null` when not set. */
|
|
411
657
|
name: string | null;
|
|
658
|
+
/** The user's public email, or `null` when not set. */
|
|
412
659
|
email: string | null;
|
|
413
660
|
}
|
|
661
|
+
/** The authenticated user and, for a token that expires, when. */
|
|
662
|
+
interface GitHubUserWithExpiry {
|
|
663
|
+
/** The authenticated user. */
|
|
664
|
+
user: GitHubUser;
|
|
665
|
+
/** When the token stops working, ISO 8601 in UTC. Absent for a token that never expires. */
|
|
666
|
+
expiresAt?: string;
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* The expiry GitHub reports in the `github-authentication-token-expiration` header (`2026-11-19 03:46:04 UTC`) as
|
|
670
|
+
* ISO 8601, or `undefined` when the header is missing or is not a date.
|
|
671
|
+
*/
|
|
672
|
+
export declare function parseTokenExpiration(header: string | null): string | undefined;
|
|
673
|
+
/** A workflow run as GitHub returns it, with only the fields this client reads. */
|
|
414
674
|
interface GitHubWorkflowRun {
|
|
675
|
+
/** The run's numeric id. */
|
|
415
676
|
id: number;
|
|
677
|
+
/** The workflow's name, or `null` when unnamed. */
|
|
416
678
|
name: string | null;
|
|
679
|
+
/** The run's display title. */
|
|
417
680
|
display_title: string;
|
|
681
|
+
/** The branch the run was triggered on. */
|
|
418
682
|
head_branch: string;
|
|
683
|
+
/** The commit SHA the run was triggered on. */
|
|
419
684
|
head_sha: string;
|
|
685
|
+
/** The run's status, e.g. `queued`, `in_progress` or `completed`. */
|
|
420
686
|
status: string;
|
|
687
|
+
/** The run's result once completed, or `null` before. */
|
|
421
688
|
conclusion: string | null;
|
|
689
|
+
/** The URL of the run's page on GitHub. */
|
|
422
690
|
html_url: string;
|
|
691
|
+
/** When the run was created, as an ISO 8601 timestamp. */
|
|
423
692
|
created_at: string;
|
|
693
|
+
/** When the run was last updated, as an ISO 8601 timestamp. */
|
|
424
694
|
updated_at: string;
|
|
425
695
|
}
|
|
696
|
+
/** Filters for listing workflow runs. */
|
|
426
697
|
interface WorkflowRunFilter {
|
|
698
|
+
/** Only runs on this branch. */
|
|
427
699
|
branch?: string;
|
|
700
|
+
/** The maximum number of runs to return. */
|
|
428
701
|
limit?: number;
|
|
702
|
+
/** Only runs with this status. */
|
|
429
703
|
status?: string;
|
|
430
704
|
}
|
|
705
|
+
/** The credentials identifying a GitHub App: its id and private key. */
|
|
431
706
|
interface GitHubAppCredentials {
|
|
432
707
|
/** The App's numeric id (not the client id). */
|
|
433
708
|
appId: string;
|
|
434
709
|
/** PEM-encoded RSA private key — PKCS#1 (GitHub's default download format) or PKCS#8, either works. */
|
|
435
710
|
privateKey: string;
|
|
436
711
|
}
|
|
712
|
+
/** A short-lived installation access token and when it expires. */
|
|
437
713
|
interface InstallationAccessToken {
|
|
714
|
+
/** The installation access token, used as a bearer token for the REST API. */
|
|
438
715
|
token: string;
|
|
439
716
|
/** ISO 8601 — installation tokens are short-lived, about an hour. */
|
|
440
717
|
expiresAt: string;
|
|
@@ -484,6 +761,7 @@ export declare function verifyGitHubWebhookSignature(input: {
|
|
|
484
761
|
signature: string | undefined;
|
|
485
762
|
secret: string;
|
|
486
763
|
}): boolean;
|
|
764
|
+
/** The three GitHub webhook headers a consumer needs. */
|
|
487
765
|
interface GitHubWebhookHeaders {
|
|
488
766
|
/** `X-GitHub-Event` — the event category, e.g. `"push"`, `"pull_request"`. */
|
|
489
767
|
event: string | undefined;
|
|
@@ -494,31 +772,62 @@ interface GitHubWebhookHeaders {
|
|
|
494
772
|
}
|
|
495
773
|
/** Extracts GitHub's three webhook headers, case-insensitively (Node's raw headers may arrive lower-cased, or as an array when a header repeats). */
|
|
496
774
|
export declare function parseGitHubWebhookHeaders(headers: Record<string, string | string[] | undefined>): GitHubWebhookHeaders;
|
|
775
|
+
/** The payload of an `installation` webhook delivery. */
|
|
497
776
|
interface GitHubInstallationWebhookPayload {
|
|
777
|
+
/** What happened to the installation, e.g. `created` or `deleted`. */
|
|
498
778
|
action: string;
|
|
779
|
+
/** The installation the delivery is about. */
|
|
499
780
|
installation: {
|
|
781
|
+
/** The installation id. */
|
|
500
782
|
id: number;
|
|
501
783
|
};
|
|
502
784
|
}
|
|
785
|
+
/** The payload of a `push` webhook delivery. */
|
|
503
786
|
interface GitHubPushWebhookPayload {
|
|
787
|
+
/** The full name of the pushed ref, e.g. `refs/heads/main`. */
|
|
504
788
|
ref: string;
|
|
789
|
+
/** The installation the delivery is about, when sent. */
|
|
505
790
|
installation?: {
|
|
791
|
+
/** The installation id. */
|
|
506
792
|
id: number;
|
|
507
793
|
};
|
|
794
|
+
/** The repository that was pushed to. */
|
|
508
795
|
repository: {
|
|
796
|
+
/** The repository's owner/name. */
|
|
509
797
|
full_name: string;
|
|
798
|
+
/** The name of the default branch. */
|
|
510
799
|
default_branch: string;
|
|
511
800
|
};
|
|
512
801
|
}
|
|
802
|
+
/** The payload of a `pull_request` webhook delivery. */
|
|
513
803
|
interface GitHubPullRequestWebhookPayload {
|
|
804
|
+
/** What happened to the pull request, e.g. `opened` or `closed`. */
|
|
514
805
|
action: string;
|
|
806
|
+
/** For an `edited` action, the fields that changed (each holds the previous value); absent for other actions. */
|
|
807
|
+
changes?: {
|
|
808
|
+
/** Present when the title was edited. */
|
|
809
|
+
title?: {
|
|
810
|
+
/** The title before the edit. */
|
|
811
|
+
from: string;
|
|
812
|
+
};
|
|
813
|
+
/** Present when the description was edited. */
|
|
814
|
+
body?: {
|
|
815
|
+
/** The description before the edit; `null` when it was empty. */
|
|
816
|
+
from: string | null;
|
|
817
|
+
};
|
|
818
|
+
};
|
|
819
|
+
/** The installation the delivery is about, when sent. */
|
|
515
820
|
installation?: {
|
|
821
|
+
/** The installation id. */
|
|
516
822
|
id: number;
|
|
517
823
|
};
|
|
824
|
+
/** The repository the pull request belongs to. */
|
|
518
825
|
repository: {
|
|
826
|
+
/** The repository's owner/name. */
|
|
519
827
|
full_name: string;
|
|
520
828
|
};
|
|
521
829
|
}
|
|
830
|
+
/** 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. */
|
|
522
831
|
export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
523
832
|
branches: {
|
|
524
833
|
protectBranch: (repo: string, branch: string, payload: Record<string, unknown>) => Promise<void>;
|
|
@@ -552,6 +861,8 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
552
861
|
updateRef: (repo: string, ref: string, sha: string, force?: boolean) => Promise<GitRef>;
|
|
553
862
|
createPull: (repo: string, input: CreatePullInput) => Promise<GitPull>;
|
|
554
863
|
};
|
|
864
|
+
/** The GraphQL client, for the callers whose API (Projects v2) has no REST form. */
|
|
865
|
+
graphql: GraphQLClient;
|
|
555
866
|
issues: {
|
|
556
867
|
listIssues: (repo: string, params?: IssueSearchParams) => Promise<GitHubIssue[]>;
|
|
557
868
|
getIssue: (repo: string, number: number) => Promise<GitHubIssue>;
|
|
@@ -583,6 +894,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
583
894
|
updatePages: (repo: string, payload: UpdatePagesPayload) => Promise<void>;
|
|
584
895
|
};
|
|
585
896
|
properties: {
|
|
897
|
+
getValues: (repo: string) => Promise<RepoPropertyValue[]>;
|
|
586
898
|
orgSchema: (org: string) => Promise<OrgProperty[]>;
|
|
587
899
|
setProperties: (repo: string, values: Record<string, string | string[]>) => Promise<void>;
|
|
588
900
|
};
|
|
@@ -601,6 +913,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
601
913
|
getContents: (repo: string, path: string) => Promise<GitHubContents>;
|
|
602
914
|
};
|
|
603
915
|
rulesets: {
|
|
916
|
+
getRuleset: (repo: string, id: number) => Promise<GitHubRulesetDetail>;
|
|
604
917
|
listRulesets: (repo: string) => Promise<GitHubRuleset[]>;
|
|
605
918
|
createRuleset: (repo: string, payload: Record<string, unknown>) => Promise<GitHubRuleset>;
|
|
606
919
|
updateRuleset: (repo: string, id: number, payload: Record<string, unknown>) => Promise<GitHubRuleset>;
|
|
@@ -612,6 +925,10 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
612
925
|
deleteSecret: (repo: string, scope: SecretScope, name: string) => Promise<void>;
|
|
613
926
|
};
|
|
614
927
|
security: {
|
|
928
|
+
vulnerabilityAlertsEnabled: (repo: string) => Promise<boolean>;
|
|
929
|
+
automatedSecurityFixesEnabled: (repo: string) => Promise<boolean>;
|
|
930
|
+
privateVulnerabilityReportingEnabled: (repo: string) => Promise<boolean>;
|
|
931
|
+
codeScanningDefaultSetupState: (repo: string) => Promise<string>;
|
|
615
932
|
enableVulnerabilityAlerts: (repo: string) => Promise<void>;
|
|
616
933
|
enableAutomatedSecurityFixes: (repo: string) => Promise<void>;
|
|
617
934
|
enableSecretScanning: (repo: string) => Promise<void>;
|
|
@@ -622,6 +939,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
622
939
|
};
|
|
623
940
|
teams: {
|
|
624
941
|
members: (org: string, teamSlug: string) => Promise<TeamMember[]>;
|
|
942
|
+
listForRepo: (repo: string) => Promise<RepoTeam[]>;
|
|
625
943
|
addRepo: (org: string, teamSlug: string, owner: string, repo: string, permission: TeamPermission) => Promise<void>;
|
|
626
944
|
};
|
|
627
945
|
topics: {
|
|
@@ -636,6 +954,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
636
954
|
};
|
|
637
955
|
user: {
|
|
638
956
|
getCurrentUser: () => Promise<GitHubUser>;
|
|
957
|
+
getCurrentUserWithExpiry(): Promise<GitHubUserWithExpiry>;
|
|
639
958
|
};
|
|
640
959
|
workflows: {
|
|
641
960
|
listRuns: (repo: string, filter?: WorkflowRunFilter) => Promise<GitHubWorkflowRun[]>;
|
|
@@ -643,5 +962,6 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
643
962
|
createWorkflowDispatch: (repo: string, workflowFile: string, ref: string, inputs?: Record<string, string>) => Promise<void>;
|
|
644
963
|
};
|
|
645
964
|
};
|
|
965
|
+
/** The client returned by `createGitHubClient()`: one group of methods per GitHub API area. */
|
|
646
966
|
export type GitHubClient = ReturnType<typeof createGitHubClient>;
|
|
647
|
-
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, GitHubUser, GitHubVariable, GitHubWebhookHeaders, GitHubWorkflowRun, GitPull, GitRef, GitTree, GitTreeItem, InstallationAccessToken, IssueSearchParams, OrgProperty, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdatePagesPayload, VariableScope, VariableVisibility, WorkflowRunFilter };
|
|
967
|
+
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, GraphQLClient, InstallationAccessToken, IssueSearchParams, OrgProperty, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, RepoPropertyValue, RepoTeam, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdatePagesPayload, VariableScope, VariableVisibility, WorkflowRunFilter };
|
package/dist/index.mjs
CHANGED
|
@@ -293,6 +293,8 @@ function pages(rest) {
|
|
|
293
293
|
// src/properties/properties.ts
|
|
294
294
|
function properties(rest) {
|
|
295
295
|
return {
|
|
296
|
+
/** The custom property values set on a repository (read-only). */
|
|
297
|
+
getValues: (repo) => rest.request(`${repoBase(repo)}/properties/values`),
|
|
296
298
|
/**
|
|
297
299
|
* The custom properties an organization defines, with their types and allowed values (read-only).
|
|
298
300
|
* The token needs read access to the organization's custom properties.
|
|
@@ -431,6 +433,7 @@ function repos(rest) {
|
|
|
431
433
|
// src/rulesets/rulesets.ts
|
|
432
434
|
function rulesets(rest) {
|
|
433
435
|
return {
|
|
436
|
+
getRuleset: (repo, id) => rest.request(`${repoBase(repo)}/rulesets/${id}`),
|
|
434
437
|
listRulesets: (repo) => rest.request(`${repoBase(repo)}/rulesets`),
|
|
435
438
|
createRuleset: (repo, payload) => rest.request(`${repoBase(repo)}/rulesets`, {
|
|
436
439
|
method: "POST",
|
|
@@ -468,6 +471,22 @@ function secrets(rest) {
|
|
|
468
471
|
// src/security/security.ts
|
|
469
472
|
function security(rest) {
|
|
470
473
|
return {
|
|
474
|
+
/** Whether vulnerability alerts are on: GitHub answers 204 when they are and 404 when they are not. */
|
|
475
|
+
vulnerabilityAlertsEnabled: async (repo) => {
|
|
476
|
+
try {
|
|
477
|
+
await rest.request(`${repoBase(repo)}/vulnerability-alerts`, { expectNoContent: true });
|
|
478
|
+
return true;
|
|
479
|
+
} catch (err) {
|
|
480
|
+
if (err instanceof ProviderApiError && err.status === 404) return false;
|
|
481
|
+
throw err;
|
|
482
|
+
}
|
|
483
|
+
},
|
|
484
|
+
/** Whether Dependabot security updates are on. */
|
|
485
|
+
automatedSecurityFixesEnabled: async (repo) => (await rest.request(`${repoBase(repo)}/automated-security-fixes`)).enabled,
|
|
486
|
+
/** Whether private vulnerability reporting is on. */
|
|
487
|
+
privateVulnerabilityReportingEnabled: async (repo) => (await rest.request(`${repoBase(repo)}/private-vulnerability-reporting`)).enabled,
|
|
488
|
+
/** The state of CodeQL default setup: `configured` or `not-configured`. */
|
|
489
|
+
codeScanningDefaultSetupState: async (repo) => (await rest.request(`${repoBase(repo)}/code-scanning/default-setup`)).state,
|
|
471
490
|
enableVulnerabilityAlerts: (repo) => rest.request(`${repoBase(repo)}/vulnerability-alerts`, {
|
|
472
491
|
method: "PUT",
|
|
473
492
|
expectNoContent: true
|
|
@@ -535,6 +554,8 @@ function teams(rest) {
|
|
|
535
554
|
if ((await read(51)).length > 0) throw new Error(`team ${org}/${teamSlug} has more than 5000 members; refusing to read them all`);
|
|
536
555
|
return all;
|
|
537
556
|
},
|
|
557
|
+
/** The teams that have access to a repository, with each team's permission there (read-only). */
|
|
558
|
+
listForRepo: (repo) => rest.request(`${repoBase(repo)}/teams`, { query: { per_page: String(PAGE$1) } }),
|
|
538
559
|
addRepo: (org, teamSlug, owner, repo, permission) => rest.request(`/orgs/${org}/teams/${teamSlug}/repos/${owner}/${repo}`, {
|
|
539
560
|
method: "PUT",
|
|
540
561
|
body: { permission }
|
|
@@ -549,8 +570,31 @@ function topics(rest) {
|
|
|
549
570
|
}) };
|
|
550
571
|
}
|
|
551
572
|
// src/user/user.ts
|
|
573
|
+
/**
|
|
574
|
+
* The expiry GitHub reports in the `github-authentication-token-expiration` header (`2026-11-19 03:46:04 UTC`) as
|
|
575
|
+
* ISO 8601, or `undefined` when the header is missing or is not a date.
|
|
576
|
+
*/
|
|
577
|
+
function parseTokenExpiration(header) {
|
|
578
|
+
if (!header) return void 0;
|
|
579
|
+
const time = Date.parse(header.replace(/ UTC$/, "Z").replace(" ", "T"));
|
|
580
|
+
return Number.isNaN(time) ? void 0 : new Date(time).toISOString();
|
|
581
|
+
}
|
|
552
582
|
function user(rest) {
|
|
553
|
-
return {
|
|
583
|
+
return {
|
|
584
|
+
getCurrentUser: () => rest.request("/user"),
|
|
585
|
+
/** The authenticated user plus when the token expires, read from the response header on the same call. */
|
|
586
|
+
async getCurrentUserWithExpiry() {
|
|
587
|
+
let header = null;
|
|
588
|
+
const me = await rest.request("/user", { onResponse: (headers) => {
|
|
589
|
+
header = headers.get("github-authentication-token-expiration");
|
|
590
|
+
} });
|
|
591
|
+
const expiresAt = parseTokenExpiration(header);
|
|
592
|
+
return expiresAt ? {
|
|
593
|
+
user: me,
|
|
594
|
+
expiresAt
|
|
595
|
+
} : { user: me };
|
|
596
|
+
}
|
|
597
|
+
};
|
|
554
598
|
}
|
|
555
599
|
// src/variables/variables.ts
|
|
556
600
|
/** GitHub's maximum page size for this listing is 30, not the usual 100. */
|
|
@@ -847,6 +891,7 @@ function parseGitHubWebhookHeaders(headers) {
|
|
|
847
891
|
};
|
|
848
892
|
}
|
|
849
893
|
// src/index.ts
|
|
894
|
+
/** 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. */
|
|
850
895
|
function createGitHubClient(opts) {
|
|
851
896
|
const rest = createGitHubRestClient(opts);
|
|
852
897
|
const graphql = createGitHubGraphQLApiClient(opts);
|
|
@@ -855,6 +900,8 @@ function createGitHubClient(opts) {
|
|
|
855
900
|
checks: checks(rest),
|
|
856
901
|
environments: environments(rest),
|
|
857
902
|
git: git(rest),
|
|
903
|
+
/** The GraphQL client, for the callers whose API (Projects v2) has no REST form. */
|
|
904
|
+
graphql,
|
|
858
905
|
issues: issues(rest),
|
|
859
906
|
labels: labels(rest),
|
|
860
907
|
pages: pages(rest),
|
|
@@ -871,4 +918,4 @@ function createGitHubClient(opts) {
|
|
|
871
918
|
workflows: workflows(rest)
|
|
872
919
|
};
|
|
873
920
|
}
|
|
874
|
-
export { MAX_CHECK_RUN_ANNOTATIONS, createAppJWT, createGitHubClient, createInstallationClient, getInstallationAccessToken, parseGitHubWebhookHeaders, verifyGitHubWebhookSignature };
|
|
921
|
+
export { MAX_CHECK_RUN_ANNOTATIONS, createAppJWT, createGitHubClient, createInstallationClient, getInstallationAccessToken, 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.10",
|
|
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.10",
|
|
36
|
+
"@theholocron/observability": "^0.7.0-alpha.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^26",
|
|
40
40
|
"@vitest/coverage-v8": "^5.0.5",
|
|
41
|
-
"@vitest/eslint-plugin": "^1.6.
|
|
42
|
-
"eslint": "^10.
|
|
43
|
-
"eslint-plugin-n": "^18.
|
|
44
|
-
"globals": "^17.
|
|
45
|
-
"tsdown": "^0.23.
|
|
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.4",
|
|
46
46
|
"typescript": "^5.9.3",
|
|
47
47
|
"vitest": "^5.0.5",
|
|
48
|
-
"@theholocron/tsconfig": "^8.9.0-alpha.
|
|
49
|
-
"@theholocron/
|
|
50
|
-
"@theholocron/
|
|
51
|
-
"@theholocron/vitest-config": "^8.9.0-alpha.
|
|
48
|
+
"@theholocron/tsconfig": "^8.9.0-alpha.8",
|
|
49
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.8",
|
|
50
|
+
"@theholocron/eslint-config": "^8.9.0-alpha.8",
|
|
51
|
+
"@theholocron/vitest-config": "^8.9.0-alpha.8"
|
|
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
|
}
|