@theholocron/github-client 1.58.0-alpha.51 → 1.58.0-alpha.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -104,6 +104,8 @@ interface CreateCheckRunInput {
104
104
  output?: CheckRunOutput;
105
105
  /** URL for the "Details" link on the check run. GitHub defaults to the check suite's own summary page when omitted. */
106
106
  details_url?: string;
107
+ /** When the run started, an ISO time; GitHub uses the time of the request when omitted. */
108
+ started_at?: string;
107
109
  }
108
110
  /** A check run as GitHub returns it, with only the fields this client reads. */
109
111
  interface GitHubCheckRun {
@@ -123,6 +125,11 @@ interface GitHubCheckRun {
123
125
  details_url?: string | null;
124
126
  /** When the run started, an ISO time; absent while it is queued. */
125
127
  started_at?: string | null;
128
+ /** The GitHub App that posted the run; absent from a payload that leaves it out. */
129
+ app?: {
130
+ id: number;
131
+ slug?: string;
132
+ } | null;
126
133
  }
127
134
  /** The body of an `updateCheckRun()` request; every field is optional. */
128
135
  interface UpdateCheckRunInput {
@@ -135,6 +142,21 @@ interface UpdateCheckRunInput {
135
142
  /** URL for the "Details" link on the check run. */
136
143
  details_url?: string;
137
144
  }
145
+ /** The state of a commit status. */
146
+ type CommitStatusState = "error" | "failure" | "pending" | "success";
147
+ /** One commit status as GitHub returns it, with only the fields this client reads. */
148
+ interface GitHubCommitStatus {
149
+ /** The status's numeric id. */
150
+ id: number;
151
+ /** The context that posted it, such as `codecov/patch`. */
152
+ context: string;
153
+ /** Where the context stands. */
154
+ state: CommitStatusState;
155
+ /** The link the status points to, `null` when it set none. */
156
+ target_url: string | null;
157
+ /** When the status was created, an ISO time. */
158
+ created_at: string;
159
+ }
138
160
  /** A deployment environment of a repository and its protection settings. */
139
161
  interface GitHubEnvironment {
140
162
  /** The environment's name. */
@@ -378,6 +400,32 @@ interface IssueFieldValueInput {
378
400
  /** The option's name, text, number or date. */
379
401
  value: string | number;
380
402
  }
403
+ /** The colour words GitHub's issue Types take. */
404
+ type IssueTypeColor = "gray" | "blue" | "green" | "yellow" | "orange" | "red" | "pink" | "purple";
405
+ /** One issue Type of an organization. */
406
+ interface OrgIssueTypeInfo {
407
+ /** GitHub's numeric id. */
408
+ id: number;
409
+ /** The Type's name. */
410
+ name: string;
411
+ /** One line, or `null`. */
412
+ description?: string | null;
413
+ /** The colour word, or `null`. */
414
+ color?: IssueTypeColor | null;
415
+ /** Whether new issues may take it. */
416
+ is_enabled: boolean;
417
+ }
418
+ /** What GitHub takes when a Type is made or replaced (`name` and `is_enabled` are required). */
419
+ interface IssueTypeInput {
420
+ /** The Type's name. */
421
+ name: string;
422
+ /** Whether new issues may take it. */
423
+ is_enabled: boolean;
424
+ /** One line. */
425
+ description?: string | null;
426
+ /** The colour word. */
427
+ color?: IssueTypeColor | null;
428
+ }
381
429
  /** An issue as GitHub returns it, with only the fields this client reads. */
382
430
  interface GitHubIssue {
383
431
  /** The issue's numeric id. */
@@ -999,6 +1047,45 @@ interface GitHubAppInstallation {
999
1047
  export declare function getApp(creds: GitHubAppCredentials, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubApp>;
1000
1048
  /** Every installation of the App this JWT identifies, with what each has accepted. Reads all pages. */
1001
1049
  export declare function listAppInstallations(creds: GitHubAppCredentials, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<GitHubAppInstallation[]>;
1050
+ /** One delivery of a webhook event to the App, as `GET /app/hook/deliveries` reports it. */
1051
+ interface GitHubAppDelivery {
1052
+ /** The delivery's id, which a redelivery is asked for by. */
1053
+ id: number;
1054
+ /** The delivery's GUID, shared by the first attempt and every redelivery of it (`X-GitHub-Delivery`). */
1055
+ guid: string;
1056
+ /** When it was delivered, an ISO time. */
1057
+ deliveredAt: string;
1058
+ /** Whether this attempt was itself a redelivery. */
1059
+ redelivery: boolean;
1060
+ /** The HTTP status the App's endpoint answered, or `0` when it gave none (a timeout, a refused connection). */
1061
+ statusCode: number;
1062
+ /** GitHub's own word for the outcome: `OK`, or the failure (`Invalid HTTP Response: 500`, `Timed out`). */
1063
+ status: string;
1064
+ /** The event, such as `check_run`. */
1065
+ event: string;
1066
+ /** The event's action, `null` for an event with none. */
1067
+ action: string | null;
1068
+ /** The installation it was for, `null` when it was for none. */
1069
+ installationId: number | null;
1070
+ }
1071
+ /** What {@link listAppDeliveries} reads. */
1072
+ interface ListAppDeliveriesOptions extends Pick<GitHubClientOptions, "baseUrl" | "fetch"> {
1073
+ /** Stop at deliveries older than this ISO time. Without it, every page up to `maxPages` is read. */
1074
+ since?: string;
1075
+ /** The most pages to read, 100 deliveries each; defaults to 10, so 1,000 deliveries. */
1076
+ maxPages?: number;
1077
+ }
1078
+ /**
1079
+ * The webhook deliveries of the App this JWT identifies, newest first (`GET /app/hook/deliveries`), a page at a time by
1080
+ * the cursor GitHub hands back, until a delivery older than `since`, the last page, or `maxPages`. A delivery older than
1081
+ * `since` is left out. Needs no repository permission: the App's own JWT is the credential.
1082
+ */
1083
+ export declare function listAppDeliveries(creds: GitHubAppCredentials, opts?: ListAppDeliveriesOptions): Promise<GitHubAppDelivery[]>;
1084
+ /**
1085
+ * Asks GitHub to deliver one webhook delivery again (`POST /app/hook/deliveries/{id}/attempts`). GitHub answers 202 and
1086
+ * sends it asynchronously, so this says only that it was accepted.
1087
+ */
1088
+ export declare function redeliverAppDelivery(creds: GitHubAppCredentials, deliveryId: number, opts?: Pick<GitHubClientOptions, "baseUrl" | "fetch">): Promise<void>;
1002
1089
  /**
1003
1090
  * GitHub's own webhook mechanics — signature verification and header/
1004
1091
  * payload shapes. Pure functions, no REST call, no auth token: these
@@ -1107,6 +1194,9 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
1107
1194
  createCheckRun: (repo: string, input: CreateCheckRunInput) => Promise<GitHubCheckRun>;
1108
1195
  updateCheckRun: (repo: string, checkRunId: number, input: UpdateCheckRunInput) => Promise<GitHubCheckRun>;
1109
1196
  };
1197
+ statuses: {
1198
+ listCommitStatuses: (repo: string, ref: string) => Promise<GitHubCommitStatus[]>;
1199
+ };
1110
1200
  environments: {
1111
1201
  listEnvironments: (repo: string) => Promise<GitHubEnvironment[]>;
1112
1202
  upsertEnvironment: (repo: string, name: string, body: Record<string, unknown>) => Promise<void>;
@@ -1144,6 +1234,11 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
1144
1234
  addValues: (repo: string, number: number, values: IssueFieldValueInput[]) => Promise<GitHubIssueFieldValue[]>;
1145
1235
  deleteValue: (repo: string, number: number, fieldId: number) => Promise<void>;
1146
1236
  };
1237
+ issueTypes: {
1238
+ list: (org: string) => Promise<OrgIssueTypeInfo[]>;
1239
+ create: (org: string, input: IssueTypeInput) => Promise<OrgIssueTypeInfo>;
1240
+ update: (org: string, id: number, input: IssueTypeInput) => Promise<OrgIssueTypeInfo>;
1241
+ };
1147
1242
  issues: {
1148
1243
  listIssues: (repo: string, params?: IssueSearchParams) => Promise<GitHubIssue[]>;
1149
1244
  getIssue: (repo: string, number: number) => Promise<GitHubIssue>;
@@ -1261,4 +1356,4 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
1261
1356
  };
1262
1357
  /** The client returned by `createGitHubClient()`: one group of methods per GitHub API area. */
1263
1358
  export type GitHubClient = ReturnType<typeof createGitHubClient>;
1264
- export type { CheckRunAnnotation, CheckRunAnnotationLevel, CheckRunConclusion, CheckRunOutput, CheckRunStatus, CodeScanningSetupResult, CreateCheckRunInput, CreateHookInput, CreatePagesPayload, CreatePullInput, CreatePullRequestInput, CreateReviewComment, CreateReviewInput, GitBlob, GitCommit, GitContents, GitDirectoryEntry, GitHubApp, GitHubAppAccount, GitHubAppCredentials, GitHubAppInstallation, GitHubCheckRun, GitHubClientOptions, GitHubContents, GitHubEnvironment, GitHubHook, 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, HookScope, InstallationAccessToken, IssueFieldValueInput, IssueSearchParams, ListDirectoryOptions, OrgProperty, OrgSecretInfo, OrgSecretVisibility, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, RepoPropertyValue, RepoTeam, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdateHookInput, UpdatePagesPayload, UpdatePullRequestInput, VariableScope, VariableVisibility, WorkflowRunFilter };
1359
+ export type { CheckRunAnnotation, CheckRunAnnotationLevel, CheckRunConclusion, CheckRunOutput, CheckRunStatus, CodeScanningSetupResult, CommitStatusState, CreateCheckRunInput, CreateHookInput, CreatePagesPayload, CreatePullInput, CreatePullRequestInput, CreateReviewComment, CreateReviewInput, GitBlob, GitCommit, GitContents, GitDirectoryEntry, GitHubApp, GitHubAppAccount, GitHubAppCredentials, GitHubAppDelivery, GitHubAppInstallation, GitHubCheckRun, GitHubClientOptions, GitHubCommitStatus, GitHubContents, GitHubEnvironment, GitHubHook, 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, HookScope, InstallationAccessToken, IssueFieldValueInput, IssueSearchParams, IssueTypeColor, IssueTypeInput, ListAppDeliveriesOptions, ListDirectoryOptions, OrgIssueTypeInfo, OrgProperty, OrgSecretInfo, OrgSecretVisibility, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, RepoPropertyValue, RepoTeam, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdateHookInput, UpdatePagesPayload, UpdatePullRequestInput, VariableScope, VariableVisibility, WorkflowRunFilter };
package/dist/index.mjs CHANGED
@@ -349,6 +349,28 @@ function issueFields(rest) {
349
349
  })
350
350
  };
351
351
  }
352
+ // src/issue-types/issue-types.ts
353
+ /**
354
+ * The organization's issue Types (REST, `Issue types`). Deliberately has no `delete`: the CLI never removes a Type,
355
+ * and a method that is not here cannot be called by mistake. The token needs the organization permission Issue types
356
+ * (read to list, write to create or update) and, to write, an organization administrator.
357
+ */
358
+ function issueTypes(rest) {
359
+ return {
360
+ /** The Types the organization has. */
361
+ list: (org) => rest.request(`/orgs/${segment(org)}/issue-types`),
362
+ /** Makes a Type. */
363
+ create: (org, input) => rest.request(`/orgs/${segment(org)}/issue-types`, {
364
+ method: "POST",
365
+ body: input
366
+ }),
367
+ /** Replaces a Type: send back the name and `is_enabled` it already has, or they change. */
368
+ update: (org, id, input) => rest.request(`/orgs/${segment(org)}/issue-types/${id}`, {
369
+ method: "PUT",
370
+ body: input
371
+ })
372
+ };
373
+ }
352
374
  // src/issues/issues.ts
353
375
  function issues(rest) {
354
376
  return {
@@ -789,6 +811,26 @@ function security(rest) {
789
811
  })
790
812
  };
791
813
  }
814
+ // src/statuses/statuses.ts
815
+ /** Page size and the most pages {@link statuses}`.listCommitStatuses` reads: 100 a page over 10 pages. */
816
+ const STATUS_PAGE_SIZE = 100;
817
+ const STATUS_MAX_PAGES = 10;
818
+ function statuses(rest) {
819
+ return {
820
+ /**
821
+ * Every commit status on a ref, newest first (`GET /commits/{ref}/statuses`), read a page at a time until a page comes
822
+ * back short. A context that posted more than once appears once per post: the first one is the current state.
823
+ */
824
+ listCommitStatuses: async (repo, ref) => {
825
+ const all = [];
826
+ for (let page = 1; page <= STATUS_MAX_PAGES; page++) {
827
+ const batch = await rest.request(`${repoBase(repo)}/commits/${ref}/statuses?per_page=${STATUS_PAGE_SIZE}&page=${page}`);
828
+ all.push(...batch);
829
+ if (batch.length < STATUS_PAGE_SIZE) break;
830
+ }
831
+ return all;
832
+ } };
833
+ }
792
834
  // src/teams/teams.ts
793
835
  const PAGE$1 = 100;
794
836
  /** A guard so a runaway listing cannot loop forever: 50 pages of 100 is far more than any team. */
@@ -1122,19 +1164,25 @@ const account = (value) => {
1122
1164
  type: typeof type === "string" ? type : ""
1123
1165
  } : null;
1124
1166
  };
1125
- async function appGet(creds, path, opts) {
1167
+ async function appFetch(creds, path, opts, method = "GET") {
1126
1168
  const jwt = await createAppJWT(creds);
1127
1169
  const baseUrl = opts.baseUrl ?? "https://api.github.com";
1128
- const res = await (opts.fetch ?? globalThis.fetch)(`${baseUrl}${path}`, { headers: {
1129
- authorization: `Bearer ${jwt}`,
1130
- accept: "application/vnd.github+json",
1131
- "x-github-api-version": "2022-11-28"
1132
- } });
1170
+ const res = await (opts.fetch ?? globalThis.fetch)(`${baseUrl}${path}`, {
1171
+ method,
1172
+ headers: {
1173
+ authorization: `Bearer ${jwt}`,
1174
+ accept: "application/vnd.github+json",
1175
+ "x-github-api-version": "2022-11-28"
1176
+ }
1177
+ });
1133
1178
  if (!res.ok) {
1134
1179
  const body = await res.text().catch(() => "");
1135
- throw new ProviderApiError(`GitHub GET ${path} → ${res.status}`, res.status, body);
1180
+ throw new ProviderApiError(`GitHub ${method} ${path} → ${res.status}`, res.status, body);
1136
1181
  }
1137
- return res.json();
1182
+ return res;
1183
+ }
1184
+ async function appGet(creds, path, opts) {
1185
+ return (await appFetch(creds, path, opts)).json();
1138
1186
  }
1139
1187
  /** The App this JWT identifies: its slug, owner and the permissions and events it asks for now. */
1140
1188
  async function getApp(creds, opts = {}) {
@@ -1161,6 +1209,47 @@ async function listAppInstallations(creds, opts = {}) {
1161
1209
  if (raws.length < PAGE_SIZE) return installations;
1162
1210
  }
1163
1211
  }
1212
+ const DELIVERY_PAGES = 10;
1213
+ /** The `cursor` of the `rel="next"` link of a `Link` header, `undefined` when there is none. */
1214
+ function nextCursor(link) {
1215
+ const next = link?.split(",").find((part) => part.includes("rel=\"next\""));
1216
+ return /[?&]cursor=([^&>]+)/.exec(next ?? "")?.[1];
1217
+ }
1218
+ /**
1219
+ * The webhook deliveries of the App this JWT identifies, newest first (`GET /app/hook/deliveries`), a page at a time by
1220
+ * the cursor GitHub hands back, until a delivery older than `since`, the last page, or `maxPages`. A delivery older than
1221
+ * `since` is left out. Needs no repository permission: the App's own JWT is the credential.
1222
+ */
1223
+ async function listAppDeliveries(creds, opts = {}) {
1224
+ const deliveries = [];
1225
+ let cursor;
1226
+ for (let page = 0; page < (opts.maxPages ?? DELIVERY_PAGES); page++) {
1227
+ const res = await appFetch(creds, `/app/hook/deliveries?per_page=${PAGE_SIZE}${cursor === void 0 ? "" : `&cursor=${cursor}`}`, opts);
1228
+ const raws = await res.json();
1229
+ for (const raw of raws) deliveries.push({
1230
+ id: Number(raw.id),
1231
+ guid: String(raw.guid),
1232
+ deliveredAt: String(raw.delivered_at),
1233
+ redelivery: raw.redelivery === true,
1234
+ statusCode: Number(raw.status_code ?? 0),
1235
+ status: String(raw.status ?? ""),
1236
+ event: String(raw.event),
1237
+ action: typeof raw.action === "string" ? raw.action : null,
1238
+ installationId: typeof raw.installation_id === "number" ? raw.installation_id : null
1239
+ });
1240
+ cursor = nextCursor(res.headers.get("link"));
1241
+ const oldest = deliveries.at(-1);
1242
+ if (cursor === void 0 || opts.since !== void 0 && oldest !== void 0 && oldest.deliveredAt < opts.since) break;
1243
+ }
1244
+ return opts.since === void 0 ? deliveries : deliveries.filter((delivery) => delivery.deliveredAt >= opts.since);
1245
+ }
1246
+ /**
1247
+ * Asks GitHub to deliver one webhook delivery again (`POST /app/hook/deliveries/{id}/attempts`). GitHub answers 202 and
1248
+ * sends it asynchronously, so this says only that it was accepted.
1249
+ */
1250
+ async function redeliverAppDelivery(creds, deliveryId, opts = {}) {
1251
+ await appFetch(creds, `/app/hook/deliveries/${deliveryId}/attempts`, opts, "POST");
1252
+ }
1164
1253
  // src/webhooks/webhooks.ts
1165
1254
  /**
1166
1255
  * GitHub's own webhook mechanics — signature verification and header/
@@ -1214,12 +1303,14 @@ function createGitHubClient(opts) {
1214
1303
  return {
1215
1304
  branches: branches(rest),
1216
1305
  checks: checks(rest),
1306
+ statuses: statuses(rest),
1217
1307
  environments: environments(rest),
1218
1308
  git: git(rest),
1219
1309
  /** The GraphQL client, for the callers whose API (Projects v2) has no REST form. */
1220
1310
  graphql,
1221
1311
  hooks: hooks(rest),
1222
1312
  issueFields: issueFields(rest),
1313
+ issueTypes: issueTypes(rest),
1223
1314
  issues: issues(rest),
1224
1315
  labels: labels(rest),
1225
1316
  pages: pages(rest),
@@ -1236,4 +1327,4 @@ function createGitHubClient(opts) {
1236
1327
  workflows: workflows(rest)
1237
1328
  };
1238
1329
  }
1239
- export { MAX_CHECK_RUN_ANNOTATIONS, createAppJWT, createGitHubClient, createInstallationClient, getApp, getInstallationAccessToken, listAppInstallations, parseGitHubWebhookHeaders, parseTokenExpiration, verifyGitHubWebhookSignature };
1330
+ export { MAX_CHECK_RUN_ANNOTATIONS, createAppJWT, createGitHubClient, createInstallationClient, getApp, getInstallationAccessToken, listAppDeliveries, listAppInstallations, parseGitHubWebhookHeaders, parseTokenExpiration, redeliverAppDelivery, verifyGitHubWebhookSignature };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/github-client",
3
- "version": "1.58.0-alpha.51",
3
+ "version": "1.58.0-alpha.53",
4
4
  "description": "A TypeScript client for the GitHub REST API",
5
5
  "keywords": [
6
6
  "github",
@@ -32,7 +32,7 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@theholocron/http-client": "^1.58.0-alpha.51",
35
+ "@theholocron/http-client": "^1.58.0-alpha.53",
36
36
  "@theholocron/observability": "^0.7.0-alpha.6"
37
37
  },
38
38
  "devDependencies": {
@@ -45,8 +45,8 @@
45
45
  "tsdown": "^0.23.7",
46
46
  "typescript": "^6.0.3",
47
47
  "vitest": "^5.1.0",
48
- "@theholocron/eslint-config": "^8.9.0-alpha.22",
49
48
  "@theholocron/tsconfig": "^8.9.0-alpha.22",
49
+ "@theholocron/eslint-config": "^8.9.0-alpha.22",
50
50
  "@theholocron/tsdown-config": "^8.9.0-alpha.22",
51
51
  "@theholocron/vitest-config": "^8.9.0-alpha.22"
52
52
  },