@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
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional pacing caps (#1911): at most `maxNewPrsPerDay` new PRs and
|
|
3
|
+
* `maxNewForksPerDay` new forks in any rolling 24 hours. Both are unset by
|
|
4
|
+
* default, and nothing here runs then.
|
|
5
|
+
*
|
|
6
|
+
* Counts come from local state only, never a GitHub search:
|
|
7
|
+
* - PRs: those the tool recorded when it opened them (`recentNewPRs`,
|
|
8
|
+
* written by `work release --pr`), plus the open PRs of the last digest
|
|
9
|
+
* (`createdAt`) and the merged and closed PRs the digest and the outcome
|
|
10
|
+
* ledger record (`openedAt`), once per URL. A PR opened outside the tool
|
|
11
|
+
* counts once a `daily` run has seen it.
|
|
12
|
+
* - Forks: state records no fork creation. A fork is made for the first PR
|
|
13
|
+
* into a repo, so a counted PR that is the earliest known PR in its repo
|
|
14
|
+
* counts as one new fork. This is a soft limit: a fork made without a PR
|
|
15
|
+
* is not seen, and the first PR into a repo forked long ago counts.
|
|
16
|
+
* PRs to the user's own repos never count.
|
|
17
|
+
*/
|
|
18
|
+
import { isOwnRepo, parseGitHubUrl } from './urls.js';
|
|
19
|
+
export const PACING_WINDOW_MS = 24 * 60 * 60 * 1000;
|
|
20
|
+
/** ISO time of an epoch-ms value. */
|
|
21
|
+
export function isoAt(ms) {
|
|
22
|
+
const date = new Date(ms);
|
|
23
|
+
return date.toISOString();
|
|
24
|
+
}
|
|
25
|
+
/** Each recorded PR's URL with its open time, from the digest and the outcome ledger. */
|
|
26
|
+
function recordedPRs(state) {
|
|
27
|
+
const digest = state.lastDigest;
|
|
28
|
+
return [
|
|
29
|
+
...(state.recentNewPRs ?? []).map((pr) => ({ url: pr.url, at: pr.openedAt })),
|
|
30
|
+
...(digest?.openPRs ?? []).map((pr) => ({ url: pr.url, at: pr.createdAt })),
|
|
31
|
+
...(digest?.recentlyMergedPRs ?? []).map((pr) => ({ url: pr.url, at: pr.openedAt })),
|
|
32
|
+
...(digest?.recentlyClosedPRs ?? []).map((pr) => ({ url: pr.url, at: pr.openedAt })),
|
|
33
|
+
...(state.mergedPRs ?? []).map((pr) => ({ url: pr.url, at: pr.openedAt })),
|
|
34
|
+
...(state.closedPRs ?? []).map((pr) => ({ url: pr.url, at: pr.openedAt })),
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
/** Epoch ms of a stamp; null when absent or unparseable. */
|
|
38
|
+
function parseTime(at) {
|
|
39
|
+
const ms = at ? Date.parse(at) : NaN;
|
|
40
|
+
return Number.isNaN(ms) ? null : ms;
|
|
41
|
+
}
|
|
42
|
+
/** Every PR to a repo the user does not own, once each, with when it was opened (null when not recorded). */
|
|
43
|
+
function knownPRs(state, login) {
|
|
44
|
+
const byUrl = new Map();
|
|
45
|
+
for (const { url, at } of recordedPRs(state)) {
|
|
46
|
+
const parsed = parseGitHubUrl(url);
|
|
47
|
+
const key = url.toLowerCase();
|
|
48
|
+
const isOwn = parsed !== null && login !== '' && isOwnRepo(parsed.owner, login);
|
|
49
|
+
// A dated record wins over an undated one for the same PR.
|
|
50
|
+
if (parsed && !isOwn && byUrl.get(key)?.openedAtMs == null) {
|
|
51
|
+
byUrl.set(key, { repo: `${parsed.owner}/${parsed.repo}`.toLowerCase(), openedAtMs: parseTime(at) });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return byUrl;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Open times inside the window ending at `nowMs`; a PR opened exactly 24 hours ago is out.
|
|
58
|
+
* A time in the future (another host's clock runs ahead) counts as now: the PR exists.
|
|
59
|
+
*/
|
|
60
|
+
function inWindow(times, nowMs) {
|
|
61
|
+
const clamped = times.map((t) => Math.min(t, nowMs));
|
|
62
|
+
// eslint-disable-next-line unicorn/no-array-sort -- sorts the fresh array filter() returns; toSorted needs lib es2023, which core does not target
|
|
63
|
+
return clamped.filter((t) => t > nowMs - PACING_WINDOW_MS).sort((a, b) => a - b);
|
|
64
|
+
}
|
|
65
|
+
/** New forks: the earliest known PR of each repo. A PR without an open time is older than any dated one. */
|
|
66
|
+
function forkTimes(prs) {
|
|
67
|
+
const earliest = new Map();
|
|
68
|
+
for (const pr of prs.values()) {
|
|
69
|
+
const seen = earliest.get(pr.repo);
|
|
70
|
+
const isEarlier = seen === undefined || pr.openedAtMs === null || (seen !== null && pr.openedAtMs < seen);
|
|
71
|
+
if (isEarlier)
|
|
72
|
+
earliest.set(pr.repo, pr.openedAtMs);
|
|
73
|
+
}
|
|
74
|
+
const times = [];
|
|
75
|
+
for (const t of earliest.values())
|
|
76
|
+
if (t !== null)
|
|
77
|
+
times.push(t);
|
|
78
|
+
return times;
|
|
79
|
+
}
|
|
80
|
+
function pacingCount(cap, times, nowMs) {
|
|
81
|
+
const counted = inWindow(times, nowMs);
|
|
82
|
+
const count = counted.length;
|
|
83
|
+
// Below the cap again once the (count - cap + 1) oldest have left the window.
|
|
84
|
+
const freesAt = count >= cap ? isoAt(counted[count - cap] + PACING_WINDOW_MS) : null;
|
|
85
|
+
return { atCap: freesAt !== null, cap, count, freesAt };
|
|
86
|
+
}
|
|
87
|
+
/** The pacing caps that are set, with their counts; null when neither is set. */
|
|
88
|
+
export function getPacingStatus(state, nowMs = Date.now()) {
|
|
89
|
+
const { maxNewPrsPerDay = 0, maxNewForksPerDay = 0, githubUsername = '' } = state.config ?? {};
|
|
90
|
+
if (maxNewPrsPerDay <= 0 && maxNewForksPerDay <= 0)
|
|
91
|
+
return null;
|
|
92
|
+
const prs = knownPRs(state, githubUsername);
|
|
93
|
+
const dated = [];
|
|
94
|
+
for (const pr of prs.values())
|
|
95
|
+
if (pr.openedAtMs !== null)
|
|
96
|
+
dated.push(pr.openedAtMs);
|
|
97
|
+
return {
|
|
98
|
+
...(maxNewPrsPerDay > 0 && { prs: pacingCount(maxNewPrsPerDay, dated, nowMs) }),
|
|
99
|
+
...(maxNewForksPerDay > 0 && { forks: pacingCount(maxNewForksPerDay, forkTimes(prs), nowMs) }),
|
|
100
|
+
countedAt: state.lastDigestAt ?? null,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function pacingLine(c, what) {
|
|
104
|
+
const until = c.freesAt ? `, at the cap until ${c.freesAt}` : '';
|
|
105
|
+
return `${c.count}/${c.cap} new ${what} in the last 24h${until}`;
|
|
106
|
+
}
|
|
107
|
+
/** One line per set cap, e.g. `3/5 new PRs in the last 24h`; empty when no cap is set. */
|
|
108
|
+
export function pacingLines(pacing) {
|
|
109
|
+
if (!pacing)
|
|
110
|
+
return [];
|
|
111
|
+
return [
|
|
112
|
+
...(pacing.prs ? [pacingLine(pacing.prs, 'PRs')] : []),
|
|
113
|
+
...(pacing.forks ? [pacingLine(pacing.forks, 'forks')] : []),
|
|
114
|
+
];
|
|
115
|
+
}
|
|
@@ -36,3 +36,58 @@ export declare function paginateAllDetailed<T>(fetchPage: (page: number) => Prom
|
|
|
36
36
|
export declare function paginateAll<T>(fetchPage: (page: number) => Promise<{
|
|
37
37
|
data: T[];
|
|
38
38
|
}>, perPage?: number, maxPages?: number): Promise<T[]>;
|
|
39
|
+
/** The part of a Search API response {@link searchAllPages} reads. */
|
|
40
|
+
export interface SearchPage<T> {
|
|
41
|
+
total_count: number;
|
|
42
|
+
incomplete_results?: boolean;
|
|
43
|
+
items: T[];
|
|
44
|
+
}
|
|
45
|
+
/** Result of {@link searchAllPages}. */
|
|
46
|
+
export interface SearchPagesResult<T> {
|
|
47
|
+
/** The items of every page read, unique by `html_url`, in the order first seen. */
|
|
48
|
+
items: T[];
|
|
49
|
+
/** `total_count` from the last page read; 0 when none was. */
|
|
50
|
+
totalCount: number;
|
|
51
|
+
/** Pages read successfully. */
|
|
52
|
+
pagesRead: number;
|
|
53
|
+
/** GitHub flagged a page `incomplete_results` (the search timed out server-side and returned what it had). */
|
|
54
|
+
incomplete: boolean;
|
|
55
|
+
/** The page after the first whose request failed, with the error; the pages before it were kept. */
|
|
56
|
+
failure?: {
|
|
57
|
+
page: number;
|
|
58
|
+
error: unknown;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* True when `items` is not the whole result: a later page failed, GitHub
|
|
62
|
+
* flagged a page incomplete, or fewer unique items were read than
|
|
63
|
+
* `totalCount` (the page cap, or the list shifted between page requests
|
|
64
|
+
* and an item was skipped). Callers must surface this and must not read
|
|
65
|
+
* "absent from the items" as "does not exist" (#1928).
|
|
66
|
+
*/
|
|
67
|
+
truncated: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Page cap for {@link searchAllPages}. The Search API gets unreliable (500s,
|
|
71
|
+
* ECONNRESET) past page 3 and allows 30 requests a minute, so callers narrow
|
|
72
|
+
* the query rather than raise this.
|
|
73
|
+
*/
|
|
74
|
+
export declare const SEARCH_MAX_PAGES = 3;
|
|
75
|
+
/**
|
|
76
|
+
* Read a Search API query page by page until every result is read or the
|
|
77
|
+
* page cap is reached. The search is sorted by update time, so an item
|
|
78
|
+
* updated between two page requests can come back on the next page too:
|
|
79
|
+
* items are deduplicated by `html_url`.
|
|
80
|
+
*
|
|
81
|
+
* A page after the first that fails ends the search with the items read so
|
|
82
|
+
* far, `failure` set and `truncated` true; the caller reports it.
|
|
83
|
+
*
|
|
84
|
+
* @param fetchPage Function that fetches a single page given a page number
|
|
85
|
+
* @param maxPages Maximum pages to fetch (default {@link SEARCH_MAX_PAGES})
|
|
86
|
+
* @param perPage Items per page (default 100)
|
|
87
|
+
* @throws Any error from page 1, and a rate-limit or auth error from any page, unchanged
|
|
88
|
+
*/
|
|
89
|
+
export declare function searchAllPages<T extends {
|
|
90
|
+
html_url: string;
|
|
91
|
+
}>(fetchPage: (page: number) => Promise<{
|
|
92
|
+
data: SearchPage<T>;
|
|
93
|
+
}>, maxPages?: number, perPage?: number): Promise<SearchPagesResult<T>>;
|
package/dist/core/pagination.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isRateLimitOrAuthError } from './errors.js';
|
|
1
2
|
/** Maximum pages to fetch to prevent runaway pagination */
|
|
2
3
|
const MAX_PAGES = 10;
|
|
3
4
|
/**
|
|
@@ -36,3 +37,61 @@ export async function paginateAll(fetchPage, perPage = 100, maxPages = MAX_PAGES
|
|
|
36
37
|
const { items } = await paginateAllDetailed(fetchPage, perPage, maxPages);
|
|
37
38
|
return items;
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Page cap for {@link searchAllPages}. The Search API gets unreliable (500s,
|
|
42
|
+
* ECONNRESET) past page 3 and allows 30 requests a minute, so callers narrow
|
|
43
|
+
* the query rather than raise this.
|
|
44
|
+
*/
|
|
45
|
+
export const SEARCH_MAX_PAGES = 3;
|
|
46
|
+
/** One page, or the error of a later page the search can go on without. */
|
|
47
|
+
async function readSearchPage(fetchPage, page) {
|
|
48
|
+
try {
|
|
49
|
+
return await fetchPage(page);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (page === 1 || isRateLimitOrAuthError(error))
|
|
53
|
+
throw error;
|
|
54
|
+
return { error };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Read a Search API query page by page until every result is read or the
|
|
59
|
+
* page cap is reached. The search is sorted by update time, so an item
|
|
60
|
+
* updated between two page requests can come back on the next page too:
|
|
61
|
+
* items are deduplicated by `html_url`.
|
|
62
|
+
*
|
|
63
|
+
* A page after the first that fails ends the search with the items read so
|
|
64
|
+
* far, `failure` set and `truncated` true; the caller reports it.
|
|
65
|
+
*
|
|
66
|
+
* @param fetchPage Function that fetches a single page given a page number
|
|
67
|
+
* @param maxPages Maximum pages to fetch (default {@link SEARCH_MAX_PAGES})
|
|
68
|
+
* @param perPage Items per page (default 100)
|
|
69
|
+
* @throws Any error from page 1, and a rate-limit or auth error from any page, unchanged
|
|
70
|
+
*/
|
|
71
|
+
export async function searchAllPages(fetchPage, maxPages = SEARCH_MAX_PAGES, perPage = 100) {
|
|
72
|
+
const seen = new Set();
|
|
73
|
+
const result = { items: [], totalCount: 0, pagesRead: 0, incomplete: false, truncated: false };
|
|
74
|
+
let fetched = 0;
|
|
75
|
+
for (let page = 1, hasMore = true; hasMore && page <= maxPages; page++) {
|
|
76
|
+
const outcome = await readSearchPage(fetchPage, page);
|
|
77
|
+
if ('error' in outcome) {
|
|
78
|
+
result.failure = { page, error: outcome.error };
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
const { data } = outcome;
|
|
82
|
+
result.pagesRead = page;
|
|
83
|
+
result.totalCount = data.total_count;
|
|
84
|
+
if (data.incomplete_results)
|
|
85
|
+
result.incomplete = true;
|
|
86
|
+
for (const item of data.items) {
|
|
87
|
+
if (seen.has(item.html_url))
|
|
88
|
+
continue;
|
|
89
|
+
seen.add(item.html_url);
|
|
90
|
+
result.items.push(item);
|
|
91
|
+
}
|
|
92
|
+
fetched += data.items.length;
|
|
93
|
+
hasMore = data.items.length >= perPage && fetched < result.totalCount;
|
|
94
|
+
}
|
|
95
|
+
result.truncated = result.failure !== undefined || result.incomplete || result.items.length < result.totalCount;
|
|
96
|
+
return result;
|
|
97
|
+
}
|
package/dist/core/paths.d.ts
CHANGED
|
@@ -75,6 +75,13 @@ export declare function getGistIdPath(): string;
|
|
|
75
75
|
* share an id.
|
|
76
76
|
*/
|
|
77
77
|
export declare function getMachineIdPath(): string;
|
|
78
|
+
/**
|
|
79
|
+
* Returns the path to the per-machine settings file (`~/.oss-autopilot/local-config.json`).
|
|
80
|
+
*
|
|
81
|
+
* Holds values that are only valid on this machine (#1950): filesystem paths
|
|
82
|
+
* and the local repo cache. It is local only: the Gist never carries it.
|
|
83
|
+
*/
|
|
84
|
+
export declare function getLocalConfigPath(): string;
|
|
78
85
|
/**
|
|
79
86
|
* Returns the path to the local state cache file (`~/.oss-autopilot/state-cache.json`).
|
|
80
87
|
*
|
package/dist/core/paths.js
CHANGED
|
@@ -128,6 +128,15 @@ export function getGistIdPath() {
|
|
|
128
128
|
export function getMachineIdPath() {
|
|
129
129
|
return path.join(getDataDir(), 'machine-id');
|
|
130
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Returns the path to the per-machine settings file (`~/.oss-autopilot/local-config.json`).
|
|
133
|
+
*
|
|
134
|
+
* Holds values that are only valid on this machine (#1950): filesystem paths
|
|
135
|
+
* and the local repo cache. It is local only: the Gist never carries it.
|
|
136
|
+
*/
|
|
137
|
+
export function getLocalConfigPath() {
|
|
138
|
+
return path.join(getDataDir(), 'local-config.json');
|
|
139
|
+
}
|
|
131
140
|
/**
|
|
132
141
|
* Returns the path to the local state cache file (`~/.oss-autopilot/state-cache.json`).
|
|
133
142
|
*
|
|
@@ -32,6 +32,8 @@ export interface AssemblyReview {
|
|
|
32
32
|
submitted_at?: string | null;
|
|
33
33
|
state?: string | null;
|
|
34
34
|
id?: number;
|
|
35
|
+
/** The head commit the review was submitted against. */
|
|
36
|
+
commit_id?: string | null;
|
|
35
37
|
}
|
|
36
38
|
/**
|
|
37
39
|
* Normalized, transport-agnostic PR signals consumed by {@link assembleFetchedPR}.
|
package/dist/core/pr-assembly.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { daysBetween } from './dates.js';
|
|
13
13
|
import { determineStatus } from './status-determination.js';
|
|
14
|
-
import { determineReviewDecision, getLatestChangesRequestedDate, checkUnrespondedComments, getFirstMaintainerResponseAt, getLastMaintainerActivity, } from './review-analysis.js';
|
|
14
|
+
import { determineReviewDecision, getLatestChangesRequestedDate, getStandingApprovalDate, checkUnrespondedComments, getFirstMaintainerResponseAt, getLastMaintainerActivity, } from './review-analysis.js';
|
|
15
15
|
import { analyzeChecklist } from './checklist-analysis.js';
|
|
16
16
|
import { closingIssueUrl, mentionedIssueUrls } from './github-stats.js';
|
|
17
17
|
import { extractMaintainerActionHints } from './maintainer-analysis.js';
|
|
@@ -36,7 +36,7 @@ export async function assembleFetchedPR(signals, config, commitInfo) {
|
|
|
36
36
|
const reviewDecision = determineReviewDecision(reviews);
|
|
37
37
|
const mergeConflict = signals.hasMergeConflict;
|
|
38
38
|
// Check if there's an unresponded maintainer comment (delegated to review-analysis module)
|
|
39
|
-
const { hasUnrespondedComment, lastMaintainerComment } = checkUnrespondedComments(comments, reviews, reviewComments, config.githubUsername);
|
|
39
|
+
const { hasUnrespondedComment, lastMaintainerComment, unrespondedComments } = checkUnrespondedComments(comments, reviews, reviewComments, config.githubUsername);
|
|
40
40
|
// Earliest maintainer response, computed from the comment/review timeline (#1461).
|
|
41
41
|
const firstMaintainerResponseAt = getFirstMaintainerResponseAt(comments, reviews, config.githubUsername);
|
|
42
42
|
// We need the commit date when hasUnrespondedComment is true (to distinguish
|
|
@@ -88,6 +88,10 @@ export async function assembleFetchedPR(signals, config, commitInfo) {
|
|
|
88
88
|
contributorUsername: config.githubUsername,
|
|
89
89
|
lastMaintainerCommentDate: lastMaintainerComment?.createdAt,
|
|
90
90
|
latestChangesRequestedDate,
|
|
91
|
+
unansweredComments: unrespondedComments.map((c) => ({
|
|
92
|
+
createdAt: c.createdAt,
|
|
93
|
+
authorApprovalDate: getStandingApprovalDate(reviews, c.author),
|
|
94
|
+
})),
|
|
91
95
|
hasActionableCIFailure,
|
|
92
96
|
});
|
|
93
97
|
const pr = {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import type { Octokit } from '@octokit/rest';
|
|
26
26
|
import { CIStatusResult } from './types.js';
|
|
27
|
-
import type
|
|
27
|
+
import { type ActivityEvent, type ReviewComment } from './review-analysis.js';
|
|
28
28
|
import type { AssemblyComment, AssemblyReview, CommitInfo } from './pr-assembly.js';
|
|
29
29
|
/** PRs per aliased GraphQL query. GitHub recommends modest batch sizes; ~10 keeps
|
|
30
30
|
* each query cheap (~1 point) and well under node/complexity limits. */
|
|
@@ -43,6 +43,29 @@ export declare const CI_CONTEXTS_CAP = 100;
|
|
|
43
43
|
* requested per PR. Only the newest non-contributor event matters for the
|
|
44
44
|
* dormancy clock, so overflow is not routed to REST. */
|
|
45
45
|
export declare const TIMELINE_CAP = 50;
|
|
46
|
+
/** Wait before the single re-query of PRs whose mergeability GitHub had not
|
|
47
|
+
* computed yet. The first query starts the computation; it usually lands
|
|
48
|
+
* within a couple of seconds. */
|
|
49
|
+
export declare const MERGEABLE_RETRY_DELAY_MS = 2000;
|
|
50
|
+
/**
|
|
51
|
+
* Fixed fragments of the log lines the open-PR fetch writes to stderr. The log
|
|
52
|
+
* sites and the tests that read stderr (#1941) share them, so rewording a
|
|
53
|
+
* message cannot silently blind a test.
|
|
54
|
+
*/
|
|
55
|
+
export declare const PR_FETCH_LOG: {
|
|
56
|
+
/** Debug timing label, followed by ` <count> PRs`. */
|
|
57
|
+
readonly fetchDetails: "Fetch details for";
|
|
58
|
+
/** Debug suffix of the line logged for each PR enriched through REST. */
|
|
59
|
+
readonly restFallback: "(REST fallback)";
|
|
60
|
+
/** Warning: one batch query failed and its PRs went to REST. */
|
|
61
|
+
readonly batchFailed: "GraphQL batch failed";
|
|
62
|
+
/** Warning: the batch fetch threw (rate limit, auth) and every PR went to REST. */
|
|
63
|
+
readonly enrichmentFailed: "GraphQL batch enrichment failed";
|
|
64
|
+
/** Warning: one node could not be normalized and that PR went to REST. */
|
|
65
|
+
readonly normalizeFailed: "Failed to normalize";
|
|
66
|
+
/** Warning: a resolved PR could not be assembled and is reported as a failure. */
|
|
67
|
+
readonly assembleFailed: "Error assembling";
|
|
68
|
+
};
|
|
46
69
|
/** A single PR to enrich. */
|
|
47
70
|
export interface PRRef {
|
|
48
71
|
owner: string;
|
|
@@ -63,7 +86,8 @@ export interface NormalizedPRData {
|
|
|
63
86
|
body: string;
|
|
64
87
|
createdAt: string;
|
|
65
88
|
updatedAt: string;
|
|
66
|
-
|
|
89
|
+
/** `null` when GitHub reported `UNKNOWN` (mergeability not computed yet). */
|
|
90
|
+
hasMergeConflict: boolean | null;
|
|
67
91
|
headSha: string;
|
|
68
92
|
comments: AssemblyComment[];
|
|
69
93
|
reviews: AssemblyReview[];
|
|
@@ -85,6 +109,7 @@ interface GraphQLActor {
|
|
|
85
109
|
__typename?: string;
|
|
86
110
|
}
|
|
87
111
|
type GraphQLGitActor = {
|
|
112
|
+
email?: string | null;
|
|
88
113
|
user: {
|
|
89
114
|
login: string;
|
|
90
115
|
} | null;
|
|
@@ -108,6 +133,13 @@ interface GraphQLCheckRunNode {
|
|
|
108
133
|
conclusion: string | null;
|
|
109
134
|
status: string | null;
|
|
110
135
|
startedAt: string | null;
|
|
136
|
+
checkSuite?: {
|
|
137
|
+
workflowRun: {
|
|
138
|
+
workflow: {
|
|
139
|
+
databaseId: number | null;
|
|
140
|
+
};
|
|
141
|
+
} | null;
|
|
142
|
+
} | null;
|
|
111
143
|
}
|
|
112
144
|
interface GraphQLStatusContextNode {
|
|
113
145
|
__typename: 'StatusContext';
|
|
@@ -121,9 +153,17 @@ type GraphQLRollupContextNode = GraphQLCheckRunNode | GraphQLStatusContextNode |
|
|
|
121
153
|
interface GraphQLCommitNode {
|
|
122
154
|
oid: string;
|
|
123
155
|
authoredDate: string | null;
|
|
156
|
+
committedDate: string | null;
|
|
124
157
|
author: {
|
|
158
|
+
email?: string | null;
|
|
125
159
|
user: GraphQLActor | null;
|
|
126
160
|
} | null;
|
|
161
|
+
committer: GraphQLGitActor;
|
|
162
|
+
parents?: {
|
|
163
|
+
nodes: Array<{
|
|
164
|
+
oid: string;
|
|
165
|
+
}>;
|
|
166
|
+
};
|
|
127
167
|
status: {
|
|
128
168
|
state: string;
|
|
129
169
|
contexts: Array<{
|
|
@@ -166,6 +206,14 @@ interface GraphQLPullRequestNode {
|
|
|
166
206
|
submittedAt: string | null;
|
|
167
207
|
author: GraphQLActor | null;
|
|
168
208
|
authorAssociation?: string | null;
|
|
209
|
+
commit?: {
|
|
210
|
+
oid: string;
|
|
211
|
+
parents: {
|
|
212
|
+
nodes: Array<{
|
|
213
|
+
oid: string;
|
|
214
|
+
}>;
|
|
215
|
+
};
|
|
216
|
+
} | null;
|
|
169
217
|
}>;
|
|
170
218
|
};
|
|
171
219
|
reviewThreads: {
|
|
@@ -237,8 +285,9 @@ export declare function isGraphqlRateLimited(err: unknown): boolean;
|
|
|
237
285
|
* Enrich a set of PRs via batched GraphQL queries.
|
|
238
286
|
*
|
|
239
287
|
* Returns the PRs that resolved cleanly plus the URLs that must fall back to the
|
|
240
|
-
* REST enrichment path.
|
|
241
|
-
*
|
|
288
|
+
* REST enrichment path. PRs whose mergeability GitHub had not computed yet
|
|
289
|
+
* (`UNKNOWN`) are re-queried once after {@link MERGEABLE_RETRY_DELAY_MS}; one
|
|
290
|
+
* still unknown keeps `hasMergeConflict: null` for the caller to resolve.
|
|
242
291
|
*/
|
|
243
292
|
export declare function batchFetchPRDetails(octokit: Octokit, refs: PRRef[]): Promise<BatchPRResult>;
|
|
244
293
|
export {};
|
package/dist/core/pr-graphql.js
CHANGED
|
@@ -23,8 +23,11 @@
|
|
|
23
23
|
* - A missing / inaccessible / malformed PR node → REST.
|
|
24
24
|
*/
|
|
25
25
|
import { computeCIStatus } from './ci-analysis.js';
|
|
26
|
+
import { getChangesRequestedCommitSha } from './review-analysis.js';
|
|
27
|
+
import { commitDateOf } from './commit-date.js';
|
|
26
28
|
import { isRateLimitOrAuthError, errorMessage } from './errors.js';
|
|
27
29
|
import { warn } from './logger.js';
|
|
30
|
+
import { sleep } from './concurrency.js';
|
|
28
31
|
const MODULE = 'pr-graphql';
|
|
29
32
|
/** PRs per aliased GraphQL query. GitHub recommends modest batch sizes; ~10 keeps
|
|
30
33
|
* each query cheap (~1 point) and well under node/complexity limits. */
|
|
@@ -43,6 +46,29 @@ export const CI_CONTEXTS_CAP = 100;
|
|
|
43
46
|
* requested per PR. Only the newest non-contributor event matters for the
|
|
44
47
|
* dormancy clock, so overflow is not routed to REST. */
|
|
45
48
|
export const TIMELINE_CAP = 50;
|
|
49
|
+
/** Wait before the single re-query of PRs whose mergeability GitHub had not
|
|
50
|
+
* computed yet. The first query starts the computation; it usually lands
|
|
51
|
+
* within a couple of seconds. */
|
|
52
|
+
export const MERGEABLE_RETRY_DELAY_MS = 2000;
|
|
53
|
+
/**
|
|
54
|
+
* Fixed fragments of the log lines the open-PR fetch writes to stderr. The log
|
|
55
|
+
* sites and the tests that read stderr (#1941) share them, so rewording a
|
|
56
|
+
* message cannot silently blind a test.
|
|
57
|
+
*/
|
|
58
|
+
export const PR_FETCH_LOG = {
|
|
59
|
+
/** Debug timing label, followed by ` <count> PRs`. */
|
|
60
|
+
fetchDetails: 'Fetch details for',
|
|
61
|
+
/** Debug suffix of the line logged for each PR enriched through REST. */
|
|
62
|
+
restFallback: '(REST fallback)',
|
|
63
|
+
/** Warning: one batch query failed and its PRs went to REST. */
|
|
64
|
+
batchFailed: 'GraphQL batch failed',
|
|
65
|
+
/** Warning: the batch fetch threw (rate limit, auth) and every PR went to REST. */
|
|
66
|
+
enrichmentFailed: 'GraphQL batch enrichment failed',
|
|
67
|
+
/** Warning: one node could not be normalized and that PR went to REST. */
|
|
68
|
+
normalizeFailed: 'Failed to normalize',
|
|
69
|
+
/** Warning: a resolved PR could not be assembled and is reported as a failure. */
|
|
70
|
+
assembleFailed: 'Error assembling',
|
|
71
|
+
};
|
|
46
72
|
/**
|
|
47
73
|
* GraphQL reports a GitHub App as `__typename: 'Bot'` with a bare login, where
|
|
48
74
|
* REST reports the same account as `login: 'name[bot]'`. Restore the REST spelling
|
|
@@ -92,7 +118,7 @@ const PR_FIELDS = `
|
|
|
92
118
|
}
|
|
93
119
|
reviews(last: ${REVIEWS_CAP}) {
|
|
94
120
|
totalCount
|
|
95
|
-
nodes { databaseId state body submittedAt author { login __typename } authorAssociation }
|
|
121
|
+
nodes { databaseId state body submittedAt author { login __typename } authorAssociation commit { oid parents(first: 1) { nodes { oid } } } }
|
|
96
122
|
}
|
|
97
123
|
reviewThreads(last: ${REVIEW_THREADS_CAP}) {
|
|
98
124
|
totalCount
|
|
@@ -125,14 +151,17 @@ const PR_FIELDS = `
|
|
|
125
151
|
commit {
|
|
126
152
|
oid
|
|
127
153
|
authoredDate
|
|
128
|
-
|
|
154
|
+
committedDate
|
|
155
|
+
author { email user { login } }
|
|
156
|
+
committer { email user { login } }
|
|
157
|
+
parents(first: 1) { nodes { oid } }
|
|
129
158
|
status { state contexts { context state description } }
|
|
130
159
|
statusCheckRollup {
|
|
131
160
|
contexts(first: ${CI_CONTEXTS_CAP}) {
|
|
132
161
|
totalCount
|
|
133
162
|
nodes {
|
|
134
163
|
__typename
|
|
135
|
-
... on CheckRun { name conclusion status startedAt }
|
|
164
|
+
... on CheckRun { name conclusion status startedAt checkSuite { workflowRun { workflow { databaseId } } } }
|
|
136
165
|
... on StatusContext { context state description }
|
|
137
166
|
}
|
|
138
167
|
}
|
|
@@ -160,10 +189,13 @@ export function buildBatchQuery(refs) {
|
|
|
160
189
|
const query = `query batchPRDetails(${varDefs.join(', ')}) {\n${selections.join('\n')}\n}`;
|
|
161
190
|
return { query, variables };
|
|
162
191
|
}
|
|
163
|
-
/** Map GraphQL `mergeable` enum to the REST `mergeConflict`
|
|
192
|
+
/** Map GraphQL `mergeable` enum to the REST `mergeConflict` value. */
|
|
164
193
|
function toMergeConflict(mergeable) {
|
|
165
194
|
// CONFLICTING mirrors REST `mergeable === false` / `mergeable_state === 'dirty'`.
|
|
166
|
-
// UNKNOWN mirrors REST `mergeable === null` (GitHub hasn't computed it yet)
|
|
195
|
+
// UNKNOWN mirrors REST `mergeable === null` (GitHub hasn't computed it yet):
|
|
196
|
+
// neither clean nor conflicted, so it stays `null` for the caller to resolve.
|
|
197
|
+
if (mergeable === 'UNKNOWN')
|
|
198
|
+
return null;
|
|
167
199
|
return mergeable === 'CONFLICTING';
|
|
168
200
|
}
|
|
169
201
|
/** Map a GraphQL commit's rollup + legacy status into the CI result via the shared computer. */
|
|
@@ -177,6 +209,9 @@ function toCIStatus(commit) {
|
|
|
177
209
|
conclusion: n.conclusion ? n.conclusion.toLowerCase() : null,
|
|
178
210
|
status: (n.status ?? '').toLowerCase(),
|
|
179
211
|
started_at: n.startedAt ?? null,
|
|
212
|
+
// `Workflow.databaseId` is the same id as REST `workflow_id`, so both
|
|
213
|
+
// transports dedupe on an identical workflow id + job name key (#1917).
|
|
214
|
+
workflowId: n.checkSuite?.workflowRun?.workflow.databaseId ?? null,
|
|
180
215
|
}));
|
|
181
216
|
// Combined statuses come from the legacy status object (mirrors
|
|
182
217
|
// `repos.getCombinedStatusForRef`). When absent, an empty statuses list is
|
|
@@ -228,6 +263,7 @@ export function normalizePRNode(node) {
|
|
|
228
263
|
submitted_at: r.submittedAt,
|
|
229
264
|
state: r.state,
|
|
230
265
|
id: r.databaseId ?? undefined,
|
|
266
|
+
commit_id: r.commit?.oid ?? null,
|
|
231
267
|
}));
|
|
232
268
|
const reviewComments = node.reviewThreads.nodes.flatMap((thread) => thread.comments.nodes.map((c) => ({
|
|
233
269
|
id: c.databaseId ?? 0,
|
|
@@ -239,8 +275,22 @@ export function normalizePRNode(node) {
|
|
|
239
275
|
pull_request_review_id: c.pullRequestReview?.databaseId ?? null,
|
|
240
276
|
})));
|
|
241
277
|
const commit = node.commits.nodes[0]?.commit;
|
|
278
|
+
// The commit the latest change request was made against and its parent: a
|
|
279
|
+
// head rebased off that parent has not addressed the review (#2042).
|
|
280
|
+
const reviewedSha = getChangesRequestedCommitSha(reviews);
|
|
281
|
+
const reviewedCommit = node.reviews.nodes.find((r) => r.commit?.oid === reviewedSha)?.commit;
|
|
242
282
|
const commitInfo = {
|
|
243
|
-
date:
|
|
283
|
+
date: commitDateOf({
|
|
284
|
+
authorDate: commit?.authoredDate,
|
|
285
|
+
committerDate: commit?.committedDate,
|
|
286
|
+
authorLogin: commit?.author?.user?.login,
|
|
287
|
+
committerLogin: commit?.committer?.user?.login,
|
|
288
|
+
authorEmail: commit?.author?.email,
|
|
289
|
+
committerEmail: commit?.committer?.email,
|
|
290
|
+
parentSha: commit?.parents?.nodes[0]?.oid,
|
|
291
|
+
reviewedParentSha: reviewedCommit?.parents.nodes[0]?.oid,
|
|
292
|
+
reviewedSha,
|
|
293
|
+
}),
|
|
244
294
|
author: commit?.author?.user?.login ?? undefined,
|
|
245
295
|
};
|
|
246
296
|
return {
|
|
@@ -302,7 +352,7 @@ async function runBatch(octokit, refs) {
|
|
|
302
352
|
const partial = err.data;
|
|
303
353
|
if (partial)
|
|
304
354
|
return partial;
|
|
305
|
-
warn(MODULE,
|
|
355
|
+
warn(MODULE, `${PR_FETCH_LOG.batchFailed}, falling back to REST: ${errorMessage(err)}`);
|
|
306
356
|
return null;
|
|
307
357
|
}
|
|
308
358
|
}
|
|
@@ -310,19 +360,42 @@ async function runBatch(octokit, refs) {
|
|
|
310
360
|
* Enrich a set of PRs via batched GraphQL queries.
|
|
311
361
|
*
|
|
312
362
|
* Returns the PRs that resolved cleanly plus the URLs that must fall back to the
|
|
313
|
-
* REST enrichment path.
|
|
314
|
-
*
|
|
363
|
+
* REST enrichment path. PRs whose mergeability GitHub had not computed yet
|
|
364
|
+
* (`UNKNOWN`) are re-queried once after {@link MERGEABLE_RETRY_DELAY_MS}; one
|
|
365
|
+
* still unknown keeps `hasMergeConflict: null` for the caller to resolve.
|
|
315
366
|
*/
|
|
316
367
|
export async function batchFetchPRDetails(octokit, refs) {
|
|
317
|
-
const resolved = new Map();
|
|
318
|
-
const restFallbackUrls = [];
|
|
319
368
|
if (refs.length === 0)
|
|
320
|
-
return { resolved, restFallbackUrls };
|
|
369
|
+
return { resolved: new Map(), restFallbackUrls: [] };
|
|
321
370
|
// No GraphQL client available (e.g. a stubbed Octokit in tests) — everything
|
|
322
371
|
// to REST. Guards against calling a non-function `.graphql`.
|
|
323
372
|
if (typeof octokit.graphql !== 'function') {
|
|
324
|
-
return { resolved, restFallbackUrls: refs.map((r) => r.url) };
|
|
373
|
+
return { resolved: new Map(), restFallbackUrls: refs.map((r) => r.url) };
|
|
325
374
|
}
|
|
375
|
+
const result = await fetchBatches(octokit, refs);
|
|
376
|
+
const unknown = refs.filter((r) => result.resolved.get(r.url)?.hasMergeConflict === null);
|
|
377
|
+
if (unknown.length > 0) {
|
|
378
|
+
await sleep(MERGEABLE_RETRY_DELAY_MS);
|
|
379
|
+
try {
|
|
380
|
+
// Only a clean re-resolve replaces the first answer; a PR the retry could
|
|
381
|
+
// not resolve keeps its first-pass data instead of moving to REST.
|
|
382
|
+
const retry = await fetchBatches(octokit, unknown);
|
|
383
|
+
for (const [url, data] of retry.resolved)
|
|
384
|
+
result.resolved.set(url, data);
|
|
385
|
+
}
|
|
386
|
+
catch (err) {
|
|
387
|
+
// The first pass already succeeded, so a failed re-query (even a rate
|
|
388
|
+
// limit) costs only the mergeability answer, not the whole run.
|
|
389
|
+
warn(MODULE, `Mergeability re-query failed, keeping first-pass data: ${errorMessage(err)}`);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return result;
|
|
393
|
+
}
|
|
394
|
+
/** Run the batches sequentially (GitHub recommends serial requests); with ~3
|
|
395
|
+
* queries for 30 PRs there is no concurrency benefit. */
|
|
396
|
+
async function fetchBatches(octokit, refs) {
|
|
397
|
+
const resolved = new Map();
|
|
398
|
+
const restFallbackUrls = [];
|
|
326
399
|
for (const batch of chunk(refs, BATCH_SIZE)) {
|
|
327
400
|
const data = await runBatch(octokit, batch);
|
|
328
401
|
if (!data) {
|
|
@@ -340,7 +413,7 @@ export async function batchFetchPRDetails(octokit, refs) {
|
|
|
340
413
|
outcome = normalizePRNode(data[`pr${i}`]?.pullRequest);
|
|
341
414
|
}
|
|
342
415
|
catch (err) {
|
|
343
|
-
warn(MODULE,
|
|
416
|
+
warn(MODULE, `${PR_FETCH_LOG.normalizeFailed} ${ref.url}, falling back to REST: ${errorMessage(err)}`);
|
|
344
417
|
outcome = { kind: 'missing' };
|
|
345
418
|
}
|
|
346
419
|
if (outcome.kind === 'ok') {
|