@theholocron/github-client 1.58.0-alpha.3 → 1.58.0-alpha.8
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 +247 -1
- package/dist/index.mjs +3 -0
- 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,90 +239,150 @@ 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;
|
|
@@ -249,11 +394,17 @@ interface RepoPropertyValue {
|
|
|
249
394
|
/** A string, a string array for `multi_select`, or `null` when unset. */
|
|
250
395
|
value: string | string[] | null;
|
|
251
396
|
}
|
|
397
|
+
/** A pull request as GitHub returns it, with only the fields this client reads. */
|
|
252
398
|
interface GitHubPullRequest {
|
|
399
|
+
/** The pull request's number. */
|
|
253
400
|
number: number;
|
|
401
|
+
/** The pull request's title. */
|
|
254
402
|
title: string;
|
|
403
|
+
/** Whether the pull request is open or closed. */
|
|
255
404
|
state: "open" | "closed";
|
|
405
|
+
/** When the pull request was merged as an ISO 8601 timestamp, or `null` if it was not merged. */
|
|
256
406
|
merged_at: string | null;
|
|
407
|
+
/** The URL of the pull request's page on GitHub. */
|
|
257
408
|
html_url: string;
|
|
258
409
|
/** The head branch: its name and the commit it pointed at when the PR was read. */
|
|
259
410
|
head: {
|
|
@@ -270,10 +421,15 @@ interface GitHubCommitIdentity {
|
|
|
270
421
|
}
|
|
271
422
|
/** One commit as returned by `GET /pulls/{pull_number}/commits` — only the fields any known consumer needs. */
|
|
272
423
|
interface GitHubPullRequestCommit {
|
|
424
|
+
/** The commit's SHA. */
|
|
273
425
|
sha: string;
|
|
426
|
+
/** The commit's message and git identities. */
|
|
274
427
|
commit: {
|
|
428
|
+
/** The commit message. */
|
|
275
429
|
message: string;
|
|
430
|
+
/** The commit's author, as git recorded it. */
|
|
276
431
|
author: GitHubCommitIdentity;
|
|
432
|
+
/** The commit's committer, as git recorded it. */
|
|
277
433
|
committer: GitHubCommitIdentity;
|
|
278
434
|
};
|
|
279
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). */
|
|
@@ -288,7 +444,9 @@ interface GitHubPullRequestCommit {
|
|
|
288
444
|
}
|
|
289
445
|
/** One file as returned by `GET /pulls/{pull_number}/files` — only the fields any known consumer needs. */
|
|
290
446
|
interface GitHubPullRequestFile {
|
|
447
|
+
/** The file's path in the repository. */
|
|
291
448
|
filename: string;
|
|
449
|
+
/** How the pull request changes the file. */
|
|
292
450
|
status: "added" | "removed" | "modified" | "renamed" | "copied" | "changed" | "unchanged";
|
|
293
451
|
/** Set only when `status === "renamed"`. */
|
|
294
452
|
previous_filename?: string;
|
|
@@ -308,8 +466,10 @@ interface CreateReviewComment {
|
|
|
308
466
|
line: number;
|
|
309
467
|
/** Almost always `"RIGHT"` (the PR's own new content) — `"LEFT"` targets the base/pre-PR version instead. */
|
|
310
468
|
side: "LEFT" | "RIGHT";
|
|
469
|
+
/** The comment text. */
|
|
311
470
|
body: string;
|
|
312
471
|
}
|
|
472
|
+
/** The body of a review creation request. */
|
|
313
473
|
interface CreateReviewInput {
|
|
314
474
|
/** The PR's head SHA the review attaches to. */
|
|
315
475
|
commit_id: string;
|
|
@@ -322,11 +482,14 @@ interface CreateReviewInput {
|
|
|
322
482
|
* required-approval counts and dismissal.
|
|
323
483
|
*/
|
|
324
484
|
event: "COMMENT" | "REQUEST_CHANGES" | "APPROVE";
|
|
485
|
+
/** Inline comments to post with the review. */
|
|
325
486
|
comments?: CreateReviewComment[];
|
|
326
487
|
}
|
|
327
488
|
/** `POST /pulls/{pull_number}/reviews`'s response — only the fields any known consumer needs. */
|
|
328
489
|
interface GitHubPullRequestReview {
|
|
490
|
+
/** The review's numeric id. */
|
|
329
491
|
id: number;
|
|
492
|
+
/** The URL of the review on GitHub. */
|
|
330
493
|
html_url: string;
|
|
331
494
|
}
|
|
332
495
|
/**
|
|
@@ -337,7 +500,9 @@ interface GitHubPullRequestReview {
|
|
|
337
500
|
* never compare it against a REST-sourced ID.
|
|
338
501
|
*/
|
|
339
502
|
interface ReviewThread {
|
|
503
|
+
/** The thread's GraphQL node id. */
|
|
340
504
|
id: string;
|
|
505
|
+
/** Whether the thread is resolved. */
|
|
341
506
|
isResolved: boolean;
|
|
342
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. */
|
|
343
508
|
authorLogin: string | undefined;
|
|
@@ -355,8 +520,11 @@ interface ReviewThread {
|
|
|
355
520
|
*/
|
|
356
521
|
body: string | undefined;
|
|
357
522
|
}
|
|
523
|
+
/** A repository as GitHub returns it, with only the fields this client reads. */
|
|
358
524
|
interface GitHubRepo {
|
|
525
|
+
/** The name of the repository's default branch. */
|
|
359
526
|
default_branch: string;
|
|
527
|
+
/** The repository's `owner/name`. */
|
|
360
528
|
full_name: string;
|
|
361
529
|
/** The repository description. */
|
|
362
530
|
description?: string | null;
|
|
@@ -389,13 +557,20 @@ interface GitHubRepo {
|
|
|
389
557
|
status: string;
|
|
390
558
|
} | undefined> | null;
|
|
391
559
|
}
|
|
560
|
+
/** A file's contents as the contents API returns them. */
|
|
392
561
|
interface GitHubContents {
|
|
562
|
+
/** The file content, encoded as named by `encoding`. */
|
|
393
563
|
content: string;
|
|
564
|
+
/** The encoding of `content`, normally `base64`. */
|
|
394
565
|
encoding: string;
|
|
395
566
|
}
|
|
567
|
+
/** A repository ruleset in summary form. */
|
|
396
568
|
interface GitHubRuleset {
|
|
569
|
+
/** The ruleset's numeric id. */
|
|
397
570
|
id: number;
|
|
571
|
+
/** The ruleset's name. */
|
|
398
572
|
name: string;
|
|
573
|
+
/** How the ruleset is enforced, e.g. `active`, `evaluate` or `disabled`. */
|
|
399
574
|
enforcement: string;
|
|
400
575
|
}
|
|
401
576
|
/** One ruleset in full, as `GET /repos/{repo}/rulesets/{id}` returns it. */
|
|
@@ -408,6 +583,7 @@ interface GitHubRulesetDetail extends GitHubRuleset {
|
|
|
408
583
|
parameters?: Record<string, unknown>;
|
|
409
584
|
}>;
|
|
410
585
|
}
|
|
586
|
+
/** Where a secret lives: the repository, one of its environments, or an organization. */
|
|
411
587
|
type SecretScope = {
|
|
412
588
|
kind: "repo";
|
|
413
589
|
} | {
|
|
@@ -417,14 +593,21 @@ type SecretScope = {
|
|
|
417
593
|
kind: "organization";
|
|
418
594
|
org: string;
|
|
419
595
|
};
|
|
596
|
+
/** A public key used to encrypt a secret before it is sent. */
|
|
420
597
|
interface GitHubPublicKey {
|
|
598
|
+
/** The key's id, sent back with the encrypted secret. */
|
|
421
599
|
key_id: string;
|
|
600
|
+
/** The Base64-encoded public key. */
|
|
422
601
|
key: string;
|
|
423
602
|
}
|
|
603
|
+
/** The workflow run that a code scanning setup started. */
|
|
424
604
|
interface CodeScanningSetupResult {
|
|
605
|
+
/** The id of the workflow run. */
|
|
425
606
|
run_id: number;
|
|
607
|
+
/** The URL of the workflow run. */
|
|
426
608
|
run_url: string;
|
|
427
609
|
}
|
|
610
|
+
/** A permission level a team can hold on a repository. */
|
|
428
611
|
type TeamPermission = "pull" | "triage" | "push" | "maintain" | "admin";
|
|
429
612
|
/** A team with access to a repository, and the permission it has there. */
|
|
430
613
|
interface RepoTeam {
|
|
@@ -435,10 +618,14 @@ interface RepoTeam {
|
|
|
435
618
|
}
|
|
436
619
|
/** A member of a team, as GitHub lists it. `id` is the numeric user id, which survives a rename; `login` does not. */
|
|
437
620
|
interface TeamMember {
|
|
621
|
+
/** The member's numeric user id. */
|
|
438
622
|
id: number;
|
|
623
|
+
/** The member's login. */
|
|
439
624
|
login: string;
|
|
625
|
+
/** The kind of account, e.g. `User`. */
|
|
440
626
|
type?: string;
|
|
441
627
|
}
|
|
628
|
+
/** Where a variable lives: the repository, one of its environments, or an organization. */
|
|
442
629
|
type VariableScope = {
|
|
443
630
|
kind: "repo";
|
|
444
631
|
} | {
|
|
@@ -455,14 +642,20 @@ type VariableScope = {
|
|
|
455
642
|
type VariableVisibility = "all" | "private" | "selected";
|
|
456
643
|
/** A GitHub Actions variable. Unlike a secret its value is readable, so a reconcile can tell whether it differs. */
|
|
457
644
|
interface GitHubVariable {
|
|
645
|
+
/** The variable's name. */
|
|
458
646
|
name: string;
|
|
647
|
+
/** The variable's value. */
|
|
459
648
|
value: string;
|
|
460
649
|
/** Present on organization variables only. */
|
|
461
650
|
visibility?: VariableVisibility;
|
|
462
651
|
}
|
|
652
|
+
/** The authenticated user, with only the fields this client reads. */
|
|
463
653
|
interface GitHubUser {
|
|
654
|
+
/** The user's login. */
|
|
464
655
|
login: string;
|
|
656
|
+
/** The user's display name, or `null` when not set. */
|
|
465
657
|
name: string | null;
|
|
658
|
+
/** The user's public email, or `null` when not set. */
|
|
466
659
|
email: string | null;
|
|
467
660
|
}
|
|
468
661
|
/** The authenticated user and, for a token that expires, when. */
|
|
@@ -477,30 +670,48 @@ interface GitHubUserWithExpiry {
|
|
|
477
670
|
* ISO 8601, or `undefined` when the header is missing or is not a date.
|
|
478
671
|
*/
|
|
479
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. */
|
|
480
674
|
interface GitHubWorkflowRun {
|
|
675
|
+
/** The run's numeric id. */
|
|
481
676
|
id: number;
|
|
677
|
+
/** The workflow's name, or `null` when unnamed. */
|
|
482
678
|
name: string | null;
|
|
679
|
+
/** The run's display title. */
|
|
483
680
|
display_title: string;
|
|
681
|
+
/** The branch the run was triggered on. */
|
|
484
682
|
head_branch: string;
|
|
683
|
+
/** The commit SHA the run was triggered on. */
|
|
485
684
|
head_sha: string;
|
|
685
|
+
/** The run's status, e.g. `queued`, `in_progress` or `completed`. */
|
|
486
686
|
status: string;
|
|
687
|
+
/** The run's result once completed, or `null` before. */
|
|
487
688
|
conclusion: string | null;
|
|
689
|
+
/** The URL of the run's page on GitHub. */
|
|
488
690
|
html_url: string;
|
|
691
|
+
/** When the run was created, as an ISO 8601 timestamp. */
|
|
489
692
|
created_at: string;
|
|
693
|
+
/** When the run was last updated, as an ISO 8601 timestamp. */
|
|
490
694
|
updated_at: string;
|
|
491
695
|
}
|
|
696
|
+
/** Filters for listing workflow runs. */
|
|
492
697
|
interface WorkflowRunFilter {
|
|
698
|
+
/** Only runs on this branch. */
|
|
493
699
|
branch?: string;
|
|
700
|
+
/** The maximum number of runs to return. */
|
|
494
701
|
limit?: number;
|
|
702
|
+
/** Only runs with this status. */
|
|
495
703
|
status?: string;
|
|
496
704
|
}
|
|
705
|
+
/** The credentials identifying a GitHub App: its id and private key. */
|
|
497
706
|
interface GitHubAppCredentials {
|
|
498
707
|
/** The App's numeric id (not the client id). */
|
|
499
708
|
appId: string;
|
|
500
709
|
/** PEM-encoded RSA private key — PKCS#1 (GitHub's default download format) or PKCS#8, either works. */
|
|
501
710
|
privateKey: string;
|
|
502
711
|
}
|
|
712
|
+
/** A short-lived installation access token and when it expires. */
|
|
503
713
|
interface InstallationAccessToken {
|
|
714
|
+
/** The installation access token, used as a bearer token for the REST API. */
|
|
504
715
|
token: string;
|
|
505
716
|
/** ISO 8601 — installation tokens are short-lived, about an hour. */
|
|
506
717
|
expiresAt: string;
|
|
@@ -550,6 +761,7 @@ export declare function verifyGitHubWebhookSignature(input: {
|
|
|
550
761
|
signature: string | undefined;
|
|
551
762
|
secret: string;
|
|
552
763
|
}): boolean;
|
|
764
|
+
/** The three GitHub webhook headers a consumer needs. */
|
|
553
765
|
interface GitHubWebhookHeaders {
|
|
554
766
|
/** `X-GitHub-Event` — the event category, e.g. `"push"`, `"pull_request"`. */
|
|
555
767
|
event: string | undefined;
|
|
@@ -560,31 +772,62 @@ interface GitHubWebhookHeaders {
|
|
|
560
772
|
}
|
|
561
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). */
|
|
562
774
|
export declare function parseGitHubWebhookHeaders(headers: Record<string, string | string[] | undefined>): GitHubWebhookHeaders;
|
|
775
|
+
/** The payload of an `installation` webhook delivery. */
|
|
563
776
|
interface GitHubInstallationWebhookPayload {
|
|
777
|
+
/** What happened to the installation, e.g. `created` or `deleted`. */
|
|
564
778
|
action: string;
|
|
779
|
+
/** The installation the delivery is about. */
|
|
565
780
|
installation: {
|
|
781
|
+
/** The installation id. */
|
|
566
782
|
id: number;
|
|
567
783
|
};
|
|
568
784
|
}
|
|
785
|
+
/** The payload of a `push` webhook delivery. */
|
|
569
786
|
interface GitHubPushWebhookPayload {
|
|
787
|
+
/** The full name of the pushed ref, e.g. `refs/heads/main`. */
|
|
570
788
|
ref: string;
|
|
789
|
+
/** The installation the delivery is about, when sent. */
|
|
571
790
|
installation?: {
|
|
791
|
+
/** The installation id. */
|
|
572
792
|
id: number;
|
|
573
793
|
};
|
|
794
|
+
/** The repository that was pushed to. */
|
|
574
795
|
repository: {
|
|
796
|
+
/** The repository's owner/name. */
|
|
575
797
|
full_name: string;
|
|
798
|
+
/** The name of the default branch. */
|
|
576
799
|
default_branch: string;
|
|
577
800
|
};
|
|
578
801
|
}
|
|
802
|
+
/** The payload of a `pull_request` webhook delivery. */
|
|
579
803
|
interface GitHubPullRequestWebhookPayload {
|
|
804
|
+
/** What happened to the pull request, e.g. `opened` or `closed`. */
|
|
580
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. */
|
|
581
820
|
installation?: {
|
|
821
|
+
/** The installation id. */
|
|
582
822
|
id: number;
|
|
583
823
|
};
|
|
824
|
+
/** The repository the pull request belongs to. */
|
|
584
825
|
repository: {
|
|
826
|
+
/** The repository's owner/name. */
|
|
585
827
|
full_name: string;
|
|
586
828
|
};
|
|
587
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. */
|
|
588
831
|
export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
589
832
|
branches: {
|
|
590
833
|
protectBranch: (repo: string, branch: string, payload: Record<string, unknown>) => Promise<void>;
|
|
@@ -618,6 +861,8 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
618
861
|
updateRef: (repo: string, ref: string, sha: string, force?: boolean) => Promise<GitRef>;
|
|
619
862
|
createPull: (repo: string, input: CreatePullInput) => Promise<GitPull>;
|
|
620
863
|
};
|
|
864
|
+
/** The GraphQL client, for the callers whose API (Projects v2) has no REST form. */
|
|
865
|
+
graphql: GraphQLClient;
|
|
621
866
|
issues: {
|
|
622
867
|
listIssues: (repo: string, params?: IssueSearchParams) => Promise<GitHubIssue[]>;
|
|
623
868
|
getIssue: (repo: string, number: number) => Promise<GitHubIssue>;
|
|
@@ -717,5 +962,6 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
717
962
|
createWorkflowDispatch: (repo: string, workflowFile: string, ref: string, inputs?: Record<string, string>) => Promise<void>;
|
|
718
963
|
};
|
|
719
964
|
};
|
|
965
|
+
/** The client returned by `createGitHubClient()`: one group of methods per GitHub API area. */
|
|
720
966
|
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 };
|
|
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
|
@@ -891,6 +891,7 @@ function parseGitHubWebhookHeaders(headers) {
|
|
|
891
891
|
};
|
|
892
892
|
}
|
|
893
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. */
|
|
894
895
|
function createGitHubClient(opts) {
|
|
895
896
|
const rest = createGitHubRestClient(opts);
|
|
896
897
|
const graphql = createGitHubGraphQLApiClient(opts);
|
|
@@ -899,6 +900,8 @@ function createGitHubClient(opts) {
|
|
|
899
900
|
checks: checks(rest),
|
|
900
901
|
environments: environments(rest),
|
|
901
902
|
git: git(rest),
|
|
903
|
+
/** The GraphQL client, for the callers whose API (Projects v2) has no REST form. */
|
|
904
|
+
graphql,
|
|
902
905
|
issues: issues(rest),
|
|
903
906
|
labels: labels(rest),
|
|
904
907
|
pages: pages(rest),
|
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.8",
|
|
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/
|
|
36
|
-
"@theholocron/
|
|
35
|
+
"@theholocron/observability": "^0.7.0-alpha.1",
|
|
36
|
+
"@theholocron/http-client": "^1.58.0-alpha.8"
|
|
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/eslint-config": "^8.9.0-alpha.
|
|
49
|
-
"@theholocron/
|
|
50
|
-
"@theholocron/
|
|
51
|
-
"@theholocron/vitest-config": "^8.9.0-alpha.
|
|
48
|
+
"@theholocron/eslint-config": "^8.9.0-alpha.8",
|
|
49
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.8",
|
|
50
|
+
"@theholocron/tsconfig": "^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
|
}
|