@theholocron/holocron-plugin-github 5.5.1 → 5.7.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 +4 -1
- package/dist/index.mjs +112 -6
- package/package.json +9 -9
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,11 +443,14 @@ 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;
|
|
449
451
|
}): Promise<void>;
|
|
450
452
|
ensureTag(tag: string, repo?: string): Promise<boolean>;
|
|
453
|
+
moveTag(tag: string, repo?: string): Promise<boolean>;
|
|
451
454
|
listBranches(repo?: string): Promise<SourceBranch[]>;
|
|
452
455
|
deleteBranch(name: string, repo?: string): Promise<void>;
|
|
453
456
|
listPullRequestCommits(number: number, repo?: string): Promise<string[]>;
|
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,73 @@ 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
|
+
items: tree.tree
|
|
2292
|
+
};
|
|
2293
|
+
}
|
|
2294
|
+
/** Every file (not folder) on the default branch, as a path from the repository root, sorted. Throws when GitHub cut the tree short. */
|
|
2295
|
+
async function listRepoFiles(client, repo) {
|
|
2296
|
+
const { items } = await recursiveHead(client, repo);
|
|
2297
|
+
return items.filter((item) => item.type === "blob").map((item) => item.path).sort();
|
|
2298
|
+
}
|
|
2299
|
+
/** 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. */
|
|
2300
|
+
async function readRepoTree(client, repo) {
|
|
2301
|
+
const { commit, items } = await recursiveHead(client, repo);
|
|
2302
|
+
return {
|
|
2303
|
+
commit,
|
|
2304
|
+
entries: items.filter((item) => item.type === "blob").map((item) => ({
|
|
2305
|
+
path: item.path,
|
|
2306
|
+
mode: item.mode,
|
|
2307
|
+
sha: item.sha
|
|
2308
|
+
})).sort((a, b) => Number(a.path > b.path) - Number(a.path < b.path))
|
|
2309
|
+
};
|
|
2310
|
+
}
|
|
2311
|
+
/** How many blobs are created at once: enough to be quick, few enough to stay clear of GitHub's secondary rate limit. */
|
|
2312
|
+
const BLOB_BATCH = 8;
|
|
2313
|
+
/**
|
|
2314
|
+
* Commits every change in ONE commit on the default branch: a blob per written file (base64, so a binary file is
|
|
2315
|
+
* 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,
|
|
2316
|
+
* and a ref update that is not forced. A branch that moved since `base` (or since this call read it) is refused and
|
|
2317
|
+
* nothing is changed: the blobs, tree and commit made are unreachable objects GitHub collects. No changes makes no commit.
|
|
2318
|
+
*/
|
|
2319
|
+
async function commitRepoFiles(client, repo, input) {
|
|
2320
|
+
if (input.changes.length === 0) return { committed: false };
|
|
2321
|
+
try {
|
|
2322
|
+
const head = await defaultHead(client, repo);
|
|
2323
|
+
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`);
|
|
2324
|
+
const entries = [];
|
|
2325
|
+
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) => {
|
|
2326
|
+
if ("remove" in change) return {
|
|
2327
|
+
path: change.path,
|
|
2328
|
+
mode: "100644",
|
|
2329
|
+
type: "blob",
|
|
2330
|
+
sha: null
|
|
2331
|
+
};
|
|
2332
|
+
const blob = await client.git.createBlob(repo, Buffer.from(change.content).toString("base64"), "base64");
|
|
2333
|
+
return {
|
|
2334
|
+
path: change.path,
|
|
2335
|
+
mode: change.mode,
|
|
2336
|
+
type: "blob",
|
|
2337
|
+
sha: blob.sha
|
|
2338
|
+
};
|
|
2339
|
+
})));
|
|
2340
|
+
const tree = await client.git.createTree(repo, entries, head.tree);
|
|
2341
|
+
const commit = await client.git.createCommit(repo, input.message, tree.sha, [head.commit]);
|
|
2342
|
+
try {
|
|
2343
|
+
await client.git.updateRef(repo, `heads/${head.branch}`, commit.sha);
|
|
2344
|
+
} catch (err) {
|
|
2345
|
+
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 });
|
|
2346
|
+
throw err;
|
|
2347
|
+
}
|
|
2348
|
+
return {
|
|
2349
|
+
committed: true,
|
|
2350
|
+
commit: commit.sha
|
|
2351
|
+
};
|
|
2352
|
+
} catch (err) {
|
|
2353
|
+
if (err instanceof ProviderApiError && err.status === 403) throw noAccess(repo, "write", err);
|
|
2354
|
+
throw err;
|
|
2355
|
+
}
|
|
2289
2356
|
}
|
|
2290
2357
|
/** Removes one file in a commit on the default branch; a file that is already gone is what was asked for. */
|
|
2291
2358
|
async function deleteRepoFile(client, repo, path, opts) {
|
|
@@ -2302,6 +2369,15 @@ async function deleteRepoFile(client, repo, path, opts) {
|
|
|
2302
2369
|
}
|
|
2303
2370
|
}
|
|
2304
2371
|
/**
|
|
2372
|
+
* The commit a tag reference ends at. A lightweight tag points at the commit; an annotated one points at a tag object
|
|
2373
|
+
* (which can point at another), so its SHA is never the commit's and has to be followed.
|
|
2374
|
+
*/
|
|
2375
|
+
async function tagCommit(client, repo, ref) {
|
|
2376
|
+
let object = ref.object;
|
|
2377
|
+
while (object.type === "tag") object = (await client.git.getTag(repo, object.sha)).object;
|
|
2378
|
+
return object.sha;
|
|
2379
|
+
}
|
|
2380
|
+
/**
|
|
2305
2381
|
* Tags the default branch's head `tag`. A tag already there at the same content (the same commit, or another commit
|
|
2306
2382
|
* with the same tree) is left alone and answers `false`; one at other content throws, because a version tag is never
|
|
2307
2383
|
* moved. `true` when it made the tag.
|
|
@@ -2318,10 +2394,31 @@ async function ensureRepoTag(client, repo, tag) {
|
|
|
2318
2394
|
await client.git.createRef(repo, `refs/tags/${tag}`, head.commit);
|
|
2319
2395
|
return true;
|
|
2320
2396
|
}
|
|
2321
|
-
|
|
2322
|
-
if (
|
|
2397
|
+
const target = await tagCommit(client, repo, existing);
|
|
2398
|
+
if (target === head.commit) return false;
|
|
2399
|
+
if ((await client.git.getCommit(repo, target)).tree.sha === head.tree) return false;
|
|
2323
2400
|
throw new Error(`${repo} already has the tag ${tag} at other content: bump the version instead of moving the tag`);
|
|
2324
2401
|
}
|
|
2402
|
+
/**
|
|
2403
|
+
* Points `tag`, a tag that moves (a major tag such as `templates-v1`), at the default branch's head: made when it is
|
|
2404
|
+
* missing, moved when it is elsewhere. `true` when it made or moved the tag, `false` when it was already at the head.
|
|
2405
|
+
*/
|
|
2406
|
+
async function moveRepoTag(client, repo, tag) {
|
|
2407
|
+
const head = await defaultHead(client, repo);
|
|
2408
|
+
let existing;
|
|
2409
|
+
try {
|
|
2410
|
+
existing = await client.git.getTagRef(repo, tag);
|
|
2411
|
+
} catch (err) {
|
|
2412
|
+
if (!(err instanceof ProviderApiError && err.status === 404)) throw err;
|
|
2413
|
+
}
|
|
2414
|
+
if (!existing) {
|
|
2415
|
+
await client.git.createRef(repo, `refs/tags/${tag}`, head.commit);
|
|
2416
|
+
return true;
|
|
2417
|
+
}
|
|
2418
|
+
if (await tagCommit(client, repo, existing) === head.commit) return false;
|
|
2419
|
+
await client.git.updateRef(repo, `tags/${tag}`, head.commit, true);
|
|
2420
|
+
return true;
|
|
2421
|
+
}
|
|
2325
2422
|
// src/capabilities/labels.ts
|
|
2326
2423
|
/**
|
|
2327
2424
|
* Idempotently synchronise a repo's labels to the canonical set.
|
|
@@ -3352,12 +3449,21 @@ var GitHubSource = class {
|
|
|
3352
3449
|
async listFiles(repo = this.repo) {
|
|
3353
3450
|
return listRepoFiles(this.userSyncClient ?? this.orgClient ?? this.client, repo);
|
|
3354
3451
|
}
|
|
3452
|
+
async readTree(repo = this.repo) {
|
|
3453
|
+
return readRepoTree(this.userSyncClient ?? this.orgClient ?? this.client, repo);
|
|
3454
|
+
}
|
|
3455
|
+
async commitFiles(input) {
|
|
3456
|
+
return commitRepoFiles(this.userSyncClient ?? this.orgClient ?? this.client, input.repo ?? this.repo, input);
|
|
3457
|
+
}
|
|
3355
3458
|
async deleteFile(path, opts) {
|
|
3356
3459
|
return deleteRepoFile(this.userSyncClient ?? this.orgClient ?? this.client, opts.repo ?? this.repo, path, opts);
|
|
3357
3460
|
}
|
|
3358
3461
|
async ensureTag(tag, repo = this.repo) {
|
|
3359
3462
|
return ensureRepoTag(this.userSyncClient ?? this.orgClient ?? this.client, repo, tag);
|
|
3360
3463
|
}
|
|
3464
|
+
async moveTag(tag, repo = this.repo) {
|
|
3465
|
+
return moveRepoTag(this.userSyncClient ?? this.orgClient ?? this.client, repo, tag);
|
|
3466
|
+
}
|
|
3361
3467
|
async listBranches(repo) {
|
|
3362
3468
|
return (await this.client.branches.listBranches(repo ?? this.repo)).map((b) => ({
|
|
3363
3469
|
name: b.name,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/holocron-plugin-github",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.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,21 +44,21 @@
|
|
|
44
44
|
"tsx": "4.23.15",
|
|
45
45
|
"typescript": "^6.0.3",
|
|
46
46
|
"vitest": "^5.1.2",
|
|
47
|
-
"@theholocron/cli": "5.
|
|
48
|
-
"@theholocron/eslint-config": "^9.
|
|
47
|
+
"@theholocron/cli": "5.7.0",
|
|
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.0",
|
|
51
|
+
"@theholocron/http-client": "^2.3.0",
|
|
52
52
|
"@theholocron/misc-utils": "^2.0.0",
|
|
53
|
-
"@theholocron/tsconfig": "^9.
|
|
54
|
-
"@theholocron/tsdown-config": "^9.
|
|
55
|
-
"@theholocron/vitest-config": "^9.
|
|
53
|
+
"@theholocron/tsconfig": "^9.1.0",
|
|
54
|
+
"@theholocron/tsdown-config": "^9.1.0",
|
|
55
|
+
"@theholocron/vitest-config": "^9.1.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
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.7.0"
|
|
62
62
|
},
|
|
63
63
|
"engines": {
|
|
64
64
|
"node": ">=22"
|