@theholocron/holocron-plugin-github 5.6.0 → 5.8.0
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 +11 -1
- package/dist/index.mjs +124 -4
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* receives plugin-level options from `holocron.config.json` and
|
|
8
8
|
* returns the bound implementation.
|
|
9
9
|
*/
|
|
10
|
-
import { AddedItem, Auth, AuthError, BoardItem, BoardItemInput, BoardState, BoardSummary, BoardTemplate, Ci, CiRun, CiRunFilter, EnsureRelaySourceInput, EnsureRelaySourceResult, EnsureReport, Environment, Environments, ExportInfo, ImportOptions, ImportResult, InspectRelaySourceInput, Issue, IssueCreateInput, IssuePatch, IssueRecord, IssueSearchFilter, IssueSelector, IssueTypeDeclaration, IssueTypeInfo, IssueUpdateResult, Issues, LabelDef, LifecycleResult, LifecycleSlot, MoveReport, PagesConfig, PluginToken, Projects, PullRequest, PullRequestChecks, PullRequestInput, PullRequestPatch, PullRequestResult, PullRequestState, RelaySourceState, RepoRef, RepoSettings, ResolveTokenInput, Ruleset, SecretAccess, SecretScope, Secrets, Source, SourceBranch, SourceCheckRun, SourceCheckRunWrite, SourceCommitStatus, SourceFile, SourceRepoInfo, SourceRequiredChecks, SourceRulesetDetail, SourceSecurity, SourceTeamMember, SyncResult, TeamEntry, TeamEntry as TeamEntry$1, TeamPermission, TeamPermission as TeamPermission$1, TrackerDoctorReport, TrackerUser, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess, createFeatureResolver } from "@theholocron/cli";
|
|
10
|
+
import { AddedItem, Auth, AuthError, BoardItem, BoardItemInput, BoardState, BoardSummary, BoardTemplate, Ci, CiRun, CiRunFilter, CommitFilesInput, CommitFilesResult, EnsureRelaySourceInput, EnsureRelaySourceResult, EnsureReport, Environment, Environments, ExportInfo, ImportOptions, ImportResult, InspectRelaySourceInput, Issue, IssueCreateInput, IssuePatch, IssueRecord, IssueSearchFilter, IssueSelector, IssueTypeDeclaration, IssueTypeInfo, IssueUpdateResult, Issues, LabelDef, LifecycleResult, LifecycleSlot, MoveReport, PagesConfig, PluginToken, Projects, PullRequest, PullRequestChecks, PullRequestInput, PullRequestPatch, PullRequestResult, PullRequestState, RelaySourceState, RepoRef, RepoSettings, ResolveTokenInput, Ruleset, SecretAccess, SecretScope, Secrets, Source, SourceBranch, SourceCheckRun, SourceCheckRunWrite, SourceCommitStatus, SourceFile, SourceRepoInfo, SourceRequiredChecks, SourceRulesetDetail, SourceSecurity, SourceTeamMember, SourceTree, SyncResult, TeamEntry, TeamEntry as TeamEntry$1, TeamPermission, TeamPermission as TeamPermission$1, TrackerDoctorReport, TrackerUser, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess, createFeatureResolver } from "@theholocron/cli";
|
|
11
11
|
import { GitHubClient, GitHubClientOptions, GraphQLClient, createGitHubClient } from "@theholocron/github-client";
|
|
12
12
|
/** Resolves the token for read-only GitHub access (`HOLOCRON_READ_TOKEN`, keyring key `github.read`). */
|
|
13
13
|
export declare const resolveReadToken: import("@theholocron/cli").FeatureResolver;
|
|
@@ -443,6 +443,8 @@ export declare class GitHubSource implements Source {
|
|
|
443
443
|
listPullRequests(state: "open" | "closed", repo?: string): Promise<PullRequest[]>;
|
|
444
444
|
readPullRequestState(number: number, repo?: string, required?: SourceRequiredChecks): Promise<PullRequestState | undefined>;
|
|
445
445
|
listFiles(repo?: string): Promise<string[]>;
|
|
446
|
+
readTree(repo?: string): Promise<SourceTree>;
|
|
447
|
+
commitFiles(input: CommitFilesInput): Promise<CommitFilesResult>;
|
|
446
448
|
deleteFile(path: string, opts: {
|
|
447
449
|
message: string;
|
|
448
450
|
repo?: string;
|
|
@@ -455,6 +457,14 @@ export declare class GitHubSource implements Source {
|
|
|
455
457
|
listPullRequestFiles(number: number, repo?: string): Promise<string[]>;
|
|
456
458
|
createPullRequest(input: PullRequestInput, repo?: string): Promise<PullRequestResult>;
|
|
457
459
|
updatePullRequest(number: number, patch: PullRequestPatch, repo?: string): Promise<PullRequestResult>;
|
|
460
|
+
mergePullRequest(number: number, options?: {
|
|
461
|
+
method?: "merge" | "squash" | "rebase";
|
|
462
|
+
title?: string;
|
|
463
|
+
}, repo?: string): Promise<{
|
|
464
|
+
merged: boolean;
|
|
465
|
+
commit?: string;
|
|
466
|
+
reason?: string;
|
|
467
|
+
}>;
|
|
458
468
|
markReady(number: number, repo?: string): Promise<boolean>;
|
|
459
469
|
getPullRequestChecks(number: number, repo?: string, required?: SourceRequiredChecks): Promise<PullRequestChecks>;
|
|
460
470
|
listCheckRuns(ref: string, repo?: string): Promise<SourceCheckRun[]>;
|
package/dist/index.mjs
CHANGED
|
@@ -2264,18 +2264,19 @@ async function writeRepoFile(client, repo, path, content, opts) {
|
|
|
2264
2264
|
throw err;
|
|
2265
2265
|
}
|
|
2266
2266
|
}
|
|
2267
|
-
/** The default branch's commit and tree, read from the branch the repository names. */
|
|
2267
|
+
/** The default branch's name, commit and tree, read from the branch the repository names. */
|
|
2268
2268
|
async function defaultHead(client, repo) {
|
|
2269
2269
|
const { default_branch } = await client.repos.getRepo(repo);
|
|
2270
2270
|
const ref = await client.git.getRef(repo, default_branch);
|
|
2271
2271
|
const commit = await client.git.getCommit(repo, ref.object.sha);
|
|
2272
2272
|
return {
|
|
2273
|
+
branch: default_branch,
|
|
2273
2274
|
commit: commit.sha,
|
|
2274
2275
|
tree: commit.tree.sha
|
|
2275
2276
|
};
|
|
2276
2277
|
}
|
|
2277
|
-
/**
|
|
2278
|
-
async function
|
|
2278
|
+
/** The default branch's recursive tree and the commit it was read at. Throws when the repo is not found or GitHub cut the tree short. */
|
|
2279
|
+
async function recursiveHead(client, repo) {
|
|
2279
2280
|
let head;
|
|
2280
2281
|
try {
|
|
2281
2282
|
head = await defaultHead(client, repo);
|
|
@@ -2285,7 +2286,91 @@ async function listRepoFiles(client, repo) {
|
|
|
2285
2286
|
}
|
|
2286
2287
|
const tree = await client.git.getTree(repo, head.tree, true);
|
|
2287
2288
|
if (tree.truncated) throw new Error(`${repo}: the file list is too large for GitHub to return whole`);
|
|
2288
|
-
return
|
|
2289
|
+
return {
|
|
2290
|
+
commit: head.commit,
|
|
2291
|
+
branch: head.branch,
|
|
2292
|
+
items: tree.tree
|
|
2293
|
+
};
|
|
2294
|
+
}
|
|
2295
|
+
/** Every file (not folder) on the default branch, as a path from the repository root, sorted. Throws when GitHub cut the tree short. */
|
|
2296
|
+
async function listRepoFiles(client, repo) {
|
|
2297
|
+
const { items } = await recursiveHead(client, repo);
|
|
2298
|
+
return items.filter((item) => item.type === "blob").map((item) => item.path).sort();
|
|
2299
|
+
}
|
|
2300
|
+
/** Every file on the default branch with its mode and blob sha, sorted by path, and the commit they were read at. Throws when GitHub cut the tree short. */
|
|
2301
|
+
async function readRepoTree(client, repo) {
|
|
2302
|
+
const { commit, branch, items } = await recursiveHead(client, repo);
|
|
2303
|
+
return {
|
|
2304
|
+
commit,
|
|
2305
|
+
branch,
|
|
2306
|
+
entries: items.filter((item) => item.type === "blob").map((item) => ({
|
|
2307
|
+
path: item.path,
|
|
2308
|
+
mode: item.mode,
|
|
2309
|
+
sha: item.sha
|
|
2310
|
+
})).sort((a, b) => Number(a.path > b.path) - Number(a.path < b.path))
|
|
2311
|
+
};
|
|
2312
|
+
}
|
|
2313
|
+
/** How many blobs are created at once: enough to be quick, few enough to stay clear of GitHub's secondary rate limit. */
|
|
2314
|
+
const BLOB_BATCH = 8;
|
|
2315
|
+
/**
|
|
2316
|
+
* Makes `branch` point at `commit`: created when it is missing, put back there (forced) when a run before left it
|
|
2317
|
+
* somewhere else, since the branch is only ever a carrier for one pull request.
|
|
2318
|
+
*/
|
|
2319
|
+
async function pointBranchAt(client, repo, branch, commit) {
|
|
2320
|
+
let existing;
|
|
2321
|
+
try {
|
|
2322
|
+
existing = await client.git.getRef(repo, branch);
|
|
2323
|
+
} catch (err) {
|
|
2324
|
+
if (!(err instanceof ProviderApiError && err.status === 404)) throw err;
|
|
2325
|
+
}
|
|
2326
|
+
if (!existing) await client.git.createRef(repo, `refs/heads/${branch}`, commit);
|
|
2327
|
+
else if (existing.object.sha !== commit) await client.git.updateRef(repo, `heads/${branch}`, commit, true);
|
|
2328
|
+
}
|
|
2329
|
+
/**
|
|
2330
|
+
* Commits every change in ONE commit on the default branch (or on `branch`, made from its head): a blob per written file (base64, so a binary file is
|
|
2331
|
+
* exact), one tree on top of the head's tree (a removal is an entry with no sha), one commit whose parent is the head,
|
|
2332
|
+
* and a ref update that is not forced. A branch that moved since `base` (or since this call read it) is refused and
|
|
2333
|
+
* nothing is changed: the blobs, tree and commit made are unreachable objects GitHub collects. No changes makes no commit.
|
|
2334
|
+
*/
|
|
2335
|
+
async function commitRepoFiles(client, repo, input) {
|
|
2336
|
+
if (input.changes.length === 0) return { committed: false };
|
|
2337
|
+
try {
|
|
2338
|
+
const head = await defaultHead(client, repo);
|
|
2339
|
+
if (input.base && input.base !== head.commit) throw new Error(`${repo}: ${head.branch} moved since it was read (${input.base.slice(0, 7)} to ${head.commit.slice(0, 7)}); nothing was changed, run it again`);
|
|
2340
|
+
const entries = [];
|
|
2341
|
+
for (let i = 0; i < input.changes.length; i += BLOB_BATCH) entries.push(...await Promise.all(input.changes.slice(i, i + BLOB_BATCH).map(async (change) => {
|
|
2342
|
+
if ("remove" in change) return {
|
|
2343
|
+
path: change.path,
|
|
2344
|
+
mode: "100644",
|
|
2345
|
+
type: "blob",
|
|
2346
|
+
sha: null
|
|
2347
|
+
};
|
|
2348
|
+
const blob = await client.git.createBlob(repo, Buffer.from(change.content).toString("base64"), "base64");
|
|
2349
|
+
return {
|
|
2350
|
+
path: change.path,
|
|
2351
|
+
mode: change.mode,
|
|
2352
|
+
type: "blob",
|
|
2353
|
+
sha: blob.sha
|
|
2354
|
+
};
|
|
2355
|
+
})));
|
|
2356
|
+
const tree = await client.git.createTree(repo, entries, head.tree);
|
|
2357
|
+
const commit = await client.git.createCommit(repo, input.message, tree.sha, [head.commit]);
|
|
2358
|
+
const target = input.branch ?? head.branch;
|
|
2359
|
+
if (input.branch) await pointBranchAt(client, repo, input.branch, head.commit);
|
|
2360
|
+
try {
|
|
2361
|
+
await client.git.updateRef(repo, `heads/${target}`, commit.sha);
|
|
2362
|
+
} catch (err) {
|
|
2363
|
+
if (err instanceof ProviderApiError && (err.status === 422 || err.status === 409)) throw new Error(`${repo}: ${head.branch} moved while the commit was made, so the update was refused (not a fast-forward); nothing was changed, run it again`, { cause: err });
|
|
2364
|
+
throw err;
|
|
2365
|
+
}
|
|
2366
|
+
return {
|
|
2367
|
+
committed: true,
|
|
2368
|
+
commit: commit.sha
|
|
2369
|
+
};
|
|
2370
|
+
} catch (err) {
|
|
2371
|
+
if (err instanceof ProviderApiError && err.status === 403) throw noAccess(repo, "write", err);
|
|
2372
|
+
throw err;
|
|
2373
|
+
}
|
|
2289
2374
|
}
|
|
2290
2375
|
/** Removes one file in a commit on the default branch; a file that is already gone is what was asked for. */
|
|
2291
2376
|
async function deleteRepoFile(client, repo, path, opts) {
|
|
@@ -2803,6 +2888,32 @@ async function markReady(client, repo, number) {
|
|
|
2803
2888
|
await client.pulls.markReadyForReview(raw.node_id);
|
|
2804
2889
|
return true;
|
|
2805
2890
|
}
|
|
2891
|
+
/**
|
|
2892
|
+
* Merges a pull request. GitHub answers 405 for one that is not mergeable yet (a required check pending, a review
|
|
2893
|
+
* missing, a conflict) and 409 when the head moved; both come back as `merged: false` with GitHub's reason and the
|
|
2894
|
+
* pull request stays open, so the caller can say so.
|
|
2895
|
+
*/
|
|
2896
|
+
async function mergePullRequest(client, repo, number, options = {}) {
|
|
2897
|
+
try {
|
|
2898
|
+
const done = await client.pulls.mergePullRequest(repo, number, {
|
|
2899
|
+
merge_method: options.method ?? "squash",
|
|
2900
|
+
...options.title === void 0 ? {} : { commit_title: options.title }
|
|
2901
|
+
});
|
|
2902
|
+
return done.merged ? {
|
|
2903
|
+
merged: true,
|
|
2904
|
+
commit: done.sha
|
|
2905
|
+
} : {
|
|
2906
|
+
merged: false,
|
|
2907
|
+
reason: done.message
|
|
2908
|
+
};
|
|
2909
|
+
} catch (err) {
|
|
2910
|
+
if (err instanceof ProviderApiError && (err.status === 405 || err.status === 409)) return {
|
|
2911
|
+
merged: false,
|
|
2912
|
+
reason: String(err.details || err.message)
|
|
2913
|
+
};
|
|
2914
|
+
throw err;
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2806
2917
|
// src/capabilities/read-repo.ts
|
|
2807
2918
|
/** The settings `setup` writes, which `GET /repos/{repo}` reports under the same names. */
|
|
2808
2919
|
const SETTING_KEYS = [
|
|
@@ -3382,6 +3493,12 @@ var GitHubSource = class {
|
|
|
3382
3493
|
async listFiles(repo = this.repo) {
|
|
3383
3494
|
return listRepoFiles(this.userSyncClient ?? this.orgClient ?? this.client, repo);
|
|
3384
3495
|
}
|
|
3496
|
+
async readTree(repo = this.repo) {
|
|
3497
|
+
return readRepoTree(this.userSyncClient ?? this.orgClient ?? this.client, repo);
|
|
3498
|
+
}
|
|
3499
|
+
async commitFiles(input) {
|
|
3500
|
+
return commitRepoFiles(this.userSyncClient ?? this.orgClient ?? this.client, input.repo ?? this.repo, input);
|
|
3501
|
+
}
|
|
3385
3502
|
async deleteFile(path, opts) {
|
|
3386
3503
|
return deleteRepoFile(this.userSyncClient ?? this.orgClient ?? this.client, opts.repo ?? this.repo, path, opts);
|
|
3387
3504
|
}
|
|
@@ -3418,6 +3535,9 @@ var GitHubSource = class {
|
|
|
3418
3535
|
async updatePullRequest(number, patch, repo) {
|
|
3419
3536
|
return updatePullRequest(this.pullClient, repo ?? this.repo, number, patch, this.orgClient ?? this.pullClient);
|
|
3420
3537
|
}
|
|
3538
|
+
async mergePullRequest(number, options, repo) {
|
|
3539
|
+
return mergePullRequest(this.pullClient, repo ?? this.repo, number, options);
|
|
3540
|
+
}
|
|
3421
3541
|
async markReady(number, repo) {
|
|
3422
3542
|
return markReady(this.pullClient, repo ?? this.repo, number);
|
|
3423
3543
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/holocron-plugin-github",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.8.0",
|
|
4
4
|
"description": "Holocron plugin for GitHub. Implements source, ci, secrets, environments, and issues capabilities against the GitHub REST API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ci",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"tsx": "4.23.15",
|
|
45
45
|
"typescript": "^6.0.3",
|
|
46
46
|
"vitest": "^5.1.2",
|
|
47
|
-
"@theholocron/cli": "5.
|
|
47
|
+
"@theholocron/cli": "5.8.0",
|
|
48
48
|
"@theholocron/eslint-config": "^9.1.0",
|
|
49
49
|
"@theholocron/fs-utils": "^2.0.0",
|
|
50
|
-
"@theholocron/github-client": "^2.
|
|
51
|
-
"@theholocron/http-client": "^2.
|
|
50
|
+
"@theholocron/github-client": "^2.3.1",
|
|
51
|
+
"@theholocron/http-client": "^2.3.1",
|
|
52
52
|
"@theholocron/misc-utils": "^2.0.0",
|
|
53
53
|
"@theholocron/tsconfig": "^9.1.0",
|
|
54
54
|
"@theholocron/tsdown-config": "^9.1.0",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@theholocron/fs-utils": "^2.0.0",
|
|
59
59
|
"@theholocron/github-client": "^2.0.0",
|
|
60
60
|
"@theholocron/misc-utils": "^2.0.0",
|
|
61
|
-
"@theholocron/cli": "5.
|
|
61
|
+
"@theholocron/cli": "5.8.0"
|
|
62
62
|
},
|
|
63
63
|
"engines": {
|
|
64
64
|
"node": ">=22"
|