@theholocron/github-client 1.57.1-alpha.2 → 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 +14 -0
- package/dist/index.mjs +37 -4
- package/package.json +2 -2
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";
|
|
@@ -241,8 +248,12 @@ interface GitHubPullRequest {
|
|
|
241
248
|
state: "open" | "closed";
|
|
242
249
|
merged_at: string | null;
|
|
243
250
|
html_url: string;
|
|
251
|
+
/** The head branch: its name and the commit it pointed at when the PR was read. */
|
|
244
252
|
head: {
|
|
253
|
+
/** The branch name, e.g. `fix/my-change`. */
|
|
245
254
|
ref: string;
|
|
255
|
+
/** The head commit. */
|
|
256
|
+
sha: string;
|
|
246
257
|
};
|
|
247
258
|
}
|
|
248
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). */
|
|
@@ -511,6 +522,8 @@ interface GitHubPullRequestWebhookPayload {
|
|
|
511
522
|
export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
512
523
|
branches: {
|
|
513
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>;
|
|
514
527
|
};
|
|
515
528
|
checks: {
|
|
516
529
|
createCheckRun: (repo: string, input: CreateCheckRunInput) => Promise<GitHubCheckRun>;
|
|
@@ -575,6 +588,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
|
|
|
575
588
|
};
|
|
576
589
|
pulls: {
|
|
577
590
|
getPullRequest: (repo: string, number: number) => Promise<GitHubPullRequest>;
|
|
591
|
+
listPullRequests: (repo: string, state: "open" | "closed") => Promise<GitHubPullRequest[]>;
|
|
578
592
|
listCommits: (repo: string, number: number) => Promise<GitHubPullRequestCommit[]>;
|
|
579
593
|
listFiles: (repo: string, number: number) => Promise<GitHubPullRequestFile[]>;
|
|
580
594
|
createReview: (repo: string, number: number, input: CreateReviewInput) => Promise<GitHubPullRequestReview>;
|
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
|
/**
|
|
@@ -331,10 +348,26 @@ const RESOLVE_REVIEW_THREAD_MUTATION = `
|
|
|
331
348
|
}
|
|
332
349
|
}
|
|
333
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;
|
|
334
354
|
function pulls(rest, graphql) {
|
|
335
355
|
return {
|
|
336
356
|
getPullRequest: (repo, number) => rest.request(`${repoBase(repo)}/pulls/${number}`),
|
|
337
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
|
+
/**
|
|
338
371
|
* A PR's own commits, in commit order. `per_page=100` — GitHub's max —
|
|
339
372
|
* covers every real PR in this org; a PR genuinely exceeding 100
|
|
340
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,7 +32,7 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@theholocron/http-client": "^1.
|
|
35
|
+
"@theholocron/http-client": "^1.58.0-alpha.1",
|
|
36
36
|
"@theholocron/observability": "^0.6.1-alpha.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|