mirror of
https://github.com/storytold/autocraft.git
synced 2026-12-01 10:33:55 +01:00
Whitelist tiers, overrides and the pipeline's own tier belong to accounts and heads; removing an operator ends what acts as them
- History counts per GitHub account: a PR row with an id counts for that id, an id-less row for the account the login is bound to, and for nobody while the login is unbound. The sync no longer binds a login that has id-less merged or closed PRs; the backfill binds it from the history's own author. A failed binding pass shows as the author-ids health warning. - An allow override stores the account it was given to (looked up when set) and counts only for it; a deny holds for any account under the login, in any letter case. The outside-author limits read the same per-account standing. - The pipeline's own Fix, main CI fix and security fix PRs keep their own tier only while the head is a commit the pipeline pushed to its own branch (own_commits), or reached from one only through its own later pushes; otherwise a person is asked. - Removing or demoting an operator revokes their org setup links, and a link works only while its creator is an operator. Removal drops Discord links and codes in any letter case. - Decision alerts to maintainers need a repo permission read within a day. - A cached author permission is not used for another account under the login, nor once its refresh has failed too often or for too long. - Pushes to new branches and new PRs need the grant of a step that opens the pipeline's own PRs; security fix writes carry their own grant kind.
This commit is contained in:
1 parent
50801c93c9
commit
de0547d883
24 files changed
+313
-102
No files matched your search
+14
-3
@@ -42,6 +42,13 @@ function covers(g: Guarded | Grant, repo: string, number?: number): void {
|
||||
if (g.repo !== repo || (number !== undefined && "number" in g && g.number !== number)) throw new Error(`the guard covers ${g.repo}${"number" in g ? `#${g.number}` : ""}, not ${repo}${number === undefined ? "" : `#${number}`}`);
|
||||
}
|
||||
|
||||
/** A push to the pipeline's own branch and a new PR are made only under the grants of the steps that open the pipeline's own PRs. */
|
||||
function opensOwnPr(g: Grant, repo: string): void {
|
||||
covers(g, repo);
|
||||
const ok = g.scope === "item" ? g.action.kind === "fixissue-collect" : g.need === "main-fix" || g.need === "merge" || g.need === "security";
|
||||
if (!ok) throw new Error(`a ${g.scope === "item" ? `${g.action.kind} grant` : `grant for ${g.need ?? "no approval"}`} does not allow a push to a new branch or a new pull request`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Who a write is made as, for the audit row's `identity`: `legacy` while the grant's repo is on the box account, else
|
||||
* the grant's identity (src/github/identity.ts). Every write takes it from its grant, so none goes unmapped.
|
||||
@@ -461,7 +468,7 @@ export function ghDeleteComment(w: Writer, g: CommentGrant, exec: Exec, action:
|
||||
}
|
||||
|
||||
export function ghOpenPr(w: Writer, g: Grant, exec: Exec, action: string, o: { repo: string; target: string; base: string; head: string; title: string; body: string }, note: Note, details: Details = {}): Promise<ExecResult> {
|
||||
covers(g, o.repo);
|
||||
opensOwnPr(g, o.repo);
|
||||
exec = laneExec(w, g, exec);
|
||||
const body = withNote(note, o.body);
|
||||
return viaGh(w, idOf(w, g), exec, action, o.target, { ...details, text: body },
|
||||
@@ -598,10 +605,14 @@ export function pushBranch(w: Writer, git: Pick<Git, "git">, action: string, g:
|
||||
|
||||
/** Pushes `sha` to `branch` of the pipeline's own fork, replacing the branch. */
|
||||
export function pushOwnBranch(w: Writer, g: Grant, git: Pick<Git, "git">, action: string, o: { repo: string; number?: number; remote: string; branch: string; sha: string }, details: Details = {}, /** The push needs the box account whatever the repo's identity (an advisory's private fork, which the app cannot reach). */ asBox = false): Promise<ExecResult> {
|
||||
covers(g, o.repo);
|
||||
opensOwnPr(g, o.repo);
|
||||
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*\/[A-Za-z0-9._-]+$/.test(o.remote) || o.branch.startsWith("-") || !/^[0-9a-f]{40,64}$/.test(o.sha)) throw new Error("the push target is not a repository and branch");
|
||||
// A new branch has no PR yet: its outcome is matched to the PR by commit once the PR's checks arrive.
|
||||
return pushed(w, g, git, action, o.number === undefined ? `${o.repo}:${o.branch}` : refOf(o.repo, o.number), o, "--force", details, { repo: o.repo, number: null }, asBox);
|
||||
return pushed(w, g, git, action, o.number === undefined ? `${o.repo}:${o.branch}` : refOf(o.repo, o.number), o, "--force", details, { repo: o.repo, number: null }, asBox).then((r) => {
|
||||
// Without this row the pipeline's own PR at this commit is not counted as its own (a person is asked), so a failed write only holds it.
|
||||
if (r.code === 0) try { w.db.prepare("INSERT OR IGNORE INTO main.own_commits (repo, sha, action, at) VALUES (?, ?, ?, ?)").run(o.repo, o.sha, action, new Date().toISOString()); } catch (e) { console.error(`own commit not recorded: ${oneLine(String((e as Error).message ?? e))}`); }
|
||||
return r;
|
||||
});
|
||||
}
|
||||
|
||||
async function pushed(w: Writer, g: Guarded | Grant, git: Pick<Git, "git">, action: string, target: string, o: { remote: string; branch: string; sha: string }, lease: string, details: Details, pr: { repo: string; number: number | null }, asBox = false): Promise<ExecResult> {
|
||||
|
||||
Reference in new issue
Block a user