@futurelastic/colab-handbook 1.21.0-rc.5 → 1.21.0-rc.6
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/package.json +1 -1
- package/tools/colab +118 -34
- package/tools/lib/git.js +25 -1
- package/tools/lib/trust-humans.js +46 -1
package/package.json
CHANGED
package/tools/colab
CHANGED
|
@@ -4371,6 +4371,80 @@ function migrationGrantRoundtripCheck(repoAbs, branch, rec) {
|
|
|
4371
4371
|
if (!c.ok) throw new UserError(`${c.reason}; nothing was posted`);
|
|
4372
4372
|
}
|
|
4373
4373
|
|
|
4374
|
+
// ---- #732: the grant writers judge their own poster, the way the readers judge it ----------------
|
|
4375
|
+
// The readers (ci-grant.js, migration-grant.js) reject a grant whose author's association is not
|
|
4376
|
+
// OWNER/MEMBER/COLLABORATOR (and, for a human grant under trust-humans, whose login is unlisted).
|
|
4377
|
+
// The writers never asked, so an account whose comments read `NONE` — while the permission API said
|
|
4378
|
+
// `write` — posted a grant and its label that the ship gate then refused: the hold lifted, the owner
|
|
4379
|
+
// thought the ship unblocked, the red row surfaced a pass later. Two layers, used by all four writers
|
|
4380
|
+
// (ci-grant human + reviewer, migration-grant human + reviewer) so they cannot drift:
|
|
4381
|
+
// 1. grantPosterPrecheck — BEFORE anything is written: predicts from a comment this account
|
|
4382
|
+
// already has (the association is computed per author at read time, so an old comment reads
|
|
4383
|
+
// exactly as the new one will). Refuses on a known-untrusted poster; nothing is posted.
|
|
4384
|
+
// 2. postGrantVerified — the comment FIRST, read back through the reader's own path, judged by the
|
|
4385
|
+
// reader's rule; the label only after it passes. A rejected comment is deleted again and the
|
|
4386
|
+
// label never applied — the label is what a tracker watcher reads as "unblocked", so it must
|
|
4387
|
+
// never flash for a grant the gate will refuse. Comment-without-label reads "not granted" to
|
|
4388
|
+
// every reader, so the gap between the two writes is inert.
|
|
4389
|
+
|
|
4390
|
+
/** The refusal for a poster the gate would reject — names the cause, the fix and the re-run. */
|
|
4391
|
+
function grantPosterRefusal(kind, p, remedy) {
|
|
4392
|
+
const byAssociation = !!p.association && !trustHumans.TRUSTED_ASSOCIATIONS.has(p.association);
|
|
4393
|
+
const fix = byAssociation || !/trust-humans/.test(p.reason)
|
|
4394
|
+
? 'Post it from an account this repo lists as owner, member or collaborator — or, if this account was invited, accept the invitation first (`gh api user/repository_invitations` lists it; GitHub reports a pending invitee as NONE)'
|
|
4395
|
+
: 'Post it from a login listed in trunk\'s project.yml `trust-humans:`, or add this login there through a trunk change';
|
|
4396
|
+
return `${kind} grant not posted — the ship gate would reject it: ${p.reason}. ${fix}, then re-run: ${remedy}`;
|
|
4397
|
+
}
|
|
4398
|
+
|
|
4399
|
+
/**
|
|
4400
|
+
* Layer 1. `comments` = the issue's comments from the writer's own `ghIssueView` read (the reader's
|
|
4401
|
+
* path). Falls back to one page of the repo's newest comments when the account has none on this
|
|
4402
|
+
* issue. Throws on a known-untrusted poster; returns the context postGrantVerified needs.
|
|
4403
|
+
* `trust` = trunk's trust-humans for a human grant (null for a reviewer grant). A migration grant is
|
|
4404
|
+
* read against its merge TARGET's list (shipMigrationCtx); the writer cannot know an integration-line
|
|
4405
|
+
* target here, so it reads trunk's — identical for every branch cut from trunk.
|
|
4406
|
+
*/
|
|
4407
|
+
function grantPosterPrecheck(repoAbs, { kind, role, comments, trust, remedy }) {
|
|
4408
|
+
const login = git.ghCurrentLogin();
|
|
4409
|
+
let p = trustHumans.posterTrust({ login, comments, trust, role });
|
|
4410
|
+
if (p.verdict === 'unknown' && login) {
|
|
4411
|
+
const recent = git.ghRecentRepoComments(repoAbs);
|
|
4412
|
+
if (recent) p = trustHumans.posterTrust({ login, comments: recent, trust, role });
|
|
4413
|
+
}
|
|
4414
|
+
const ctx = { kind, role, trust, login, remedy };
|
|
4415
|
+
if (p.verdict === 'untrusted') throw new UserError(grantPosterRefusal(kind, p, ctx.remedy));
|
|
4416
|
+
return ctx;
|
|
4417
|
+
}
|
|
4418
|
+
|
|
4419
|
+
/** Layer 2. Posts `body`, verifies its author by the reader's rule, then applies the label. */
|
|
4420
|
+
function postGrantVerified(repoAbs, num, body, labelArgs, poster) {
|
|
4421
|
+
const commentR = git.ghIssueComment(repoAbs, num, body);
|
|
4422
|
+
if (!commentR.ok) {
|
|
4423
|
+
throw new UserError(`the grant comment failed to post (${commentR.stderr.split('\n')[0] || commentR.code}) — nothing was written (the label is applied only after the comment). Re-run: ${poster.remedy}`);
|
|
4424
|
+
}
|
|
4425
|
+
const back = git.ghIssueView(repoAbs, num, ['comments']);
|
|
4426
|
+
const posted = back ? (back.comments || []).filter((c) => String((c && c.body) || '').trim() === body.trim()).pop() : null;
|
|
4427
|
+
if (!posted) {
|
|
4428
|
+
warn(`could not read the grant comment back from #${num} to confirm the ship gate will trust its author — check it before relying on it: colab ${poster.kind === 'CI' ? 'ci-grant' : 'migration-grant'} --list`);
|
|
4429
|
+
} else {
|
|
4430
|
+
const login = (posted.author && posted.author.login) || poster.login;
|
|
4431
|
+
const p = trustHumans.posterTrust({ login, comments: [posted], trust: poster.trust, role: poster.role });
|
|
4432
|
+
if (p.verdict !== 'trusted') {
|
|
4433
|
+
const why = p.verdict === 'untrusted' ? p : { ...p, reason: `${login || '(unknown)'} (no association reported) — not a repo owner/member/collaborator` };
|
|
4434
|
+
const del = git.ghDeleteIssueComment(repoAbs, posted.url);
|
|
4435
|
+
if (!del.ok) {
|
|
4436
|
+
throw new UserError(`${grantPosterRefusal(poster.kind, why, poster.remedy)}. The comment was posted and could NOT be deleted (${String(del.stderr || '').split('\n')[0] || del.code}); the label was not applied, so it grants nothing — delete it by hand (${posted.url || `the newest grant comment on #${num}`}): \`gh api -X DELETE repos/{owner}/{repo}/issues/comments/<id>\``);
|
|
4437
|
+
}
|
|
4438
|
+
throw new UserError(`${grantPosterRefusal(poster.kind, why, poster.remedy)}. (Its association was only readable after posting; the comment was deleted again and the label never applied.)`);
|
|
4439
|
+
}
|
|
4440
|
+
}
|
|
4441
|
+
const editR = git.ghIssueEdit(repoAbs, num, labelArgs);
|
|
4442
|
+
if (!editR.ok) {
|
|
4443
|
+
const del = posted ? git.ghDeleteIssueComment(repoAbs, posted.url) : { ok: false };
|
|
4444
|
+
throw new UserError(`the grant comment posted but the label failed (${editR.stderr.split('\n')[0] || editR.code}) — ${del.ok ? 'deleted the comment again' : `the comment stays, inert without the label${posted && posted.url ? ` (${posted.url})` : ''}`}, so this does not read as granted. Re-run: ${poster.remedy}`);
|
|
4445
|
+
}
|
|
4446
|
+
}
|
|
4447
|
+
|
|
4374
4448
|
function cmdMigrationGrantCreate(repoAbs, num, opts) {
|
|
4375
4449
|
// --branch and branch existence are already validated by cmdMigrationGrant, ahead of the
|
|
4376
4450
|
// isGhUsable gate — see the comment there. Kept as a defensive re-check in case this function is
|
|
@@ -4382,7 +4456,8 @@ function cmdMigrationGrantCreate(repoAbs, num, opts) {
|
|
|
4382
4456
|
throw new UserError(`branch "${opts.branch}" does not resolve to a ref (locally or on origin) — refusing to bind a grant to a name nothing exists at`);
|
|
4383
4457
|
}
|
|
4384
4458
|
|
|
4385
|
-
|
|
4459
|
+
// `comments` (#732): the poster check reads this account's existing association from them.
|
|
4460
|
+
const info = git.ghIssueView(repoAbs, num, opts.versionBinding ? ['state', 'labels', 'body', 'comments'] : ['state', 'labels', 'comments']);
|
|
4386
4461
|
if (!info) throw new UserError(`could not read #${num} from the tracker — refusing to write a grant blind`);
|
|
4387
4462
|
if (info.state !== 'OPEN') {
|
|
4388
4463
|
throw new UserError(`#${num} is ${info.state} — a grant expires the instant its issue closes, so granting a closed one would do nothing (CONVENTIONS.md §5, Migration exemption)`);
|
|
@@ -4402,25 +4477,26 @@ function cmdMigrationGrantCreate(repoAbs, num, opts) {
|
|
|
4402
4477
|
|| `this repo has no \`${labels.MIGRATION_GRANT_LABEL}\` label`);
|
|
4403
4478
|
}
|
|
4404
4479
|
|
|
4480
|
+
// #732: would the ship gate trust this account's grant? Refuse before writing when it is already
|
|
4481
|
+
// known not to — a human grant by the human readers' rule (trust-humans from trunk), a reviewer
|
|
4482
|
+
// grant by the bare association class its reader applies.
|
|
4483
|
+
const poster = grantPosterPrecheck(repoAbs, {
|
|
4484
|
+
kind: 'Migration', role: opts.reviewRecord ? 'reviewer' : 'human', comments: info.comments,
|
|
4485
|
+
trust: opts.reviewRecord ? null : trustAt(repoAbs, resolveTrunk(repoAbs, projectDoc(repoAbs))),
|
|
4486
|
+
remedy: opts.reviewRecord ? `the same \`colab migration-grant ${num} --branch ${opts.branch} --role ${migrationGrant.REVIEWER_ROLE} …\`` : `COLAB_HUMAN=1 colab migration-grant ${num} --branch ${opts.branch}`,
|
|
4487
|
+
});
|
|
4488
|
+
|
|
4405
4489
|
// #457: a record claiming a CI round-trip pass is checked against CI BEFORE anything is written.
|
|
4406
4490
|
if (opts.reviewRecord) migrationGrantRoundtripCheck(repoAbs, opts.branch, opts.reviewRecord);
|
|
4407
4491
|
|
|
4408
|
-
const editR = git.ghIssueEdit(repoAbs, num, labels.migrationGrantLabelArgs({}));
|
|
4409
|
-
if (!editR.ok) throw new UserError(`gh edit #${num} failed (${editR.stderr.split('\n')[0] || editR.code})`);
|
|
4410
|
-
|
|
4411
4492
|
// The comment is the AUTHORITY (it carries the branch binding) — not best-effort, unlike a
|
|
4412
|
-
// claim comment.
|
|
4413
|
-
//
|
|
4414
|
-
// leave that state.
|
|
4493
|
+
// claim comment. #732: it is posted FIRST and its author verified before the label goes on, so a
|
|
4494
|
+
// grant the gate would refuse never shows the label (postGrantVerified).
|
|
4415
4495
|
const iso = nowISO();
|
|
4416
4496
|
const body = opts.reviewRecord
|
|
4417
4497
|
? migrationGrant.reviewGrantCommentBody(opts.branch, commentHost(repoAbs), iso, opts.reviewRecord)
|
|
4418
4498
|
: migrationGrant.grantCommentBody(opts.branch, commentHost(repoAbs), iso);
|
|
4419
|
-
|
|
4420
|
-
if (!commentR.ok) {
|
|
4421
|
-
git.ghIssueEdit(repoAbs, num, labels.migrationGrantLabelArgs({ clear: true }));
|
|
4422
|
-
throw new UserError(`label applied but the grant comment failed to post (${commentR.stderr.split('\n')[0] || commentR.code}) — rolled the label back so this does not read as granted. Re-run.`);
|
|
4423
|
-
}
|
|
4499
|
+
postGrantVerified(repoAbs, num, body, labels.migrationGrantLabelArgs({}), poster);
|
|
4424
4500
|
|
|
4425
4501
|
if (opts.reviewRecord) {
|
|
4426
4502
|
print(`Recorded a ${migrationGrant.REVIEWER_ROLE} grant on #${num} in ${shortRepo(repoAbs)} — reviewer "${opts.reviewRecord.reviewer}", branch "${opts.branch}" @ ${opts.reviewRecord.head.slice(0, 12)}.`);
|
|
@@ -4460,9 +4536,10 @@ function cmdMigrationGrantRevoke(repoAbs, num) {
|
|
|
4460
4536
|
return 0;
|
|
4461
4537
|
}
|
|
4462
4538
|
|
|
4463
|
-
// Remove the label FIRST — the mirror image of grant's order. Grant
|
|
4464
|
-
//
|
|
4465
|
-
// the safe state to fail toward here is "already revoked,"
|
|
4539
|
+
// Remove the label FIRST — the mirror image of grant's order. Grant posts the comment first and
|
|
4540
|
+
// applies the label only once its author is verified (#732, postGrantVerified); revoke does the
|
|
4541
|
+
// GATE-RESTORING half first, because the safe state to fail toward here is "already revoked,"
|
|
4542
|
+
// not "still granted."
|
|
4466
4543
|
if (hasLabel) {
|
|
4467
4544
|
const r = git.ghIssueEdit(repoAbs, num, labels.migrationGrantLabelArgs({ clear: true }));
|
|
4468
4545
|
if (!r.ok) {
|
|
@@ -5250,7 +5327,8 @@ function cmdCiGrantReviewer(num, opts) {
|
|
|
5250
5327
|
throw new UserError(`gh not usable here (${ghUnusableWhy(repoAbs)}) — a CI grant lives on the tracker, visible from any machine to the gate that reads it, and there is deliberately no local-only fallback`);
|
|
5251
5328
|
}
|
|
5252
5329
|
|
|
5253
|
-
|
|
5330
|
+
// `comments` (#732): the poster check reads this account's existing association from them.
|
|
5331
|
+
const info = git.ghIssueView(repoAbs, num, ['state', 'labels', 'title', 'comments']);
|
|
5254
5332
|
if (!info) throw new UserError(`could not read #${num} from the tracker — refusing to write a grant blind`);
|
|
5255
5333
|
if (info.state !== 'OPEN') throw new UserError(`#${num} is ${info.state} — a grant expires the instant its issue closes`);
|
|
5256
5334
|
if (!ciGrant.titleIsTrunkRed(info.title)) {
|
|
@@ -5261,6 +5339,13 @@ function cmdCiGrantReviewer(num, opts) {
|
|
|
5261
5339
|
throw new UserError(labels.ciGrantMissingLabelHint(present) || `this repo has no \`${labels.CI_GRANT_LABEL}\` label`);
|
|
5262
5340
|
}
|
|
5263
5341
|
|
|
5342
|
+
// #732: the reviewer reader trusts the bare association class (ci-grant.js evaluateReviewerIssue),
|
|
5343
|
+
// so the writer refuses an account it would reject — before any CI read, nothing written.
|
|
5344
|
+
const poster = grantPosterPrecheck(repoAbs, {
|
|
5345
|
+
kind: 'CI', role: 'reviewer', comments: info.comments, trust: null,
|
|
5346
|
+
remedy: `the same \`colab ci-grant ${num} --branch ${opts.branch} --role ${ciGrant.REVIEWER_ROLE} …\``,
|
|
5347
|
+
});
|
|
5348
|
+
|
|
5264
5349
|
// Trunk red, in ship's sense — the identical classification cmdCiGrantCreate uses (#155).
|
|
5265
5350
|
git.git(['fetch', git.remoteFor(repoAbs), trunk], repoAbs);
|
|
5266
5351
|
const trunkRun = git.ghRunForSha(repoAbs, trunk);
|
|
@@ -5298,14 +5383,10 @@ function cmdCiGrantReviewer(num, opts) {
|
|
|
5298
5383
|
const v = ciGrant.validateReviewRecord(rec);
|
|
5299
5384
|
if (!v.passing) throw new UserError(`the review record is invalid: ${v.problems.join('; ')}`);
|
|
5300
5385
|
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
if (!commentR.ok) {
|
|
5306
|
-
git.ghIssueEdit(repoAbs, num, labels.ciGrantLabelArgs({ clear: true }));
|
|
5307
|
-
throw new UserError(`label applied but the grant comment failed to post (${commentR.stderr.split('\n')[0] || commentR.code}) — rolled the label back so this does not read as granted. Re-run.`);
|
|
5308
|
-
}
|
|
5386
|
+
// #732: comment first, its author verified, the label last (postGrantVerified).
|
|
5387
|
+
postGrantVerified(repoAbs, num,
|
|
5388
|
+
ciGrant.reviewGrantCommentBody(opts.branch, trunk, commentHost(repoAbs), nowISO(), rec),
|
|
5389
|
+
labels.ciGrantLabelArgs({}), poster);
|
|
5309
5390
|
|
|
5310
5391
|
print(`Recorded a ${ciGrant.REVIEWER_ROLE} CI grant on #${num} in ${shortRepo(repoAbs)} — reviewer "${rec.reviewer}", branch "${opts.branch}" @ ${head.slice(0, 12)}.`);
|
|
5311
5392
|
print(` Bound to that HEAD and to red ${trunk}@${shortSha(redSha)}: a new commit on either voids it. Cures: ${rec.cures}.`);
|
|
@@ -5322,7 +5403,8 @@ function cmdCiGrantCreate(repoAbs, num, opts) {
|
|
|
5322
5403
|
throw new UserError(`branch "${opts.branch}" does not resolve to a ref (locally or on origin) — refusing to bind a grant to a name nothing exists at`);
|
|
5323
5404
|
}
|
|
5324
5405
|
|
|
5325
|
-
|
|
5406
|
+
// `comments` (#732): the poster check reads this account's existing association from them.
|
|
5407
|
+
const info = git.ghIssueView(repoAbs, num, ['state', 'labels', 'comments']);
|
|
5326
5408
|
if (!info) throw new UserError(`could not read #${num} from the tracker — refusing to write a grant blind`);
|
|
5327
5409
|
if (info.state !== 'OPEN') {
|
|
5328
5410
|
throw new UserError(`#${num} is ${info.state} — a grant expires the instant its issue closes, so granting a closed one would do nothing (CONVENTIONS.md §5, Red-trunk exemption)`);
|
|
@@ -5337,6 +5419,13 @@ function cmdCiGrantCreate(repoAbs, num, opts) {
|
|
|
5337
5419
|
const trunk = resolveTrunk(repoAbs, doc);
|
|
5338
5420
|
if (!trunk) throw new UserError('Could not determine trunk branch (set project.yml trunk:)');
|
|
5339
5421
|
|
|
5422
|
+
// #732: refuse before writing (and before measuring CI) when the ship gate is already known to
|
|
5423
|
+
// reject this account's grant — the human readers' rule, trust-humans read from trunk as ship does.
|
|
5424
|
+
const poster = grantPosterPrecheck(repoAbs, {
|
|
5425
|
+
kind: 'CI', role: 'human', comments: info.comments, trust: trustAt(repoAbs, trunk),
|
|
5426
|
+
remedy: `COLAB_HUMAN=1 colab ci-grant ${num} --branch ${opts.branch}`,
|
|
5427
|
+
});
|
|
5428
|
+
|
|
5340
5429
|
// ---- GUARD 2 (anti-stacking) FIRST — cheaper to fail here than after measuring evidence ----
|
|
5341
5430
|
git.git(['fetch', git.remoteFor(repoAbs), trunk], repoAbs);
|
|
5342
5431
|
const trunkRun = git.ghRunForSha(repoAbs, trunk);
|
|
@@ -5370,16 +5459,11 @@ function cmdCiGrantCreate(repoAbs, num, opts) {
|
|
|
5370
5459
|
}
|
|
5371
5460
|
const evidenceSha = evRun.sha;
|
|
5372
5461
|
|
|
5373
|
-
|
|
5374
|
-
if (!editR.ok) throw new UserError(`gh edit #${num} failed (${editR.stderr.split('\n')[0] || editR.code})`);
|
|
5375
|
-
|
|
5462
|
+
// #732: comment first, its author verified, the label last (postGrantVerified).
|
|
5376
5463
|
const iso = nowISO();
|
|
5377
|
-
|
|
5378
|
-
ciGrant.grantCommentBody(opts.branch, trunk, redSha, evidenceSha, commentHost(repoAbs), iso)
|
|
5379
|
-
|
|
5380
|
-
git.ghIssueEdit(repoAbs, num, labels.ciGrantLabelArgs({ clear: true }));
|
|
5381
|
-
throw new UserError(`label applied but the grant comment failed to post (${commentR.stderr.split('\n')[0] || commentR.code}) — rolled the label back so this does not read as granted. Re-run.`);
|
|
5382
|
-
}
|
|
5464
|
+
postGrantVerified(repoAbs, num,
|
|
5465
|
+
ciGrant.grantCommentBody(opts.branch, trunk, redSha, evidenceSha, commentHost(repoAbs), iso),
|
|
5466
|
+
labels.ciGrantLabelArgs({}), poster);
|
|
5383
5467
|
|
|
5384
5468
|
print(`Granted #${num} in ${shortRepo(repoAbs)} a CI exemption for branch "${opts.branch}".`);
|
|
5385
5469
|
print(` Bound to red trunk sha ${shortSha(redSha)} and evidence run ${shortSha(evidenceSha)}.`);
|
package/tools/lib/git.js
CHANGED
|
@@ -774,6 +774,30 @@ function ghIssueComment(repo, issueNum, body) {
|
|
|
774
774
|
return ghApi(repo, ['-X', 'POST', `repos/{owner}/{repo}/issues/${issueNum}/comments`, '-f', `body=${body}`]);
|
|
775
775
|
}
|
|
776
776
|
|
|
777
|
+
/**
|
|
778
|
+
* #732: the newest page of this repo's issue comments (REST, newest-first, up to 100) — the second
|
|
779
|
+
* place a grant writer looks for an existing comment by the posting account, whose
|
|
780
|
+
* `author_association` predicts the grant comment's (tools/lib/trust-humans.js posterTrust). Null on
|
|
781
|
+
* any failure: "could not read", never "no comments".
|
|
782
|
+
*/
|
|
783
|
+
function ghRecentRepoComments(repo) {
|
|
784
|
+
const r = ghApi(repo, ['repos/{owner}/{repo}/issues/comments?sort=created&direction=desc&per_page=100']);
|
|
785
|
+
if (!r.ok) return null;
|
|
786
|
+
try { const v = JSON.parse(r.stdout); return Array.isArray(v) ? v : null; }
|
|
787
|
+
catch (_) { return null; }
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* #732: delete one issue comment, named by its url (`…#issuecomment-<id>`, the shape
|
|
792
|
+
* `gh issue view --json comments` reports) — returns {ok, stderr}. Used only to take back a grant
|
|
793
|
+
* comment the reader would reject; a url carrying no id is a refusal, never a guess.
|
|
794
|
+
*/
|
|
795
|
+
function ghDeleteIssueComment(repo, url) {
|
|
796
|
+
const m = /#issuecomment-(\d+)$/.exec(String(url || ''));
|
|
797
|
+
if (!m) return { ok: false, code: 'no-id', stderr: `no comment id in ${JSON.stringify(url || '')}` };
|
|
798
|
+
return ghApi(repo, ['-X', 'DELETE', `repos/{owner}/{repo}/issues/comments/${m[1]}`]);
|
|
799
|
+
}
|
|
800
|
+
|
|
777
801
|
/**
|
|
778
802
|
* #357: the created-at timestamps of every `labeled` event for `label` on one issue (issue
|
|
779
803
|
* events API, paginated), oldest-first — or null when the read failed. Null is "could not read",
|
|
@@ -1669,7 +1693,7 @@ module.exports = {
|
|
|
1669
1693
|
worktreeList, worktreeListDetailed, resolveWorktreePathForBranch, gitFailureLine,
|
|
1670
1694
|
dirtyTracked, dirtyUntracked, dirtyAny,
|
|
1671
1695
|
ghAvailable, ghState, ghInstalled, ghApiConditional, ghRunsAtShaRest, ghRunsAtShaUnfiltered, fullSha, ghIssueEdit, ghListLabels, ghOpenIssueNumbersByLabel, ghAssignedIssues,
|
|
1672
|
-
ghCurrentLogin, ghIssueView, ghIssueComment, ghRunForSha, ghRunForCommit, ghRunsForCommit, ghRunsForRef, ghWorkflowStates, ghRunsAtCommit, ghRunForCommitAnyRef, commitTimeMs, ghRunsSince, summarizeRunsForCommit, isRepoOwnedRun,
|
|
1696
|
+
ghCurrentLogin, ghIssueView, ghIssueComment, ghRecentRepoComments, ghDeleteIssueComment, ghRunForSha, ghRunForCommit, ghRunsForCommit, ghRunsForRef, ghWorkflowStates, ghRunsAtCommit, ghRunForCommitAnyRef, commitTimeMs, ghRunsSince, summarizeRunsForCommit, isRepoOwnedRun,
|
|
1673
1697
|
ghRunJobCount, ghRunJobs, ghActiveRunsOfWorkflow, ghWorkflowDispatch,
|
|
1674
1698
|
ghIssueListByLabel, ghLabelDelete, ghLabelCreate, ghListLabelsDetailed, ghLabelEditDescription,
|
|
1675
1699
|
ghApi, isGraphqlRateLimit, ghIssueRelease, ghClaimHolder, ghIssueLabelEvents, ghIssueLabelActors,
|
|
@@ -101,4 +101,49 @@ function labelApplierIsHuman(actors, trust, labelName) {
|
|
|
101
101
|
return { ok: true, reason: '' };
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
/**
|
|
105
|
+
* The WRITER's half (#732): will a grant this account is about to post read as trusted to the
|
|
106
|
+
* reader above? The readers judged the author; the writers (`colab ci-grant`, `colab
|
|
107
|
+
* migration-grant`) never did, so an account whose comments read `NONE` posted a grant that was
|
|
108
|
+
* dead from the moment it landed — label applied, hold lifted, and the ship pass found the red row
|
|
109
|
+
* later. The repo-permission API cannot predict this (it reported `write` for exactly such an
|
|
110
|
+
* account), so nothing here asks it.
|
|
111
|
+
*
|
|
112
|
+
* WHY EXISTING COMMENTS PREDICT A NEW ONE. GitHub computes `authorAssociation` per author at read
|
|
113
|
+
* time, not per comment at write time, so every comment one author already has reads the same
|
|
114
|
+
* association to one reader as the grant comment will. No comment by this login anywhere the caller
|
|
115
|
+
* looked → `unknown`, and the caller verifies the posted comment instead.
|
|
116
|
+
*
|
|
117
|
+
* login — the posting account (`gh api user`), or null when it could not be read.
|
|
118
|
+
* comments — any mix of gh's shape `{ author: { login }, authorAssociation }` and the REST shape
|
|
119
|
+
* `{ user: { login }, author_association }`. The LAST one by `login` decides.
|
|
120
|
+
* trust — parseTrustHumans(...) for the human role; ignored for the reviewer role.
|
|
121
|
+
* role — 'human' judges by authorIsHuman (the human readers' rule); anything else judges by
|
|
122
|
+
* the bare association class (the reviewer readers' rule, ci-grant.js / migration-grant.js
|
|
123
|
+
* reviewer branch). Mirror each reader exactly: a stricter writer refuses grants the
|
|
124
|
+
* gate would honour, a looser one is this issue.
|
|
125
|
+
* Returns { verdict: 'trusted' | 'untrusted' | 'unknown', reason, association }.
|
|
126
|
+
*/
|
|
127
|
+
function posterTrust({ login, comments, trust, role }) {
|
|
128
|
+
const me = String(login || '').toLowerCase();
|
|
129
|
+
const human = role === 'human';
|
|
130
|
+
const declared = human && trust && trust.declared;
|
|
131
|
+
// A declared list decides the login half with no comment at all.
|
|
132
|
+
if (declared && me && !(trust.humans && trust.humans.has(me))) {
|
|
133
|
+
return { verdict: 'untrusted', association: '',
|
|
134
|
+
reason: `${login} is not listed in trust-humans${trust.valid ? '' : ' (the list is malformed, so nobody is)'}` };
|
|
135
|
+
}
|
|
136
|
+
if (!me) return { verdict: 'unknown', association: '', reason: 'the posting account could not be read' };
|
|
137
|
+
const authorOf = (c) => String((c && ((c.author && c.author.login) || (c.user && c.user.login))) || '').toLowerCase();
|
|
138
|
+
const assocOf = (c) => String((c && (c.authorAssociation || c.author_association)) || '');
|
|
139
|
+
const mine = (Array.isArray(comments) ? comments : []).filter((c) => authorOf(c) === me && assocOf(c));
|
|
140
|
+
if (mine.length === 0) return { verdict: 'unknown', association: '', reason: `no comment by ${login} to read its association from` };
|
|
141
|
+
const association = assocOf(mine[mine.length - 1]);
|
|
142
|
+
const who = human
|
|
143
|
+
? authorIsHuman({ login, authorAssociation: association }, trust)
|
|
144
|
+
: (TRUSTED_ASSOCIATIONS.has(association) ? { ok: true, reason: '' }
|
|
145
|
+
: { ok: false, reason: `${login} (${association}) — not a repo owner/member/collaborator` });
|
|
146
|
+
return who.ok ? { verdict: 'trusted', association, reason: '' } : { verdict: 'untrusted', association, reason: who.reason };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = { KEY, LOGIN_RE, TRUSTED_ASSOCIATIONS, parseTrustHumans, authorIsHuman, labelApplierIsHuman, posterTrust };
|