@theholocron/github-client 1.58.0-alpha.2 → 1.58.0-alpha.20

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 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,99 +265,204 @@ 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;
445
+ }
446
+ /** One custom property value set on a repository. */
447
+ interface RepoPropertyValue {
448
+ /** The property's name. */
449
+ property_name: string;
450
+ /** A string, a string array for `multi_select`, or `null` when unset. */
451
+ value: string | string[] | null;
244
452
  }
453
+ /** A pull request as GitHub returns it, with only the fields this client reads. */
245
454
  interface GitHubPullRequest {
455
+ /** The pull request's number. */
246
456
  number: number;
457
+ /** The pull request's title. */
247
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. */
248
462
  state: "open" | "closed";
463
+ /** When the pull request was merged as an ISO 8601 timestamp, or `null` if it was not merged. */
249
464
  merged_at: string | null;
465
+ /** The URL of the pull request's page on GitHub. */
250
466
  html_url: string;
251
467
  /** The head branch: its name and the commit it pointed at when the PR was read. */
252
468
  head: {
@@ -255,6 +471,40 @@ interface GitHubPullRequest {
255
471
  /** The head commit. */
256
472
  sha: string;
257
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;
258
508
  }
259
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). */
260
510
  interface GitHubCommitIdentity {
@@ -263,10 +513,15 @@ interface GitHubCommitIdentity {
263
513
  }
264
514
  /** One commit as returned by `GET /pulls/{pull_number}/commits` — only the fields any known consumer needs. */
265
515
  interface GitHubPullRequestCommit {
516
+ /** The commit's SHA. */
266
517
  sha: string;
518
+ /** The commit's message and git identities. */
267
519
  commit: {
520
+ /** The commit message. */
268
521
  message: string;
522
+ /** The commit's author, as git recorded it. */
269
523
  author: GitHubCommitIdentity;
524
+ /** The commit's committer, as git recorded it. */
270
525
  committer: GitHubCommitIdentity;
271
526
  };
272
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). */
@@ -281,7 +536,9 @@ interface GitHubPullRequestCommit {
281
536
  }
282
537
  /** One file as returned by `GET /pulls/{pull_number}/files` — only the fields any known consumer needs. */
283
538
  interface GitHubPullRequestFile {
539
+ /** The file's path in the repository. */
284
540
  filename: string;
541
+ /** How the pull request changes the file. */
285
542
  status: "added" | "removed" | "modified" | "renamed" | "copied" | "changed" | "unchanged";
286
543
  /** Set only when `status === "renamed"`. */
287
544
  previous_filename?: string;
@@ -301,8 +558,10 @@ interface CreateReviewComment {
301
558
  line: number;
302
559
  /** Almost always `"RIGHT"` (the PR's own new content) — `"LEFT"` targets the base/pre-PR version instead. */
303
560
  side: "LEFT" | "RIGHT";
561
+ /** The comment text. */
304
562
  body: string;
305
563
  }
564
+ /** The body of a review creation request. */
306
565
  interface CreateReviewInput {
307
566
  /** The PR's head SHA the review attaches to. */
308
567
  commit_id: string;
@@ -315,12 +574,21 @@ interface CreateReviewInput {
315
574
  * required-approval counts and dismissal.
316
575
  */
317
576
  event: "COMMENT" | "REQUEST_CHANGES" | "APPROVE";
577
+ /** Inline comments to post with the review. */
318
578
  comments?: CreateReviewComment[];
319
579
  }
320
580
  /** `POST /pulls/{pull_number}/reviews`'s response — only the fields any known consumer needs. */
321
581
  interface GitHubPullRequestReview {
582
+ /** The review's numeric id. */
322
583
  id: number;
584
+ /** The URL of the review on GitHub. */
323
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;
324
592
  }
325
593
  /**
326
594
  * One review thread — GraphQL-only (`resolveReviewThread`, the mutation
@@ -330,7 +598,9 @@ interface GitHubPullRequestReview {
330
598
  * never compare it against a REST-sourced ID.
331
599
  */
332
600
  interface ReviewThread {
601
+ /** The thread's GraphQL node id. */
333
602
  id: string;
603
+ /** Whether the thread is resolved. */
334
604
  isResolved: boolean;
335
605
  /** 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
606
  authorLogin: string | undefined;
@@ -348,19 +618,72 @@ interface ReviewThread {
348
618
  */
349
619
  body: string | undefined;
350
620
  }
621
+ /** A repository as GitHub returns it, with only the fields this client reads. */
351
622
  interface GitHubRepo {
623
+ /** The name of the repository's default branch. */
352
624
  default_branch: string;
625
+ /** The repository's `owner/name`. */
353
626
  full_name: string;
627
+ /** Whether the repository is archived (read-only). */
628
+ archived?: boolean;
629
+ /** The repository description. */
630
+ description?: string | null;
631
+ /** The repository homepage URL. */
632
+ homepage?: string | null;
633
+ /** The topics set on the repository. */
634
+ topics?: string[];
635
+ /** Whether squash merging is allowed. */
636
+ allow_squash_merge?: boolean;
637
+ /** Whether merge commits are allowed. */
638
+ allow_merge_commit?: boolean;
639
+ /** Whether rebase merging is allowed. */
640
+ allow_rebase_merge?: boolean;
641
+ /** Whether auto-merge is allowed. */
642
+ allow_auto_merge?: boolean;
643
+ /** Whether a pull request branch can be updated from its base. */
644
+ allow_update_branch?: boolean;
645
+ /** Whether a merged pull request's branch is deleted. */
646
+ delete_branch_on_merge?: boolean;
647
+ /** Whether issues are enabled. */
648
+ has_issues?: boolean;
649
+ /** Whether discussions are enabled. */
650
+ has_discussions?: boolean;
651
+ /** Whether projects are enabled. */
652
+ has_projects?: boolean;
653
+ /** Whether the wiki is enabled. */
654
+ has_wiki?: boolean;
655
+ /** Each feature's `status` (`enabled` / `disabled`). Only an admin token sees it; absent for the rest. */
656
+ security_and_analysis?: Record<string, {
657
+ status: string;
658
+ } | undefined> | null;
354
659
  }
660
+ /** A file's contents as the contents API returns them. */
355
661
  interface GitHubContents {
662
+ /** The file content, encoded as named by `encoding`. */
356
663
  content: string;
664
+ /** The encoding of `content`, normally `base64`. */
357
665
  encoding: string;
358
666
  }
667
+ /** A repository ruleset in summary form. */
359
668
  interface GitHubRuleset {
669
+ /** The ruleset's numeric id. */
360
670
  id: number;
671
+ /** The ruleset's name. */
361
672
  name: string;
673
+ /** How the ruleset is enforced, e.g. `active`, `evaluate` or `disabled`. */
362
674
  enforcement: string;
363
675
  }
676
+ /** One ruleset in full, as `GET /repos/{repo}/rulesets/{id}` returns it. */
677
+ interface GitHubRulesetDetail extends GitHubRuleset {
678
+ /** What the ruleset applies to, e.g. `branch`. */
679
+ target?: string;
680
+ /** Each rule has a `type`; some carry `parameters`. */
681
+ rules?: Array<{
682
+ type: string;
683
+ parameters?: Record<string, unknown>;
684
+ }>;
685
+ }
686
+ /** Where a secret lives: the repository, one of its environments, or an organization. */
364
687
  type SecretScope = {
365
688
  kind: "repo";
366
689
  } | {
@@ -370,21 +693,39 @@ type SecretScope = {
370
693
  kind: "organization";
371
694
  org: string;
372
695
  };
696
+ /** A public key used to encrypt a secret before it is sent. */
373
697
  interface GitHubPublicKey {
698
+ /** The key's id, sent back with the encrypted secret. */
374
699
  key_id: string;
700
+ /** The Base64-encoded public key. */
375
701
  key: string;
376
702
  }
703
+ /** The workflow run that a code scanning setup started. */
377
704
  interface CodeScanningSetupResult {
705
+ /** The id of the workflow run. */
378
706
  run_id: number;
707
+ /** The URL of the workflow run. */
379
708
  run_url: string;
380
709
  }
710
+ /** A permission level a team can hold on a repository. */
381
711
  type TeamPermission = "pull" | "triage" | "push" | "maintain" | "admin";
712
+ /** A team with access to a repository, and the permission it has there. */
713
+ interface RepoTeam {
714
+ /** The team's slug. */
715
+ slug: string;
716
+ /** The team's permission on the repository. */
717
+ permission: TeamPermission;
718
+ }
382
719
  /** A member of a team, as GitHub lists it. `id` is the numeric user id, which survives a rename; `login` does not. */
383
720
  interface TeamMember {
721
+ /** The member's numeric user id. */
384
722
  id: number;
723
+ /** The member's login. */
385
724
  login: string;
725
+ /** The kind of account, e.g. `User`. */
386
726
  type?: string;
387
727
  }
728
+ /** Where a variable lives: the repository, one of its environments, or an organization. */
388
729
  type VariableScope = {
389
730
  kind: "repo";
390
731
  } | {
@@ -401,14 +742,20 @@ type VariableScope = {
401
742
  type VariableVisibility = "all" | "private" | "selected";
402
743
  /** A GitHub Actions variable. Unlike a secret its value is readable, so a reconcile can tell whether it differs. */
403
744
  interface GitHubVariable {
745
+ /** The variable's name. */
404
746
  name: string;
747
+ /** The variable's value. */
405
748
  value: string;
406
749
  /** Present on organization variables only. */
407
750
  visibility?: VariableVisibility;
408
751
  }
752
+ /** The authenticated user, with only the fields this client reads. */
409
753
  interface GitHubUser {
754
+ /** The user's login. */
410
755
  login: string;
756
+ /** The user's display name, or `null` when not set. */
411
757
  name: string | null;
758
+ /** The user's public email, or `null` when not set. */
412
759
  email: string | null;
413
760
  }
414
761
  /** The authenticated user and, for a token that expires, when. */
@@ -423,30 +770,48 @@ interface GitHubUserWithExpiry {
423
770
  * ISO 8601, or `undefined` when the header is missing or is not a date.
424
771
  */
425
772
  export declare function parseTokenExpiration(header: string | null): string | undefined;
773
+ /** A workflow run as GitHub returns it, with only the fields this client reads. */
426
774
  interface GitHubWorkflowRun {
775
+ /** The run's numeric id. */
427
776
  id: number;
777
+ /** The workflow's name, or `null` when unnamed. */
428
778
  name: string | null;
779
+ /** The run's display title. */
429
780
  display_title: string;
781
+ /** The branch the run was triggered on. */
430
782
  head_branch: string;
783
+ /** The commit SHA the run was triggered on. */
431
784
  head_sha: string;
785
+ /** The run's status, e.g. `queued`, `in_progress` or `completed`. */
432
786
  status: string;
787
+ /** The run's result once completed, or `null` before. */
433
788
  conclusion: string | null;
789
+ /** The URL of the run's page on GitHub. */
434
790
  html_url: string;
791
+ /** When the run was created, as an ISO 8601 timestamp. */
435
792
  created_at: string;
793
+ /** When the run was last updated, as an ISO 8601 timestamp. */
436
794
  updated_at: string;
437
795
  }
796
+ /** Filters for listing workflow runs. */
438
797
  interface WorkflowRunFilter {
798
+ /** Only runs on this branch. */
439
799
  branch?: string;
800
+ /** The maximum number of runs to return. */
440
801
  limit?: number;
802
+ /** Only runs with this status. */
441
803
  status?: string;
442
804
  }
805
+ /** The credentials identifying a GitHub App: its id and private key. */
443
806
  interface GitHubAppCredentials {
444
807
  /** The App's numeric id (not the client id). */
445
808
  appId: string;
446
809
  /** PEM-encoded RSA private key — PKCS#1 (GitHub's default download format) or PKCS#8, either works. */
447
810
  privateKey: string;
448
811
  }
812
+ /** A short-lived installation access token and when it expires. */
449
813
  interface InstallationAccessToken {
814
+ /** The installation access token, used as a bearer token for the REST API. */
450
815
  token: string;
451
816
  /** ISO 8601 — installation tokens are short-lived, about an hour. */
452
817
  expiresAt: string;
@@ -466,6 +831,41 @@ export declare function createAppJWT(creds: GitHubAppCredentials, now?: number):
466
831
  export declare function getInstallationAccessToken(creds: GitHubAppCredentials, installationId: number, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<InstallationAccessToken>;
467
832
  /** The whole flow in one call — an already-authenticated `GitHubClient` scoped to one installation. */
468
833
  export declare function createInstallationClient(creds: GitHubAppCredentials, installationId: number, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubClient>;
834
+ /** The account an App or one of its installations belongs to. */
835
+ interface GitHubAppAccount {
836
+ /** The user or organization login. */
837
+ login: string;
838
+ /** `User` or `Organization` (GitHub also reports `Enterprise` for an enterprise-owned App). */
839
+ type: string;
840
+ }
841
+ /** An App as `GET /app` reports it. */
842
+ interface GitHubApp {
843
+ /** The App's URL name, as in `github.com/apps/<slug>`. */
844
+ slug: string;
845
+ /** The App's display name. */
846
+ name: string;
847
+ /** Who owns the App: decides which settings page its permissions live on. */
848
+ owner: GitHubAppAccount | null;
849
+ /** The permissions the App asks for now: name to `read`, `write` or `admin`. */
850
+ permissions: Record<string, string>;
851
+ /** The webhook events the App is subscribed to now. */
852
+ events: string[];
853
+ }
854
+ /** One installation of an App as `GET /app/installations` reports it. */
855
+ interface GitHubAppInstallation {
856
+ /** The installation id. */
857
+ id: number;
858
+ /** The account the App is installed on. */
859
+ account: GitHubAppAccount | null;
860
+ /** What this installation has accepted: it lags the App's own list until an owner accepts a new request. */
861
+ permissions: Record<string, string>;
862
+ /** The events delivered to this installation. */
863
+ events: string[];
864
+ }
865
+ /** The App this JWT identifies: its slug, owner and the permissions and events it asks for now. */
866
+ export declare function getApp(creds: GitHubAppCredentials, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubApp>;
867
+ /** Every installation of the App this JWT identifies, with what each has accepted. Reads all pages. */
868
+ export declare function listAppInstallations(creds: GitHubAppCredentials, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubAppInstallation[]>;
469
869
  /**
470
870
  * GitHub's own webhook mechanics — signature verification and header/
471
871
  * payload shapes. Pure functions, no REST call, no auth token: these
@@ -496,6 +896,7 @@ export declare function verifyGitHubWebhookSignature(input: {
496
896
  signature: string | undefined;
497
897
  secret: string;
498
898
  }): boolean;
899
+ /** The three GitHub webhook headers a consumer needs. */
499
900
  interface GitHubWebhookHeaders {
500
901
  /** `X-GitHub-Event` — the event category, e.g. `"push"`, `"pull_request"`. */
501
902
  event: string | undefined;
@@ -506,31 +907,62 @@ interface GitHubWebhookHeaders {
506
907
  }
507
908
  /** Extracts GitHub's three webhook headers, case-insensitively (Node's raw headers may arrive lower-cased, or as an array when a header repeats). */
508
909
  export declare function parseGitHubWebhookHeaders(headers: Record<string, string | string[] | undefined>): GitHubWebhookHeaders;
910
+ /** The payload of an `installation` webhook delivery. */
509
911
  interface GitHubInstallationWebhookPayload {
912
+ /** What happened to the installation, e.g. `created` or `deleted`. */
510
913
  action: string;
914
+ /** The installation the delivery is about. */
511
915
  installation: {
916
+ /** The installation id. */
512
917
  id: number;
513
918
  };
514
919
  }
920
+ /** The payload of a `push` webhook delivery. */
515
921
  interface GitHubPushWebhookPayload {
922
+ /** The full name of the pushed ref, e.g. `refs/heads/main`. */
516
923
  ref: string;
924
+ /** The installation the delivery is about, when sent. */
517
925
  installation?: {
926
+ /** The installation id. */
518
927
  id: number;
519
928
  };
929
+ /** The repository that was pushed to. */
520
930
  repository: {
931
+ /** The repository's owner/name. */
521
932
  full_name: string;
933
+ /** The name of the default branch. */
522
934
  default_branch: string;
523
935
  };
524
936
  }
937
+ /** The payload of a `pull_request` webhook delivery. */
525
938
  interface GitHubPullRequestWebhookPayload {
939
+ /** What happened to the pull request, e.g. `opened` or `closed`. */
526
940
  action: string;
941
+ /** For an `edited` action, the fields that changed (each holds the previous value); absent for other actions. */
942
+ changes?: {
943
+ /** Present when the title was edited. */
944
+ title?: {
945
+ /** The title before the edit. */
946
+ from: string;
947
+ };
948
+ /** Present when the description was edited. */
949
+ body?: {
950
+ /** The description before the edit; `null` when it was empty. */
951
+ from: string | null;
952
+ };
953
+ };
954
+ /** The installation the delivery is about, when sent. */
527
955
  installation?: {
956
+ /** The installation id. */
528
957
  id: number;
529
958
  };
959
+ /** The repository the pull request belongs to. */
530
960
  repository: {
961
+ /** The repository's owner/name. */
531
962
  full_name: string;
532
963
  };
533
964
  }
965
+ /** 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. */
534
966
  export declare function createGitHubClient(opts: GitHubClientOptions): {
535
967
  branches: {
536
968
  protectBranch: (repo: string, branch: string, payload: Record<string, unknown>) => Promise<void>;
@@ -538,6 +970,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
538
970
  removeBranch: (repo: string, branch: string) => Promise<void>;
539
971
  };
540
972
  checks: {
973
+ listCheckRunsForRef: (repo: string, ref: string) => Promise<GitHubCheckRun[]>;
541
974
  createCheckRun: (repo: string, input: CreateCheckRunInput) => Promise<GitHubCheckRun>;
542
975
  updateCheckRun: (repo: string, checkRunId: number, input: UpdateCheckRunInput) => Promise<GitHubCheckRun>;
543
976
  };
@@ -551,6 +984,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
551
984
  getCommit: (repo: string, sha: string) => Promise<GitCommit>;
552
985
  getTree: (repo: string, sha: string, recursive?: boolean) => Promise<GitTree>;
553
986
  getContents: (repo: string, path: string, ref?: string) => Promise<GitContents>;
987
+ listDirectory: (repo: string, path: string, options?: ListDirectoryOptions) => Promise<GitDirectoryEntry[]>;
554
988
  putContents: (repo: string, path: string, input: PutContentsInput) => Promise<PutContentsResult>;
555
989
  createBlob: (repo: string, content: string, encoding?: string) => Promise<GitBlob>;
556
990
  createTree: (repo: string, tree: Array<{
@@ -564,6 +998,8 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
564
998
  updateRef: (repo: string, ref: string, sha: string, force?: boolean) => Promise<GitRef>;
565
999
  createPull: (repo: string, input: CreatePullInput) => Promise<GitPull>;
566
1000
  };
1001
+ /** The GraphQL client, for the callers whose API (Projects v2) has no REST form. */
1002
+ graphql: GraphQLClient;
567
1003
  issues: {
568
1004
  listIssues: (repo: string, params?: IssueSearchParams) => Promise<GitHubIssue[]>;
569
1005
  getIssue: (repo: string, number: number) => Promise<GitHubIssue>;
@@ -572,6 +1008,8 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
572
1008
  addLabels: (repo: string, number: number, labels: string[]) => Promise<void>;
573
1009
  removeLabel: (repo: string, number: number, label: string) => Promise<void>;
574
1010
  createComment: (repo: string, number: number, body: string) => Promise<void>;
1011
+ listComments: (repo: string, number: number) => Promise<GitHubIssueComment[]>;
1012
+ createMilestone: (repo: string, title: string) => Promise<GitHubMilestone>;
575
1013
  listMilestones: (repo: string, params?: {
576
1014
  state?: "open" | "closed" | "all";
577
1015
  }) => Promise<GitHubMilestone[]>;
@@ -595,7 +1033,9 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
595
1033
  updatePages: (repo: string, payload: UpdatePagesPayload) => Promise<void>;
596
1034
  };
597
1035
  properties: {
1036
+ getValues: (repo: string) => Promise<RepoPropertyValue[]>;
598
1037
  orgSchema: (org: string) => Promise<OrgProperty[]>;
1038
+ setOrgProperty: (org: string, property: OrgProperty) => Promise<OrgProperty>;
599
1039
  setProperties: (repo: string, values: Record<string, string | string[]>) => Promise<void>;
600
1040
  };
601
1041
  pulls: {
@@ -603,6 +1043,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
603
1043
  listPullRequests: (repo: string, state: "open" | "closed") => Promise<GitHubPullRequest[]>;
604
1044
  listCommits: (repo: string, number: number) => Promise<GitHubPullRequestCommit[]>;
605
1045
  listFiles: (repo: string, number: number) => Promise<GitHubPullRequestFile[]>;
1046
+ listReviews: (repo: string, number: number) => Promise<GitHubPullRequestReview[]>;
606
1047
  createReview: (repo: string, number: number, input: CreateReviewInput) => Promise<GitHubPullRequestReview>;
607
1048
  listReviewThreads: (repo: string, number: number) => Promise<ReviewThread[]>;
608
1049
  resolveReviewThread: (threadId: string) => Promise<void>;
@@ -613,6 +1054,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
613
1054
  getContents: (repo: string, path: string) => Promise<GitHubContents>;
614
1055
  };
615
1056
  rulesets: {
1057
+ getRuleset: (repo: string, id: number) => Promise<GitHubRulesetDetail>;
616
1058
  listRulesets: (repo: string) => Promise<GitHubRuleset[]>;
617
1059
  createRuleset: (repo: string, payload: Record<string, unknown>) => Promise<GitHubRuleset>;
618
1060
  updateRuleset: (repo: string, id: number, payload: Record<string, unknown>) => Promise<GitHubRuleset>;
@@ -624,6 +1066,10 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
624
1066
  deleteSecret: (repo: string, scope: SecretScope, name: string) => Promise<void>;
625
1067
  };
626
1068
  security: {
1069
+ vulnerabilityAlertsEnabled: (repo: string) => Promise<boolean>;
1070
+ automatedSecurityFixesEnabled: (repo: string) => Promise<boolean>;
1071
+ privateVulnerabilityReportingEnabled: (repo: string) => Promise<boolean>;
1072
+ codeScanningDefaultSetupState: (repo: string) => Promise<string>;
627
1073
  enableVulnerabilityAlerts: (repo: string) => Promise<void>;
628
1074
  enableAutomatedSecurityFixes: (repo: string) => Promise<void>;
629
1075
  enableSecretScanning: (repo: string) => Promise<void>;
@@ -634,6 +1080,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
634
1080
  };
635
1081
  teams: {
636
1082
  members: (org: string, teamSlug: string) => Promise<TeamMember[]>;
1083
+ listForRepo: (repo: string) => Promise<RepoTeam[]>;
637
1084
  addRepo: (org: string, teamSlug: string, owner: string, repo: string, permission: TeamPermission) => Promise<void>;
638
1085
  };
639
1086
  topics: {
@@ -656,5 +1103,6 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
656
1103
  createWorkflowDispatch: (repo: string, workflowFile: string, ref: string, inputs?: Record<string, string>) => Promise<void>;
657
1104
  };
658
1105
  };
1106
+ /** The client returned by `createGitHubClient()`: one group of methods per GitHub API area. */
659
1107
  export type GitHubClient = ReturnType<typeof createGitHubClient>;
660
- 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, GitHubUserWithExpiry, GitHubVariable, GitHubWebhookHeaders, GitHubWorkflowRun, GitPull, GitRef, GitTree, GitTreeItem, InstallationAccessToken, IssueSearchParams, OrgProperty, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdatePagesPayload, VariableScope, VariableVisibility, WorkflowRunFilter };
1108
+ 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, 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);
@@ -293,12 +351,27 @@ function pages(rest) {
293
351
  // src/properties/properties.ts
294
352
  function properties(rest) {
295
353
  return {
354
+ /** The custom property values set on a repository (read-only). */
355
+ getValues: (repo) => rest.request(`${repoBase(repo)}/properties/values`),
296
356
  /**
297
357
  * The custom properties an organization defines, with their types and allowed values (read-only).
298
358
  * The token needs read access to the organization's custom properties.
299
359
  */
300
360
  orgSchema: (org) => rest.request(`/orgs/${segment(org)}/properties/schema`),
301
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
+ /**
302
375
  * `value` is a plain string for `string`/`single_select`/`true_false`
303
376
  * custom properties, or a string array for `multi_select` ones —
304
377
  * GitHub's own PATCH body accepts either per property. A single-string
@@ -381,6 +454,8 @@ function pulls(rest, graphql) {
381
454
  * is an edge case no consumer here needs to paginate for today.
382
455
  */
383
456
  listFiles: (repo, number) => rest.request(`${repoBase(repo)}/pulls/${number}/files?per_page=100`),
457
+ /** A PR's reviews, oldest first. `per_page=100` covers every real PR in this org. */
458
+ listReviews: (repo, number) => rest.request(`${repoBase(repo)}/pulls/${number}/reviews?per_page=100`),
384
459
  /**
385
460
  * Submits a review in one call — GitHub has no separate "create draft,
386
461
  * then submit" step when `event` is provided directly (the multi-step
@@ -431,6 +506,7 @@ function repos(rest) {
431
506
  // src/rulesets/rulesets.ts
432
507
  function rulesets(rest) {
433
508
  return {
509
+ getRuleset: (repo, id) => rest.request(`${repoBase(repo)}/rulesets/${id}`),
434
510
  listRulesets: (repo) => rest.request(`${repoBase(repo)}/rulesets`),
435
511
  createRuleset: (repo, payload) => rest.request(`${repoBase(repo)}/rulesets`, {
436
512
  method: "POST",
@@ -468,6 +544,22 @@ function secrets(rest) {
468
544
  // src/security/security.ts
469
545
  function security(rest) {
470
546
  return {
547
+ /** Whether vulnerability alerts are on: GitHub answers 204 when they are and 404 when they are not. */
548
+ vulnerabilityAlertsEnabled: async (repo) => {
549
+ try {
550
+ await rest.request(`${repoBase(repo)}/vulnerability-alerts`, { expectNoContent: true });
551
+ return true;
552
+ } catch (err) {
553
+ if (err instanceof ProviderApiError && err.status === 404) return false;
554
+ throw err;
555
+ }
556
+ },
557
+ /** Whether Dependabot security updates are on. */
558
+ automatedSecurityFixesEnabled: async (repo) => (await rest.request(`${repoBase(repo)}/automated-security-fixes`)).enabled,
559
+ /** Whether private vulnerability reporting is on. */
560
+ privateVulnerabilityReportingEnabled: async (repo) => (await rest.request(`${repoBase(repo)}/private-vulnerability-reporting`)).enabled,
561
+ /** The state of CodeQL default setup: `configured` or `not-configured`. */
562
+ codeScanningDefaultSetupState: async (repo) => (await rest.request(`${repoBase(repo)}/code-scanning/default-setup`)).state,
471
563
  enableVulnerabilityAlerts: (repo) => rest.request(`${repoBase(repo)}/vulnerability-alerts`, {
472
564
  method: "PUT",
473
565
  expectNoContent: true
@@ -535,6 +627,8 @@ function teams(rest) {
535
627
  if ((await read(51)).length > 0) throw new Error(`team ${org}/${teamSlug} has more than 5000 members; refusing to read them all`);
536
628
  return all;
537
629
  },
630
+ /** The teams that have access to a repository, with each team's permission there (read-only). */
631
+ listForRepo: (repo) => rest.request(`${repoBase(repo)}/teams`, { query: { per_page: String(PAGE$1) } }),
538
632
  addRepo: (org, teamSlug, owner, repo, permission) => rest.request(`/orgs/${org}/teams/${teamSlug}/repos/${owner}/${repo}`, {
539
633
  method: "PUT",
540
634
  body: { permission }
@@ -824,6 +918,62 @@ async function createInstallationClient(creds, installationId, opts = {}) {
824
918
  fetch: opts.fetch
825
919
  });
826
920
  }
921
+ // src/app-info/app-info.ts
922
+ /**
923
+ * What a GitHub App is right now, read with the App's own JWT (`GET /app`, `GET /app/installations`). GitHub has no
924
+ * endpoint that changes an existing App's permissions or event subscriptions, so these reads are how a caller
925
+ * checks the settings page was done by hand.
926
+ *
927
+ * https://docs.github.com/en/rest/apps/apps#get-the-authenticated-app
928
+ * https://docs.github.com/en/rest/apps/apps#list-installations-for-the-authenticated-app
929
+ */
930
+ const PAGE_SIZE = 100;
931
+ const account = (value) => {
932
+ const { login, type } = value ?? {};
933
+ return typeof login === "string" ? {
934
+ login,
935
+ type: typeof type === "string" ? type : ""
936
+ } : null;
937
+ };
938
+ async function appGet(creds, path, opts) {
939
+ const jwt = await createAppJWT(creds);
940
+ const baseUrl = opts.baseUrl ?? "https://api.github.com";
941
+ const res = await (opts.fetch ?? globalThis.fetch)(`${baseUrl}${path}`, { headers: {
942
+ authorization: `Bearer ${jwt}`,
943
+ accept: "application/vnd.github+json",
944
+ "x-github-api-version": "2022-11-28"
945
+ } });
946
+ if (!res.ok) {
947
+ const body = await res.text().catch(() => "");
948
+ throw new ProviderApiError(`GitHub GET ${path} → ${res.status}`, res.status, body);
949
+ }
950
+ return res.json();
951
+ }
952
+ /** The App this JWT identifies: its slug, owner and the permissions and events it asks for now. */
953
+ async function getApp(creds, opts = {}) {
954
+ const raw = await appGet(creds, "/app", opts);
955
+ return {
956
+ slug: String(raw.slug),
957
+ name: String(raw.name),
958
+ owner: account(raw.owner),
959
+ permissions: raw.permissions ?? {},
960
+ events: raw.events ?? []
961
+ };
962
+ }
963
+ /** Every installation of the App this JWT identifies, with what each has accepted. Reads all pages. */
964
+ async function listAppInstallations(creds, opts = {}) {
965
+ const installations = [];
966
+ for (let page = 1;; page++) {
967
+ const raws = await appGet(creds, `/app/installations?per_page=${PAGE_SIZE}&page=${page}`, opts);
968
+ for (const raw of raws) installations.push({
969
+ id: Number(raw.id),
970
+ account: account(raw.account),
971
+ permissions: raw.permissions ?? {},
972
+ events: raw.events ?? []
973
+ });
974
+ if (raws.length < PAGE_SIZE) return installations;
975
+ }
976
+ }
827
977
  // src/webhooks/webhooks.ts
828
978
  /**
829
979
  * GitHub's own webhook mechanics — signature verification and header/
@@ -870,6 +1020,7 @@ function parseGitHubWebhookHeaders(headers) {
870
1020
  };
871
1021
  }
872
1022
  // src/index.ts
1023
+ /** 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. */
873
1024
  function createGitHubClient(opts) {
874
1025
  const rest = createGitHubRestClient(opts);
875
1026
  const graphql = createGitHubGraphQLApiClient(opts);
@@ -878,6 +1029,8 @@ function createGitHubClient(opts) {
878
1029
  checks: checks(rest),
879
1030
  environments: environments(rest),
880
1031
  git: git(rest),
1032
+ /** The GraphQL client, for the callers whose API (Projects v2) has no REST form. */
1033
+ graphql,
881
1034
  issues: issues(rest),
882
1035
  labels: labels(rest),
883
1036
  pages: pages(rest),
@@ -894,4 +1047,4 @@ function createGitHubClient(opts) {
894
1047
  workflows: workflows(rest)
895
1048
  };
896
1049
  }
897
- export { MAX_CHECK_RUN_ANNOTATIONS, createAppJWT, createGitHubClient, createInstallationClient, getInstallationAccessToken, parseGitHubWebhookHeaders, parseTokenExpiration, verifyGitHubWebhookSignature };
1050
+ 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.2",
3
+ "version": "1.58.0-alpha.20",
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.2",
36
- "@theholocron/observability": "^0.6.1-alpha.1"
35
+ "@theholocron/observability": "^0.7.0-alpha.2",
36
+ "@theholocron/http-client": "^1.58.0-alpha.20"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^26",
40
- "@vitest/coverage-v8": "^5.0.5",
41
- "@vitest/eslint-plugin": "^1.6.27",
42
- "eslint": "^10.8.1",
43
- "eslint-plugin-n": "^18.3.0",
44
- "globals": "^17.11.0",
45
- "tsdown": "^0.23.3",
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.5",
48
- "@theholocron/eslint-config": "^8.9.0-alpha.3",
49
- "@theholocron/tsconfig": "^8.9.0-alpha.3",
50
- "@theholocron/tsdown-config": "^8.9.0-alpha.3",
51
- "@theholocron/vitest-config": "^8.9.0-alpha.3"
47
+ "vitest": "^5.1.0",
48
+ "@theholocron/tsconfig": "^8.9.0-alpha.12",
49
+ "@theholocron/tsdown-config": "^8.9.0-alpha.12",
50
+ "@theholocron/vitest-config": "^8.9.0-alpha.12",
51
+ "@theholocron/eslint-config": "^8.9.0-alpha.12"
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
- "delivery.build": "tsdown && node ../scripts/check-bundle-size.mjs",
61
- "sourceQuality.staticAnalysis": "eslint .",
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
- "verification.typeSafety": "tsc --noEmit",
64
- "verification.unitTests": "vitest run"
64
+ "typecheck": "tsc --noEmit"
65
65
  }
66
66
  }