@oss-autopilot/core 3.42.5 → 3.44.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/cli-pre-action.js +8 -3
- package/dist/cli-registry.js +428 -27
- package/dist/cli.bundle.cjs +212 -156
- package/dist/commands/check-integration.js +5 -1
- package/dist/commands/cleanup.d.ts +80 -0
- package/dist/commands/cleanup.js +334 -0
- package/dist/commands/comments.d.ts +14 -1
- package/dist/commands/comments.js +17 -5
- package/dist/commands/config.d.ts +2 -0
- package/dist/commands/config.js +63 -6
- package/dist/commands/daily-dismiss-filter.d.ts +7 -0
- package/dist/commands/daily-dismiss-filter.js +17 -1
- package/dist/commands/daily-ledger.d.ts +150 -0
- package/dist/commands/daily-ledger.js +248 -0
- package/dist/commands/daily-recent-prs.d.ts +26 -0
- package/dist/commands/daily-recent-prs.js +55 -0
- package/dist/commands/daily-render.d.ts +2 -1
- package/dist/commands/daily-render.js +4 -1
- package/dist/commands/daily.d.ts +5 -1
- package/dist/commands/daily.js +83 -93
- package/dist/commands/dashboard-cache.d.ts +2 -0
- package/dist/commands/dashboard-cache.js +33 -8
- package/dist/commands/dashboard-data.js +113 -69
- package/dist/commands/dashboard-gist-sync.js +3 -1
- package/dist/commands/dashboard-lifecycle.d.ts +36 -8
- package/dist/commands/dashboard-lifecycle.js +132 -39
- package/dist/commands/dashboard-process.d.ts +49 -1
- package/dist/commands/dashboard-process.js +111 -12
- package/dist/commands/dashboard-server.js +89 -23
- package/dist/commands/detect-formatters.js +1 -0
- package/dist/commands/dismiss.js +11 -7
- package/dist/commands/doctor.d.ts +15 -1
- package/dist/commands/doctor.js +66 -5
- package/dist/commands/draft.d.ts +77 -0
- package/dist/commands/draft.js +218 -0
- package/dist/commands/eval.js +1 -0
- package/dist/commands/fork-prune.d.ts +58 -0
- package/dist/commands/fork-prune.js +247 -0
- package/dist/commands/guidelines.d.ts +69 -2
- package/dist/commands/guidelines.js +158 -14
- package/dist/commands/index.d.ts +29 -4
- package/dist/commands/index.js +20 -3
- package/dist/commands/issue-thread.d.ts +46 -0
- package/dist/commands/issue-thread.js +123 -0
- package/dist/commands/ledger-backfill.d.ts +9 -0
- package/dist/commands/ledger-backfill.js +44 -1
- package/dist/commands/list-mark-done.d.ts +2 -1
- package/dist/commands/list-mark-done.js +3 -1
- package/dist/commands/list-move-tier.d.ts +2 -1
- package/dist/commands/list-move-tier.js +3 -1
- package/dist/commands/local-repos.js +10 -5
- package/dist/commands/locate-issue-list.d.ts +40 -17
- package/dist/commands/locate-issue-list.js +148 -88
- package/dist/commands/move.js +7 -1
- package/dist/commands/overnight-handoff.d.ts +17 -7
- package/dist/commands/overnight-handoff.js +36 -14
- package/dist/commands/overnight-push-prep.d.ts +14 -8
- package/dist/commands/overnight-push-prep.js +107 -35
- package/dist/commands/overnight-tool-rules.d.ts +54 -0
- package/dist/commands/overnight-tool-rules.js +217 -0
- package/dist/commands/overnight.d.ts +5 -6
- package/dist/commands/overnight.js +61 -140
- package/dist/commands/parse-list.js +7 -1
- package/dist/commands/policy.d.ts +90 -0
- package/dist/commands/policy.js +276 -0
- package/dist/commands/pr-create.d.ts +48 -0
- package/dist/commands/pr-create.js +200 -0
- package/dist/commands/pr-preflight.d.ts +69 -0
- package/dist/commands/pr-preflight.js +348 -0
- package/dist/commands/repo-vet.d.ts +9 -0
- package/dist/commands/repo-vet.js +36 -11
- package/dist/commands/scout-bridge.js +18 -8
- package/dist/commands/search.js +7 -0
- package/dist/commands/setup.d.ts +3 -3
- package/dist/commands/setup.js +160 -48
- package/dist/commands/skip-add.js +10 -1
- package/dist/commands/startup.d.ts +12 -3
- package/dist/commands/startup.js +82 -49
- package/dist/commands/state-cmd.d.ts +2 -0
- package/dist/commands/state-cmd.js +5 -1
- package/dist/commands/stats.js +1 -0
- package/dist/commands/status.js +6 -0
- package/dist/commands/strategy.js +1 -0
- package/dist/commands/validation.d.ts +5 -0
- package/dist/commands/validation.js +5 -0
- package/dist/commands/vet-list.d.ts +6 -0
- package/dist/commands/vet-list.js +26 -1
- package/dist/commands/vet.d.ts +20 -0
- package/dist/commands/vet.js +133 -2
- package/dist/commands/work.d.ts +4 -0
- package/dist/commands/work.js +34 -11
- package/dist/core/__fixtures__/prompt-injection-payloads.js +31 -0
- package/dist/core/anti-llm-policy.d.ts +3 -0
- package/dist/core/anti-llm-policy.js +3 -0
- package/dist/core/auth.js +2 -0
- package/dist/core/ci-analysis.d.ts +7 -2
- package/dist/core/ci-analysis.js +76 -21
- package/dist/core/commit-date.d.ts +45 -0
- package/dist/core/commit-date.js +45 -0
- package/dist/core/compliance-score.d.ts +3 -0
- package/dist/core/compliance-score.js +13 -9
- package/dist/core/config-registry.d.ts +27 -2
- package/dist/core/config-registry.js +94 -7
- package/dist/core/contributing.d.ts +2 -3
- package/dist/core/contributing.js +2 -3
- package/dist/core/daily-logic.d.ts +30 -5
- package/dist/core/daily-logic.js +68 -19
- package/dist/core/errors.d.ts +37 -3
- package/dist/core/errors.js +54 -5
- package/dist/core/fork-prune.d.ts +149 -0
- package/dist/core/fork-prune.js +333 -0
- package/dist/core/gist-health.d.ts +15 -3
- package/dist/core/gist-health.js +8 -0
- package/dist/core/gist-state-store.d.ts +24 -4
- package/dist/core/gist-state-store.js +98 -51
- package/dist/core/github-stats.d.ts +110 -16
- package/dist/core/github-stats.js +295 -110
- package/dist/core/http-cache.d.ts +0 -10
- package/dist/core/http-cache.js +0 -19
- package/dist/core/index.d.ts +13 -6
- package/dist/core/index.js +16 -6
- package/dist/core/issue-conversation.d.ts +8 -2
- package/dist/core/issue-conversation.js +31 -12
- package/dist/core/local-config.d.ts +95 -0
- package/dist/core/local-config.js +270 -0
- package/dist/core/merged-pr-notes.d.ts +2 -2
- package/dist/core/pacing.d.ts +41 -0
- package/dist/core/pacing.js +115 -0
- package/dist/core/pagination.d.ts +55 -0
- package/dist/core/pagination.js +59 -0
- package/dist/core/paths.d.ts +7 -0
- package/dist/core/paths.js +9 -0
- package/dist/core/pr-assembly.d.ts +2 -0
- package/dist/core/pr-assembly.js +6 -2
- package/dist/core/pr-graphql.d.ts +53 -4
- package/dist/core/pr-graphql.js +87 -14
- package/dist/core/pr-monitor.d.ts +35 -12
- package/dist/core/pr-monitor.js +110 -26
- package/dist/core/pr-preflight.d.ts +154 -0
- package/dist/core/pr-preflight.js +753 -0
- package/dist/core/pr-quality-rubric.d.ts +0 -6
- package/dist/core/pr-quality-rubric.js +0 -8
- package/dist/core/pr-template.d.ts +2 -0
- package/dist/core/pr-template.js +5 -1
- package/dist/core/prose-script.d.ts +72 -0
- package/dist/core/prose-script.js +223 -0
- package/dist/core/repo-policy.d.ts +111 -0
- package/dist/core/repo-policy.js +428 -0
- package/dist/core/repo-score-manager.d.ts +66 -0
- package/dist/core/repo-score-manager.js +140 -1
- package/dist/core/review-analysis.d.ts +49 -21
- package/dist/core/review-analysis.js +89 -15
- package/dist/core/reviewed-prs-fetch.js +11 -29
- package/dist/core/reviewed-prs.js +8 -15
- package/dist/core/stale-data.d.ts +78 -0
- package/dist/core/stale-data.js +153 -0
- package/dist/core/state-persistence.d.ts +62 -27
- package/dist/core/state-persistence.js +338 -119
- package/dist/core/state-schema.d.ts +152 -210
- package/dist/core/state-schema.js +232 -80
- package/dist/core/state.d.ts +81 -8
- package/dist/core/state.js +239 -46
- package/dist/core/status-determination.js +32 -12
- package/dist/core/strategy.js +3 -1
- package/dist/core/types.d.ts +22 -1
- package/dist/core/types.js +1 -0
- package/dist/core/untrusted-content.d.ts +30 -11
- package/dist/core/untrusted-content.js +95 -42
- package/dist/core/urls.d.ts +33 -0
- package/dist/core/urls.js +94 -0
- package/dist/dashboard/assets/chart-panel-B-nLVgzQ.js +3 -0
- package/dist/dashboard/assets/index-5IvMGokL.js +55 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/formatters/json.d.ts +432 -10
- package/dist/formatters/json.js +156 -1
- package/package.json +6 -6
- package/dist/core/ci-enforced-tools.d.ts +0 -35
- package/dist/core/ci-enforced-tools.js +0 -109
- package/dist/core/comment-decision.d.ts +0 -79
- package/dist/core/comment-decision.js +0 -82
- package/dist/core/extraction-categories.d.ts +0 -55
- package/dist/core/extraction-categories.js +0 -108
- package/dist/core/follow-up-history.d.ts +0 -40
- package/dist/core/follow-up-history.js +0 -71
- package/dist/core/issue-effort.d.ts +0 -29
- package/dist/core/issue-effort.js +0 -47
- package/dist/core/maintainer-hints.d.ts +0 -23
- package/dist/core/maintainer-hints.js +0 -36
- package/dist/core/workflow-state.d.ts +0 -56
- package/dist/core/workflow-state.js +0 -101
- package/dist/dashboard/assets/chart-panel-DPKNBUts.js +0 -3
- package/dist/dashboard/assets/index-B25bZOYX.js +0 -55
package/dist/core/errors.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* propagate to the caller via isRateLimitError/isRateLimitOrAuthError.
|
|
8
8
|
* Other errors degrade gracefully — modules return partial results and log warnings.
|
|
9
9
|
*/
|
|
10
|
+
import type { StateFileIdentity } from './state-persistence.js';
|
|
10
11
|
/**
|
|
11
12
|
* Base error for all oss-autopilot errors.
|
|
12
13
|
*/
|
|
@@ -69,13 +70,36 @@ export declare class GistCorruptError extends ConfigurationError {
|
|
|
69
70
|
*
|
|
70
71
|
* Library consumers should call `stateManager.reloadIfChanged()` and
|
|
71
72
|
* re-apply their mutation. The runtime `message` is phrased for CLI
|
|
72
|
-
* end-users; the structured
|
|
73
|
-
*
|
|
73
|
+
* end-users; the structured fields are for programmatic handling.
|
|
74
|
+
* `expectedMtimeMs` / `actualMtimeMs` stay for compatibility, but the check
|
|
75
|
+
* compares the whole file identity (mtime, inode, size; #2006), so the two
|
|
76
|
+
* mtimes can be equal. `expectedIdentity` / `actualIdentity` carry what was
|
|
77
|
+
* compared; they are undefined when no comparison ran (a lock timeout).
|
|
78
|
+
* An `actualIdentity` with a NaN mtime means the file could not be stat'ed.
|
|
74
79
|
*/
|
|
75
80
|
export declare class ConcurrencyError extends OssAutopilotError {
|
|
76
81
|
readonly expectedMtimeMs: number;
|
|
77
82
|
readonly actualMtimeMs: number;
|
|
78
|
-
|
|
83
|
+
readonly expectedIdentity?: StateFileIdentity | undefined;
|
|
84
|
+
readonly actualIdentity?: StateFileIdentity | undefined;
|
|
85
|
+
constructor(expectedMtimeMs: number, actualMtimeMs: number, message?: string, expectedIdentity?: StateFileIdentity | undefined, actualIdentity?: StateFileIdentity | undefined);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Thrown when the state.json advisory lock stayed held for the whole bounded
|
|
89
|
+
* wait (#1951). The write was not made. A {@link ConcurrencyError} so callers
|
|
90
|
+
* that reload and retry on a writer collision do the same here.
|
|
91
|
+
*/
|
|
92
|
+
export declare class StateLockTimeoutError extends ConcurrencyError {
|
|
93
|
+
constructor(lockPath: string, waitedMs: number);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Thrown when stored state (the state file, the Gist, or its local cache)
|
|
97
|
+
* carries a schema version above this release's (#1951). It is not corruption:
|
|
98
|
+
* it is never restored over, replaced by fresh state, or moved aside. A
|
|
99
|
+
* {@link ConfigurationError} because it stays until the user updates.
|
|
100
|
+
*/
|
|
101
|
+
export declare class NewerStateVersionError extends ConfigurationError {
|
|
102
|
+
constructor(source: string, version: number, supported: number);
|
|
79
103
|
}
|
|
80
104
|
/**
|
|
81
105
|
* Thrown when a Gist push collides with a concurrent write from another
|
|
@@ -105,6 +129,16 @@ export declare const GIST_FILE_SIZE_REMEDY: string;
|
|
|
105
129
|
export declare class GistFileSizeError extends ConfigurationError {
|
|
106
130
|
constructor(message: string);
|
|
107
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* The search for the existing state Gist could not settle whether one exists:
|
|
134
|
+
* the Gist list is longer than the search window, or the only Gist carrying
|
|
135
|
+
* the state description is public. A {@link ConfigurationError} because
|
|
136
|
+
* retrying cannot fix it and creating a new Gist would fork state across
|
|
137
|
+
* machines (#1926); the message says which Gist ID to write to the gist-id file.
|
|
138
|
+
*/
|
|
139
|
+
export declare class GistDiscoveryError extends ConfigurationError {
|
|
140
|
+
constructor(message: string);
|
|
141
|
+
}
|
|
108
142
|
/**
|
|
109
143
|
* Extract a human-readable message from an unknown error value.
|
|
110
144
|
*/
|
package/dist/core/errors.js
CHANGED
|
@@ -105,20 +105,56 @@ export class GistCorruptError extends ConfigurationError {
|
|
|
105
105
|
*
|
|
106
106
|
* Library consumers should call `stateManager.reloadIfChanged()` and
|
|
107
107
|
* re-apply their mutation. The runtime `message` is phrased for CLI
|
|
108
|
-
* end-users; the structured
|
|
109
|
-
*
|
|
108
|
+
* end-users; the structured fields are for programmatic handling.
|
|
109
|
+
* `expectedMtimeMs` / `actualMtimeMs` stay for compatibility, but the check
|
|
110
|
+
* compares the whole file identity (mtime, inode, size; #2006), so the two
|
|
111
|
+
* mtimes can be equal. `expectedIdentity` / `actualIdentity` carry what was
|
|
112
|
+
* compared; they are undefined when no comparison ran (a lock timeout).
|
|
113
|
+
* An `actualIdentity` with a NaN mtime means the file could not be stat'ed.
|
|
110
114
|
*/
|
|
111
115
|
export class ConcurrencyError extends OssAutopilotError {
|
|
112
116
|
expectedMtimeMs;
|
|
113
117
|
actualMtimeMs;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
expectedIdentity;
|
|
119
|
+
actualIdentity;
|
|
120
|
+
constructor(expectedMtimeMs, actualMtimeMs, message = 'Another oss-autopilot process wrote state.json concurrently. ' +
|
|
121
|
+
'Re-run the command to retry — the last write wins and no data was lost from the other process.', expectedIdentity, actualIdentity) {
|
|
122
|
+
super(message, 'CONCURRENCY_ERROR');
|
|
117
123
|
this.expectedMtimeMs = expectedMtimeMs;
|
|
118
124
|
this.actualMtimeMs = actualMtimeMs;
|
|
125
|
+
this.expectedIdentity = expectedIdentity;
|
|
126
|
+
this.actualIdentity = actualIdentity;
|
|
119
127
|
this.name = 'ConcurrencyError';
|
|
120
128
|
}
|
|
121
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Thrown when the state.json advisory lock stayed held for the whole bounded
|
|
132
|
+
* wait (#1951). The write was not made. A {@link ConcurrencyError} so callers
|
|
133
|
+
* that reload and retry on a writer collision do the same here.
|
|
134
|
+
*/
|
|
135
|
+
export class StateLockTimeoutError extends ConcurrencyError {
|
|
136
|
+
constructor(lockPath, waitedMs) {
|
|
137
|
+
super(0, 0, `State file is locked by another process (waited ${waitedMs} ms). Nothing was written; re-run the command. ` +
|
|
138
|
+
'A lock left by a crashed process expires after 30 seconds, or after 10 minutes when its PID now belongs ' +
|
|
139
|
+
`to a live process. To clear it by hand, make sure no oss-autopilot process is running and delete ${lockPath}.`);
|
|
140
|
+
this.name = 'StateLockTimeoutError';
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Thrown when stored state (the state file, the Gist, or its local cache)
|
|
145
|
+
* carries a schema version above this release's (#1951). It is not corruption:
|
|
146
|
+
* it is never restored over, replaced by fresh state, or moved aside. A
|
|
147
|
+
* {@link ConfigurationError} because it stays until the user updates.
|
|
148
|
+
*/
|
|
149
|
+
export class NewerStateVersionError extends ConfigurationError {
|
|
150
|
+
constructor(source, version, supported) {
|
|
151
|
+
super(`The ${source} was written by a newer oss-autopilot release (schema version ${version}; this release ` +
|
|
152
|
+
`reads up to ${supported}). Nothing was changed. Update this client and retry: run ` +
|
|
153
|
+
'`claude plugin update oss-autopilot@oss-autopilot` and restart Claude Code, or install the latest ' +
|
|
154
|
+
'@oss-autopilot packages.');
|
|
155
|
+
this.name = 'NewerStateVersionError';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
122
158
|
/**
|
|
123
159
|
* Thrown when a Gist push collides with a concurrent write from another
|
|
124
160
|
* machine and the in-flight merge attempt also lost the race (#1115).
|
|
@@ -157,6 +193,19 @@ export class GistFileSizeError extends ConfigurationError {
|
|
|
157
193
|
this.name = 'GistFileSizeError';
|
|
158
194
|
}
|
|
159
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* The search for the existing state Gist could not settle whether one exists:
|
|
198
|
+
* the Gist list is longer than the search window, or the only Gist carrying
|
|
199
|
+
* the state description is public. A {@link ConfigurationError} because
|
|
200
|
+
* retrying cannot fix it and creating a new Gist would fork state across
|
|
201
|
+
* machines (#1926); the message says which Gist ID to write to the gist-id file.
|
|
202
|
+
*/
|
|
203
|
+
export class GistDiscoveryError extends ConfigurationError {
|
|
204
|
+
constructor(message) {
|
|
205
|
+
super(message);
|
|
206
|
+
this.name = 'GistDiscoveryError';
|
|
207
|
+
}
|
|
208
|
+
}
|
|
160
209
|
/**
|
|
161
210
|
* Extract a human-readable message from an unknown error value.
|
|
162
211
|
*/
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which of the user's forks can be deleted (#1912).
|
|
3
|
+
*
|
|
4
|
+
* A fork is prunable only when none of five keep conditions holds:
|
|
5
|
+
* 1. an open PR anywhere has it as its head repository: one of the user's
|
|
6
|
+
* open PRs, or an open PR by any account on any of its branches;
|
|
7
|
+
* 2. an open PR targets the fork itself;
|
|
8
|
+
* 3. a branch tip is the user's own commit (authored or committed) and the
|
|
9
|
+
* work is not done: done means a merged or closed PR into another
|
|
10
|
+
* repository whose head was exactly this tip, or the tip commit merged
|
|
11
|
+
* through a PR into another repository (PR state, not Git ancestry:
|
|
12
|
+
* squash merges leave no ancestry). A PR merged inside the fork, a
|
|
13
|
+
* branch pushed to after its PR, or a reused branch name stays kept;
|
|
14
|
+
* 4. local state references it (claimed issues, work claims, prepared
|
|
15
|
+
* overnight branches): matched on the fork or its parent;
|
|
16
|
+
* 5. it, or its parent, is on `config.keepForks`.
|
|
17
|
+
*
|
|
18
|
+
* A fork whose parent is gone, or whose branches could not all be read, is
|
|
19
|
+
* kept too. The dry run and `--apply` share {@link evaluateFork}, so what a
|
|
20
|
+
* dry run lists is what apply would delete. Reads go through paginated GraphQL.
|
|
21
|
+
*/
|
|
22
|
+
import type { Octokit } from '@octokit/rest';
|
|
23
|
+
/** One branch of a fork: its tip commit, who wrote and committed it, and its open PRs. */
|
|
24
|
+
export interface ForkBranch {
|
|
25
|
+
name: string;
|
|
26
|
+
tipOid: string | null;
|
|
27
|
+
/** GitHub login of the tip commit's author; null when the author email is not linked to an account. */
|
|
28
|
+
tipAuthorLogin: string | null;
|
|
29
|
+
/** GitHub login of the tip commit's committer (a cherry-pick or `git am` keeps someone else as author). */
|
|
30
|
+
tipCommitterLogin: string | null;
|
|
31
|
+
tipCommittedAt: string | null;
|
|
32
|
+
/** Open PRs by any account with this branch as head; null until read ({@link evaluateAll} reads it only where it decides the verdict). */
|
|
33
|
+
openPRs: number | null;
|
|
34
|
+
}
|
|
35
|
+
/** What GitHub says about one fork. */
|
|
36
|
+
export interface ForkFacts {
|
|
37
|
+
/** `owner/name` of the fork. */
|
|
38
|
+
repo: string;
|
|
39
|
+
/** `owner/name` of the parent; null when the parent is gone or hidden. */
|
|
40
|
+
parent: string | null;
|
|
41
|
+
isFork: boolean;
|
|
42
|
+
createdAt: string;
|
|
43
|
+
/** Open PRs whose base repository is this fork. */
|
|
44
|
+
openPRsToFork: number;
|
|
45
|
+
branchCount: number;
|
|
46
|
+
/** Every branch, all pages. */
|
|
47
|
+
branches: ForkBranch[];
|
|
48
|
+
/** False when a page of branches could not be read: the list is partial and the fork is kept. */
|
|
49
|
+
hasAllBranches: boolean;
|
|
50
|
+
}
|
|
51
|
+
/** One PR as fork-prune reads it. */
|
|
52
|
+
export interface PRFact {
|
|
53
|
+
state: string;
|
|
54
|
+
/** `owner/name` the PR targets; null when unknown. */
|
|
55
|
+
baseRepo: string | null;
|
|
56
|
+
/** The head commit the PR last had; null when unknown or not asked for. */
|
|
57
|
+
headOid: string | null;
|
|
58
|
+
}
|
|
59
|
+
/** PR facts for one of the user's own branches. */
|
|
60
|
+
export interface BranchPRs {
|
|
61
|
+
/** PRs whose head is this branch name, at any commit. */
|
|
62
|
+
prs: PRFact[];
|
|
63
|
+
/** PRs the tip commit belongs to (a merged squash or merge commit points at its PR). */
|
|
64
|
+
tipPRs: PRFact[];
|
|
65
|
+
}
|
|
66
|
+
/** Everything outside the fork that decides its verdict. */
|
|
67
|
+
export interface PruneContext {
|
|
68
|
+
login: string;
|
|
69
|
+
/** Lowercase `owner/name` of every head repository of the user's open PRs. */
|
|
70
|
+
openPRHeadRepos: ReadonlySet<string>;
|
|
71
|
+
/** Lowercase `owner/name` of repos local state refers to. */
|
|
72
|
+
referencedRepos: ReadonlySet<string>;
|
|
73
|
+
/** Lowercase `config.keepForks`. */
|
|
74
|
+
keepForks: ReadonlySet<string>;
|
|
75
|
+
/** PR facts for the user's own branches, keyed by `branchKey`. */
|
|
76
|
+
branchPRs: ReadonlyMap<string, BranchPRs>;
|
|
77
|
+
}
|
|
78
|
+
export interface OwnBranch {
|
|
79
|
+
name: string;
|
|
80
|
+
prStates: string[];
|
|
81
|
+
}
|
|
82
|
+
export interface ForkVerdict {
|
|
83
|
+
repo: string;
|
|
84
|
+
parent: string | null;
|
|
85
|
+
verdict: 'PRUNE' | 'KEEP';
|
|
86
|
+
branchCount: number;
|
|
87
|
+
openPRsToFork: number;
|
|
88
|
+
hasOpenPRFromFork: boolean;
|
|
89
|
+
/** The branches counted as the user's own work, with their PR states. */
|
|
90
|
+
ownBranches: OwnBranch[];
|
|
91
|
+
/** Why the fork is kept; empty for PRUNE. */
|
|
92
|
+
reasons: string[];
|
|
93
|
+
}
|
|
94
|
+
export declare function branchKey(repo: string, branch: string): string;
|
|
95
|
+
/**
|
|
96
|
+
* The tip is the user's own work: authored or committed under their login,
|
|
97
|
+
* or by an identity with no linked account committed after the fork was
|
|
98
|
+
* created (such a commit cannot be told apart from the user's, so it is kept
|
|
99
|
+
* rather than risked). Login only: there is no verified-email lookup in this
|
|
100
|
+
* code base, so a tip authored and committed under an unlinked email and
|
|
101
|
+
* dated before the fork was created is not recognised.
|
|
102
|
+
*/
|
|
103
|
+
export declare function isOwnTip(branch: ForkBranch, fork: ForkFacts, login: string): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* The branch's PRs are read: the user's own tips, and any tip committed after
|
|
106
|
+
* the fork was created (someone else's PR merged into the fork in the web UI
|
|
107
|
+
* leaves a tip authored by them and committed by `web-flow`). Tips older than
|
|
108
|
+
* the fork are inherited and need no lookup.
|
|
109
|
+
*/
|
|
110
|
+
export declare function isPRLookupNeeded(branch: ForkBranch, fork: ForkFacts, login: string): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* The work on an own branch is done: a merged or closed PR into another
|
|
113
|
+
* repository had exactly this tip as head, or the tip commit itself was
|
|
114
|
+
* merged into another repository. Anything unknown counts as not done.
|
|
115
|
+
*/
|
|
116
|
+
export declare function isBranchDone(branch: ForkBranch, fork: ForkFacts, prs: BranchPRs | undefined): boolean;
|
|
117
|
+
/** The keep reason of a fork whose branches have not been checked for open PRs by other accounts yet. */
|
|
118
|
+
export declare const UNCHECKED_OPEN_PRS = "its branches were not checked for open PRs";
|
|
119
|
+
/** The verdict for one fork under the five keep conditions. Pure. */
|
|
120
|
+
export declare function evaluateFork(fork: ForkFacts, ctx: PruneContext): ForkVerdict;
|
|
121
|
+
type GraphQL = Octokit['graphql'];
|
|
122
|
+
/** Counts the GraphQL requests one scan makes. */
|
|
123
|
+
export declare class CountingGraphQL {
|
|
124
|
+
private readonly graphql;
|
|
125
|
+
requests: number;
|
|
126
|
+
constructor(graphql: GraphQL);
|
|
127
|
+
query<T>(query: string, variables?: Record<string, unknown>): Promise<T>;
|
|
128
|
+
}
|
|
129
|
+
/** The viewer's login and every fork they own, with all branches. */
|
|
130
|
+
export declare function fetchForks(gql: CountingGraphQL): Promise<{
|
|
131
|
+
login: string;
|
|
132
|
+
forks: ForkFacts[];
|
|
133
|
+
}>;
|
|
134
|
+
/** One repository read fresh, or null when it no longer exists. */
|
|
135
|
+
export declare function fetchFork(gql: CountingGraphQL, repo: string): Promise<ForkFacts | null>;
|
|
136
|
+
/** Lowercase head repositories of the viewer's open PRs. */
|
|
137
|
+
export declare function fetchOpenPRHeadRepos(gql: CountingGraphQL): Promise<Set<string>>;
|
|
138
|
+
/** PR facts for the branches {@link isPRLookupNeeded} picks, in aliased batches; branch names travel as variables. */
|
|
139
|
+
export declare function fetchBranchPRs(gql: CountingGraphQL, forks: readonly ForkFacts[], login: string): Promise<Map<string, BranchPRs>>;
|
|
140
|
+
/** `fork` with every branch's count of open PRs (any author) read; a branch that could not be read stays null, so the fork is kept. */
|
|
141
|
+
export declare function withOpenPRCounts(gql: CountingGraphQL, fork: ForkFacts): Promise<ForkFacts>;
|
|
142
|
+
/**
|
|
143
|
+
* Verdicts for `forks`. Open PRs by other accounts are read branch by branch
|
|
144
|
+
* only for a fork whose one remaining reason is that they were not read, then
|
|
145
|
+
* it is evaluated again: every branch of every fork that could be pruned is
|
|
146
|
+
* checked, without a lookup per branch of every fork.
|
|
147
|
+
*/
|
|
148
|
+
export declare function evaluateAll(gql: CountingGraphQL, forks: readonly ForkFacts[], ctx: PruneContext): Promise<ForkVerdict[]>;
|
|
149
|
+
export {};
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which of the user's forks can be deleted (#1912).
|
|
3
|
+
*
|
|
4
|
+
* A fork is prunable only when none of five keep conditions holds:
|
|
5
|
+
* 1. an open PR anywhere has it as its head repository: one of the user's
|
|
6
|
+
* open PRs, or an open PR by any account on any of its branches;
|
|
7
|
+
* 2. an open PR targets the fork itself;
|
|
8
|
+
* 3. a branch tip is the user's own commit (authored or committed) and the
|
|
9
|
+
* work is not done: done means a merged or closed PR into another
|
|
10
|
+
* repository whose head was exactly this tip, or the tip commit merged
|
|
11
|
+
* through a PR into another repository (PR state, not Git ancestry:
|
|
12
|
+
* squash merges leave no ancestry). A PR merged inside the fork, a
|
|
13
|
+
* branch pushed to after its PR, or a reused branch name stays kept;
|
|
14
|
+
* 4. local state references it (claimed issues, work claims, prepared
|
|
15
|
+
* overnight branches): matched on the fork or its parent;
|
|
16
|
+
* 5. it, or its parent, is on `config.keepForks`.
|
|
17
|
+
*
|
|
18
|
+
* A fork whose parent is gone, or whose branches could not all be read, is
|
|
19
|
+
* kept too. The dry run and `--apply` share {@link evaluateFork}, so what a
|
|
20
|
+
* dry run lists is what apply would delete. Reads go through paginated GraphQL.
|
|
21
|
+
*/
|
|
22
|
+
export function branchKey(repo, branch) {
|
|
23
|
+
return `${repo.toLowerCase()}#${branch}`;
|
|
24
|
+
}
|
|
25
|
+
function isSameRepo(a, b) {
|
|
26
|
+
return a !== null && a.toLowerCase() === b.toLowerCase();
|
|
27
|
+
}
|
|
28
|
+
function isCommittedAfterFork(branch, fork) {
|
|
29
|
+
return branch.tipCommittedAt !== null && Date.parse(branch.tipCommittedAt) > Date.parse(fork.createdAt);
|
|
30
|
+
}
|
|
31
|
+
/** One identity on the tip is the user's: their login, or no linked account on a commit made after the fork was created. */
|
|
32
|
+
function isOwnIdentity(identityLogin, branch, fork, login) {
|
|
33
|
+
if (identityLogin !== null)
|
|
34
|
+
return identityLogin.toLowerCase() === login.toLowerCase();
|
|
35
|
+
return isCommittedAfterFork(branch, fork);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The tip is the user's own work: authored or committed under their login,
|
|
39
|
+
* or by an identity with no linked account committed after the fork was
|
|
40
|
+
* created (such a commit cannot be told apart from the user's, so it is kept
|
|
41
|
+
* rather than risked). Login only: there is no verified-email lookup in this
|
|
42
|
+
* code base, so a tip authored and committed under an unlinked email and
|
|
43
|
+
* dated before the fork was created is not recognised.
|
|
44
|
+
*/
|
|
45
|
+
export function isOwnTip(branch, fork, login) {
|
|
46
|
+
return (isOwnIdentity(branch.tipAuthorLogin, branch, fork, login) ||
|
|
47
|
+
isOwnIdentity(branch.tipCommitterLogin, branch, fork, login));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The branch's PRs are read: the user's own tips, and any tip committed after
|
|
51
|
+
* the fork was created (someone else's PR merged into the fork in the web UI
|
|
52
|
+
* leaves a tip authored by them and committed by `web-flow`). Tips older than
|
|
53
|
+
* the fork are inherited and need no lookup.
|
|
54
|
+
*/
|
|
55
|
+
export function isPRLookupNeeded(branch, fork, login) {
|
|
56
|
+
return isOwnTip(branch, fork, login) || isCommittedAfterFork(branch, fork);
|
|
57
|
+
}
|
|
58
|
+
/** A PR merged into the fork itself sits on this branch or its tip: work that may exist nowhere else. */
|
|
59
|
+
function isMergedIntoFork(fork, prs) {
|
|
60
|
+
if (prs === undefined)
|
|
61
|
+
return false;
|
|
62
|
+
return [...prs.prs, ...prs.tipPRs].some((pr) => pr.state === 'MERGED' && isSameRepo(pr.baseRepo, fork.repo));
|
|
63
|
+
}
|
|
64
|
+
function isFinished(pr) {
|
|
65
|
+
return pr.state === 'MERGED' || pr.state === 'CLOSED';
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The work on an own branch is done: a merged or closed PR into another
|
|
69
|
+
* repository had exactly this tip as head, or the tip commit itself was
|
|
70
|
+
* merged into another repository. Anything unknown counts as not done.
|
|
71
|
+
*/
|
|
72
|
+
export function isBranchDone(branch, fork, prs) {
|
|
73
|
+
if (prs === undefined)
|
|
74
|
+
return false;
|
|
75
|
+
const isElsewhere = (pr) => pr.baseRepo !== null && !isSameRepo(pr.baseRepo, fork.repo);
|
|
76
|
+
const isAtTip = (pr) => pr.headOid !== null && pr.headOid === branch.tipOid;
|
|
77
|
+
const isSubmittedTip = prs.prs.some((pr) => isFinished(pr) && isElsewhere(pr) && isAtTip(pr));
|
|
78
|
+
return isSubmittedTip || prs.tipPRs.some((pr) => pr.state === 'MERGED' && isElsewhere(pr));
|
|
79
|
+
}
|
|
80
|
+
function isListed(set, fork) {
|
|
81
|
+
return set.has(fork.repo.toLowerCase()) || (fork.parent !== null && set.has(fork.parent.toLowerCase()));
|
|
82
|
+
}
|
|
83
|
+
/** The keep reason of a fork whose branches have not been checked for open PRs by other accounts yet. */
|
|
84
|
+
export const UNCHECKED_OPEN_PRS = 'its branches were not checked for open PRs';
|
|
85
|
+
/** Why the fork itself must stay: not a fork, its parent gone, or a partial branch list. */
|
|
86
|
+
function repoReasons(fork) {
|
|
87
|
+
const reasons = [];
|
|
88
|
+
if (!fork.isFork)
|
|
89
|
+
reasons.push('not a fork');
|
|
90
|
+
if (fork.parent === null)
|
|
91
|
+
reasons.push('its parent repository is gone or hidden');
|
|
92
|
+
if (!fork.hasAllBranches)
|
|
93
|
+
reasons.push('not all of its branches could be read');
|
|
94
|
+
if (fork.branches.some((branch) => branch.openPRs === null))
|
|
95
|
+
reasons.push(UNCHECKED_OPEN_PRS);
|
|
96
|
+
return reasons;
|
|
97
|
+
}
|
|
98
|
+
/** Branches with an open PR (any account), and the user's branches whose work no PR finished. */
|
|
99
|
+
function branchReasons(fork, ownBranches, ctx) {
|
|
100
|
+
const open = fork.branches
|
|
101
|
+
.filter((branch) => branch.openPRs !== null && branch.openPRs > 0)
|
|
102
|
+
.map((branch) => `branch ${branch.name} is the head of an open PR (any account)`);
|
|
103
|
+
const unfinished = ownBranches
|
|
104
|
+
.filter(({ branch, prs }) => !isBranchDone(branch, fork, prs))
|
|
105
|
+
.map(({ branch }) => `branch ${branch.name} holds your commits that no PR finished`);
|
|
106
|
+
// Someone else's tip: kept only when a PR was merged into the fork itself.
|
|
107
|
+
const mergedHere = fork.branches
|
|
108
|
+
.filter((branch) => !isOwnTip(branch, fork, ctx.login))
|
|
109
|
+
.filter((branch) => isMergedIntoFork(fork, ctx.branchPRs.get(branchKey(fork.repo, branch.name))))
|
|
110
|
+
.map((branch) => `branch ${branch.name} holds work merged into this fork`);
|
|
111
|
+
return [...open, ...unfinished, ...mergedHere];
|
|
112
|
+
}
|
|
113
|
+
/** The verdict for one fork under the five keep conditions. Pure. */
|
|
114
|
+
export function evaluateFork(fork, ctx) {
|
|
115
|
+
const reasons = repoReasons(fork);
|
|
116
|
+
const hasOpenPRFromFork = ctx.openPRHeadRepos.has(fork.repo.toLowerCase());
|
|
117
|
+
if (hasOpenPRFromFork)
|
|
118
|
+
reasons.push('an open PR has this fork as its head');
|
|
119
|
+
if (fork.openPRsToFork > 0)
|
|
120
|
+
reasons.push(`${fork.openPRsToFork} open PR(s) target this fork`);
|
|
121
|
+
const ownBranches = fork.branches
|
|
122
|
+
.filter((branch) => isOwnTip(branch, fork, ctx.login))
|
|
123
|
+
.map((branch) => ({ branch, prs: ctx.branchPRs.get(branchKey(fork.repo, branch.name)) }));
|
|
124
|
+
reasons.push(...branchReasons(fork, ownBranches, ctx));
|
|
125
|
+
if (isListed(ctx.referencedRepos, fork))
|
|
126
|
+
reasons.push('local state refers to it (claimed issue, work claim or prepared branch)');
|
|
127
|
+
if (isListed(ctx.keepForks, fork))
|
|
128
|
+
reasons.push('on keepForks');
|
|
129
|
+
return {
|
|
130
|
+
repo: fork.repo,
|
|
131
|
+
parent: fork.parent,
|
|
132
|
+
verdict: reasons.length === 0 ? 'PRUNE' : 'KEEP',
|
|
133
|
+
branchCount: fork.branchCount,
|
|
134
|
+
openPRsToFork: fork.openPRsToFork,
|
|
135
|
+
ownBranches: ownBranches.map(({ branch, prs }) => ({
|
|
136
|
+
name: branch.name,
|
|
137
|
+
prStates: (prs?.prs ?? []).map((pr) => pr.state),
|
|
138
|
+
})),
|
|
139
|
+
hasOpenPRFromFork,
|
|
140
|
+
reasons,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/** Forks per page: each carries its first 100 branches, so a page stays well inside GitHub's node limits. */
|
|
144
|
+
const FORKS_PER_PAGE = 25;
|
|
145
|
+
const REFS_PER_PAGE = 100;
|
|
146
|
+
/** Own branches looked up per aliased PR query. */
|
|
147
|
+
const BRANCHES_PER_QUERY = 20;
|
|
148
|
+
const REF_FIELDS = `name target { oid ... on Commit { committedDate author { user { login } } committer { user { login } } } }`;
|
|
149
|
+
/**
|
|
150
|
+
* Branches per open-PR lookup. Each branch's lookup is a search on GitHub's
|
|
151
|
+
* side: 25 forks of 100 branches each in one query exceeded GitHub's resource
|
|
152
|
+
* limits on a real account, so these are read only for forks nothing else
|
|
153
|
+
* keeps, a small page at a time.
|
|
154
|
+
*/
|
|
155
|
+
const OPEN_PR_REFS_PER_PAGE = 25;
|
|
156
|
+
const OPEN_PR_REFS_QUERY = `query($owner: String!, $name: String!, $after: String) { repository(owner: $owner, name: $name) {
|
|
157
|
+
refs(refPrefix: "refs/heads/", first: ${OPEN_PR_REFS_PER_PAGE}, after: $after) {
|
|
158
|
+
pageInfo { hasNextPage endCursor } nodes { name associatedPullRequests(states: OPEN, first: 1) { totalCount } } } } }`;
|
|
159
|
+
const REPO_FIELDS = `nameWithOwner isFork createdAt parent { nameWithOwner }
|
|
160
|
+
pullRequests(states: OPEN) { totalCount }
|
|
161
|
+
refs(refPrefix: "refs/heads/", first: ${REFS_PER_PAGE}) { totalCount pageInfo { hasNextPage endCursor } nodes { ${REF_FIELDS} } }`;
|
|
162
|
+
const FORKS_QUERY = `query($after: String) { viewer { login
|
|
163
|
+
repositories(isFork: true, ownerAffiliations: [OWNER], first: ${FORKS_PER_PAGE}, after: $after) {
|
|
164
|
+
pageInfo { hasNextPage endCursor } nodes { ${REPO_FIELDS} } } } }`;
|
|
165
|
+
const MORE_REFS_QUERY = `query($owner: String!, $name: String!, $after: String) { repository(owner: $owner, name: $name) {
|
|
166
|
+
refs(refPrefix: "refs/heads/", first: ${REFS_PER_PAGE}, after: $after) {
|
|
167
|
+
totalCount pageInfo { hasNextPage endCursor } nodes { ${REF_FIELDS} } } } }`;
|
|
168
|
+
const ONE_FORK_QUERY = `query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { ${REPO_FIELDS} } }`;
|
|
169
|
+
const OPEN_PRS_QUERY = `query($after: String) { viewer { login
|
|
170
|
+
pullRequests(states: OPEN, first: 100, after: $after) {
|
|
171
|
+
pageInfo { hasNextPage endCursor } nodes { headRepository { nameWithOwner } } } } }`;
|
|
172
|
+
/** Counts the GraphQL requests one scan makes. */
|
|
173
|
+
export class CountingGraphQL {
|
|
174
|
+
graphql;
|
|
175
|
+
requests = 0;
|
|
176
|
+
constructor(graphql) {
|
|
177
|
+
this.graphql = graphql;
|
|
178
|
+
}
|
|
179
|
+
async query(query, variables = {}) {
|
|
180
|
+
this.requests += 1;
|
|
181
|
+
return this.graphql(query, variables);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function splitName(repo) {
|
|
185
|
+
const [owner, name] = repo.split('/', 2);
|
|
186
|
+
return { owner, name };
|
|
187
|
+
}
|
|
188
|
+
function toBranch(node) {
|
|
189
|
+
return {
|
|
190
|
+
name: node.name,
|
|
191
|
+
tipOid: node.target?.oid ?? null,
|
|
192
|
+
tipAuthorLogin: node.target?.author?.user?.login ?? null,
|
|
193
|
+
tipCommitterLogin: node.target?.committer?.user?.login ?? null,
|
|
194
|
+
tipCommittedAt: node.target?.committedDate ?? null,
|
|
195
|
+
openPRs: null,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/** Every branch of the fork: the first page from `node`, the rest page by page; `complete` is false when a page could not be read. */
|
|
199
|
+
async function allBranches(gql, node) {
|
|
200
|
+
const branches = node.refs.nodes.map((ref) => toBranch(ref));
|
|
201
|
+
let page = node.refs.pageInfo;
|
|
202
|
+
while (page.hasNextPage) {
|
|
203
|
+
const data = await gql.query(MORE_REFS_QUERY, {
|
|
204
|
+
...splitName(node.nameWithOwner),
|
|
205
|
+
after: page.endCursor,
|
|
206
|
+
});
|
|
207
|
+
if (!data.repository)
|
|
208
|
+
return { branches, complete: false };
|
|
209
|
+
branches.push(...data.repository.refs.nodes.map((ref) => toBranch(ref)));
|
|
210
|
+
page = data.repository.refs.pageInfo;
|
|
211
|
+
}
|
|
212
|
+
return { branches, complete: true };
|
|
213
|
+
}
|
|
214
|
+
async function toFacts(gql, node) {
|
|
215
|
+
const { branches, complete } = await allBranches(gql, node);
|
|
216
|
+
return {
|
|
217
|
+
repo: node.nameWithOwner,
|
|
218
|
+
parent: node.parent?.nameWithOwner ?? null,
|
|
219
|
+
isFork: node.isFork,
|
|
220
|
+
createdAt: node.createdAt,
|
|
221
|
+
openPRsToFork: node.pullRequests.totalCount,
|
|
222
|
+
branchCount: node.refs.totalCount,
|
|
223
|
+
hasAllBranches: complete,
|
|
224
|
+
branches,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/** The viewer's login and every fork they own, with all branches. */
|
|
228
|
+
export async function fetchForks(gql) {
|
|
229
|
+
const forks = [];
|
|
230
|
+
let login;
|
|
231
|
+
let after = null;
|
|
232
|
+
do {
|
|
233
|
+
const data = await gql.query(FORKS_QUERY, { after });
|
|
234
|
+
login = data.viewer.login;
|
|
235
|
+
for (const node of data.viewer.repositories.nodes)
|
|
236
|
+
forks.push(await toFacts(gql, node));
|
|
237
|
+
after = data.viewer.repositories.pageInfo.hasNextPage ? data.viewer.repositories.pageInfo.endCursor : null;
|
|
238
|
+
} while (after !== null);
|
|
239
|
+
return { login: login ?? '', forks };
|
|
240
|
+
}
|
|
241
|
+
/** One repository read fresh, or null when it no longer exists. */
|
|
242
|
+
export async function fetchFork(gql, repo) {
|
|
243
|
+
const data = await gql.query(ONE_FORK_QUERY, splitName(repo));
|
|
244
|
+
return data.repository ? toFacts(gql, data.repository) : null;
|
|
245
|
+
}
|
|
246
|
+
/** Lowercase head repositories of the viewer's open PRs. */
|
|
247
|
+
export async function fetchOpenPRHeadRepos(gql) {
|
|
248
|
+
const heads = new Set();
|
|
249
|
+
let after = null;
|
|
250
|
+
do {
|
|
251
|
+
const data = await gql.query(OPEN_PRS_QUERY, { after });
|
|
252
|
+
for (const pr of data.viewer.pullRequests.nodes) {
|
|
253
|
+
if (pr.headRepository)
|
|
254
|
+
heads.add(pr.headRepository.nameWithOwner.toLowerCase());
|
|
255
|
+
}
|
|
256
|
+
after = data.viewer.pullRequests.pageInfo.hasNextPage ? data.viewer.pullRequests.pageInfo.endCursor : null;
|
|
257
|
+
} while (after !== null);
|
|
258
|
+
return heads;
|
|
259
|
+
}
|
|
260
|
+
function toPRFact(pr) {
|
|
261
|
+
return { state: pr.state, baseRepo: pr.baseRepository?.nameWithOwner ?? null, headOid: pr.headRefOid ?? null };
|
|
262
|
+
}
|
|
263
|
+
/** PR facts for the branches {@link isPRLookupNeeded} picks, in aliased batches; branch names travel as variables. */
|
|
264
|
+
export async function fetchBranchPRs(gql, forks, login) {
|
|
265
|
+
const wanted = forks.flatMap((fork) => fork.branches.filter((branch) => isPRLookupNeeded(branch, fork, login)).map((branch) => ({ fork, branch })));
|
|
266
|
+
const result = new Map();
|
|
267
|
+
for (let start = 0; start < wanted.length; start += BRANCHES_PER_QUERY) {
|
|
268
|
+
const batch = wanted.slice(start, start + BRANCHES_PER_QUERY);
|
|
269
|
+
const variables = {};
|
|
270
|
+
const declarations = [];
|
|
271
|
+
const fields = batch.map(({ fork, branch }, i) => {
|
|
272
|
+
const { owner, name } = splitName(fork.repo);
|
|
273
|
+
Object.assign(variables, { [`o${i}`]: owner, [`n${i}`]: name, [`r${i}`]: `refs/heads/${branch.name}` });
|
|
274
|
+
declarations.push(`$o${i}: String!, $n${i}: String!, $r${i}: String!`);
|
|
275
|
+
return `b${i}: repository(owner: $o${i}, name: $n${i}) { ref(qualifiedName: $r${i}) {
|
|
276
|
+
associatedPullRequests(first: 20) { nodes { state headRefOid baseRepository { nameWithOwner } } }
|
|
277
|
+
target { ... on Commit { associatedPullRequests(first: 5) { nodes { state baseRepository { nameWithOwner } } } } } } }`;
|
|
278
|
+
});
|
|
279
|
+
const data = await gql.query(`query(${declarations.join(', ')}) { ${fields.join('\n')} }`, variables);
|
|
280
|
+
for (const [i, { fork, branch }] of batch.entries()) {
|
|
281
|
+
const ref = data[`b${i}`]?.ref;
|
|
282
|
+
if (!ref)
|
|
283
|
+
continue;
|
|
284
|
+
result.set(branchKey(fork.repo, branch.name), {
|
|
285
|
+
prs: ref.associatedPullRequests.nodes.map((pr) => toPRFact(pr)),
|
|
286
|
+
tipPRs: (ref.target?.associatedPullRequests?.nodes ?? []).map((pr) => toPRFact(pr)),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return result;
|
|
291
|
+
}
|
|
292
|
+
/** `fork` with every branch's count of open PRs (any author) read; a branch that could not be read stays null, so the fork is kept. */
|
|
293
|
+
export async function withOpenPRCounts(gql, fork) {
|
|
294
|
+
const counts = new Map();
|
|
295
|
+
let after = null;
|
|
296
|
+
do {
|
|
297
|
+
const data = await gql.query(OPEN_PR_REFS_QUERY, { ...splitName(fork.repo), after });
|
|
298
|
+
if (!data.repository)
|
|
299
|
+
break;
|
|
300
|
+
for (const ref of data.repository.refs.nodes)
|
|
301
|
+
counts.set(ref.name, ref.associatedPullRequests.totalCount);
|
|
302
|
+
after = data.repository.refs.pageInfo.hasNextPage ? data.repository.refs.pageInfo.endCursor : null;
|
|
303
|
+
} while (after !== null);
|
|
304
|
+
// A branch created since the first listing was never evaluated: leave the whole fork unchecked, so it is kept.
|
|
305
|
+
const known = new Set(fork.branches.map((branch) => branch.name));
|
|
306
|
+
let hasNewBranch = false;
|
|
307
|
+
for (const name of counts.keys())
|
|
308
|
+
hasNewBranch ||= !known.has(name);
|
|
309
|
+
return {
|
|
310
|
+
...fork,
|
|
311
|
+
branches: fork.branches.map((branch) => ({
|
|
312
|
+
...branch,
|
|
313
|
+
openPRs: hasNewBranch ? null : (counts.get(branch.name) ?? null),
|
|
314
|
+
})),
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Verdicts for `forks`. Open PRs by other accounts are read branch by branch
|
|
319
|
+
* only for a fork whose one remaining reason is that they were not read, then
|
|
320
|
+
* it is evaluated again: every branch of every fork that could be pruned is
|
|
321
|
+
* checked, without a lookup per branch of every fork.
|
|
322
|
+
*/
|
|
323
|
+
export async function evaluateAll(gql, forks, ctx) {
|
|
324
|
+
const verdicts = [];
|
|
325
|
+
for (const fork of forks) {
|
|
326
|
+
const first = evaluateFork(fork, ctx);
|
|
327
|
+
const isOnlyUnchecked = first.reasons.length === 1 && first.reasons[0] === UNCHECKED_OPEN_PRS;
|
|
328
|
+
// A fork kept for another reason needs no lookup; the unchecked note would only be noise next to it.
|
|
329
|
+
const kept = { ...first, reasons: first.reasons.filter((reason) => reason !== UNCHECKED_OPEN_PRS) };
|
|
330
|
+
verdicts.push(isOnlyUnchecked ? evaluateFork(await withOpenPRCounts(gql, fork), ctx) : kept);
|
|
331
|
+
}
|
|
332
|
+
return verdicts;
|
|
333
|
+
}
|
|
@@ -20,8 +20,11 @@
|
|
|
20
20
|
* - `bootstrap-degraded`: the manager IS gist-backed, but the bootstrap fell
|
|
21
21
|
* back to the local cache and the store is disarmed (#1443) — reads may be
|
|
22
22
|
* stale and pushes fail.
|
|
23
|
+
* - `unknown-mode`: config names a persistence mode a newer release added
|
|
24
|
+
* (#2005). This release runs it local-only, so writes do not sync until the
|
|
25
|
+
* user upgrades. Rendered by {@link renderUnknownModeWarning}.
|
|
23
26
|
*/
|
|
24
|
-
export type GistHealthDegradedCause = 'configured-but-local' | 'bootstrap-degraded';
|
|
27
|
+
export type GistHealthDegradedCause = 'configured-but-local' | 'bootstrap-degraded' | 'unknown-mode';
|
|
25
28
|
/**
|
|
26
29
|
* Causes {@link renderGistWarning} can name. Superset of
|
|
27
30
|
* {@link GistHealthDegradedCause}: the process-level bootstrap outcomes are
|
|
@@ -35,7 +38,7 @@ export type GistHealthDegradedCause = 'configured-but-local' | 'bootstrap-degrad
|
|
|
35
38
|
* reported `'degraded'` (transient network fallback, or a #1443 degraded
|
|
36
39
|
* bootstrap, which it deliberately conflates at that layer).
|
|
37
40
|
*/
|
|
38
|
-
export type GistWarningCause = GistHealthDegradedCause | 'no-token' | 'state-unreadable' | 'init-fallback';
|
|
41
|
+
export type GistWarningCause = Exclude<GistHealthDegradedCause, 'unknown-mode'> | 'no-token' | 'state-unreadable' | 'init-fallback';
|
|
39
42
|
/**
|
|
40
43
|
* Snapshot of gist persistence health from the one source of truth
|
|
41
44
|
* (`StateManager.getGistHealth()`), shaped per #1444.
|
|
@@ -48,7 +51,11 @@ export interface GistHealth {
|
|
|
48
51
|
* gist-backed with an armed store. Non-null when this process is not
|
|
49
52
|
* reliably syncing to the Gist. */
|
|
50
53
|
degraded: null | {
|
|
51
|
-
cause:
|
|
54
|
+
cause: 'unknown-mode'; /** The mode as stored. */
|
|
55
|
+
mode: string;
|
|
56
|
+
recoverable: false;
|
|
57
|
+
} | {
|
|
58
|
+
cause: Exclude<GistHealthDegradedCause, 'unknown-mode'>;
|
|
52
59
|
/** ISO timestamp when the degradation was first observed, when known
|
|
53
60
|
* (a degraded bootstrap seeds the staleness marker; a
|
|
54
61
|
* configured-but-local manager has no marker to date it by). */
|
|
@@ -79,3 +86,8 @@ export declare function renderGistWarning(cause: GistWarningCause | {
|
|
|
79
86
|
}, opts?: {
|
|
80
87
|
retryHint?: string;
|
|
81
88
|
}): string;
|
|
89
|
+
/**
|
|
90
|
+
* The warning for a persistence mode a newer release wrote (#2005). This
|
|
91
|
+
* release cannot sync through that mode, so it runs local-only.
|
|
92
|
+
*/
|
|
93
|
+
export declare function renderUnknownModeWarning(mode: string): string;
|