@theholocron/github-client 1.58.0-alpha.4 → 1.58.0-alpha.41

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,5 +1,26 @@
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
+ }
3
24
  /** Options for creating a GitHub client. */
4
25
  interface GitHubClientOptions {
5
26
  /** The token sent as the bearer credential. */
@@ -98,6 +119,8 @@ interface GitHubCheckRun {
98
119
  conclusion: CheckRunConclusion | null;
99
120
  /** The URL of the check run's page on GitHub. */
100
121
  html_url: string;
122
+ /** The check's own "Details" link, when it set one. */
123
+ details_url?: string | null;
101
124
  }
102
125
  /** The body of an `updateCheckRun()` request; every field is optional. */
103
126
  interface UpdateCheckRunInput {
@@ -192,6 +215,26 @@ interface GitContents {
192
215
  /** The file's path in the repository. */
193
216
  path: string;
194
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
+ }
195
238
  /** What `git.putContents` returns: the file's new blob sha (the `sha` to pass next time) and the commit it made. */
196
239
  interface PutContentsResult {
197
240
  /** The file written: its path and its new blob SHA. */
@@ -249,6 +292,48 @@ interface CreatePullInput {
249
292
  /** The pull request's description. */
250
293
  body?: string;
251
294
  }
295
+ /** One option of a single-select issue field. */
296
+ interface GitHubIssueFieldOption {
297
+ /** The option's id. */
298
+ id: number;
299
+ /** The option's name, which is how a value is set. */
300
+ name: string;
301
+ }
302
+ /** An issue field an organization defines (Priority, Effort, Start date and so on). */
303
+ interface GitHubIssueField {
304
+ /** The field's id, which is how a value is set. */
305
+ id: number;
306
+ /** The field's name. */
307
+ name: string;
308
+ /** `single_select`, `text`, `number` or `date`. */
309
+ data_type: string;
310
+ /** The options of a single-select field. */
311
+ options?: GitHubIssueFieldOption[];
312
+ }
313
+ /** The value an issue has for one field. */
314
+ interface GitHubIssueFieldValue {
315
+ /** The id of the field. */
316
+ issue_field_id: number;
317
+ /** The name of the field, when GitHub gives it. */
318
+ issue_field_name?: string;
319
+ /** The field's type. */
320
+ data_type: string;
321
+ /** The value; for a single-select field read the option from `single_select_option`. */
322
+ value: string | number;
323
+ /** The selected option of a single-select field, or `null`. */
324
+ single_select_option?: {
325
+ id: number;
326
+ name: string;
327
+ color: string;
328
+ } | null;
329
+ }
330
+ /** One value to set: a field's id and, for a single-select field, the option's name. */
331
+ interface IssueFieldValueInput {
332
+ /** The field's id. */
333
+ field_id: number;
334
+ /** The option's name, text, number or date. */
335
+ value: string | number;
336
+ }
252
337
  /** An issue as GitHub returns it, with only the fields this client reads. */
253
338
  interface GitHubIssue {
254
339
  /** The issue's numeric id. */
@@ -275,6 +360,15 @@ interface GitHubIssue {
275
360
  updated_at: string;
276
361
  /** The URL of the issue's page on GitHub. */
277
362
  html_url: string;
363
+ /** When the issue was created, as an ISO 8601 timestamp. */
364
+ created_at?: string;
365
+ /** The milestone the issue belongs to, or `null` when none. */
366
+ milestone?: {
367
+ number: number;
368
+ title: string;
369
+ } | null;
370
+ /** The issue's GraphQL node id. */
371
+ node_id?: string;
278
372
  /** Set when the item is a pull request; GitHub's issues API returns pull requests too. */
279
373
  pull_request?: unknown;
280
374
  }
@@ -285,8 +379,23 @@ interface GitHubMilestone {
285
379
  /** The milestone's title. */
286
380
  title: string;
287
381
  }
382
+ /** A comment on an issue, with only the fields this client reads. */
383
+ interface GitHubIssueComment {
384
+ /** The comment's text. */
385
+ body: string;
386
+ /** When it was written, as an ISO 8601 timestamp. */
387
+ created_at: string;
388
+ /** Who wrote it. */
389
+ user: {
390
+ login: string;
391
+ } | null;
392
+ }
288
393
  /** Filters for listing issues. */
289
394
  interface IssueSearchParams {
395
+ /** The page to read, from 1. */
396
+ page?: number;
397
+ /** A milestone number, `*` for any or `none`. */
398
+ milestone?: string;
290
399
  /** Which issues to list by state; GitHub defaults to `open`. */
291
400
  state?: "open" | "closed" | "all";
292
401
  /** The field to sort by, passed through to GitHub. */
@@ -369,6 +478,12 @@ interface OrgProperty {
369
478
  required?: boolean;
370
479
  /** The values a `single_select` or `multi_select` property accepts; `null` for any other type. */
371
480
  allowed_values?: string[] | null;
481
+ /** The value a repository gets when it sets none, or `null`. */
482
+ default_value?: string | string[] | null;
483
+ /** A line saying what the property is for, or `null`. */
484
+ description?: string | null;
485
+ /** Who may edit the property's value on a repository: `org_actors` or `org_and_repo_actors`, or `null`. */
486
+ values_editable_by?: string | null;
372
487
  }
373
488
  /** One custom property value set on a repository. */
374
489
  interface RepoPropertyValue {
@@ -383,6 +498,8 @@ interface GitHubPullRequest {
383
498
  number: number;
384
499
  /** The pull request's title. */
385
500
  title: string;
501
+ /** The pull request's description, as written (markdown); `null` when it has none. */
502
+ body?: string | null;
386
503
  /** Whether the pull request is open or closed. */
387
504
  state: "open" | "closed";
388
505
  /** When the pull request was merged as an ISO 8601 timestamp, or `null` if it was not merged. */
@@ -396,6 +513,40 @@ interface GitHubPullRequest {
396
513
  /** The head commit. */
397
514
  sha: string;
398
515
  };
516
+ /** Whether the pull request is a draft. */
517
+ draft?: boolean;
518
+ /** When the pull request was opened, as an ISO 8601 timestamp. */
519
+ created_at?: string;
520
+ /** The author. */
521
+ user?: {
522
+ /** The author's login. */
523
+ login: string;
524
+ /** The account type: `User` or `Bot` (Dependabot is a `Bot`). */
525
+ type: string;
526
+ };
527
+ /** Who merged it; `null` for a pull request that is not merged. */
528
+ merged_by?: {
529
+ login: string;
530
+ } | null;
531
+ /** The base branch. */
532
+ base?: {
533
+ /** The base branch's name, e.g. `alpha`. */
534
+ ref: string;
535
+ };
536
+ /** The people whose review is still asked for. */
537
+ requested_reviewers?: {
538
+ login: string;
539
+ }[];
540
+ /** Lines added, as the single-pull-request endpoint returns it (the list endpoint omits it). */
541
+ additions?: number;
542
+ /** Lines removed; see `additions`. */
543
+ deletions?: number;
544
+ /** Files changed; see `additions`. */
545
+ changed_files?: number;
546
+ /** Whether it merges cleanly; `null` while GitHub is still working it out. */
547
+ mergeable?: boolean | null;
548
+ /** `dirty` means it conflicts with its base; see `mergeable`. */
549
+ mergeable_state?: string;
399
550
  }
400
551
  /** 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). */
401
552
  interface GitHubCommitIdentity {
@@ -474,6 +625,14 @@ interface GitHubPullRequestReview {
474
625
  id: number;
475
626
  /** The URL of the review on GitHub. */
476
627
  html_url: string;
628
+ /** `APPROVED`, `CHANGES_REQUESTED`, `COMMENTED`, `DISMISSED` or `PENDING`; set on a review read back. */
629
+ state?: string;
630
+ /** The reviewer; set on a review read back. */
631
+ user?: {
632
+ login: string;
633
+ } | null;
634
+ /** The review's summary text (markdown); set on a review read back, and `null` or empty when it has none. */
635
+ body?: string | null;
477
636
  }
478
637
  /**
479
638
  * One review thread — GraphQL-only (`resolveReviewThread`, the mutation
@@ -505,10 +664,14 @@ interface ReviewThread {
505
664
  }
506
665
  /** A repository as GitHub returns it, with only the fields this client reads. */
507
666
  interface GitHubRepo {
667
+ /** The repository's numeric id, which organization secrets and variables name their readers by. */
668
+ id: number;
508
669
  /** The name of the repository's default branch. */
509
670
  default_branch: string;
510
671
  /** The repository's `owner/name`. */
511
672
  full_name: string;
673
+ /** Whether the repository is archived (read-only). */
674
+ archived?: boolean;
512
675
  /** The repository description. */
513
676
  description?: string | null;
514
677
  /** The repository homepage URL. */
@@ -583,6 +746,15 @@ interface GitHubPublicKey {
583
746
  /** The Base64-encoded public key. */
584
747
  key: string;
585
748
  }
749
+ /** Who can read an organization secret: every repository, every private one, or the ones listed. */
750
+ type OrgSecretVisibility = "all" | "private" | "selected";
751
+ /** An organization secret as the list returns it: its name and who can read it (never its value). */
752
+ interface OrgSecretInfo {
753
+ /** The secret's name. */
754
+ name: string;
755
+ /** Who can read it. */
756
+ visibility: OrgSecretVisibility;
757
+ }
586
758
  /** The workflow run that a code scanning setup started. */
587
759
  interface CodeScanningSetupResult {
588
760
  /** The id of the workflow run. */
@@ -714,6 +886,41 @@ export declare function createAppJWT(creds: GitHubAppCredentials, now?: number):
714
886
  export declare function getInstallationAccessToken(creds: GitHubAppCredentials, installationId: number, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<InstallationAccessToken>;
715
887
  /** The whole flow in one call — an already-authenticated `GitHubClient` scoped to one installation. */
716
888
  export declare function createInstallationClient(creds: GitHubAppCredentials, installationId: number, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubClient>;
889
+ /** The account an App or one of its installations belongs to. */
890
+ interface GitHubAppAccount {
891
+ /** The user or organization login. */
892
+ login: string;
893
+ /** `User` or `Organization` (GitHub also reports `Enterprise` for an enterprise-owned App). */
894
+ type: string;
895
+ }
896
+ /** An App as `GET /app` reports it. */
897
+ interface GitHubApp {
898
+ /** The App's URL name, as in `github.com/apps/<slug>`. */
899
+ slug: string;
900
+ /** The App's display name. */
901
+ name: string;
902
+ /** Who owns the App: decides which settings page its permissions live on. */
903
+ owner: GitHubAppAccount | null;
904
+ /** The permissions the App asks for now: name to `read`, `write` or `admin`. */
905
+ permissions: Record<string, string>;
906
+ /** The webhook events the App is subscribed to now. */
907
+ events: string[];
908
+ }
909
+ /** One installation of an App as `GET /app/installations` reports it. */
910
+ interface GitHubAppInstallation {
911
+ /** The installation id. */
912
+ id: number;
913
+ /** The account the App is installed on. */
914
+ account: GitHubAppAccount | null;
915
+ /** What this installation has accepted: it lags the App's own list until an owner accepts a new request. */
916
+ permissions: Record<string, string>;
917
+ /** The events delivered to this installation. */
918
+ events: string[];
919
+ }
920
+ /** The App this JWT identifies: its slug, owner and the permissions and events it asks for now. */
921
+ export declare function getApp(creds: GitHubAppCredentials, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubApp>;
922
+ /** Every installation of the App this JWT identifies, with what each has accepted. Reads all pages. */
923
+ export declare function listAppInstallations(creds: GitHubAppCredentials, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubAppInstallation[]>;
717
924
  /**
718
925
  * GitHub's own webhook mechanics — signature verification and header/
719
926
  * payload shapes. Pure functions, no REST call, no auth token: these
@@ -818,6 +1025,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
818
1025
  removeBranch: (repo: string, branch: string) => Promise<void>;
819
1026
  };
820
1027
  checks: {
1028
+ listCheckRunsForRef: (repo: string, ref: string) => Promise<GitHubCheckRun[]>;
821
1029
  createCheckRun: (repo: string, input: CreateCheckRunInput) => Promise<GitHubCheckRun>;
822
1030
  updateCheckRun: (repo: string, checkRunId: number, input: UpdateCheckRunInput) => Promise<GitHubCheckRun>;
823
1031
  };
@@ -831,6 +1039,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
831
1039
  getCommit: (repo: string, sha: string) => Promise<GitCommit>;
832
1040
  getTree: (repo: string, sha: string, recursive?: boolean) => Promise<GitTree>;
833
1041
  getContents: (repo: string, path: string, ref?: string) => Promise<GitContents>;
1042
+ listDirectory: (repo: string, path: string, options?: ListDirectoryOptions) => Promise<GitDirectoryEntry[]>;
834
1043
  putContents: (repo: string, path: string, input: PutContentsInput) => Promise<PutContentsResult>;
835
1044
  createBlob: (repo: string, content: string, encoding?: string) => Promise<GitBlob>;
836
1045
  createTree: (repo: string, tree: Array<{
@@ -844,6 +1053,14 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
844
1053
  updateRef: (repo: string, ref: string, sha: string, force?: boolean) => Promise<GitRef>;
845
1054
  createPull: (repo: string, input: CreatePullInput) => Promise<GitPull>;
846
1055
  };
1056
+ /** The GraphQL client, for the callers whose API (Projects v2) has no REST form. */
1057
+ graphql: GraphQLClient;
1058
+ issueFields: {
1059
+ list: (org: string) => Promise<GitHubIssueField[]>;
1060
+ values: (repo: string, number: number) => Promise<GitHubIssueFieldValue[]>;
1061
+ addValues: (repo: string, number: number, values: IssueFieldValueInput[]) => Promise<GitHubIssueFieldValue[]>;
1062
+ deleteValue: (repo: string, number: number, fieldId: number) => Promise<void>;
1063
+ };
847
1064
  issues: {
848
1065
  listIssues: (repo: string, params?: IssueSearchParams) => Promise<GitHubIssue[]>;
849
1066
  getIssue: (repo: string, number: number) => Promise<GitHubIssue>;
@@ -852,6 +1069,8 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
852
1069
  addLabels: (repo: string, number: number, labels: string[]) => Promise<void>;
853
1070
  removeLabel: (repo: string, number: number, label: string) => Promise<void>;
854
1071
  createComment: (repo: string, number: number, body: string) => Promise<void>;
1072
+ listComments: (repo: string, number: number) => Promise<GitHubIssueComment[]>;
1073
+ createMilestone: (repo: string, title: string) => Promise<GitHubMilestone>;
855
1074
  listMilestones: (repo: string, params?: {
856
1075
  state?: "open" | "closed" | "all";
857
1076
  }) => Promise<GitHubMilestone[]>;
@@ -877,6 +1096,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
877
1096
  properties: {
878
1097
  getValues: (repo: string) => Promise<RepoPropertyValue[]>;
879
1098
  orgSchema: (org: string) => Promise<OrgProperty[]>;
1099
+ setOrgProperty: (org: string, property: OrgProperty) => Promise<OrgProperty>;
880
1100
  setProperties: (repo: string, values: Record<string, string | string[]>) => Promise<void>;
881
1101
  };
882
1102
  pulls: {
@@ -884,6 +1104,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
884
1104
  listPullRequests: (repo: string, state: "open" | "closed") => Promise<GitHubPullRequest[]>;
885
1105
  listCommits: (repo: string, number: number) => Promise<GitHubPullRequestCommit[]>;
886
1106
  listFiles: (repo: string, number: number) => Promise<GitHubPullRequestFile[]>;
1107
+ listReviews: (repo: string, number: number) => Promise<GitHubPullRequestReview[]>;
887
1108
  createReview: (repo: string, number: number, input: CreateReviewInput) => Promise<GitHubPullRequestReview>;
888
1109
  listReviewThreads: (repo: string, number: number) => Promise<ReviewThread[]>;
889
1110
  resolveReviewThread: (threadId: string) => Promise<void>;
@@ -901,6 +1122,8 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
901
1122
  };
902
1123
  secrets: {
903
1124
  listSecrets: (repo: string, scope: SecretScope) => Promise<string[]>;
1125
+ listOrgSecretInfo: (org: string) => Promise<OrgSecretInfo[]>;
1126
+ listSelectedRepositories: (org: string, name: string) => Promise<string[]>;
904
1127
  getPublicKey: (repo: string, scope: SecretScope) => Promise<GitHubPublicKey>;
905
1128
  putSecret: (repo: string, scope: SecretScope, name: string, body: Record<string, unknown>) => Promise<void>;
906
1129
  deleteSecret: (repo: string, scope: SecretScope, name: string) => Promise<void>;
@@ -945,4 +1168,4 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
945
1168
  };
946
1169
  /** The client returned by `createGitHubClient()`: one group of methods per GitHub API area. */
947
1170
  export type GitHubClient = ReturnType<typeof createGitHubClient>;
948
- 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 };
1171
+ 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, GitHubIssueField, GitHubIssueFieldOption, GitHubIssueFieldValue, GitHubLabel, GitHubMilestone, GitHubPages, GitHubPublicKey, GitHubPullRequest, GitHubPullRequestCommit, GitHubPullRequestFile, GitHubPullRequestReview, GitHubPullRequestWebhookPayload, GitHubPushWebhookPayload, GitHubRepo, GitHubRuleset, GitHubRulesetDetail, GitHubUser, GitHubUserWithExpiry, GitHubVariable, GitHubWebhookHeaders, GitHubWorkflowRun, GitPull, GitRef, GitTree, GitTreeItem, GraphQLClient, InstallationAccessToken, IssueFieldValueInput, IssueSearchParams, ListDirectoryOptions, OrgProperty, OrgSecretInfo, OrgSecretVisibility, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, RepoPropertyValue, RepoTeam, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdatePagesPayload, VariableScope, VariableVisibility, WorkflowRunFilter };
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ProviderApiError, createRestClient } from "@theholocron/http-client";
2
2
  import { createHmac, timingSafeEqual } from "node:crypto";
3
3
  // src/graphql/graphql.ts
4
+ /** A {@link GraphQLClient} for GitHub's GraphQL API, built on the shared REST transport. */
4
5
  function createGitHubGraphQLClient(config) {
5
6
  const rest = createRestClient({
6
7
  baseUrl: config.baseUrl ?? "https://api.github.com",
@@ -107,8 +108,21 @@ function branches(rest) {
107
108
  * do for you; slice with it rather than hardcoding the number.
108
109
  */
109
110
  const MAX_CHECK_RUN_ANNOTATIONS = 50;
111
+ /** Page size and the most pages {@link checks}`.listCheckRunsForRef` reads: 100 a page over 10 pages, so 1,000 check runs. */
112
+ const CHECK_RUN_PAGE_SIZE = 100;
113
+ const CHECK_RUN_MAX_PAGES = 10;
110
114
  function checks(rest) {
111
115
  return {
116
+ /** Every check run on a commit, read a page at a time until a page comes back short. */
117
+ listCheckRunsForRef: async (repo, ref) => {
118
+ const all = [];
119
+ for (let page = 1; page <= CHECK_RUN_MAX_PAGES; page++) {
120
+ const batch = await rest.request(`${repoBase(repo)}/commits/${ref}/check-runs?per_page=${CHECK_RUN_PAGE_SIZE}&page=${page}`);
121
+ all.push(...batch.check_runs);
122
+ if (batch.check_runs.length < CHECK_RUN_PAGE_SIZE) break;
123
+ }
124
+ return all;
125
+ },
112
126
  createCheckRun: (repo, input) => rest.request(`${repoBase(repo)}/check-runs`, {
113
127
  method: "POST",
114
128
  body: input
@@ -150,6 +164,36 @@ function git(rest) {
150
164
  */
151
165
  getContents: (repo, path, ref) => rest.request(`${repoBase(repo)}/contents/${path}`, ref ? { query: { ref } } : void 0),
152
166
  /**
167
+ * Lists the directory at `path` through the contents API (`GET /repos/:repo/contents/:path`, which
168
+ * answers an array for a directory). A 404 (no such directory) is an empty list, not an error; any
169
+ * other failure is the usual `ProviderApiError`. One request lists one level: with
170
+ * `recursive: true` it makes one more request per nested directory and returns a flat list of
171
+ * full paths (directories included). A `path` that is a file, not a directory, throws.
172
+ */
173
+ listDirectory: async (repo, path, options = {}) => {
174
+ const list = async (at) => {
175
+ let body;
176
+ try {
177
+ body = await rest.request(`${repoBase(repo)}/contents/${filePath(at)}`, options.ref ? { query: { ref: options.ref } } : void 0);
178
+ } catch (err) {
179
+ if (err instanceof ProviderApiError && err.status === 404) return [];
180
+ throw err;
181
+ }
182
+ if (!Array.isArray(body)) throw new Error(`${repo}:${at} is a file, not a directory`);
183
+ const entries = body.map(({ name, path: p, type, size, sha }) => ({
184
+ name,
185
+ path: p,
186
+ type,
187
+ size,
188
+ sha
189
+ }));
190
+ if (!options.recursive) return entries;
191
+ const nested = await Promise.all(entries.filter((e) => e.type === "dir").map((e) => list(e.path)));
192
+ return [...entries, ...nested.flat()];
193
+ };
194
+ return list(path.replace(/^\/+|\/+$/g, ""));
195
+ },
196
+ /**
153
197
  * `PUT /repos/:repo/contents/:path` — creates or updates one file in a single commit. Pass `sha` when
154
198
  * updating so a concurrent change is refused (409) and not silently overwritten.
155
199
  */
@@ -204,6 +248,28 @@ function git(rest) {
204
248
  })
205
249
  };
206
250
  }
251
+ // src/issue-fields/issue-fields.ts
252
+ function issueFields(rest) {
253
+ return {
254
+ /** The issue fields an organization defines (read-only). */
255
+ list: (org) => rest.request(`/orgs/${segment(org)}/issue-fields`),
256
+ /** The values an issue has for the organization's issue fields (read-only). */
257
+ values: (repo, number) => rest.request(`${repoBase(repo)}/issues/${number}/issue-field-values`),
258
+ /**
259
+ * Adds values to an issue without touching the others it has. The caller needs push access to the repository.
260
+ * (GitHub's `PUT` on the same path replaces every value of the issue, so this client never uses it.)
261
+ */
262
+ addValues: (repo, number, values) => rest.request(`${repoBase(repo)}/issues/${number}/issue-field-values`, {
263
+ method: "POST",
264
+ body: { issue_field_values: values }
265
+ }),
266
+ /** Removes an issue's value for one field. */
267
+ deleteValue: (repo, number, fieldId) => rest.request(`${repoBase(repo)}/issues/${number}/issue-field-values/${fieldId}`, {
268
+ method: "DELETE",
269
+ expectNoContent: true
270
+ })
271
+ };
272
+ }
207
273
  // src/issues/issues.ts
208
274
  function issues(rest) {
209
275
  return {
@@ -215,6 +281,8 @@ function issues(rest) {
215
281
  if (params.per_page) qs.set("per_page", String(params.per_page));
216
282
  if (params.filter) qs.set("filter", params.filter);
217
283
  if (params.assignee) qs.set("assignee", params.assignee);
284
+ if (params.page) qs.set("page", String(params.page));
285
+ if (params.milestone) qs.set("milestone", params.milestone);
218
286
  const q = qs.toString();
219
287
  const path = q ? `${repoBase(repo)}/issues?${q}` : `${repoBase(repo)}/issues`;
220
288
  return rest.request(path);
@@ -237,6 +305,18 @@ function issues(rest) {
237
305
  method: "POST",
238
306
  body: { body }
239
307
  }),
308
+ listComments: async (repo, number) => {
309
+ const all = [];
310
+ for (let page = 1;; page++) {
311
+ const batch = await rest.request(`${repoBase(repo)}/issues/${number}/comments?per_page=100&page=${page}`);
312
+ all.push(...batch);
313
+ if (batch.length < 100) return all;
314
+ }
315
+ },
316
+ createMilestone: (repo, title) => rest.request(`${repoBase(repo)}/milestones`, {
317
+ method: "POST",
318
+ body: { title }
319
+ }),
240
320
  listMilestones: (repo, params = {}) => {
241
321
  const qs = new URLSearchParams({ per_page: "100" });
242
322
  if (params.state) qs.set("state", params.state);
@@ -291,6 +371,15 @@ function pages(rest) {
291
371
  };
292
372
  }
293
373
  // src/properties/properties.ts
374
+ /** The keys of an {@link OrgProperty} that GitHub accepts when a definition is written. */
375
+ const WRITABLE_FIELDS = [
376
+ "value_type",
377
+ "required",
378
+ "default_value",
379
+ "description",
380
+ "allowed_values",
381
+ "values_editable_by"
382
+ ];
294
383
  function properties(rest) {
295
384
  return {
296
385
  /** The custom property values set on a repository (read-only). */
@@ -301,6 +390,19 @@ function properties(rest) {
301
390
  */
302
391
  orgSchema: (org) => rest.request(`/orgs/${segment(org)}/properties/schema`),
303
392
  /**
393
+ * Creates or replaces one custom property definition of the organization. GitHub replaces the whole definition,
394
+ * so send back every field the property already has (`orgSchema` has them); a field left out is reset.
395
+ * The token needs write access to the organization's custom properties (`Custom properties: admin`).
396
+ */
397
+ setOrgProperty: (org, property) => {
398
+ const { property_name } = property;
399
+ const body = Object.fromEntries(WRITABLE_FIELDS.map((key) => [key, property[key]]).filter(([, v]) => v !== void 0));
400
+ return rest.request(`/orgs/${segment(org)}/properties/schema/${segment(property_name)}`, {
401
+ method: "PUT",
402
+ body
403
+ });
404
+ },
405
+ /**
304
406
  * `value` is a plain string for `string`/`single_select`/`true_false`
305
407
  * custom properties, or a string array for `multi_select` ones —
306
408
  * GitHub's own PATCH body accepts either per property. A single-string
@@ -353,6 +455,9 @@ const RESOLVE_REVIEW_THREAD_MUTATION = `
353
455
  /** Page size and the most pages {@link pulls}`.listPullRequests` reads: 100 a page (GitHub's maximum) over 100 pages, so 10,000 pull requests. */
354
456
  const PULL_REQUEST_PAGE_SIZE = 100;
355
457
  const PULL_REQUEST_MAX_PAGES = 100;
458
+ /** Page size and the most pages {@link pulls}`.listFiles` reads: 100 a page over 30 pages, the 3000 files GitHub serves. */
459
+ const FILE_PAGE_SIZE = 100;
460
+ const FILE_MAX_PAGES = 30;
356
461
  function pulls(rest, graphql) {
357
462
  return {
358
463
  getPullRequest: (repo, number) => rest.request(`${repoBase(repo)}/pulls/${number}`),
@@ -377,12 +482,20 @@ function pulls(rest, graphql) {
377
482
  */
378
483
  listCommits: (repo, number) => rest.request(`${repoBase(repo)}/pulls/${number}/commits?per_page=100`),
379
484
  /**
380
- * A PR's own changed files. `per_page=100` — GitHub's max — covers
381
- * every real PR in this org; a PR genuinely exceeding 100 changed
382
- * files (GitHub caps this endpoint at 3000 regardless of pagination)
383
- * is an edge case no consumer here needs to paginate for today.
485
+ * A PR's own changed files, read a page at a time until a page comes back short. GitHub serves at most
486
+ * 3000 files from this endpoint, so a larger PR is cut at that cap.
384
487
  */
385
- listFiles: (repo, number) => rest.request(`${repoBase(repo)}/pulls/${number}/files?per_page=100`),
488
+ listFiles: async (repo, number) => {
489
+ const all = [];
490
+ for (let page = 1; page <= FILE_MAX_PAGES; page++) {
491
+ const batch = await rest.request(`${repoBase(repo)}/pulls/${number}/files?per_page=${FILE_PAGE_SIZE}&page=${page}`);
492
+ all.push(...batch);
493
+ if (batch.length < FILE_PAGE_SIZE) break;
494
+ }
495
+ return all;
496
+ },
497
+ /** A PR's reviews, oldest first. `per_page=100` covers every real PR in this org. */
498
+ listReviews: (repo, number) => rest.request(`${repoBase(repo)}/pulls/${number}/reviews?per_page=100`),
386
499
  /**
387
500
  * Submits a review in one call — GitHub has no separate "create draft,
388
501
  * then submit" step when `event` is provided directly (the multi-step
@@ -456,6 +569,13 @@ function scopeBase$1(repo, scope) {
456
569
  function secrets(rest) {
457
570
  return {
458
571
  listSecrets: (repo, scope) => rest.request(`${scopeBase$1(repo, scope)}/secrets`).then((r) => r.secrets.map((s) => s.name)),
572
+ /** The organization's secrets with their visibility, names only (first 100). */
573
+ listOrgSecretInfo: (org) => rest.request(`/orgs/${org}/actions/secrets?per_page=100`).then((r) => r.secrets.map((s) => ({
574
+ name: s.name,
575
+ visibility: s.visibility
576
+ }))),
577
+ /** The names of the repositories that can read one organization secret of visibility `selected` (first 100). */
578
+ listSelectedRepositories: (org, name) => rest.request(`/orgs/${org}/actions/secrets/${name}/repositories?per_page=100`).then((r) => r.repositories.map((repo) => repo.name)),
459
579
  getPublicKey: (repo, scope) => rest.request(`${scopeBase$1(repo, scope)}/secrets/public-key`),
460
580
  putSecret: (repo, scope, name, body) => rest.request(`${scopeBase$1(repo, scope)}/secrets/${name}`, {
461
581
  method: "PUT",
@@ -845,6 +965,62 @@ async function createInstallationClient(creds, installationId, opts = {}) {
845
965
  fetch: opts.fetch
846
966
  });
847
967
  }
968
+ // src/app-info/app-info.ts
969
+ /**
970
+ * What a GitHub App is right now, read with the App's own JWT (`GET /app`, `GET /app/installations`). GitHub has no
971
+ * endpoint that changes an existing App's permissions or event subscriptions, so these reads are how a caller
972
+ * checks the settings page was done by hand.
973
+ *
974
+ * https://docs.github.com/en/rest/apps/apps#get-the-authenticated-app
975
+ * https://docs.github.com/en/rest/apps/apps#list-installations-for-the-authenticated-app
976
+ */
977
+ const PAGE_SIZE = 100;
978
+ const account = (value) => {
979
+ const { login, type } = value ?? {};
980
+ return typeof login === "string" ? {
981
+ login,
982
+ type: typeof type === "string" ? type : ""
983
+ } : null;
984
+ };
985
+ async function appGet(creds, path, opts) {
986
+ const jwt = await createAppJWT(creds);
987
+ const baseUrl = opts.baseUrl ?? "https://api.github.com";
988
+ const res = await (opts.fetch ?? globalThis.fetch)(`${baseUrl}${path}`, { headers: {
989
+ authorization: `Bearer ${jwt}`,
990
+ accept: "application/vnd.github+json",
991
+ "x-github-api-version": "2022-11-28"
992
+ } });
993
+ if (!res.ok) {
994
+ const body = await res.text().catch(() => "");
995
+ throw new ProviderApiError(`GitHub GET ${path} → ${res.status}`, res.status, body);
996
+ }
997
+ return res.json();
998
+ }
999
+ /** The App this JWT identifies: its slug, owner and the permissions and events it asks for now. */
1000
+ async function getApp(creds, opts = {}) {
1001
+ const raw = await appGet(creds, "/app", opts);
1002
+ return {
1003
+ slug: String(raw.slug),
1004
+ name: String(raw.name),
1005
+ owner: account(raw.owner),
1006
+ permissions: raw.permissions ?? {},
1007
+ events: raw.events ?? []
1008
+ };
1009
+ }
1010
+ /** Every installation of the App this JWT identifies, with what each has accepted. Reads all pages. */
1011
+ async function listAppInstallations(creds, opts = {}) {
1012
+ const installations = [];
1013
+ for (let page = 1;; page++) {
1014
+ const raws = await appGet(creds, `/app/installations?per_page=${PAGE_SIZE}&page=${page}`, opts);
1015
+ for (const raw of raws) installations.push({
1016
+ id: Number(raw.id),
1017
+ account: account(raw.account),
1018
+ permissions: raw.permissions ?? {},
1019
+ events: raw.events ?? []
1020
+ });
1021
+ if (raws.length < PAGE_SIZE) return installations;
1022
+ }
1023
+ }
848
1024
  // src/webhooks/webhooks.ts
849
1025
  /**
850
1026
  * GitHub's own webhook mechanics — signature verification and header/
@@ -900,6 +1076,9 @@ function createGitHubClient(opts) {
900
1076
  checks: checks(rest),
901
1077
  environments: environments(rest),
902
1078
  git: git(rest),
1079
+ /** The GraphQL client, for the callers whose API (Projects v2) has no REST form. */
1080
+ graphql,
1081
+ issueFields: issueFields(rest),
903
1082
  issues: issues(rest),
904
1083
  labels: labels(rest),
905
1084
  pages: pages(rest),
@@ -916,4 +1095,4 @@ function createGitHubClient(opts) {
916
1095
  workflows: workflows(rest)
917
1096
  };
918
1097
  }
919
- export { MAX_CHECK_RUN_ANNOTATIONS, createAppJWT, createGitHubClient, createInstallationClient, getInstallationAccessToken, parseGitHubWebhookHeaders, parseTokenExpiration, verifyGitHubWebhookSignature };
1098
+ 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.4",
3
+ "version": "1.58.0-alpha.41",
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.4",
36
- "@theholocron/observability": "^0.6.1-alpha.1"
35
+ "@theholocron/http-client": "^1.58.0-alpha.41",
36
+ "@theholocron/observability": "^0.7.0-alpha.5"
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.7",
46
46
  "typescript": "^5.9.3",
47
- "vitest": "^5.0.5",
48
- "@theholocron/tsconfig": "^8.9.0-alpha.5",
49
- "@theholocron/tsdown-config": "^8.9.0-alpha.5",
50
- "@theholocron/vitest-config": "^8.9.0-alpha.5",
51
- "@theholocron/eslint-config": "^8.9.0-alpha.5"
47
+ "vitest": "^5.1.0",
48
+ "@theholocron/eslint-config": "^8.9.0-alpha.21",
49
+ "@theholocron/tsdown-config": "^8.9.0-alpha.21",
50
+ "@theholocron/vitest-config": "^8.9.0-alpha.21",
51
+ "@theholocron/tsconfig": "^8.9.0-alpha.21"
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
  }