@oss-autopilot/core 3.16.1 → 3.17.1
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.bundle.cjs +150 -92
- package/dist/core/ci-analysis.d.ts +31 -0
- package/dist/core/ci-analysis.js +28 -14
- package/dist/core/github.d.ts +2 -1
- package/dist/core/github.js +11 -2
- package/dist/core/issue-conversation.js +16 -7
- package/dist/core/pr-assembly.d.ts +79 -0
- package/dist/core/pr-assembly.js +114 -0
- package/dist/core/pr-graphql.d.ts +211 -0
- package/dist/core/pr-graphql.js +303 -0
- package/dist/core/pr-monitor.d.ts +18 -4
- package/dist/core/pr-monitor.js +128 -131
- package/dist/core/status-determination.js +12 -0
- package/package.json +3 -2
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batched GraphQL enrichment of open-PR details.
|
|
3
|
+
*
|
|
4
|
+
* The REST enrichment path (`PRMonitor.fetchPRDetails`) makes ~6 REST calls per
|
|
5
|
+
* PR — `pulls.get`, paginated `issues.listComments`, `pulls.listReviews`,
|
|
6
|
+
* paginated `pulls.listReviewComments`, CI status (combined-status + check-runs),
|
|
7
|
+
* and a conditional `repos.getCommit`. For 30 open PRs that is ~180 core-quota
|
|
8
|
+
* REST requests every daily run.
|
|
9
|
+
*
|
|
10
|
+
* `batchFetchPRDetails` collapses that into a handful of aliased GraphQL queries
|
|
11
|
+
* (one per batch of {@link BATCH_SIZE} PRs) drawn from GitHub's SEPARATE GraphQL
|
|
12
|
+
* point bucket (5000 points/hr; a multi-alias PR query costs ~1 point). Each PR's
|
|
13
|
+
* data is mapped back into the same REST-equivalent shapes the shared
|
|
14
|
+
* {@link PRSignals} pipeline consumes, so status determination is unchanged.
|
|
15
|
+
*
|
|
16
|
+
* Fallbacks (all route the affected PR back to the REST path):
|
|
17
|
+
* - GraphQL unavailable (no `.graphql` on the client) → every PR to REST.
|
|
18
|
+
* - A batch-level GraphQL error: fatal errors (401 / rate limit) rethrow; a
|
|
19
|
+
* partial-data error keeps the aliases that resolved and sends the rest to REST.
|
|
20
|
+
* - A PR that hit a `last:`/`first:` connection cap (comments > 100, reviews > 50,
|
|
21
|
+
* review threads > 50, or any thread's comments > 20) → REST, so pagination is
|
|
22
|
+
* complete and unresponded-comment detection stays correct.
|
|
23
|
+
* - A missing / inaccessible / malformed PR node → REST.
|
|
24
|
+
*/
|
|
25
|
+
import { computeCIStatus } from './ci-analysis.js';
|
|
26
|
+
import { isRateLimitOrAuthError, errorMessage } from './errors.js';
|
|
27
|
+
import { warn } from './logger.js';
|
|
28
|
+
const MODULE = 'pr-graphql';
|
|
29
|
+
/** PRs per aliased GraphQL query. GitHub recommends modest batch sizes; ~10 keeps
|
|
30
|
+
* each query cheap (~1 point) and well under node/complexity limits. */
|
|
31
|
+
export const BATCH_SIZE = 10;
|
|
32
|
+
/** Connection page caps requested per PR. A PR exceeding any of these is sent to
|
|
33
|
+
* the REST path (which paginates fully) rather than silently truncated. */
|
|
34
|
+
export const COMMENTS_CAP = 100;
|
|
35
|
+
export const REVIEWS_CAP = 50;
|
|
36
|
+
export const REVIEW_THREADS_CAP = 50;
|
|
37
|
+
export const THREAD_COMMENTS_CAP = 20;
|
|
38
|
+
/** Status-check rollup contexts requested per commit. A PR with more distinct CI
|
|
39
|
+
* contexts than this is sent to REST so a failing check beyond the cap can't be
|
|
40
|
+
* silently dropped and mislabel the PR as passing. */
|
|
41
|
+
export const CI_CONTEXTS_CAP = 100;
|
|
42
|
+
const PR_FIELDS = `
|
|
43
|
+
databaseId
|
|
44
|
+
number
|
|
45
|
+
title
|
|
46
|
+
url
|
|
47
|
+
mergeable
|
|
48
|
+
body
|
|
49
|
+
createdAt
|
|
50
|
+
updatedAt
|
|
51
|
+
comments(last: ${COMMENTS_CAP}) {
|
|
52
|
+
totalCount
|
|
53
|
+
nodes { author { login } body createdAt }
|
|
54
|
+
}
|
|
55
|
+
reviews(last: ${REVIEWS_CAP}) {
|
|
56
|
+
totalCount
|
|
57
|
+
nodes { databaseId state body submittedAt author { login } }
|
|
58
|
+
}
|
|
59
|
+
reviewThreads(last: ${REVIEW_THREADS_CAP}) {
|
|
60
|
+
totalCount
|
|
61
|
+
nodes {
|
|
62
|
+
comments(last: ${THREAD_COMMENTS_CAP}) {
|
|
63
|
+
totalCount
|
|
64
|
+
nodes {
|
|
65
|
+
databaseId
|
|
66
|
+
body
|
|
67
|
+
createdAt
|
|
68
|
+
author { login }
|
|
69
|
+
replyTo { databaseId }
|
|
70
|
+
pullRequestReview { databaseId }
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
commits(last: 1) {
|
|
76
|
+
nodes {
|
|
77
|
+
commit {
|
|
78
|
+
oid
|
|
79
|
+
authoredDate
|
|
80
|
+
author { user { login } }
|
|
81
|
+
status { state contexts { context state description } }
|
|
82
|
+
statusCheckRollup {
|
|
83
|
+
contexts(first: ${CI_CONTEXTS_CAP}) {
|
|
84
|
+
totalCount
|
|
85
|
+
nodes {
|
|
86
|
+
__typename
|
|
87
|
+
... on CheckRun { name conclusion status startedAt }
|
|
88
|
+
... on StatusContext { context state description }
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
`;
|
|
96
|
+
/**
|
|
97
|
+
* Build a parameterized aliased GraphQL query for a batch of PRs. Owner / repo /
|
|
98
|
+
* number are passed as GraphQL variables — never string-interpolated into the
|
|
99
|
+
* query body — so there is no injection surface.
|
|
100
|
+
*/
|
|
101
|
+
export function buildBatchQuery(refs) {
|
|
102
|
+
const varDefs = [];
|
|
103
|
+
const selections = [];
|
|
104
|
+
const variables = {};
|
|
105
|
+
refs.forEach((ref, i) => {
|
|
106
|
+
varDefs.push(`$o${i}: String!, $r${i}: String!, $n${i}: Int!`);
|
|
107
|
+
variables[`o${i}`] = ref.owner;
|
|
108
|
+
variables[`r${i}`] = ref.repo;
|
|
109
|
+
variables[`n${i}`] = ref.number;
|
|
110
|
+
selections.push(`pr${i}: repository(owner: $o${i}, name: $r${i}) {\n pullRequest(number: $n${i}) {${PR_FIELDS}}\n}`);
|
|
111
|
+
});
|
|
112
|
+
const query = `query batchPRDetails(${varDefs.join(', ')}) {\n${selections.join('\n')}\n}`;
|
|
113
|
+
return { query, variables };
|
|
114
|
+
}
|
|
115
|
+
/** Map GraphQL `mergeable` enum to the REST `mergeConflict` boolean. */
|
|
116
|
+
function toMergeConflict(mergeable) {
|
|
117
|
+
// CONFLICTING mirrors REST `mergeable === false` / `mergeable_state === 'dirty'`.
|
|
118
|
+
// UNKNOWN mirrors REST `mergeable === null` (GitHub hasn't computed it yet) → not a conflict.
|
|
119
|
+
return mergeable === 'CONFLICTING';
|
|
120
|
+
}
|
|
121
|
+
/** Map a GraphQL commit's rollup + legacy status into the CI result via the shared computer. */
|
|
122
|
+
function toCIStatus(commit) {
|
|
123
|
+
// Check runs come from the rollup (mirrors `checks.listForRef`); only CheckRun
|
|
124
|
+
// nodes are read here so StatusContexts aren't double-counted.
|
|
125
|
+
const checkRuns = (commit?.statusCheckRollup?.contexts.nodes ?? [])
|
|
126
|
+
.filter((n) => n.__typename === 'CheckRun')
|
|
127
|
+
.map((n) => ({
|
|
128
|
+
name: n.name,
|
|
129
|
+
conclusion: n.conclusion ? n.conclusion.toLowerCase() : null,
|
|
130
|
+
status: (n.status ?? '').toLowerCase(),
|
|
131
|
+
started_at: n.startedAt ?? null,
|
|
132
|
+
}));
|
|
133
|
+
// Combined statuses come from the legacy status object (mirrors
|
|
134
|
+
// `repos.getCombinedStatusForRef`). When absent, an empty statuses list is
|
|
135
|
+
// equivalent to the REST empty-combined-status response (the `state` field is
|
|
136
|
+
// ignored by `analyzeCombinedStatus` when there are no statuses).
|
|
137
|
+
const combinedStatus = commit?.status
|
|
138
|
+
? {
|
|
139
|
+
state: commit.status.state.toLowerCase(),
|
|
140
|
+
statuses: commit.status.contexts.map((c) => ({
|
|
141
|
+
state: c.state.toLowerCase(),
|
|
142
|
+
context: c.context,
|
|
143
|
+
description: c.description ?? null,
|
|
144
|
+
})),
|
|
145
|
+
}
|
|
146
|
+
: { state: 'success', statuses: [] };
|
|
147
|
+
return computeCIStatus(checkRuns, combinedStatus);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Normalize a single GraphQL pull-request node into {@link NormalizedPRData},
|
|
151
|
+
* or signal that it must fall back to REST (`overflow` — a connection cap was
|
|
152
|
+
* hit; `missing` — the node was absent, inaccessible, or lacked a database id).
|
|
153
|
+
*/
|
|
154
|
+
export function normalizePRNode(node) {
|
|
155
|
+
if (!node || node.databaseId == null)
|
|
156
|
+
return { kind: 'missing' };
|
|
157
|
+
// Any connection that hit its cap means data is incomplete — REST paginates fully.
|
|
158
|
+
const rollupTotal = node.commits.nodes[0]?.commit?.statusCheckRollup?.contexts.totalCount ?? 0;
|
|
159
|
+
if (node.comments.totalCount > COMMENTS_CAP ||
|
|
160
|
+
node.reviews.totalCount > REVIEWS_CAP ||
|
|
161
|
+
node.reviewThreads.totalCount > REVIEW_THREADS_CAP ||
|
|
162
|
+
node.reviewThreads.nodes.some((t) => t.comments.totalCount > THREAD_COMMENTS_CAP) ||
|
|
163
|
+
rollupTotal > CI_CONTEXTS_CAP) {
|
|
164
|
+
return { kind: 'overflow' };
|
|
165
|
+
}
|
|
166
|
+
const comments = node.comments.nodes.map((c) => ({
|
|
167
|
+
user: c.author ? { login: c.author.login } : null,
|
|
168
|
+
body: c.body,
|
|
169
|
+
created_at: c.createdAt,
|
|
170
|
+
}));
|
|
171
|
+
// Drop PENDING reviews: REST `listReviews` only returns submitted reviews, and
|
|
172
|
+
// a PENDING (draft) review has no `submittedAt`. Filtering keeps parity.
|
|
173
|
+
const reviews = node.reviews.nodes
|
|
174
|
+
.filter((r) => r.state !== 'PENDING')
|
|
175
|
+
.map((r) => ({
|
|
176
|
+
user: r.author ? { login: r.author.login } : null,
|
|
177
|
+
body: r.body,
|
|
178
|
+
submitted_at: r.submittedAt,
|
|
179
|
+
state: r.state,
|
|
180
|
+
id: r.databaseId ?? undefined,
|
|
181
|
+
}));
|
|
182
|
+
const reviewComments = node.reviewThreads.nodes.flatMap((thread) => thread.comments.nodes.map((c) => ({
|
|
183
|
+
id: c.databaseId ?? 0,
|
|
184
|
+
user: c.author ? { login: c.author.login } : null,
|
|
185
|
+
body: c.body,
|
|
186
|
+
created_at: c.createdAt,
|
|
187
|
+
in_reply_to_id: c.replyTo?.databaseId ?? undefined,
|
|
188
|
+
pull_request_review_id: c.pullRequestReview?.databaseId ?? null,
|
|
189
|
+
})));
|
|
190
|
+
const commit = node.commits.nodes[0]?.commit;
|
|
191
|
+
const commitInfo = {
|
|
192
|
+
date: commit?.authoredDate ?? undefined,
|
|
193
|
+
author: commit?.author?.user?.login ?? undefined,
|
|
194
|
+
};
|
|
195
|
+
return {
|
|
196
|
+
kind: 'ok',
|
|
197
|
+
data: {
|
|
198
|
+
id: node.databaseId,
|
|
199
|
+
title: node.title,
|
|
200
|
+
body: node.body ?? '',
|
|
201
|
+
createdAt: node.createdAt,
|
|
202
|
+
updatedAt: node.updatedAt,
|
|
203
|
+
hasMergeConflict: toMergeConflict(node.mergeable),
|
|
204
|
+
headSha: commit?.oid ?? '',
|
|
205
|
+
comments,
|
|
206
|
+
reviews,
|
|
207
|
+
reviewComments,
|
|
208
|
+
ciStatus: toCIStatus(commit),
|
|
209
|
+
commitInfo,
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/** Split an array into fixed-size chunks. */
|
|
214
|
+
function chunk(items, size) {
|
|
215
|
+
const out = [];
|
|
216
|
+
for (let i = 0; i < items.length; i += size)
|
|
217
|
+
out.push(items.slice(i, i + size));
|
|
218
|
+
return out;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Detect GitHub's primary GraphQL rate limit. Unlike a REST 429/403, an
|
|
222
|
+
* exhausted GraphQL point budget arrives as an HTTP 200 with an
|
|
223
|
+
* `errors[].type === 'RATE_LIMITED'` entry and NO numeric `.status`, so the
|
|
224
|
+
* HTTP-status-based {@link isRateLimitOrAuthError} misses it. Treat it as fatal
|
|
225
|
+
* (rethrow) rather than silently absorbing it into the REST fallback.
|
|
226
|
+
*/
|
|
227
|
+
export function isGraphqlRateLimited(err) {
|
|
228
|
+
const errors = err?.errors;
|
|
229
|
+
return Array.isArray(errors) && errors.some((e) => e?.type === 'RATE_LIMITED');
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Run one batch's GraphQL query and return the raw alias→node response. On a
|
|
233
|
+
* partial-data GraphQL error, returns the resolved aliases attached to the
|
|
234
|
+
* error's `.data`. Fatal errors (401 / auth / rate limit — REST-style OR the
|
|
235
|
+
* GraphQL-native `RATE_LIMITED`) rethrow; any other error returns `null` so the
|
|
236
|
+
* whole batch falls back to REST.
|
|
237
|
+
*/
|
|
238
|
+
async function runBatch(octokit, refs) {
|
|
239
|
+
const { query, variables } = buildBatchQuery(refs);
|
|
240
|
+
try {
|
|
241
|
+
return await octokit.graphql(query, variables);
|
|
242
|
+
}
|
|
243
|
+
catch (err) {
|
|
244
|
+
// Fatal signals must propagate BEFORE the partial-data fallback, so a
|
|
245
|
+
// RATE_LIMITED error that arrives alongside partial data isn't swallowed.
|
|
246
|
+
if (isRateLimitOrAuthError(err) || isGraphqlRateLimited(err))
|
|
247
|
+
throw err;
|
|
248
|
+
// octokit's GraphqlResponseError attaches the resolved aliases to `.data`
|
|
249
|
+
// when only some PRs in the batch errored (e.g. one repo went private).
|
|
250
|
+
const partial = err.data;
|
|
251
|
+
if (partial)
|
|
252
|
+
return partial;
|
|
253
|
+
warn(MODULE, `GraphQL batch failed, falling back to REST: ${errorMessage(err)}`);
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Enrich a set of PRs via batched GraphQL queries.
|
|
259
|
+
*
|
|
260
|
+
* Returns the PRs that resolved cleanly plus the URLs that must fall back to the
|
|
261
|
+
* REST enrichment path. Batches run sequentially (GitHub recommends serial
|
|
262
|
+
* requests); with ~3 queries for 30 PRs there is no concurrency benefit.
|
|
263
|
+
*/
|
|
264
|
+
export async function batchFetchPRDetails(octokit, refs) {
|
|
265
|
+
const resolved = new Map();
|
|
266
|
+
const restFallbackUrls = [];
|
|
267
|
+
if (refs.length === 0)
|
|
268
|
+
return { resolved, restFallbackUrls };
|
|
269
|
+
// No GraphQL client available (e.g. a stubbed Octokit in tests) — everything
|
|
270
|
+
// to REST. Guards against calling a non-function `.graphql`.
|
|
271
|
+
if (typeof octokit.graphql !== 'function') {
|
|
272
|
+
return { resolved, restFallbackUrls: refs.map((r) => r.url) };
|
|
273
|
+
}
|
|
274
|
+
for (const batch of chunk(refs, BATCH_SIZE)) {
|
|
275
|
+
const data = await runBatch(octokit, batch);
|
|
276
|
+
if (!data) {
|
|
277
|
+
// Whole-batch failure — every PR in this batch falls back to REST.
|
|
278
|
+
for (const ref of batch)
|
|
279
|
+
restFallbackUrls.push(ref.url);
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
batch.forEach((ref, i) => {
|
|
283
|
+
// A malformed node (unexpected null sub-connection, etc.) routes just this
|
|
284
|
+
// one PR to REST rather than rejecting the whole batch and discarding the
|
|
285
|
+
// siblings that resolved cleanly.
|
|
286
|
+
let outcome;
|
|
287
|
+
try {
|
|
288
|
+
outcome = normalizePRNode(data[`pr${i}`]?.pullRequest);
|
|
289
|
+
}
|
|
290
|
+
catch (err) {
|
|
291
|
+
warn(MODULE, `Failed to normalize ${ref.url}, falling back to REST: ${errorMessage(err)}`);
|
|
292
|
+
outcome = { kind: 'missing' };
|
|
293
|
+
}
|
|
294
|
+
if (outcome.kind === 'ok') {
|
|
295
|
+
resolved.set(ref.url, outcome.data);
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
restFallbackUrls.push(ref.url);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
return { resolved, restFallbackUrls };
|
|
303
|
+
}
|
|
@@ -78,14 +78,28 @@ export declare class PRMonitor {
|
|
|
78
78
|
*/
|
|
79
79
|
fetchUserOpenPRs(): Promise<FetchPRsResult>;
|
|
80
80
|
/**
|
|
81
|
-
* Fetch detailed information for a single PR
|
|
81
|
+
* Fetch detailed information for a single PR via the REST enrichment path.
|
|
82
|
+
*
|
|
83
|
+
* This is the fallback path in the GraphQL-batched architecture (#1539
|
|
84
|
+
* lineage): PRs that the batched GraphQL query couldn't resolve (a connection
|
|
85
|
+
* cap, a missing/inaccessible node, or a GraphQL outage) are enriched here.
|
|
86
|
+
* Both paths funnel through the shared {@link assembleFetchedPR} pipeline, so
|
|
87
|
+
* the computed status is identical regardless of transport.
|
|
82
88
|
*/
|
|
83
89
|
private fetchPRDetails;
|
|
84
90
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
91
|
+
* Fetch the HEAD commit's author date and login via REST `repos.getCommit`.
|
|
92
|
+
* Rate-limit errors propagate (silently swallowing them produces misleading
|
|
93
|
+
* status, e.g. needs_changes when changes were addressed) (#469); other
|
|
94
|
+
* failures degrade to `undefined` so the PR is still returned.
|
|
95
|
+
*/
|
|
96
|
+
private fetchCommitInfo;
|
|
97
|
+
/**
|
|
98
|
+
* Assemble a {@link FetchedPR} from GraphQL-batched {@link NormalizedPRData}.
|
|
99
|
+
* No network calls: the batch already carries the commit info, so the shared
|
|
100
|
+
* pipeline's lazy commit thunk just returns it.
|
|
87
101
|
*/
|
|
88
|
-
private
|
|
102
|
+
private assembleFromNormalized;
|
|
89
103
|
/**
|
|
90
104
|
* Fetch merged PR counts and latest merge dates per repository for the configured user.
|
|
91
105
|
* @param starFilter - Optional filter to exclude low-star repos
|
package/dist/core/pr-monitor.js
CHANGED
|
@@ -14,19 +14,15 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { getOctokit } from './github.js';
|
|
16
16
|
import { getStateManager } from './state.js';
|
|
17
|
-
import { daysBetween } from './dates.js';
|
|
18
17
|
import { parseGitHubUrl, extractOwnerRepo, isOwnRepo } from './urls.js';
|
|
19
18
|
import { DEFAULT_CONCURRENCY, runWorkerPool } from './concurrency.js';
|
|
20
|
-
import { determineStatus } from './status-determination.js';
|
|
21
19
|
import { ConfigurationError, ValidationError, errorMessage, getHttpStatusCode, isInvalidUserSearchError, isRateLimitOrAuthError, } from './errors.js';
|
|
22
20
|
import { paginateAllDetailed } from './pagination.js';
|
|
23
21
|
import { debug, warn, timed } from './logger.js';
|
|
24
22
|
import { getHttpCache, cachedRequest } from './http-cache.js';
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import { extractMaintainerActionHints } from './maintainer-analysis.js';
|
|
29
|
-
import { computeDisplayLabel } from './display-utils.js';
|
|
23
|
+
import { getCIStatus } from './ci-analysis.js';
|
|
24
|
+
import { assembleFetchedPR } from './pr-assembly.js';
|
|
25
|
+
import { batchFetchPRDetails } from './pr-graphql.js';
|
|
30
26
|
import { fetchUserMergedPRCounts as fetchUserMergedPRCountsImpl, fetchUserClosedPRCounts as fetchUserClosedPRCountsImpl, fetchRecentlyClosedPRs as fetchRecentlyClosedPRsImpl, fetchRecentlyMergedPRs as fetchRecentlyMergedPRsImpl, } from './github-stats.js';
|
|
31
27
|
import { isPlaceholderUsername } from './placeholder-usernames.js';
|
|
32
28
|
// Re-export so existing consumers can still import from pr-monitor
|
|
@@ -234,19 +230,63 @@ export class PRMonitor {
|
|
|
234
230
|
return true;
|
|
235
231
|
});
|
|
236
232
|
debug('pr-monitor', `Filtered to ${filteredItems.length} PRs after excluding own repos`);
|
|
237
|
-
//
|
|
238
|
-
|
|
239
|
-
|
|
233
|
+
// Build PR references for the batched GraphQL enrichment. `parseGitHubUrl`
|
|
234
|
+
// is the authoritative parser (the filter above used `extractOwnerRepo`);
|
|
235
|
+
// anything it can't parse as a PR is skipped with a warning.
|
|
236
|
+
const refs = [];
|
|
237
|
+
const refByUrl = new Map();
|
|
238
|
+
for (const item of filteredItems) {
|
|
239
|
+
const parsed = parseGitHubUrl(item.html_url);
|
|
240
|
+
if (!parsed || parsed.type !== 'pull') {
|
|
241
|
+
warn(MODULE, `Skipping PR with unparseable URL: ${item.html_url}`);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
const ref = { owner: parsed.owner, repo: parsed.repo, number: parsed.number, url: item.html_url };
|
|
245
|
+
refs.push(ref);
|
|
246
|
+
refByUrl.set(item.html_url, ref);
|
|
247
|
+
}
|
|
248
|
+
// Enrich PRs. The batched GraphQL path (separate 5000-point/hr bucket) handles
|
|
249
|
+
// the common case in a handful of ~1-point queries; anything it can't resolve
|
|
250
|
+
// (connection cap overflow, missing node, GraphQL outage) falls back to the
|
|
251
|
+
// per-PR REST path via the worker pool.
|
|
252
|
+
await timed('pr-monitor', `Fetch details for ${refs.length} PRs`, async () => {
|
|
253
|
+
let batch;
|
|
254
|
+
try {
|
|
255
|
+
batch = await batchFetchPRDetails(this.octokit, refs);
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
// A fatal batch-level GraphQL error (rate limit / auth). Don't crash the
|
|
259
|
+
// run — route every PR to the REST path, which surfaces per-PR failures
|
|
260
|
+
// exactly as the pre-GraphQL implementation did.
|
|
261
|
+
warn(MODULE, `GraphQL batch enrichment failed (${errorMessage(error)}); falling back to REST for all PRs`);
|
|
262
|
+
batch = { resolved: new Map(), restFallbackUrls: refs.map((r) => r.url) };
|
|
263
|
+
}
|
|
264
|
+
// Assemble GraphQL-resolved PRs (no additional network calls).
|
|
265
|
+
for (const [url, data] of batch.resolved) {
|
|
266
|
+
const ref = refByUrl.get(url);
|
|
267
|
+
if (!ref)
|
|
268
|
+
continue;
|
|
269
|
+
try {
|
|
270
|
+
prs.push(await this.assembleFromNormalized(ref, data));
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
const errMsg = errorMessage(error);
|
|
274
|
+
warn('pr-monitor', `Error assembling ${url}: ${errMsg}`);
|
|
275
|
+
failures.push({ prUrl: url, error: errMsg });
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
// REST fallback for the remainder, using a worker pool for bounded concurrency.
|
|
279
|
+
await runWorkerPool(batch.restFallbackUrls, async (url) => {
|
|
240
280
|
try {
|
|
241
|
-
debug('pr-monitor', `Fetching details for ${
|
|
242
|
-
const pr = await this.fetchPRDetails(
|
|
281
|
+
debug('pr-monitor', `Fetching details for ${url} (REST fallback)`);
|
|
282
|
+
const pr = await this.fetchPRDetails(url, warnings);
|
|
243
283
|
if (pr)
|
|
244
284
|
prs.push(pr);
|
|
245
285
|
}
|
|
246
286
|
catch (error) {
|
|
247
287
|
const errMsg = errorMessage(error);
|
|
248
|
-
warn('pr-monitor', `Error fetching ${
|
|
249
|
-
failures.push({ prUrl:
|
|
288
|
+
warn('pr-monitor', `Error fetching ${url}: ${errMsg}`);
|
|
289
|
+
failures.push({ prUrl: url, error: errMsg });
|
|
250
290
|
}
|
|
251
291
|
}, MAX_CONCURRENT_REQUESTS);
|
|
252
292
|
});
|
|
@@ -259,7 +299,13 @@ export class PRMonitor {
|
|
|
259
299
|
return warnings.length > 0 ? { prs, failures, warnings } : { prs, failures };
|
|
260
300
|
}
|
|
261
301
|
/**
|
|
262
|
-
* Fetch detailed information for a single PR
|
|
302
|
+
* Fetch detailed information for a single PR via the REST enrichment path.
|
|
303
|
+
*
|
|
304
|
+
* This is the fallback path in the GraphQL-batched architecture (#1539
|
|
305
|
+
* lineage): PRs that the batched GraphQL query couldn't resolve (a connection
|
|
306
|
+
* cap, a missing/inaccessible node, or a GraphQL outage) are enriched here.
|
|
307
|
+
* Both paths funnel through the shared {@link assembleFetchedPR} pipeline, so
|
|
308
|
+
* the computed status is identical regardless of transport.
|
|
263
309
|
*/
|
|
264
310
|
async fetchPRDetails(prUrl, warnings) {
|
|
265
311
|
const parsed = parseGitHubUrl(prUrl);
|
|
@@ -314,130 +360,81 @@ export class PRMonitor {
|
|
|
314
360
|
}
|
|
315
361
|
const ghPR = prResponse.data;
|
|
316
362
|
const reviews = reviewsResponse.data;
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
//
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
// outcome ledger can recover it after the PR merges or closes.
|
|
326
|
-
const firstMaintainerResponseAt = getFirstMaintainerResponseAt(comments, reviews, config.githubUsername);
|
|
327
|
-
// Fetch CI status and (conditionally) latest commit date in parallel
|
|
328
|
-
// We need the commit date when hasUnrespondedComment is true (to distinguish
|
|
329
|
-
// "needs_response" from "waiting_on_maintainer") OR when reviewDecision is "changes_requested"
|
|
330
|
-
// (to detect needs_changes: review requested changes but no new commits pushed)
|
|
331
|
-
const ciPromise = getCIStatus(this.octokit, owner, repo, ghPR.head.sha);
|
|
332
|
-
const needCommitDate = hasUnrespondedComment || reviewDecision === 'changes_requested';
|
|
333
|
-
const commitInfoPromise = needCommitDate
|
|
334
|
-
? this.octokit.repos
|
|
335
|
-
.getCommit({ owner, repo, ref: ghPR.head.sha })
|
|
336
|
-
.then((res) => ({
|
|
337
|
-
date: res.data.commit.author?.date,
|
|
338
|
-
// GitHub user login of the commit author (may differ from git author)
|
|
339
|
-
author: res.data.author?.login,
|
|
340
|
-
}))
|
|
341
|
-
.catch((err) => {
|
|
342
|
-
// Rate limit errors must propagate — silently swallowing them produces
|
|
343
|
-
// misleading status (e.g. needs_changes when changes were addressed) (#469).
|
|
344
|
-
const status = getHttpStatusCode(err);
|
|
345
|
-
if (status === 429)
|
|
346
|
-
throw err;
|
|
347
|
-
if (status === 403) {
|
|
348
|
-
const msg = errorMessage(err).toLowerCase();
|
|
349
|
-
if (msg.includes('rate limit') || msg.includes('abuse detection'))
|
|
350
|
-
throw err;
|
|
351
|
-
// Non-rate-limit 403 (DMCA, private repo, SSO) — degrade gracefully
|
|
352
|
-
warn('pr-monitor', `403 fetching commit date for ${owner}/${repo}@${ghPR.head.sha.slice(0, 7)}: ${errorMessage(err)}`);
|
|
353
|
-
return undefined;
|
|
354
|
-
}
|
|
355
|
-
warn('pr-monitor', `Failed to fetch commit date for ${owner}/${repo}@${ghPR.head.sha.slice(0, 7)}: ${errorMessage(err)}`);
|
|
356
|
-
return undefined;
|
|
357
|
-
})
|
|
358
|
-
: Promise.resolve(undefined);
|
|
359
|
-
const [{ status: ciStatus, failingCheckNames, failingCheckConclusions }, commitInfo] = await Promise.all([
|
|
360
|
-
ciPromise,
|
|
361
|
-
commitInfoPromise,
|
|
362
|
-
]);
|
|
363
|
-
const latestCommitDate = commitInfo?.date;
|
|
364
|
-
const latestCommitAuthor = commitInfo?.author;
|
|
365
|
-
// Analyze PR body for incomplete checklists (delegated to checklist-analysis module)
|
|
366
|
-
const { hasIncompleteChecklist, checklistStats } = analyzeChecklist(ghPR.body || '');
|
|
367
|
-
// Extract maintainer action hints from comments (delegated to maintainer-analysis module)
|
|
368
|
-
const maintainerActionHints = extractMaintainerActionHints(lastMaintainerComment?.body, reviewDecision);
|
|
369
|
-
// Calculate days since activity
|
|
370
|
-
const daysSinceActivity = daysBetween(new Date(ghPR.updated_at), new Date());
|
|
371
|
-
// Find the date of the latest changes_requested review (delegated to review-analysis module)
|
|
372
|
-
const latestChangesRequestedDate = getLatestChangesRequestedDate(reviews);
|
|
373
|
-
// Classify failing checks (delegated to ci-analysis module)
|
|
374
|
-
const classifiedChecks = classifyFailingChecks(failingCheckNames, failingCheckConclusions);
|
|
375
|
-
// Aggregate 5-state CI categorization (#1272). Computed once here so
|
|
376
|
-
// agents read pr.ciCategorization rather than re-deriving the truth
|
|
377
|
-
// table in three separate prose forms.
|
|
378
|
-
const ciCategorization = categorizeCIStatus({ ciStatus, failingCheckNames, classifiedChecks });
|
|
379
|
-
// Determine status
|
|
380
|
-
const hasActionableCIFailure = ciStatus === 'failing' && classifiedChecks.some((c) => c.category === 'actionable');
|
|
381
|
-
const { status, actionReason, waitReason, stalenessTier, actionReasons } = determineStatus({
|
|
382
|
-
ciStatus,
|
|
383
|
-
hasMergeConflict: mergeConflict,
|
|
384
|
-
hasUnrespondedComment,
|
|
385
|
-
hasIncompleteChecklist,
|
|
386
|
-
reviewDecision,
|
|
387
|
-
daysSinceActivity,
|
|
388
|
-
dormantThreshold: config.dormantThresholdDays,
|
|
389
|
-
approachingThreshold: config.approachingDormantDays,
|
|
390
|
-
latestCommitDate,
|
|
391
|
-
latestCommitAuthor,
|
|
392
|
-
contributorUsername: config.githubUsername,
|
|
393
|
-
lastMaintainerCommentDate: lastMaintainerComment?.createdAt,
|
|
394
|
-
latestChangesRequestedDate,
|
|
395
|
-
hasActionableCIFailure,
|
|
396
|
-
});
|
|
397
|
-
return this.buildFetchedPR({
|
|
398
|
-
id: ghPR.id,
|
|
399
|
-
url: prUrl,
|
|
400
|
-
repo: `${owner}/${repo}`,
|
|
363
|
+
const ciStatus = await getCIStatus(this.octokit, owner, repo, ghPR.head.sha);
|
|
364
|
+
// The commit date is only consulted (and only fetched) when the PR has an
|
|
365
|
+
// unresponded maintainer comment or a changes-requested review — the shared
|
|
366
|
+
// pipeline decides via `needCommitDate` and invokes this thunk lazily.
|
|
367
|
+
return assembleFetchedPR({
|
|
368
|
+
prUrl,
|
|
369
|
+
owner,
|
|
370
|
+
repo,
|
|
401
371
|
number,
|
|
372
|
+
id: ghPR.id,
|
|
402
373
|
title: ghPR.title,
|
|
403
|
-
|
|
404
|
-
actionReason,
|
|
405
|
-
waitReason,
|
|
406
|
-
stalenessTier,
|
|
407
|
-
actionReasons,
|
|
374
|
+
body: ghPR.body || '',
|
|
408
375
|
createdAt: ghPR.created_at,
|
|
409
376
|
updatedAt: ghPR.updated_at,
|
|
410
|
-
|
|
411
|
-
|
|
377
|
+
hasMergeConflict: hasMergeConflict(ghPR.mergeable, ghPR.mergeable_state),
|
|
378
|
+
comments,
|
|
379
|
+
reviews,
|
|
380
|
+
reviewComments,
|
|
412
381
|
ciStatus,
|
|
413
|
-
|
|
414
|
-
classifiedChecks,
|
|
415
|
-
ciCategorization,
|
|
416
|
-
hasMergeConflict: mergeConflict,
|
|
417
|
-
reviewDecision,
|
|
418
|
-
hasUnrespondedComment,
|
|
419
|
-
lastMaintainerComment,
|
|
420
|
-
latestCommitDate,
|
|
421
|
-
hasIncompleteChecklist,
|
|
422
|
-
checklistStats,
|
|
423
|
-
maintainerActionHints,
|
|
424
|
-
});
|
|
382
|
+
}, config, () => this.fetchCommitInfo(owner, repo, ghPR.head.sha));
|
|
425
383
|
}
|
|
426
384
|
/**
|
|
427
|
-
*
|
|
428
|
-
*
|
|
385
|
+
* Fetch the HEAD commit's author date and login via REST `repos.getCommit`.
|
|
386
|
+
* Rate-limit errors propagate (silently swallowing them produces misleading
|
|
387
|
+
* status, e.g. needs_changes when changes were addressed) (#469); other
|
|
388
|
+
* failures degrade to `undefined` so the PR is still returned.
|
|
429
389
|
*/
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
390
|
+
async fetchCommitInfo(owner, repo, sha) {
|
|
391
|
+
try {
|
|
392
|
+
const res = await this.octokit.repos.getCommit({ owner, repo, ref: sha });
|
|
393
|
+
return {
|
|
394
|
+
date: res.data.commit.author?.date,
|
|
395
|
+
// GitHub user login of the commit author (may differ from git author)
|
|
396
|
+
author: res.data.author?.login,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
catch (err) {
|
|
400
|
+
const status = getHttpStatusCode(err);
|
|
401
|
+
if (status === 429)
|
|
402
|
+
throw err;
|
|
403
|
+
if (status === 403) {
|
|
404
|
+
const msg = errorMessage(err).toLowerCase();
|
|
405
|
+
if (msg.includes('rate limit') || msg.includes('abuse detection'))
|
|
406
|
+
throw err;
|
|
407
|
+
// Non-rate-limit 403 (DMCA, private repo, SSO) — degrade gracefully
|
|
408
|
+
warn('pr-monitor', `403 fetching commit date for ${owner}/${repo}@${sha.slice(0, 7)}: ${errorMessage(err)}`);
|
|
409
|
+
return undefined;
|
|
410
|
+
}
|
|
411
|
+
warn('pr-monitor', `Failed to fetch commit date for ${owner}/${repo}@${sha.slice(0, 7)}: ${errorMessage(err)}`);
|
|
412
|
+
return undefined;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Assemble a {@link FetchedPR} from GraphQL-batched {@link NormalizedPRData}.
|
|
417
|
+
* No network calls: the batch already carries the commit info, so the shared
|
|
418
|
+
* pipeline's lazy commit thunk just returns it.
|
|
419
|
+
*/
|
|
420
|
+
assembleFromNormalized(ref, data) {
|
|
421
|
+
const config = this.stateManager.getState().config;
|
|
422
|
+
return assembleFetchedPR({
|
|
423
|
+
prUrl: ref.url,
|
|
424
|
+
owner: ref.owner,
|
|
425
|
+
repo: ref.repo,
|
|
426
|
+
number: ref.number,
|
|
427
|
+
id: data.id,
|
|
428
|
+
title: data.title,
|
|
429
|
+
body: data.body,
|
|
430
|
+
createdAt: data.createdAt,
|
|
431
|
+
updatedAt: data.updatedAt,
|
|
432
|
+
hasMergeConflict: data.hasMergeConflict,
|
|
433
|
+
comments: data.comments,
|
|
434
|
+
reviews: data.reviews,
|
|
435
|
+
reviewComments: data.reviewComments,
|
|
436
|
+
ciStatus: data.ciStatus,
|
|
437
|
+
}, config, async () => data.commitInfo);
|
|
441
438
|
}
|
|
442
439
|
/**
|
|
443
440
|
* Fetch merged PR counts and latest merge dates per repository for the configured user.
|
|
@@ -113,7 +113,12 @@ function collectAllActionReasons(input) {
|
|
|
113
113
|
const { ciStatus, hasMergeConflict, hasUnrespondedComment, hasIncompleteChecklist, reviewDecision, lastMaintainerCommentDate, latestChangesRequestedDate, hasActionableCIFailure = true, } = input;
|
|
114
114
|
const commitDate = resolveContributorCommitDate(input);
|
|
115
115
|
const reasons = [];
|
|
116
|
+
// An unresponded maintainer comment on an already-approved, passing/unknown
|
|
117
|
+
// PR is an approval/LGTM note, not a request for action — it needs no
|
|
118
|
+
// contributor response and the PR is just awaiting merge (#1507).
|
|
119
|
+
const approvedAndMergeable = reviewDecision === 'approved' && (ciStatus === 'passing' || ciStatus === 'unknown');
|
|
116
120
|
if (hasUnrespondedComment &&
|
|
121
|
+
!approvedAndMergeable &&
|
|
117
122
|
!isCommentAddressedByCommit(commitDate, lastMaintainerCommentDate, latestChangesRequestedDate)) {
|
|
118
123
|
reasons.push('needs_response');
|
|
119
124
|
}
|
|
@@ -167,6 +172,13 @@ function determinePrimaryStatus(input) {
|
|
|
167
172
|
// the contributor can't fix them, so the relevant status is "waiting for re-review" (#502)
|
|
168
173
|
return { status: 'waiting_on_maintainer', waitReason: 'changes_addressed', stalenessTier };
|
|
169
174
|
}
|
|
175
|
+
// An unresponded comment on an already-approved, passing/unknown PR is an
|
|
176
|
+
// approval/LGTM note (e.g. a re-approval dated after the contributor's last
|
|
177
|
+
// commit), not a request for changes. It needs no contributor response, so
|
|
178
|
+
// the PR is waiting to be merged — don't trap it in needs_response (#1507).
|
|
179
|
+
if (reviewDecision === 'approved' && (ciStatus === 'passing' || ciStatus === 'unknown')) {
|
|
180
|
+
return { status: 'waiting_on_maintainer', waitReason: 'pending_merge', stalenessTier };
|
|
181
|
+
}
|
|
170
182
|
return { status: 'needs_addressing', actionReason: 'needs_response', stalenessTier };
|
|
171
183
|
}
|
|
172
184
|
// Review requested changes but no unresponded comment.
|