@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.
@@ -94,6 +94,37 @@ export declare function analyzeCombinedStatus(combinedStatus: {
94
94
  * Priority: failing > pending > passing > unknown.
95
95
  */
96
96
  export declare function mergeStatuses(checkRunAnalysis: CheckRunAnalysis, combinedAnalysis: CombinedStatusAnalysis, checkRunCount: number): CIStatusResult;
97
+ /** Minimal check-run shape consumed by {@link computeCIStatus} — shared by the
98
+ * REST (`checks.listForRef`) and GraphQL (`statusCheckRollup`) enrichment paths. */
99
+ export interface RawCheckRun {
100
+ name: string;
101
+ conclusion: string | null;
102
+ status: string;
103
+ /** ISO timestamp used to pick the most recent run when a name repeats. */
104
+ started_at?: string | null;
105
+ }
106
+ /** Minimal combined-status shape consumed by {@link computeCIStatus} — mirrors
107
+ * `repos.getCombinedStatusForRef` and GraphQL `commit.status`. */
108
+ export interface RawCombinedStatus {
109
+ state: string;
110
+ statuses: Array<{
111
+ state: string;
112
+ context: string;
113
+ description: string | null;
114
+ }>;
115
+ }
116
+ /**
117
+ * Compute a {@link CIStatusResult} from raw check runs and combined-status data.
118
+ *
119
+ * Extracted so the REST path ({@link getCIStatus}) and the batched GraphQL
120
+ * enrichment path (`pr-graphql.ts`) share identical status derivation — the
121
+ * only difference between the two is where the raw check-run / combined-status
122
+ * data comes from, guaranteeing CI-status parity by construction.
123
+ *
124
+ * Deduplicates check runs by name (keeping the most recent run per name), then
125
+ * merges the check-run and combined-status analyses.
126
+ */
127
+ export declare function computeCIStatus(checkRuns: RawCheckRun[], combinedStatus: RawCombinedStatus): CIStatusResult;
97
128
  /**
98
129
  * Get CI status for a commit SHA by querying both the combined status API and check runs API.
99
130
  * Returns the merged status and names of any failing checks for diagnostics.
@@ -279,6 +279,33 @@ export function mergeStatuses(checkRunAnalysis, combinedAnalysis, checkRunCount)
279
279
  }
280
280
  return unknownCIStatus();
281
281
  }
282
+ /**
283
+ * Compute a {@link CIStatusResult} from raw check runs and combined-status data.
284
+ *
285
+ * Extracted so the REST path ({@link getCIStatus}) and the batched GraphQL
286
+ * enrichment path (`pr-graphql.ts`) share identical status derivation — the
287
+ * only difference between the two is where the raw check-run / combined-status
288
+ * data comes from, guaranteeing CI-status parity by construction.
289
+ *
290
+ * Deduplicates check runs by name (keeping the most recent run per name), then
291
+ * merges the check-run and combined-status analyses.
292
+ */
293
+ export function computeCIStatus(checkRuns, combinedStatus) {
294
+ // Deduplicate check runs by name, keeping only the most recent run per unique name.
295
+ // GitHub returns all historical runs (including re-runs), so without deduplication
296
+ // a superseded failure will incorrectly flag the PR as failing even after a re-run passes.
297
+ const latestCheckRunsByName = new Map();
298
+ for (const check of checkRuns) {
299
+ const existing = latestCheckRunsByName.get(check.name);
300
+ if (!existing || new Date(check.started_at ?? 0) > new Date(existing.started_at ?? 0)) {
301
+ latestCheckRunsByName.set(check.name, check);
302
+ }
303
+ }
304
+ const deduped = [...latestCheckRunsByName.values()];
305
+ const checkRunAnalysis = analyzeCheckRuns(deduped);
306
+ const combinedAnalysis = analyzeCombinedStatus(combinedStatus);
307
+ return mergeStatuses(checkRunAnalysis, combinedAnalysis, deduped.length);
308
+ }
282
309
  /**
283
310
  * Get CI status for a commit SHA by querying both the combined status API and check runs API.
284
311
  * Returns the merged status and names of any failing checks for diagnostics.
@@ -312,20 +339,7 @@ export async function getCIStatus(octokit, owner, repo, sha) {
312
339
  ]);
313
340
  const combinedStatus = statusResponse.data;
314
341
  const allCheckRuns = checksResponse?.data?.check_runs || [];
315
- // Deduplicate check runs by name, keeping only the most recent run per unique name.
316
- // GitHub returns all historical runs (including re-runs), so without deduplication
317
- // a superseded failure will incorrectly flag the PR as failing even after a re-run passes.
318
- const latestCheckRunsByName = new Map();
319
- for (const check of allCheckRuns) {
320
- const existing = latestCheckRunsByName.get(check.name);
321
- if (!existing || new Date(check.started_at ?? 0) > new Date(existing.started_at ?? 0)) {
322
- latestCheckRunsByName.set(check.name, check);
323
- }
324
- }
325
- const checkRuns = [...latestCheckRunsByName.values()];
326
- const checkRunAnalysis = analyzeCheckRuns(checkRuns);
327
- const combinedAnalysis = analyzeCombinedStatus(combinedStatus);
328
- return mergeStatuses(checkRunAnalysis, combinedAnalysis, checkRuns.length);
342
+ return computeCIStatus(allCheckRuns, combinedStatus);
329
343
  }
330
344
  catch (error) {
331
345
  const statusCode = getHttpStatusCode(error);
@@ -24,7 +24,8 @@ export declare function getRateLimitCallbacks(): {
24
24
  * Returns a cached instance if the token matches, otherwise creates a new one.
25
25
  *
26
26
  * The client retries on primary rate limits (up to 2 retries) and
27
- * secondary rate limits (up to 3 retries).
27
+ * secondary rate limits (up to 3 retries), and separately retries
28
+ * transient 5xx/network errors (up to 3 retries) via `@octokit/plugin-retry`.
28
29
  *
29
30
  * @param token - GitHub personal access token
30
31
  * @returns Authenticated Octokit instance with rate limit throttling
@@ -3,9 +3,13 @@
3
3
  */
4
4
  import { Octokit } from '@octokit/rest';
5
5
  import { throttling } from '@octokit/plugin-throttling';
6
+ import { retry } from '@octokit/plugin-retry';
6
7
  import { warn } from './logger.js';
7
8
  const MODULE = 'github';
8
- const ThrottledOctokit = Octokit.plugin(throttling);
9
+ // Plugin order matches octokit.js's own composition (retry, then throttling):
10
+ // throttling must be the outermost layer so its Bottleneck-based queueing sees
11
+ // rate-limit errors first, before plugin-retry's own request-level retries.
12
+ const ThrottledOctokit = Octokit.plugin(retry, throttling);
9
13
  let _octokit = null;
10
14
  let _currentToken = null;
11
15
  /** Format a Date as HH:MM:SS for log messages. */
@@ -45,7 +49,8 @@ export function getRateLimitCallbacks() {
45
49
  * Returns a cached instance if the token matches, otherwise creates a new one.
46
50
  *
47
51
  * The client retries on primary rate limits (up to 2 retries) and
48
- * secondary rate limits (up to 3 retries).
52
+ * secondary rate limits (up to 3 retries), and separately retries
53
+ * transient 5xx/network errors (up to 3 retries) via `@octokit/plugin-retry`.
49
54
  *
50
55
  * @param token - GitHub personal access token
51
56
  * @returns Authenticated Octokit instance with rate limit throttling
@@ -66,6 +71,10 @@ export function getOctokit(token) {
66
71
  _octokit = new ThrottledOctokit({
67
72
  auth: token,
68
73
  throttle: callbacks,
74
+ // Mirrors plugin-retry's own default doNotRetry list (keep in sync on
75
+ // upgrade) plus 429, so primary rate limits stay owned by the throttling
76
+ // callbacks above instead of being retried again here with a shorter backoff.
77
+ retry: { doNotRetry: [400, 401, 403, 404, 410, 422, 429, 451] },
69
78
  });
70
79
  _currentToken = token;
71
80
  return _octokit;
@@ -8,6 +8,7 @@
8
8
  import { getOctokit } from './github.js';
9
9
  import { isBotAuthor, isAcknowledgmentComment } from './comment-utils.js';
10
10
  import { paginateAllDetailed } from './pagination.js';
11
+ import { getHttpCache, cachedRequest } from './http-cache.js';
11
12
  import { getStateManager } from './state.js';
12
13
  import { daysBetween } from './dates.js';
13
14
  import { splitRepo, extractOwnerRepo, isOwnRepo } from './urls.js';
@@ -142,13 +143,21 @@ export class IssueConversationMonitor {
142
143
  */
143
144
  async analyzeIssueConversation(item, repoFullName, username) {
144
145
  const { owner, repo } = splitRepo(repoFullName);
145
- const { items: allComments, truncated } = await paginateAllDetailed((page) => this.octokit.issues.listComments({
146
- owner,
147
- repo,
148
- issue_number: item.number,
149
- per_page: 100,
150
- page,
151
- }));
146
+ const cache = getHttpCache();
147
+ // Each page gets its own cache entry (URL includes `page`) so issues with
148
+ // >100 comments still get conditional-request savings on every page, not
149
+ // just the first.
150
+ const { items: allComments, truncated } = await paginateAllDetailed((page) => {
151
+ const url = `/repos/${owner}/${repo}/issues/${item.number}/comments?per_page=100&page=${page}`;
152
+ return cachedRequest(cache, url, (headers) => this.octokit.issues.listComments({
153
+ owner,
154
+ repo,
155
+ issue_number: item.number,
156
+ per_page: 100,
157
+ page,
158
+ headers,
159
+ })).then((data) => ({ data }));
160
+ });
152
161
  if (truncated) {
153
162
  // Comments arrive oldest-first, so hitting the pagination cap drops
154
163
  // the NEWEST responses — conversation status for this issue may be
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Shared PR assembly — turns normalized PR signals into a {@link FetchedPR}.
3
+ *
4
+ * Extracted from `PRMonitor.fetchPRDetails` (#1272 lineage) so the REST
5
+ * enrichment path and the batched GraphQL enrichment path (`pr-graphql.ts`)
6
+ * share ONE status-determination pipeline. Both paths normalize their raw
7
+ * data into {@link PRSignals} and call {@link assembleFetchedPR}, which
8
+ * guarantees the computed {@link FetchedPRStatus} (CI state, review decision,
9
+ * merge conflicts, unresponded maintainer comments) is byte-for-byte identical
10
+ * regardless of the transport used to fetch the data.
11
+ */
12
+ import { FetchedPR, CIStatusResult } from './types.js';
13
+ import { type ReviewComment } from './review-analysis.js';
14
+ /** Issue comment in the shape `checkUnrespondedComments`/`getFirstMaintainerResponseAt` read. */
15
+ export interface AssemblyComment {
16
+ user?: {
17
+ login?: string;
18
+ } | null;
19
+ body?: string | null;
20
+ created_at: string;
21
+ }
22
+ /** Submitted review in the shape the review-analysis helpers read. */
23
+ export interface AssemblyReview {
24
+ user?: {
25
+ login?: string;
26
+ } | null;
27
+ body?: string | null;
28
+ submitted_at?: string | null;
29
+ state?: string | null;
30
+ id?: number;
31
+ }
32
+ /**
33
+ * Normalized, transport-agnostic PR signals consumed by {@link assembleFetchedPR}.
34
+ * Produced by either the REST path (from `pulls.get` + list endpoints + CI
35
+ * analysis) or the GraphQL path (from a batched query mapped back into these
36
+ * REST-equivalent shapes).
37
+ */
38
+ export interface PRSignals {
39
+ prUrl: string;
40
+ owner: string;
41
+ repo: string;
42
+ number: number;
43
+ id: number;
44
+ title: string;
45
+ /** PR body; empty string when absent (matches REST `body || ''`). */
46
+ body: string;
47
+ createdAt: string;
48
+ updatedAt: string;
49
+ /** True when the PR has a merge conflict (REST `mergeable === false || mergeable_state === 'dirty'`). */
50
+ hasMergeConflict: boolean;
51
+ comments: AssemblyComment[];
52
+ reviews: AssemblyReview[];
53
+ reviewComments: ReviewComment[];
54
+ ciStatus: CIStatusResult;
55
+ }
56
+ /** Config subset the assembly needs — the fields `determineStatus` and comment analysis consume. */
57
+ export interface AssemblyConfig {
58
+ githubUsername: string;
59
+ dormantThresholdDays: number;
60
+ approachingDormantDays: number;
61
+ }
62
+ /** HEAD-commit metadata used to decide whether maintainer feedback has been addressed. */
63
+ export interface CommitInfo {
64
+ date?: string;
65
+ /** GitHub login of the HEAD commit author. */
66
+ author?: string;
67
+ }
68
+ /**
69
+ * Assemble a {@link FetchedPR} from normalized signals.
70
+ *
71
+ * `getCommitInfo` is invoked lazily — and only when the status logic actually
72
+ * needs the HEAD commit date (an unresponded maintainer comment or a
73
+ * changes-requested review). The REST path uses this to avoid an extra
74
+ * `repos.getCommit` call; the GraphQL path already has the commit in the batch
75
+ * and simply returns it. Because `determineStatus` consults the commit date
76
+ * only in those same branches, always-providing it (GraphQL) versus
77
+ * lazily-providing it (REST) yields an identical result.
78
+ */
79
+ export declare function assembleFetchedPR(signals: PRSignals, config: AssemblyConfig, getCommitInfo: () => Promise<CommitInfo | undefined>): Promise<FetchedPR>;
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Shared PR assembly — turns normalized PR signals into a {@link FetchedPR}.
3
+ *
4
+ * Extracted from `PRMonitor.fetchPRDetails` (#1272 lineage) so the REST
5
+ * enrichment path and the batched GraphQL enrichment path (`pr-graphql.ts`)
6
+ * share ONE status-determination pipeline. Both paths normalize their raw
7
+ * data into {@link PRSignals} and call {@link assembleFetchedPR}, which
8
+ * guarantees the computed {@link FetchedPRStatus} (CI state, review decision,
9
+ * merge conflicts, unresponded maintainer comments) is byte-for-byte identical
10
+ * regardless of the transport used to fetch the data.
11
+ */
12
+ import { daysBetween } from './dates.js';
13
+ import { determineStatus } from './status-determination.js';
14
+ import { determineReviewDecision, getLatestChangesRequestedDate, checkUnrespondedComments, getFirstMaintainerResponseAt, } from './review-analysis.js';
15
+ import { analyzeChecklist } from './checklist-analysis.js';
16
+ import { extractMaintainerActionHints } from './maintainer-analysis.js';
17
+ import { categorizeCIStatus, classifyFailingChecks } from './ci-analysis.js';
18
+ import { computeDisplayLabel } from './display-utils.js';
19
+ /**
20
+ * Assemble a {@link FetchedPR} from normalized signals.
21
+ *
22
+ * `getCommitInfo` is invoked lazily — and only when the status logic actually
23
+ * needs the HEAD commit date (an unresponded maintainer comment or a
24
+ * changes-requested review). The REST path uses this to avoid an extra
25
+ * `repos.getCommit` call; the GraphQL path already has the commit in the batch
26
+ * and simply returns it. Because `determineStatus` consults the commit date
27
+ * only in those same branches, always-providing it (GraphQL) versus
28
+ * lazily-providing it (REST) yields an identical result.
29
+ */
30
+ export async function assembleFetchedPR(signals, config, getCommitInfo) {
31
+ const { comments, reviews, reviewComments } = signals;
32
+ // Determine review decision (delegated to review-analysis module)
33
+ const reviewDecision = determineReviewDecision(reviews);
34
+ const mergeConflict = signals.hasMergeConflict;
35
+ // Check if there's an unresponded maintainer comment (delegated to review-analysis module)
36
+ const { hasUnrespondedComment, lastMaintainerComment } = checkUnrespondedComments(comments, reviews, reviewComments, config.githubUsername);
37
+ // Earliest maintainer response, computed from the comment/review timeline (#1461).
38
+ const firstMaintainerResponseAt = getFirstMaintainerResponseAt(comments, reviews, config.githubUsername);
39
+ // We need the commit date when hasUnrespondedComment is true (to distinguish
40
+ // "needs_response" from "waiting_on_maintainer") OR when reviewDecision is
41
+ // "changes_requested" (to detect needs_changes: review requested changes but
42
+ // no new commits pushed). Fetched lazily so the REST path skips the call when
43
+ // it isn't needed.
44
+ const needCommitDate = hasUnrespondedComment || reviewDecision === 'changes_requested';
45
+ const commitInfo = needCommitDate ? await getCommitInfo() : undefined;
46
+ const latestCommitDate = commitInfo?.date;
47
+ const latestCommitAuthor = commitInfo?.author;
48
+ // Analyze PR body for incomplete checklists (delegated to checklist-analysis module)
49
+ const { hasIncompleteChecklist, checklistStats } = analyzeChecklist(signals.body || '');
50
+ // Extract maintainer action hints from comments (delegated to maintainer-analysis module)
51
+ const maintainerActionHints = extractMaintainerActionHints(lastMaintainerComment?.body, reviewDecision);
52
+ // Calculate days since activity
53
+ const daysSinceActivity = daysBetween(new Date(signals.updatedAt), new Date());
54
+ // Find the date of the latest changes_requested review (delegated to review-analysis module)
55
+ const latestChangesRequestedDate = getLatestChangesRequestedDate(reviews);
56
+ const { status: ciStatus, failingCheckNames, failingCheckConclusions } = signals.ciStatus;
57
+ // Classify failing checks (delegated to ci-analysis module)
58
+ const classifiedChecks = classifyFailingChecks(failingCheckNames, failingCheckConclusions);
59
+ // Aggregate 5-state CI categorization (#1272).
60
+ const ciCategorization = categorizeCIStatus({ ciStatus, failingCheckNames, classifiedChecks });
61
+ // Determine status
62
+ const hasActionableCIFailure = ciStatus === 'failing' && classifiedChecks.some((c) => c.category === 'actionable');
63
+ const { status, actionReason, waitReason, stalenessTier, actionReasons } = determineStatus({
64
+ ciStatus,
65
+ hasMergeConflict: mergeConflict,
66
+ hasUnrespondedComment,
67
+ hasIncompleteChecklist,
68
+ reviewDecision,
69
+ daysSinceActivity,
70
+ dormantThreshold: config.dormantThresholdDays,
71
+ approachingThreshold: config.approachingDormantDays,
72
+ latestCommitDate,
73
+ latestCommitAuthor,
74
+ contributorUsername: config.githubUsername,
75
+ lastMaintainerCommentDate: lastMaintainerComment?.createdAt,
76
+ latestChangesRequestedDate,
77
+ hasActionableCIFailure,
78
+ });
79
+ const pr = {
80
+ id: signals.id,
81
+ url: signals.prUrl,
82
+ repo: `${signals.owner}/${signals.repo}`,
83
+ number: signals.number,
84
+ title: signals.title,
85
+ status,
86
+ actionReason,
87
+ waitReason,
88
+ stalenessTier,
89
+ actionReasons,
90
+ createdAt: signals.createdAt,
91
+ updatedAt: signals.updatedAt,
92
+ firstMaintainerResponseAt,
93
+ daysSinceActivity,
94
+ ciStatus,
95
+ failingCheckNames,
96
+ classifiedChecks,
97
+ ciCategorization,
98
+ hasMergeConflict: mergeConflict,
99
+ reviewDecision,
100
+ hasUnrespondedComment,
101
+ lastMaintainerComment,
102
+ latestCommitDate,
103
+ hasIncompleteChecklist,
104
+ checklistStats,
105
+ maintainerActionHints,
106
+ displayLabel: '', // computed below
107
+ displayDescription: '', // computed below
108
+ };
109
+ // Compute display labels (#79) — delegated to display-utils module
110
+ const { displayLabel, displayDescription } = computeDisplayLabel(pr);
111
+ pr.displayLabel = displayLabel;
112
+ pr.displayDescription = displayDescription;
113
+ return pr;
114
+ }
@@ -0,0 +1,211 @@
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 type { Octokit } from '@octokit/rest';
26
+ import { CIStatusResult } from './types.js';
27
+ import type { ReviewComment } from './review-analysis.js';
28
+ import type { AssemblyComment, AssemblyReview, CommitInfo } from './pr-assembly.js';
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 declare 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 declare const COMMENTS_CAP = 100;
35
+ export declare const REVIEWS_CAP = 50;
36
+ export declare const REVIEW_THREADS_CAP = 50;
37
+ export declare 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 declare const CI_CONTEXTS_CAP = 100;
42
+ /** A single PR to enrich. */
43
+ export interface PRRef {
44
+ owner: string;
45
+ repo: string;
46
+ number: number;
47
+ /** Original PR URL — used as the map key and to thread back into REST fallback. */
48
+ url: string;
49
+ }
50
+ /**
51
+ * Normalized PR data produced from a GraphQL node, in the REST-equivalent shapes
52
+ * the {@link assembleFetchedPR} pipeline consumes. `commitInfo` is always present
53
+ * (the batch fetches it for free) but is only consulted when the status logic
54
+ * needs it.
55
+ */
56
+ export interface NormalizedPRData {
57
+ id: number;
58
+ title: string;
59
+ body: string;
60
+ createdAt: string;
61
+ updatedAt: string;
62
+ hasMergeConflict: boolean;
63
+ headSha: string;
64
+ comments: AssemblyComment[];
65
+ reviews: AssemblyReview[];
66
+ reviewComments: ReviewComment[];
67
+ ciStatus: CIStatusResult;
68
+ commitInfo: CommitInfo;
69
+ }
70
+ /** Outcome of a batched fetch: PRs resolved via GraphQL, plus the URLs that must
71
+ * fall back to the REST path (overflow, missing, or GraphQL-unavailable). */
72
+ export interface BatchPRResult {
73
+ /** Keyed by {@link PRRef.url}. */
74
+ resolved: Map<string, NormalizedPRData>;
75
+ /** URLs the caller must enrich via the existing REST path. */
76
+ restFallbackUrls: string[];
77
+ }
78
+ interface GraphQLActor {
79
+ login: string;
80
+ }
81
+ interface GraphQLCheckRunNode {
82
+ __typename: 'CheckRun';
83
+ name: string;
84
+ conclusion: string | null;
85
+ status: string | null;
86
+ startedAt: string | null;
87
+ }
88
+ interface GraphQLStatusContextNode {
89
+ __typename: 'StatusContext';
90
+ context: string;
91
+ state: string;
92
+ description: string | null;
93
+ }
94
+ type GraphQLRollupContextNode = GraphQLCheckRunNode | GraphQLStatusContextNode | {
95
+ __typename: string;
96
+ };
97
+ interface GraphQLCommitNode {
98
+ oid: string;
99
+ authoredDate: string | null;
100
+ author: {
101
+ user: GraphQLActor | null;
102
+ } | null;
103
+ status: {
104
+ state: string;
105
+ contexts: Array<{
106
+ context: string;
107
+ state: string;
108
+ description: string | null;
109
+ }>;
110
+ } | null;
111
+ statusCheckRollup: {
112
+ contexts: {
113
+ totalCount: number;
114
+ nodes: GraphQLRollupContextNode[];
115
+ };
116
+ } | null;
117
+ }
118
+ interface GraphQLPullRequestNode {
119
+ databaseId: number | null;
120
+ number: number;
121
+ title: string;
122
+ url: string;
123
+ mergeable: 'MERGEABLE' | 'CONFLICTING' | 'UNKNOWN';
124
+ body: string | null;
125
+ createdAt: string;
126
+ updatedAt: string;
127
+ comments: {
128
+ totalCount: number;
129
+ nodes: Array<{
130
+ author: GraphQLActor | null;
131
+ body: string | null;
132
+ createdAt: string;
133
+ }>;
134
+ };
135
+ reviews: {
136
+ totalCount: number;
137
+ nodes: Array<{
138
+ databaseId: number | null;
139
+ state: string;
140
+ body: string | null;
141
+ submittedAt: string | null;
142
+ author: GraphQLActor | null;
143
+ }>;
144
+ };
145
+ reviewThreads: {
146
+ totalCount: number;
147
+ nodes: Array<{
148
+ comments: {
149
+ totalCount: number;
150
+ nodes: Array<{
151
+ databaseId: number | null;
152
+ body: string | null;
153
+ createdAt: string;
154
+ author: GraphQLActor | null;
155
+ replyTo: {
156
+ databaseId: number | null;
157
+ } | null;
158
+ pullRequestReview: {
159
+ databaseId: number | null;
160
+ } | null;
161
+ }>;
162
+ };
163
+ }>;
164
+ };
165
+ commits: {
166
+ nodes: Array<{
167
+ commit: GraphQLCommitNode;
168
+ }>;
169
+ };
170
+ }
171
+ /**
172
+ * Build a parameterized aliased GraphQL query for a batch of PRs. Owner / repo /
173
+ * number are passed as GraphQL variables — never string-interpolated into the
174
+ * query body — so there is no injection surface.
175
+ */
176
+ export declare function buildBatchQuery(refs: PRRef[]): {
177
+ query: string;
178
+ variables: Record<string, string | number>;
179
+ };
180
+ /** Discriminated outcome of normalizing one PR node. */
181
+ type NormalizeOutcome = {
182
+ kind: 'ok';
183
+ data: NormalizedPRData;
184
+ } | {
185
+ kind: 'overflow';
186
+ } | {
187
+ kind: 'missing';
188
+ };
189
+ /**
190
+ * Normalize a single GraphQL pull-request node into {@link NormalizedPRData},
191
+ * or signal that it must fall back to REST (`overflow` — a connection cap was
192
+ * hit; `missing` — the node was absent, inaccessible, or lacked a database id).
193
+ */
194
+ export declare function normalizePRNode(node: GraphQLPullRequestNode | null | undefined): NormalizeOutcome;
195
+ /**
196
+ * Detect GitHub's primary GraphQL rate limit. Unlike a REST 429/403, an
197
+ * exhausted GraphQL point budget arrives as an HTTP 200 with an
198
+ * `errors[].type === 'RATE_LIMITED'` entry and NO numeric `.status`, so the
199
+ * HTTP-status-based {@link isRateLimitOrAuthError} misses it. Treat it as fatal
200
+ * (rethrow) rather than silently absorbing it into the REST fallback.
201
+ */
202
+ export declare function isGraphqlRateLimited(err: unknown): boolean;
203
+ /**
204
+ * Enrich a set of PRs via batched GraphQL queries.
205
+ *
206
+ * Returns the PRs that resolved cleanly plus the URLs that must fall back to the
207
+ * REST enrichment path. Batches run sequentially (GitHub recommends serial
208
+ * requests); with ~3 queries for 30 PRs there is no concurrency benefit.
209
+ */
210
+ export declare function batchFetchPRDetails(octokit: Octokit, refs: PRRef[]): Promise<BatchPRResult>;
211
+ export {};