@theholocron/github-client 1.57.1-alpha.1 → 1.58.0-alpha.1
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 +25 -1
- package/dist/index.mjs +62 -23
- package/package.json +8 -8
package/dist/index.d.mts
CHANGED
|
@@ -9,6 +9,13 @@ interface GitHubClientOptions {
|
|
|
9
9
|
/** Reports transport failures and unexpected 5xx. Defaults to a no-op. */
|
|
10
10
|
errors?: ErrorSink;
|
|
11
11
|
}
|
|
12
|
+
/** One branch as `GET /branches` returns it: its name and the commit it points at. */
|
|
13
|
+
interface GitHubBranch {
|
|
14
|
+
name: string;
|
|
15
|
+
commit: {
|
|
16
|
+
sha: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
12
19
|
type CheckRunStatus = "queued" | "in_progress" | "completed";
|
|
13
20
|
type CheckRunConclusion = "success" | "failure" | "neutral" | "cancelled" | "timed_out" | "action_required" | "skipped";
|
|
14
21
|
type CheckRunAnnotationLevel = "notice" | "warning" | "failure";
|
|
@@ -226,14 +233,27 @@ interface UpdatePagesPayload {
|
|
|
226
233
|
cname?: string | null;
|
|
227
234
|
https_enforced?: boolean;
|
|
228
235
|
}
|
|
236
|
+
/** One custom property of an organization, as its schema defines it. */
|
|
237
|
+
interface OrgProperty {
|
|
238
|
+
property_name: string;
|
|
239
|
+
/** `string`, `single_select`, `multi_select`, `true_false` or `url`. */
|
|
240
|
+
value_type: string;
|
|
241
|
+
required?: boolean;
|
|
242
|
+
/** The values a `single_select` or `multi_select` property accepts; `null` for any other type. */
|
|
243
|
+
allowed_values?: string[] | null;
|
|
244
|
+
}
|
|
229
245
|
interface GitHubPullRequest {
|
|
230
246
|
number: number;
|
|
231
247
|
title: string;
|
|
232
248
|
state: "open" | "closed";
|
|
233
249
|
merged_at: string | null;
|
|
234
250
|
html_url: string;
|
|
251
|
+
/** The head branch: its name and the commit it pointed at when the PR was read. */
|
|
235
252
|
head: {
|
|
253
|
+
/** The branch name, e.g. `fix/my-change`. */
|
|
236
254
|
ref: string;
|
|
255
|
+
/** The head commit. */
|
|
256
|
+
sha: string;
|
|
237
257
|
};
|
|
238
258
|
}
|
|
239
259
|
/** 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). */
|
|
@@ -502,6 +522,8 @@ interface GitHubPullRequestWebhookPayload {
|
|
|
502
522
|
export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
503
523
|
branches: {
|
|
504
524
|
protectBranch: (repo: string, branch: string, payload: Record<string, unknown>) => Promise<void>;
|
|
525
|
+
listBranches: (repo: string) => Promise<GitHubBranch[]>;
|
|
526
|
+
removeBranch: (repo: string, branch: string) => Promise<void>;
|
|
505
527
|
};
|
|
506
528
|
checks: {
|
|
507
529
|
createCheckRun: (repo: string, input: CreateCheckRunInput) => Promise<GitHubCheckRun>;
|
|
@@ -561,10 +583,12 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
561
583
|
updatePages: (repo: string, payload: UpdatePagesPayload) => Promise<void>;
|
|
562
584
|
};
|
|
563
585
|
properties: {
|
|
586
|
+
orgSchema: (org: string) => Promise<OrgProperty[]>;
|
|
564
587
|
setProperties: (repo: string, values: Record<string, string | string[]>) => Promise<void>;
|
|
565
588
|
};
|
|
566
589
|
pulls: {
|
|
567
590
|
getPullRequest: (repo: string, number: number) => Promise<GitHubPullRequest>;
|
|
591
|
+
listPullRequests: (repo: string, state: "open" | "closed") => Promise<GitHubPullRequest[]>;
|
|
568
592
|
listCommits: (repo: string, number: number) => Promise<GitHubPullRequestCommit[]>;
|
|
569
593
|
listFiles: (repo: string, number: number) => Promise<GitHubPullRequestFile[]>;
|
|
570
594
|
createReview: (repo: string, number: number, input: CreateReviewInput) => Promise<GitHubPullRequestReview>;
|
|
@@ -620,4 +644,4 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
620
644
|
};
|
|
621
645
|
};
|
|
622
646
|
export type GitHubClient = ReturnType<typeof createGitHubClient>;
|
|
623
|
-
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, GitHubVariable, GitHubWebhookHeaders, GitHubWorkflowRun, GitPull, GitRef, GitTree, GitTreeItem, InstallationAccessToken, IssueSearchParams, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdatePagesPayload, VariableScope, VariableVisibility, WorkflowRunFilter };
|
|
647
|
+
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, GitHubVariable, GitHubWebhookHeaders, GitHubWorkflowRun, GitPull, GitRef, GitTree, GitTreeItem, InstallationAccessToken, IssueSearchParams, OrgProperty, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdatePagesPayload, VariableScope, VariableVisibility, WorkflowRunFilter };
|
package/dist/index.mjs
CHANGED
|
@@ -76,11 +76,28 @@ function toBase64(text) {
|
|
|
76
76
|
return btoa(binary);
|
|
77
77
|
}
|
|
78
78
|
// src/branches/branches.ts
|
|
79
|
+
/** Page size and the most pages {@link branches}`.listBranches` reads: 100 a page (GitHub's maximum) over 100 pages. */
|
|
80
|
+
const BRANCH_PAGE_SIZE = 100;
|
|
81
|
+
const BRANCH_MAX_PAGES = 100;
|
|
79
82
|
function branches(rest) {
|
|
80
|
-
return {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
return {
|
|
84
|
+
protectBranch: (repo, branch, payload) => rest.request(`${repoBase(repo)}/branches/${encodeURIComponent(branch)}/protection`, {
|
|
85
|
+
method: "PUT",
|
|
86
|
+
body: payload
|
|
87
|
+
}),
|
|
88
|
+
/** Every branch, read a page at a time until a page comes back short. */
|
|
89
|
+
listBranches: async (repo) => {
|
|
90
|
+
const all = [];
|
|
91
|
+
for (let page = 1; page <= BRANCH_MAX_PAGES; page++) {
|
|
92
|
+
const batch = await rest.request(`${repoBase(repo)}/branches?per_page=${BRANCH_PAGE_SIZE}&page=${page}`);
|
|
93
|
+
all.push(...batch);
|
|
94
|
+
if (batch.length < BRANCH_PAGE_SIZE) break;
|
|
95
|
+
}
|
|
96
|
+
return all;
|
|
97
|
+
},
|
|
98
|
+
/** Delete one branch's ref. The name keeps its `/`s; each segment is encoded. */
|
|
99
|
+
removeBranch: (repo, branch) => rest.request(`${repoBase(repo)}/git/refs/heads/${branch.split("/").map(encodeURIComponent).join("/")}`, { method: "DELETE" })
|
|
100
|
+
};
|
|
84
101
|
}
|
|
85
102
|
// src/checks/checks.ts
|
|
86
103
|
/**
|
|
@@ -275,25 +292,31 @@ function pages(rest) {
|
|
|
275
292
|
}
|
|
276
293
|
// src/properties/properties.ts
|
|
277
294
|
function properties(rest) {
|
|
278
|
-
return {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
295
|
+
return {
|
|
296
|
+
/**
|
|
297
|
+
* The custom properties an organization defines, with their types and allowed values (read-only).
|
|
298
|
+
* The token needs read access to the organization's custom properties.
|
|
299
|
+
*/
|
|
300
|
+
orgSchema: (org) => rest.request(`/orgs/${segment(org)}/properties/schema`),
|
|
301
|
+
/**
|
|
302
|
+
* `value` is a plain string for `string`/`single_select`/`true_false`
|
|
303
|
+
* custom properties, or a string array for `multi_select` ones —
|
|
304
|
+
* GitHub's own PATCH body accepts either per property. A single-string
|
|
305
|
+
* comma-joined value has no length ceiling GitHub documents, but real
|
|
306
|
+
* usage hits one in practice (a `string`-type property with enough
|
|
307
|
+
* joined values 422s as "too long"); `multi_select` has none.
|
|
308
|
+
*/
|
|
309
|
+
setProperties: (repo, values) => {
|
|
310
|
+
const propertyList = Object.entries(values).map(([property_name, value]) => ({
|
|
311
|
+
property_name,
|
|
312
|
+
value
|
|
313
|
+
}));
|
|
314
|
+
return rest.request(`${repoBase(repo)}/properties/values`, {
|
|
315
|
+
method: "PATCH",
|
|
316
|
+
body: { properties: propertyList }
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
};
|
|
297
320
|
}
|
|
298
321
|
// src/pulls/pulls.ts
|
|
299
322
|
const LIST_REVIEW_THREADS_QUERY = `
|
|
@@ -325,10 +348,26 @@ const RESOLVE_REVIEW_THREAD_MUTATION = `
|
|
|
325
348
|
}
|
|
326
349
|
}
|
|
327
350
|
`;
|
|
351
|
+
/** Page size and the most pages {@link pulls}`.listPullRequests` reads: 100 a page (GitHub's maximum) over 100 pages, so 10,000 pull requests. */
|
|
352
|
+
const PULL_REQUEST_PAGE_SIZE = 100;
|
|
353
|
+
const PULL_REQUEST_MAX_PAGES = 100;
|
|
328
354
|
function pulls(rest, graphql) {
|
|
329
355
|
return {
|
|
330
356
|
getPullRequest: (repo, number) => rest.request(`${repoBase(repo)}/pulls/${number}`),
|
|
331
357
|
/**
|
|
358
|
+
* Every pull request in one state, newest first, read a page at a time until a page comes back short.
|
|
359
|
+
* `closed` includes the merged ones; tell them apart by `merged_at`.
|
|
360
|
+
*/
|
|
361
|
+
listPullRequests: async (repo, state) => {
|
|
362
|
+
const all = [];
|
|
363
|
+
for (let page = 1; page <= PULL_REQUEST_MAX_PAGES; page++) {
|
|
364
|
+
const batch = await rest.request(`${repoBase(repo)}/pulls?state=${state}&sort=created&direction=desc&per_page=${PULL_REQUEST_PAGE_SIZE}&page=${page}`);
|
|
365
|
+
all.push(...batch);
|
|
366
|
+
if (batch.length < PULL_REQUEST_PAGE_SIZE) break;
|
|
367
|
+
}
|
|
368
|
+
return all;
|
|
369
|
+
},
|
|
370
|
+
/**
|
|
332
371
|
* A PR's own commits, in commit order. `per_page=100` — GitHub's max —
|
|
333
372
|
* covers every real PR in this org; a PR genuinely exceeding 100
|
|
334
373
|
* commits (GitHub caps this endpoint at 250 regardless of pagination)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/github-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.58.0-alpha.1",
|
|
4
4
|
"description": "A TypeScript client for the GitHub REST API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github",
|
|
@@ -32,14 +32,10 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@theholocron/
|
|
36
|
-
"@theholocron/
|
|
35
|
+
"@theholocron/http-client": "^1.58.0-alpha.1",
|
|
36
|
+
"@theholocron/observability": "^0.6.1-alpha.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@theholocron/eslint-config": "^8.8.2",
|
|
40
|
-
"@theholocron/tsconfig": "^8.8.2",
|
|
41
|
-
"@theholocron/tsdown-config": "^8.8.2",
|
|
42
|
-
"@theholocron/vitest-config": "^8.8.2",
|
|
43
39
|
"@types/node": "^26",
|
|
44
40
|
"@vitest/coverage-v8": "^5.0.5",
|
|
45
41
|
"@vitest/eslint-plugin": "^1.6.27",
|
|
@@ -48,7 +44,11 @@
|
|
|
48
44
|
"globals": "^17.11.0",
|
|
49
45
|
"tsdown": "^0.23.3",
|
|
50
46
|
"typescript": "^5.9.3",
|
|
51
|
-
"vitest": "^5.0.5"
|
|
47
|
+
"vitest": "^5.0.5",
|
|
48
|
+
"@theholocron/tsconfig": "^8.9.0-alpha.3",
|
|
49
|
+
"@theholocron/eslint-config": "^8.9.0-alpha.3",
|
|
50
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.3",
|
|
51
|
+
"@theholocron/vitest-config": "^8.9.0-alpha.3"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=22.0.0"
|