@davidvornholt/standards 0.10.1 → 0.11.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/README.md +6 -1
- package/package.json +37 -1
- package/src/cli.ts +85 -13
- package/src/github-commands.ts +2 -0
- package/src/github-label-identity.ts +9 -0
- package/src/github-labels.ts +123 -0
- package/src/github-live-drift.ts +8 -0
- package/src/github-paginate.ts +37 -0
- package/src/github-settings-merge.ts +167 -0
- package/src/github-settings-parse.ts +82 -7
- package/src/github-settings.ts +5 -123
- package/src/poller-approval.ts +80 -0
- package/src/poller-claim.ts +154 -0
- package/src/poller-codex.ts +93 -0
- package/src/poller-commands.ts +78 -0
- package/src/poller-config.ts +188 -0
- package/src/poller-fix-outcome.ts +36 -0
- package/src/poller-fix-output.ts +135 -0
- package/src/poller-fix-publication.ts +187 -0
- package/src/poller-fix-run.ts +175 -0
- package/src/poller-fix-validation.ts +64 -0
- package/src/poller-github-publication.ts +23 -0
- package/src/poller-github-pulls.ts +189 -0
- package/src/poller-github-write.ts +87 -0
- package/src/poller-github.ts +190 -0
- package/src/poller-job-shared.ts +132 -0
- package/src/poller-outcome.ts +136 -0
- package/src/poller-output-integrity.ts +107 -0
- package/src/poller-prompts.ts +70 -0
- package/src/poller-protected-paths.ts +51 -0
- package/src/poller-protocol.ts +137 -0
- package/src/poller-review-artifacts.ts +119 -0
- package/src/poller-review-execution.ts +108 -0
- package/src/poller-review-output.ts +189 -0
- package/src/poller-review-publication.ts +153 -0
- package/src/poller-review-run.ts +160 -0
- package/src/poller-review-state.ts +126 -0
- package/src/poller-review-validation.ts +66 -0
- package/src/poller-schedule.ts +121 -0
- package/src/poller-tick.ts +144 -0
- package/src/poller-trust.ts +96 -0
- package/src/poller-units.ts +82 -0
- package/src/poller-workspace.ts +199 -0
package/README.md
CHANGED
|
@@ -12,14 +12,18 @@ standards dependabot --check
|
|
|
12
12
|
standards dependabot --write
|
|
13
13
|
standards github --check
|
|
14
14
|
standards github --apply
|
|
15
|
+
standards poller --config <path>
|
|
16
|
+
standards poller --print-units --config <path>
|
|
15
17
|
```
|
|
16
18
|
|
|
17
19
|
`dependabot --write` regenerates the composed `.github/dependabot.yml` from the canonical `.github/dependabot.base.yml` and the optional repo-owned `.github/dependabot.local.yml`; `init` and `sync` do the same automatically. `dependabot --check` verifies the generated file still matches its sources, and `doctor`/`check` include the same verification. The overlay is deliberately lean and additive only: new update blocks for repo-specific ecosystems, top-level private registry definitions, and `ignore` or `registries` entries appended by repeating a canonical block's normalized target. Matching blocks cannot add labels, groups, cooldowns, pull-request limits, or other policy.
|
|
18
20
|
|
|
19
|
-
`github --check` compares the live GitHub repository (merge settings and
|
|
21
|
+
`github --check` compares the live GitHub repository (merge settings, rulesets, and declared labels) against the merged declaration in `.github/settings.json` + `.github/settings.local.json`; `github --apply` converges that declared state. Undeclared live labels remain untouched, while undeclared repository-owned rulesets are removed. `check` runs the same comparison whenever `.github/settings.json` is present, and fails closed: declared state the token cannot see fails the gate with a message naming the token fix instead of passing unverified. The canonical workflow sets `STANDARDS_SKIP_GITHUB_CHECK=true` only in its unprivileged quality step because its isolated `github-settings` job runs the live comparison with the admin-read token; this is a workflow-internal integration seam, not a general way to disable the local gate. The CLI prints an explicit diagnostic whenever that exact value skips either `check`'s live phase or `github --check`; `github --apply` is never skipped. `--apply` re-diffs the PATCH response, so a setting GitHub accepts with HTTP 200 but silently ignores (plan-unavailable features) is a reported failure, not a false success. A repository whose GitHub plan cannot enforce rulesets can declare that in the seam (see `rulesetEnforcement` below); both commands then skip rulesets and plan-gated repository settings, converge the rest, and print an unprotected-branch notice on every run.
|
|
20
22
|
|
|
21
23
|
`structure` enforces the canonical monorepo structure contract: workspace scripts (`check-types`, `lint`, `lint:fix`, `test`), root gate scripts, filtered Turbo convenience aliases, internal `0.0.0`/`workspace:*` versioning, package `exports`, shared tsconfig inheritance, and browser a11y wiring. Only a workspace containing an explicit `*.a11y.ts` suite must provide a `test:a11y` script and direct `@axe-core/playwright` and `@playwright/test` dependencies. `check` includes `structure`, so these rules gate every consumer PR.
|
|
22
24
|
|
|
25
|
+
`poller` runs one tick of the fix poller: host-level automation that turns maintainer-approved GitHub issues into verified draft PRs and maintainer-approved draft PRs into completed review-fix cycles, using headless Codex runs. All workflow state lives in GitHub labels, comments, and draft PRs, so ticks are stateless, re-runnable, and safe to schedule from any host. A tick claims work by label (`fix-in-progress` / `review-in-progress`), releases claims stale for longer than `staleClaimHours`, and fails loudly — a red tick means jobs stalled, never silence. Trust is verified per event, not per configuration: the approval labels (`approved-for-fix`, `approved-for-review`) only count when the applying user holds the `admin` or `maintain` role, bind to the exact approved issue revision or PR head, and are revalidated before publication; only admin/maintain comments are treated as answers to agent questions. The poller removes its direct GitHub token variables before launching Codex, but the approved run shares the host service identity and can read its other ambient credentials and logged-in tool state; that accepted visibility must not be treated as credential isolation. The run works in a throwaway git worktree, hands results back through a structured outcome file, and the poller verifies effects (commits exist, no protected paths touched) before pushing, opening the draft PR, or posting the review — the required CI checks on the resulting PR remain the quality gate. Host mutation is declarative-only: `--print-units` emits a correctly escaped systemd service and timer for the polling host's infrastructure repository to adapt and deploy. That repository owns the service identity, writable HOME, PATH, GitHub token environment, lingering, and deployment. The service's tick budget (`TimeoutStartSec`) is derived from `maxJobsPerTick` × `runTimeoutMinutes` plus overhead, so re-render and redeploy the units after changing either value.
|
|
26
|
+
|
|
23
27
|
`structure --profile source` validates the standards source repository itself, which is deliberately not a consumer. The profile pins its intentional exceptions so they cannot drift silently: exact, ordered root gate scripts that run this CLI from the local checkout (`structure --profile source`, `dependabot --check` or `dependabot --write`, `github --check`, and the Turbo gate) instead of a recursive `standards check`, and a non-private published bin-only CLI workspace that carries a stable release SemVer and exactly maps the `standards` bin to `src/cli.ts` without `exports`. Every other consumer rule still applies.
|
|
24
28
|
|
|
25
29
|
## Configuration
|
|
@@ -27,6 +31,7 @@ standards github --apply
|
|
|
27
31
|
- **`.github/dependabot.local.yml`** (optional) — repo-owned Dependabot extension composed with the canonical `.github/dependabot.base.yml` into the generated `.github/dependabot.yml`. May define `updates` and top-level `registries`; a block matching a canonical normalized target may only add `ignore` and/or `registries` entries. Other matching-block policy is rejected deliberately. A missing or comments-only file means no additions. CLI 0.10.1 requires the selected content ref to contain the canonical base and rejects older refs before mutation.
|
|
28
32
|
- **`sync-standards.local.json`** (optional) — consumer-owned sync policy at the repo root, validated by `doctor`/`check` and every `init`/`sync` even when an explicit ref or local source makes its `"ref"` irrelevant. All fields optional; a missing file means the defaults. `"ref"` is a non-empty single-line string that pins a tag, branch, or full commit sha to sync from instead of `main` (an explicit `--ref` overrides it; a local-path `--from` source is used as-is and ignores only the validated pin). `"autoSync": false` is read by the standards-sync workflow, not the CLI, and skips the weekly scheduled run. Version 0.7.0 removes the legacy `STANDARDS_AUTO_SYNC` and `STANDARDS_SYNC_REF` variable behavior; consumers must upgrade the package and lockfile before adopting a policy file.
|
|
29
33
|
- **`.github/settings.local.json` `"rulesetEnforcement": "unavailable-on-plan"`** (optional) — declares that the repository's GitHub plan cannot enforce rulesets (private repositories on GitHub Free, both personal accounts and organizations). `github --check` and `--apply` then skip rulesets instead of comparing them, because a comparison cannot be trusted there: personal accounts answer ruleset reads with HTTP 403, and free-plan organizations report declared rulesets as active while silently not enforcing them. Plan-gated repository settings that only function alongside branch protection (`allow_auto_merge`) are skipped for the same reason — GitHub accepts a PATCH for them with HTTP 200 and silently keeps the old value. The remaining repository merge settings are still checked and converged, and both commands print an unprotected-branch notice on every run. The only accepted value is `"unavailable-on-plan"` (enforcement is the default; omit the key on paid plans), and combining the opt-out with additional local rulesets is rejected. After upgrading the plan, remove the declaration and run `bun standards github --apply` to restore enforcement.
|
|
34
|
+
- **Poller config file** (required for `poller`, passed via `--config`) — host-level JSON, deliberately not repository state. Required: `"repos"` (unique `owner/repo` strings — one poller watches any number of repositories), `"model"` and `"reasoningEffort"` (passed to `codex exec`; the model choice is deliberate and has no default). Optional: `"maxJobsPerTick"` (default 1 — the concurrency and rate-limit guard; subscription-authenticated Codex runs share the interactive rate window), `"staleClaimHours"` (default 6; must exceed `runTimeoutMinutes` so a sweep can never release the claim of a job that is still running), `"runTimeoutMinutes"` (default 240 — the timeout catches wedged agents, not honest multi-hour review runs), `"cacheDir"` (default `~/.cache/standards-poller`; holds bare mirrors and job worktrees; relative paths resolve against the config file), `"extraCodexArgs"` (extra `codex exec` arguments, e.g. enabling the collaboration feature for subagent fan-out). Unknown keys are rejected. The poller needs `git`, `codex` (authenticated — its rotating auth state must live in a writable location), and a GitHub token per the bullet below; the token needs issues, pull-requests, and contents write on the watched repos, and nothing else.
|
|
30
35
|
- **`GH_TOKEN` / `GITHUB_TOKEN`** (optional) — GitHub API token for the `github` command and the GitHub portion of `check`. When neither is set, the token from the local `gh` CLI is used; with no token at all, reads still work on public repositories. `--apply` needs an admin token. GitHub's REST API reveals repo merge settings only to write-capable viewers — `check` retries REST-hidden keys over GraphQL, which serves them to read-only tokens — and ruleset `bypass_actors` requires repository Administration read; a token that still cannot see declared state fails the check rather than passing unverified. In CI, where the workflow token can never hold that permission, the canonical workflow decrypts `ci.github_settings_read_token` from the SOPS-encrypted `secrets/ci.yaml` — a fine-grained PAT with read-only "Administration" access to the repository.
|
|
31
36
|
|
|
32
37
|
See the standards repository README for the ownership model and adoption workflow.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@davidvornholt/standards",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Bootstrap, synchronize, and validate davidvornholt/standards consumers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,9 +29,45 @@
|
|
|
29
29
|
"src/github-command-shared.ts",
|
|
30
30
|
"src/github-commands.ts",
|
|
31
31
|
"src/github-diff.ts",
|
|
32
|
+
"src/github-labels.ts",
|
|
33
|
+
"src/github-label-identity.ts",
|
|
32
34
|
"src/github-live-drift.ts",
|
|
35
|
+
"src/github-paginate.ts",
|
|
36
|
+
"src/github-settings-merge.ts",
|
|
33
37
|
"src/github-settings-parse.ts",
|
|
34
38
|
"src/github-settings.ts",
|
|
39
|
+
"src/poller-approval.ts",
|
|
40
|
+
"src/poller-claim.ts",
|
|
41
|
+
"src/poller-codex.ts",
|
|
42
|
+
"src/poller-commands.ts",
|
|
43
|
+
"src/poller-config.ts",
|
|
44
|
+
"src/poller-fix-outcome.ts",
|
|
45
|
+
"src/poller-fix-output.ts",
|
|
46
|
+
"src/poller-fix-publication.ts",
|
|
47
|
+
"src/poller-fix-run.ts",
|
|
48
|
+
"src/poller-fix-validation.ts",
|
|
49
|
+
"src/poller-github-pulls.ts",
|
|
50
|
+
"src/poller-github-publication.ts",
|
|
51
|
+
"src/poller-github-write.ts",
|
|
52
|
+
"src/poller-github.ts",
|
|
53
|
+
"src/poller-job-shared.ts",
|
|
54
|
+
"src/poller-outcome.ts",
|
|
55
|
+
"src/poller-output-integrity.ts",
|
|
56
|
+
"src/poller-prompts.ts",
|
|
57
|
+
"src/poller-protected-paths.ts",
|
|
58
|
+
"src/poller-protocol.ts",
|
|
59
|
+
"src/poller-review-publication.ts",
|
|
60
|
+
"src/poller-review-output.ts",
|
|
61
|
+
"src/poller-review-artifacts.ts",
|
|
62
|
+
"src/poller-review-execution.ts",
|
|
63
|
+
"src/poller-review-state.ts",
|
|
64
|
+
"src/poller-review-validation.ts",
|
|
65
|
+
"src/poller-schedule.ts",
|
|
66
|
+
"src/poller-review-run.ts",
|
|
67
|
+
"src/poller-tick.ts",
|
|
68
|
+
"src/poller-trust.ts",
|
|
69
|
+
"src/poller-units.ts",
|
|
70
|
+
"src/poller-workspace.ts",
|
|
35
71
|
"src/structure-check.ts",
|
|
36
72
|
"src/structure-profile.ts",
|
|
37
73
|
"src/structure-script.ts",
|
package/src/cli.ts
CHANGED
|
@@ -44,6 +44,7 @@ import { CANONICAL_SETTINGS_FILE, LOCAL_SETTINGS_FILE } from './github-api';
|
|
|
44
44
|
import { runGithubApply, runGithubCheck } from './github-commands';
|
|
45
45
|
import { loadGithubSettings } from './github-settings';
|
|
46
46
|
import { isNonEmptyString, isRecord } from './github-settings-parse';
|
|
47
|
+
import { runPollerCommand } from './poller-commands';
|
|
47
48
|
import { collectStructureProblems } from './structure-check';
|
|
48
49
|
import type { StructureProfile } from './structure-profile';
|
|
49
50
|
import { hasSafeCommand } from './structure-script';
|
|
@@ -54,6 +55,7 @@ const DEFAULT_UPSTREAM = 'github:davidvornholt/standards';
|
|
|
54
55
|
const HASH_PREVIEW_LENGTH = 12;
|
|
55
56
|
|
|
56
57
|
const GITHUB_PREFIX = 'github:';
|
|
58
|
+
const SKIP_GITHUB_CHECK_ENV = 'STANDARDS_SKIP_GITHUB_CHECK';
|
|
57
59
|
|
|
58
60
|
// Never mirrored, even under a managed directory path: build output, VCS
|
|
59
61
|
// metadata, and installed dependencies would otherwise pollute the lock when
|
|
@@ -91,6 +93,7 @@ type Command =
|
|
|
91
93
|
| 'github'
|
|
92
94
|
| 'help'
|
|
93
95
|
| 'init'
|
|
96
|
+
| 'poller'
|
|
94
97
|
| 'structure'
|
|
95
98
|
| 'sync';
|
|
96
99
|
|
|
@@ -103,6 +106,8 @@ type CliOptions = {
|
|
|
103
106
|
readonly apply: boolean;
|
|
104
107
|
readonly write: boolean;
|
|
105
108
|
readonly profile: StructureProfile;
|
|
109
|
+
readonly config: string | undefined;
|
|
110
|
+
readonly printUnits: boolean;
|
|
106
111
|
};
|
|
107
112
|
|
|
108
113
|
const sha256 = (buf: Buffer): string =>
|
|
@@ -778,17 +783,20 @@ Commands:
|
|
|
778
783
|
structure Validate monorepo structure rules only
|
|
779
784
|
dependabot Verify (--check) or regenerate (--write) the composed .github/dependabot.yml
|
|
780
785
|
github Compare (--check) or converge (--apply) live GitHub settings
|
|
786
|
+
poller Run one fix-poller tick over the configured repositories (host automation)
|
|
781
787
|
help Show this help
|
|
782
788
|
|
|
783
789
|
Options:
|
|
784
|
-
--dir <path>
|
|
785
|
-
--profile <p>
|
|
786
|
-
--from <src>
|
|
787
|
-
--ref <ref>
|
|
788
|
-
--dry-run
|
|
789
|
-
--check
|
|
790
|
-
--apply
|
|
791
|
-
--write
|
|
790
|
+
--dir <path> Consumer directory to operate on (default: current directory)
|
|
791
|
+
--profile <p> With structure: validate as a "consumer" (default) or as the standards "source" repository itself
|
|
792
|
+
--from <src> Upstream override for init/sync (GitHub repo or local path)
|
|
793
|
+
--ref <ref> Upstream tag, branch, or full commit sha for init/sync (remote Git/GitHub sources only; default: main)
|
|
794
|
+
--dry-run Preview a sync without writing anything
|
|
795
|
+
--check With github/dependabot: compare against the declared sources (default)
|
|
796
|
+
--apply With github: converge the live repository (needs admin auth)
|
|
797
|
+
--write With dependabot: regenerate the composed .github/dependabot.yml
|
|
798
|
+
--config <path> With poller: the host-level poller config file (required)
|
|
799
|
+
--print-units With poller: print declarative systemd unit content without touching the host`;
|
|
792
800
|
|
|
793
801
|
const commandFromArg = (arg: string): Command => {
|
|
794
802
|
if (
|
|
@@ -798,6 +806,7 @@ const commandFromArg = (arg: string): Command => {
|
|
|
798
806
|
arg === 'github' ||
|
|
799
807
|
arg === 'help' ||
|
|
800
808
|
arg === 'init' ||
|
|
809
|
+
arg === 'poller' ||
|
|
801
810
|
arg === 'structure' ||
|
|
802
811
|
arg === 'sync'
|
|
803
812
|
) {
|
|
@@ -840,12 +849,24 @@ type ParsedFlags = {
|
|
|
840
849
|
readonly write: boolean;
|
|
841
850
|
readonly ref: string | undefined;
|
|
842
851
|
readonly profile: StructureProfile | undefined;
|
|
852
|
+
readonly config: string | undefined;
|
|
853
|
+
readonly printUnits: boolean;
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
const assertPollerOptionUsage = (flags: ParsedFlags): void => {
|
|
857
|
+
if (flags.config !== undefined && flags.command !== 'poller') {
|
|
858
|
+
throw new Error('--config is only valid with the poller command');
|
|
859
|
+
}
|
|
860
|
+
if (flags.printUnits && flags.command !== 'poller') {
|
|
861
|
+
throw new Error('--print-units is only valid with the poller command');
|
|
862
|
+
}
|
|
843
863
|
};
|
|
844
864
|
|
|
845
865
|
// Every option is only meaningful with specific commands; reject the rest so a
|
|
846
866
|
// typo fails loudly instead of silently doing the default thing.
|
|
847
867
|
const assertOptionUsage = (flags: ParsedFlags): void => {
|
|
848
868
|
const { command, checkFlag, apply, write, ref, profile } = flags;
|
|
869
|
+
assertPollerOptionUsage(flags);
|
|
849
870
|
if (checkFlag && command !== 'github' && command !== 'dependabot') {
|
|
850
871
|
throw new Error(
|
|
851
872
|
'--check is only valid with the github and dependabot commands',
|
|
@@ -881,6 +902,8 @@ const parseArgs = (argv: ReadonlyArray<string>): CliOptions => {
|
|
|
881
902
|
let apply = false;
|
|
882
903
|
let write = false;
|
|
883
904
|
let profile: StructureProfile | undefined;
|
|
905
|
+
let config: string | undefined;
|
|
906
|
+
let printUnits = false;
|
|
884
907
|
|
|
885
908
|
for (let index = 0; index < argv.length; index += 1) {
|
|
886
909
|
const arg = argv[index];
|
|
@@ -888,6 +911,13 @@ const parseArgs = (argv: ReadonlyArray<string>): CliOptions => {
|
|
|
888
911
|
case '--apply':
|
|
889
912
|
apply = true;
|
|
890
913
|
break;
|
|
914
|
+
case '--config':
|
|
915
|
+
config = nextOptionValue(argv, index);
|
|
916
|
+
index += 1;
|
|
917
|
+
break;
|
|
918
|
+
case '--print-units':
|
|
919
|
+
printUnits = true;
|
|
920
|
+
break;
|
|
891
921
|
case '--check':
|
|
892
922
|
checkFlag = true;
|
|
893
923
|
break;
|
|
@@ -922,7 +952,16 @@ const parseArgs = (argv: ReadonlyArray<string>): CliOptions => {
|
|
|
922
952
|
}
|
|
923
953
|
}
|
|
924
954
|
|
|
925
|
-
assertOptionUsage({
|
|
955
|
+
assertOptionUsage({
|
|
956
|
+
command,
|
|
957
|
+
checkFlag,
|
|
958
|
+
apply,
|
|
959
|
+
write,
|
|
960
|
+
ref,
|
|
961
|
+
profile,
|
|
962
|
+
config,
|
|
963
|
+
printUnits,
|
|
964
|
+
});
|
|
926
965
|
|
|
927
966
|
return {
|
|
928
967
|
command,
|
|
@@ -933,6 +972,8 @@ const parseArgs = (argv: ReadonlyArray<string>): CliOptions => {
|
|
|
933
972
|
apply,
|
|
934
973
|
write,
|
|
935
974
|
profile: profile ?? 'consumer',
|
|
975
|
+
config,
|
|
976
|
+
printUnits,
|
|
936
977
|
};
|
|
937
978
|
};
|
|
938
979
|
|
|
@@ -964,13 +1005,27 @@ const runCheckCommand = async (consumer: string): Promise<boolean> => {
|
|
|
964
1005
|
// closed: once .github/settings.json exists, an unreachable API or an
|
|
965
1006
|
// unreadable origin is a failure, not a skip.
|
|
966
1007
|
const githubIsConverged = existsSync(join(consumer, CANONICAL_SETTINGS_FILE))
|
|
967
|
-
? await
|
|
1008
|
+
? await runGithubCheckGate(consumer)
|
|
968
1009
|
: true;
|
|
969
1010
|
return (
|
|
970
1011
|
driftIsClean && integrationIsValid && structureIsValid && githubIsConverged
|
|
971
1012
|
);
|
|
972
1013
|
};
|
|
973
1014
|
|
|
1015
|
+
// The canonical workflow sets this only for its unprivileged quality job,
|
|
1016
|
+
// where a separate isolated job runs the same live check with the admin-read
|
|
1017
|
+
// token. Absent that exact workflow seam, local and explicit checks remain
|
|
1018
|
+
// fail-closed.
|
|
1019
|
+
const runGithubCheckGate = (consumer: string): Promise<boolean> => {
|
|
1020
|
+
if (process.env[SKIP_GITHUB_CHECK_ENV] === 'true') {
|
|
1021
|
+
console.log(
|
|
1022
|
+
`standards github: live settings check skipped because ${SKIP_GITHUB_CHECK_ENV}=true; the canonical workflow's isolated github-settings job must own this check`,
|
|
1023
|
+
);
|
|
1024
|
+
return Promise.resolve(true);
|
|
1025
|
+
}
|
|
1026
|
+
return runGithubCheck(consumer);
|
|
1027
|
+
};
|
|
1028
|
+
|
|
974
1029
|
// Consumer-owned sync policy, checked in next to the canonical (read-only)
|
|
975
1030
|
// standards-sync workflow it configures — versioned and reviewable, unlike
|
|
976
1031
|
// repository Actions variables. All fields are optional; a missing file means
|
|
@@ -1116,12 +1171,22 @@ const runGateCommand = (
|
|
|
1116
1171
|
if (command === 'structure') {
|
|
1117
1172
|
return runStructure(consumer, profile);
|
|
1118
1173
|
}
|
|
1119
|
-
return apply ? runGithubApply(consumer) :
|
|
1174
|
+
return apply ? runGithubApply(consumer) : runGithubCheckGate(consumer);
|
|
1120
1175
|
};
|
|
1121
1176
|
|
|
1122
1177
|
const main = async (): Promise<void> => {
|
|
1123
|
-
const {
|
|
1124
|
-
|
|
1178
|
+
const {
|
|
1179
|
+
command,
|
|
1180
|
+
consumer,
|
|
1181
|
+
dryRun,
|
|
1182
|
+
from,
|
|
1183
|
+
ref,
|
|
1184
|
+
apply,
|
|
1185
|
+
write,
|
|
1186
|
+
profile,
|
|
1187
|
+
config,
|
|
1188
|
+
printUnits,
|
|
1189
|
+
} = parseArgs(process.argv.slice(2));
|
|
1125
1190
|
|
|
1126
1191
|
if (command === undefined) {
|
|
1127
1192
|
console.error('standards: a command is required\n');
|
|
@@ -1150,6 +1215,13 @@ const main = async (): Promise<void> => {
|
|
|
1150
1215
|
return;
|
|
1151
1216
|
}
|
|
1152
1217
|
|
|
1218
|
+
if (command === 'poller') {
|
|
1219
|
+
if (!(await runPollerCommand({ configPath: config, printUnits }))) {
|
|
1220
|
+
process.exitCode = 1;
|
|
1221
|
+
}
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1153
1225
|
if (!(await runGateCommand(command, consumer, apply, profile))) {
|
|
1154
1226
|
process.exitCode = 1;
|
|
1155
1227
|
}
|
package/src/github-commands.ts
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
enforceableRepositorySettings,
|
|
21
21
|
optOutEligibilityProblem,
|
|
22
22
|
} from './github-command-shared';
|
|
23
|
+
import { applyLabels } from './github-labels';
|
|
23
24
|
import { collectLiveDrift } from './github-live-drift';
|
|
24
25
|
import { isRecord } from './github-settings-parse';
|
|
25
26
|
|
|
@@ -108,6 +109,7 @@ export const runGithubApply = async (consumer: string): Promise<boolean> => {
|
|
|
108
109
|
if (!rulesetsSkipped) {
|
|
109
110
|
actions.push(...(await applyRulesets(token, repo, declared.merged)));
|
|
110
111
|
}
|
|
112
|
+
actions.push(...(await applyLabels(token, repo, declared.merged.labels)));
|
|
111
113
|
for (const action of actions) {
|
|
112
114
|
console.log(` ${action}`);
|
|
113
115
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const labelIdentity = (name: string): string => name.toLowerCase();
|
|
2
|
+
|
|
3
|
+
export const hasLabel = (
|
|
4
|
+
labels: ReadonlyArray<string>,
|
|
5
|
+
expected: string,
|
|
6
|
+
): boolean => {
|
|
7
|
+
const identity = labelIdentity(expected);
|
|
8
|
+
return labels.some((label) => labelIdentity(label) === identity);
|
|
9
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Live issue-label reading, drift, and convergence. Labels are an additive
|
|
2
|
+
// floor: every declared label must exist with the declared color and
|
|
3
|
+
// description; undeclared live labels (GitHub defaults, ad-hoc triage labels)
|
|
4
|
+
// are ignored. Any token that can read the repository can verify labels, so
|
|
5
|
+
// unlike merge settings there are no unverifiable states.
|
|
6
|
+
|
|
7
|
+
import { apiError, HTTP_CREATED, HTTP_OK, request } from './github-api';
|
|
8
|
+
import { labelIdentity } from './github-label-identity';
|
|
9
|
+
import { listAllPages } from './github-paginate';
|
|
10
|
+
import { isRecord, type LabelDeclaration } from './github-settings-parse';
|
|
11
|
+
|
|
12
|
+
type LiveLabel = {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly color: string;
|
|
15
|
+
readonly description: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const fetchLiveLabels = async (
|
|
19
|
+
token: string | null,
|
|
20
|
+
repo: string,
|
|
21
|
+
): Promise<ReadonlyArray<LiveLabel>> => {
|
|
22
|
+
const items = await listAllPages(
|
|
23
|
+
token,
|
|
24
|
+
`/repos/${repo}/labels`,
|
|
25
|
+
`reading labels for ${repo}`,
|
|
26
|
+
);
|
|
27
|
+
return items.filter(isRecord).map((label) => ({
|
|
28
|
+
name: typeof label.name === 'string' ? label.name : '',
|
|
29
|
+
color: typeof label.color === 'string' ? label.color : '',
|
|
30
|
+
description: typeof label.description === 'string' ? label.description : '',
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const labelDrift = (
|
|
35
|
+
declared: LabelDeclaration,
|
|
36
|
+
live: LiveLabel | undefined,
|
|
37
|
+
): string | null => {
|
|
38
|
+
if (live === undefined) {
|
|
39
|
+
return `label "${declared.name}" is declared but missing on GitHub`;
|
|
40
|
+
}
|
|
41
|
+
// GitHub reports colors in varying case; declarations are lowercase.
|
|
42
|
+
const liveColor = live.color.toLowerCase();
|
|
43
|
+
if (liveColor !== declared.color) {
|
|
44
|
+
return `label "${declared.name}" has color "${liveColor}" on GitHub, declared "${declared.color}"`;
|
|
45
|
+
}
|
|
46
|
+
if (live.description !== declared.description) {
|
|
47
|
+
return `label "${declared.name}" has a different description on GitHub than declared`;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const diffLabels = (
|
|
53
|
+
declared: ReadonlyArray<LabelDeclaration>,
|
|
54
|
+
live: ReadonlyArray<LiveLabel>,
|
|
55
|
+
): ReadonlyArray<string> => {
|
|
56
|
+
const liveByName = new Map(
|
|
57
|
+
live.map((label) => [labelIdentity(label.name), label]),
|
|
58
|
+
);
|
|
59
|
+
return declared.flatMap((label) => {
|
|
60
|
+
const drift = labelDrift(label, liveByName.get(labelIdentity(label.name)));
|
|
61
|
+
return drift === null ? [] : [drift];
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const convergeLabel = async (
|
|
66
|
+
token: string,
|
|
67
|
+
repo: string,
|
|
68
|
+
declared: LabelDeclaration,
|
|
69
|
+
live: LiveLabel | undefined,
|
|
70
|
+
): Promise<string | null> => {
|
|
71
|
+
if (labelDrift(declared, live) === null) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
if (live === undefined) {
|
|
75
|
+
const created = await request(token, 'POST', `/repos/${repo}/labels`, {
|
|
76
|
+
name: declared.name,
|
|
77
|
+
color: declared.color,
|
|
78
|
+
description: declared.description,
|
|
79
|
+
});
|
|
80
|
+
if (created.status !== HTTP_CREATED) {
|
|
81
|
+
throw new Error(apiError(`creating label "${declared.name}"`, created));
|
|
82
|
+
}
|
|
83
|
+
return `created label "${declared.name}"`;
|
|
84
|
+
}
|
|
85
|
+
const updated = await request(
|
|
86
|
+
token,
|
|
87
|
+
'PATCH',
|
|
88
|
+
`/repos/${repo}/labels/${encodeURIComponent(live.name)}`,
|
|
89
|
+
{ color: declared.color, description: declared.description },
|
|
90
|
+
);
|
|
91
|
+
if (updated.status !== HTTP_OK) {
|
|
92
|
+
throw new Error(apiError(`updating label "${declared.name}"`, updated));
|
|
93
|
+
}
|
|
94
|
+
return `updated label "${declared.name}"`;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const applyLabels = async (
|
|
98
|
+
token: string,
|
|
99
|
+
repo: string,
|
|
100
|
+
declared: ReadonlyArray<LabelDeclaration>,
|
|
101
|
+
): Promise<ReadonlyArray<string>> => {
|
|
102
|
+
if (declared.length === 0) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
const live = await fetchLiveLabels(token, repo);
|
|
106
|
+
const liveByName = new Map(
|
|
107
|
+
live.map((label) => [labelIdentity(label.name), label]),
|
|
108
|
+
);
|
|
109
|
+
const actions: Array<string> = [];
|
|
110
|
+
for (const label of declared) {
|
|
111
|
+
// biome-ignore lint/performance/noAwaitInLoops: GitHub advises against concurrent write requests (secondary rate limits); mutations run sequentially on purpose.
|
|
112
|
+
const action = await convergeLabel(
|
|
113
|
+
token,
|
|
114
|
+
repo,
|
|
115
|
+
label,
|
|
116
|
+
liveByName.get(labelIdentity(label.name)),
|
|
117
|
+
);
|
|
118
|
+
if (action !== null) {
|
|
119
|
+
actions.push(action);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return actions;
|
|
123
|
+
};
|
package/src/github-live-drift.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
unverifiableProblem,
|
|
18
18
|
} from './github-command-shared';
|
|
19
19
|
import { diffRepositorySettings, diffRulesets } from './github-diff';
|
|
20
|
+
import { diffLabels, fetchLiveLabels } from './github-labels';
|
|
20
21
|
import { type GithubSettings, isRecord } from './github-settings-parse';
|
|
21
22
|
|
|
22
23
|
const repositoryDrift = async (
|
|
@@ -87,9 +88,16 @@ export const collectLiveDrift = async (
|
|
|
87
88
|
}
|
|
88
89
|
const token = resolveToken();
|
|
89
90
|
try {
|
|
91
|
+
// No declared labels means nothing to verify — skipping the fetch is
|
|
92
|
+
// exact, not lenient.
|
|
93
|
+
const labelDrift =
|
|
94
|
+
declared.labels.length === 0
|
|
95
|
+
? []
|
|
96
|
+
: diffLabels(declared.labels, await fetchLiveLabels(token, repo));
|
|
90
97
|
return [
|
|
91
98
|
...(await repositoryDrift(token, repo, declared)),
|
|
92
99
|
...(await rulesetDrift(token, repo, declared)),
|
|
100
|
+
...labelDrift,
|
|
93
101
|
];
|
|
94
102
|
} catch (error) {
|
|
95
103
|
return [
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Exhaustive pagination for GitHub list endpoints. Single-page reads are a
|
|
2
|
+
// correctness hazard everywhere the caller needs "the latest" or "all" of
|
|
3
|
+
// something: a truncated timeline mis-attributes label approvals, truncated
|
|
4
|
+
// comments break answer detection, and truncated label lists read as drift.
|
|
5
|
+
// Overflow past the page cap fails loudly instead of silently truncating.
|
|
6
|
+
|
|
7
|
+
import { apiError, HTTP_OK, request } from './github-api';
|
|
8
|
+
|
|
9
|
+
const PAGE_SIZE = 100;
|
|
10
|
+
const MAX_PAGES = 30;
|
|
11
|
+
|
|
12
|
+
export const listAllPages = async (
|
|
13
|
+
token: string | null,
|
|
14
|
+
path: string,
|
|
15
|
+
context: string,
|
|
16
|
+
): Promise<ReadonlyArray<unknown>> => {
|
|
17
|
+
const items: Array<unknown> = [];
|
|
18
|
+
const separator = path.includes('?') ? '&' : '?';
|
|
19
|
+
for (let page = 1; page <= MAX_PAGES; page += 1) {
|
|
20
|
+
// biome-ignore lint/performance/noAwaitInLoops: pages are sequential by definition; the next request needs to know the previous page was full.
|
|
21
|
+
const response = await request(
|
|
22
|
+
token,
|
|
23
|
+
'GET',
|
|
24
|
+
`${path}${separator}per_page=${PAGE_SIZE}&page=${page}`,
|
|
25
|
+
);
|
|
26
|
+
if (response.status !== HTTP_OK || !Array.isArray(response.body)) {
|
|
27
|
+
throw new Error(apiError(context, response));
|
|
28
|
+
}
|
|
29
|
+
items.push(...response.body);
|
|
30
|
+
if (response.body.length < PAGE_SIZE) {
|
|
31
|
+
return items;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
throw new Error(
|
|
35
|
+
`${context}: more than ${MAX_PAGES * PAGE_SIZE} items; refusing to act on a truncated list`,
|
|
36
|
+
);
|
|
37
|
+
};
|