@theholocron/github-client 1.58.0-alpha.49 → 1.58.0-alpha.50
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 +48 -1
- package/dist/index.mjs +54 -0
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -294,6 +294,48 @@ interface CreatePullInput {
|
|
|
294
294
|
/** The pull request's description. */
|
|
295
295
|
body?: string;
|
|
296
296
|
}
|
|
297
|
+
/** Where a webhook lives: one repository (`owner/name`) or an organization. */
|
|
298
|
+
type HookScope = {
|
|
299
|
+
kind: "repo";
|
|
300
|
+
repo: string;
|
|
301
|
+
} | {
|
|
302
|
+
kind: "organization";
|
|
303
|
+
org: string;
|
|
304
|
+
};
|
|
305
|
+
/** A webhook as GitHub returns it. The signing secret is never part of it (GitHub shows `********` or leaves it out). */
|
|
306
|
+
interface GitHubHook {
|
|
307
|
+
/** GitHub's id for the webhook. */
|
|
308
|
+
id: number;
|
|
309
|
+
/** Whether GitHub delivers to it. */
|
|
310
|
+
active: boolean;
|
|
311
|
+
/** The events it subscribes to (`dependabot_alert`, `push`, `*`). */
|
|
312
|
+
events: string[];
|
|
313
|
+
/** Where and how it delivers. */
|
|
314
|
+
config: {
|
|
315
|
+
/** The URL GitHub posts to. */
|
|
316
|
+
url?: string;
|
|
317
|
+
/** `json` or `form`. */
|
|
318
|
+
content_type?: string;
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
/** What makes a webhook. */
|
|
322
|
+
interface CreateHookInput {
|
|
323
|
+
/** Where GitHub posts. */
|
|
324
|
+
url: string;
|
|
325
|
+
/** The secret GitHub signs each delivery with (`X-Hub-Signature-256`). A credential. */
|
|
326
|
+
secret: string;
|
|
327
|
+
/** The events to subscribe to. */
|
|
328
|
+
events: string[];
|
|
329
|
+
/** Whether it delivers; default `true`. */
|
|
330
|
+
active?: boolean;
|
|
331
|
+
}
|
|
332
|
+
/** What changes on an existing webhook: only these, so the URL and the secret are left as they are. */
|
|
333
|
+
interface UpdateHookInput {
|
|
334
|
+
/** The events to subscribe to. */
|
|
335
|
+
events?: string[];
|
|
336
|
+
/** Whether it delivers. */
|
|
337
|
+
active?: boolean;
|
|
338
|
+
}
|
|
297
339
|
/** One option of a single-select issue field. */
|
|
298
340
|
interface GitHubIssueFieldOption {
|
|
299
341
|
/** The option's id. */
|
|
@@ -1091,6 +1133,11 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
1091
1133
|
};
|
|
1092
1134
|
/** The GraphQL client, for the callers whose API (Projects v2) has no REST form. */
|
|
1093
1135
|
graphql: GraphQLClient;
|
|
1136
|
+
hooks: {
|
|
1137
|
+
listHooks: (scope: HookScope) => Promise<GitHubHook[]>;
|
|
1138
|
+
createHook: (scope: HookScope, input: CreateHookInput) => Promise<GitHubHook>;
|
|
1139
|
+
updateHook: (scope: HookScope, id: number, input: UpdateHookInput) => Promise<GitHubHook>;
|
|
1140
|
+
};
|
|
1094
1141
|
issueFields: {
|
|
1095
1142
|
list: (org: string) => Promise<GitHubIssueField[]>;
|
|
1096
1143
|
values: (repo: string, number: number) => Promise<GitHubIssueFieldValue[]>;
|
|
@@ -1214,4 +1261,4 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
1214
1261
|
};
|
|
1215
1262
|
/** The client returned by `createGitHubClient()`: one group of methods per GitHub API area. */
|
|
1216
1263
|
export type GitHubClient = ReturnType<typeof createGitHubClient>;
|
|
1217
|
-
export type { CheckRunAnnotation, CheckRunAnnotationLevel, CheckRunConclusion, CheckRunOutput, CheckRunStatus, CodeScanningSetupResult, CreateCheckRunInput, CreatePagesPayload, CreatePullInput, CreatePullRequestInput, 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, UpdatePullRequestInput, VariableScope, VariableVisibility, WorkflowRunFilter };
|
|
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -274,6 +274,59 @@ function git(rest) {
|
|
|
274
274
|
})
|
|
275
275
|
};
|
|
276
276
|
}
|
|
277
|
+
// src/hooks/hooks.ts
|
|
278
|
+
/** GitHub's largest page for this listing. */
|
|
279
|
+
const PAGE$2 = 100;
|
|
280
|
+
/** A guard so a runaway listing cannot loop forever. */
|
|
281
|
+
const MAX_PAGES$2 = 50;
|
|
282
|
+
function hooksPath(scope) {
|
|
283
|
+
if (scope.kind === "organization") return `/orgs/${segment(scope.org)}/hooks`;
|
|
284
|
+
const parts = scope.repo.split("/");
|
|
285
|
+
if (parts.length !== 2 || parts.some((p) => p === "")) throw new Error(`invalid repository: ${JSON.stringify(scope.repo)} (expected "owner/name")`);
|
|
286
|
+
return `/repos/${parts.map(segment).join("/")}/hooks`;
|
|
287
|
+
}
|
|
288
|
+
/** Webhooks of a repository or an organization (`/repos/{r}/hooks`, `/orgs/{o}/hooks`). */
|
|
289
|
+
function hooks(rest) {
|
|
290
|
+
return {
|
|
291
|
+
/** Every webhook in the scope, read page by page. */
|
|
292
|
+
listHooks: async (scope) => {
|
|
293
|
+
const path = hooksPath(scope);
|
|
294
|
+
const all = [];
|
|
295
|
+
for (let page = 1; page <= MAX_PAGES$2; page++) {
|
|
296
|
+
const batch = await rest.request(path, { query: {
|
|
297
|
+
per_page: String(PAGE$2),
|
|
298
|
+
page: String(page)
|
|
299
|
+
} });
|
|
300
|
+
all.push(...batch);
|
|
301
|
+
if (batch.length < PAGE$2) return all;
|
|
302
|
+
}
|
|
303
|
+
throw new Error(`more than 5000 webhooks in ${path}; refusing to read them all`);
|
|
304
|
+
},
|
|
305
|
+
/** Makes a JSON webhook that delivers to `url`, signed with `secret`. */
|
|
306
|
+
createHook: (scope, input) => rest.request(hooksPath(scope), {
|
|
307
|
+
method: "POST",
|
|
308
|
+
body: {
|
|
309
|
+
name: "web",
|
|
310
|
+
active: input.active ?? true,
|
|
311
|
+
events: input.events,
|
|
312
|
+
config: {
|
|
313
|
+
url: input.url,
|
|
314
|
+
content_type: "json",
|
|
315
|
+
secret: input.secret,
|
|
316
|
+
insecure_ssl: "0"
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}),
|
|
320
|
+
/** Changes a webhook's events or `active` flag; the `config` (URL and secret) is not sent, so it stays. */
|
|
321
|
+
updateHook: (scope, id, input) => rest.request(`${hooksPath(scope)}/${segment(String(id))}`, {
|
|
322
|
+
method: "PATCH",
|
|
323
|
+
body: {
|
|
324
|
+
...input.events !== void 0 ? { events: input.events } : {},
|
|
325
|
+
...input.active !== void 0 ? { active: input.active } : {}
|
|
326
|
+
}
|
|
327
|
+
})
|
|
328
|
+
};
|
|
329
|
+
}
|
|
277
330
|
// src/issue-fields/issue-fields.ts
|
|
278
331
|
function issueFields(rest) {
|
|
279
332
|
return {
|
|
@@ -1165,6 +1218,7 @@ function createGitHubClient(opts) {
|
|
|
1165
1218
|
git: git(rest),
|
|
1166
1219
|
/** The GraphQL client, for the callers whose API (Projects v2) has no REST form. */
|
|
1167
1220
|
graphql,
|
|
1221
|
+
hooks: hooks(rest),
|
|
1168
1222
|
issueFields: issueFields(rest),
|
|
1169
1223
|
issues: issues(rest),
|
|
1170
1224
|
labels: labels(rest),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/github-client",
|
|
3
|
-
"version": "1.58.0-alpha.
|
|
3
|
+
"version": "1.58.0-alpha.50",
|
|
4
4
|
"description": "A TypeScript client for the GitHub REST API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@theholocron/
|
|
36
|
-
"@theholocron/
|
|
35
|
+
"@theholocron/observability": "^0.7.0-alpha.5",
|
|
36
|
+
"@theholocron/http-client": "^1.58.0-alpha.50"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^26",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"typescript": "^5.9.3",
|
|
47
47
|
"vitest": "^5.1.0",
|
|
48
48
|
"@theholocron/tsconfig": "^8.9.0-alpha.21",
|
|
49
|
-
"@theholocron/
|
|
49
|
+
"@theholocron/eslint-config": "^8.9.0-alpha.21",
|
|
50
50
|
"@theholocron/vitest-config": "^8.9.0-alpha.21",
|
|
51
|
-
"@theholocron/
|
|
51
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.21"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=22.0.0"
|