@oss-autopilot/core 3.37.0 → 3.39.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-registry.js +7 -4
- package/dist/cli.bundle.cjs +134 -127
- package/dist/commands/comments.js +4 -3
- package/dist/commands/config.js +18 -11
- package/dist/commands/daily-dismiss-filter.d.ts +37 -0
- package/dist/commands/daily-dismiss-filter.js +80 -0
- package/dist/commands/daily-merged-pr-notes.d.ts +27 -0
- package/dist/commands/daily-merged-pr-notes.js +166 -0
- package/dist/commands/daily-reviewed-prs.d.ts +41 -0
- package/dist/commands/daily-reviewed-prs.js +270 -0
- package/dist/commands/daily-warnings.d.ts +28 -0
- package/dist/commands/daily-warnings.js +37 -0
- package/dist/commands/daily.d.ts +22 -1
- package/dist/commands/daily.js +299 -108
- package/dist/commands/dashboard-cache.js +9 -2
- package/dist/commands/dashboard-data.js +40 -20
- package/dist/commands/dashboard-gist-sync.d.ts +9 -1
- package/dist/commands/dashboard-gist-sync.js +24 -3
- package/dist/commands/dashboard-server.js +9 -5
- package/dist/commands/dismiss.d.ts +25 -5
- package/dist/commands/dismiss.js +40 -11
- package/dist/commands/guidelines.js +21 -14
- package/dist/commands/init.js +3 -2
- package/dist/commands/ledger-backfill.js +4 -3
- package/dist/commands/move.js +9 -6
- package/dist/commands/overnight-push-prep.js +5 -2
- package/dist/commands/overnight.js +62 -24
- package/dist/commands/scout-bridge.js +4 -1
- package/dist/commands/search.js +9 -6
- package/dist/commands/setup.js +7 -3
- package/dist/commands/validation.d.ts +11 -0
- package/dist/commands/validation.js +38 -0
- package/dist/core/checklist-analysis.js +34 -0
- package/dist/core/closed-pr-status.d.ts +73 -0
- package/dist/core/closed-pr-status.js +113 -0
- package/dist/core/comment-decision.d.ts +10 -3
- package/dist/core/comment-decision.js +13 -5
- package/dist/core/comment-utils.d.ts +38 -1
- package/dist/core/comment-utils.js +124 -1
- package/dist/core/concurrency.d.ts +6 -0
- package/dist/core/concurrency.js +13 -0
- package/dist/core/daily-logic.d.ts +13 -1
- package/dist/core/daily-logic.js +59 -2
- package/dist/core/engaged-issues.d.ts +93 -0
- package/dist/core/engaged-issues.js +183 -0
- package/dist/core/errors.d.ts +4 -0
- package/dist/core/errors.js +11 -1
- package/dist/core/eval-report.d.ts +9 -0
- package/dist/core/eval-report.js +4 -0
- package/dist/core/gist-state-store.d.ts +5 -2
- package/dist/core/gist-state-store.js +7 -4
- package/dist/core/github-stats.d.ts +10 -0
- package/dist/core/github-stats.js +35 -0
- package/dist/core/index.d.ts +10 -5
- package/dist/core/index.js +9 -4
- package/dist/core/issue-conversation.d.ts +83 -12
- package/dist/core/issue-conversation.js +306 -118
- package/dist/core/merged-pr-notes.d.ts +192 -0
- package/dist/core/merged-pr-notes.js +340 -0
- package/dist/core/pick-snapshot.js +1 -1
- package/dist/core/pr-assembly.js +3 -0
- package/dist/core/pr-monitor.d.ts +62 -0
- package/dist/core/pr-monitor.js +113 -3
- package/dist/core/reviewed-prs-fetch.d.ts +91 -0
- package/dist/core/reviewed-prs-fetch.js +271 -0
- package/dist/core/reviewed-prs.d.ts +244 -0
- package/dist/core/reviewed-prs.js +380 -0
- package/dist/core/state-persistence.js +8 -24
- package/dist/core/state-schema.d.ts +6 -0
- package/dist/core/state-schema.js +9 -0
- package/dist/core/state.d.ts +106 -11
- package/dist/core/state.js +246 -24
- package/dist/core/types.d.ts +47 -0
- package/dist/core/urls.d.ts +13 -0
- package/dist/core/urls.js +16 -0
- package/dist/formatters/json.d.ts +186 -1
- package/dist/formatters/json.js +78 -0
- package/package.json +1 -1
package/dist/core/pr-monitor.js
CHANGED
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
import { getOctokit } from './github.js';
|
|
16
16
|
import { getStateManager } from './state.js';
|
|
17
17
|
import { parseGitHubUrl, extractOwnerRepo, isOwnRepo, isUntrackedOrg } from './urls.js';
|
|
18
|
-
import { DEFAULT_CONCURRENCY, runWorkerPool } from './concurrency.js';
|
|
18
|
+
import { DEFAULT_CONCURRENCY, rethrowRejections, runWorkerPool } from './concurrency.js';
|
|
19
19
|
import { ConfigurationError, ValidationError, errorMessage, getHttpStatusCode, isInvalidUserSearchError, isRateLimitOrAuthError, } from './errors.js';
|
|
20
20
|
import { paginateAllDetailed } from './pagination.js';
|
|
21
21
|
import { debug, warn, timed } from './logger.js';
|
|
22
22
|
import { getHttpCache, cachedRequest } from './http-cache.js';
|
|
23
23
|
import { getCIStatus } from './ci-analysis.js';
|
|
24
|
+
import { fetchCompareStatus as fetchCompareStatusImpl, fetchReviewedOpenPRs as fetchReviewedOpenPRsImpl, fetchReviewedPRActivity as fetchReviewedPRActivityImpl, } from './reviewed-prs-fetch.js';
|
|
24
25
|
import { assembleFetchedPR } from './pr-assembly.js';
|
|
25
26
|
import { batchFetchPRDetails } from './pr-graphql.js';
|
|
26
27
|
import { fetchUserMergedPRCounts as fetchUserMergedPRCountsImpl, fetchUserClosedPRCounts as fetchUserClosedPRCountsImpl, fetchRecentlyClosedPRs as fetchRecentlyClosedPRsImpl, fetchRecentlyMergedPRs as fetchRecentlyMergedPRsImpl, } from './github-stats.js';
|
|
@@ -42,6 +43,12 @@ export function hasMergeConflict(mergeable, mergeableState) {
|
|
|
42
43
|
}
|
|
43
44
|
const MODULE = 'pr-monitor';
|
|
44
45
|
const MAX_CONCURRENT_REQUESTS = DEFAULT_CONCURRENCY;
|
|
46
|
+
/** Value of a settled promise known to have fulfilled (the caller already rethrew any rejection). */
|
|
47
|
+
function fulfilledValue(result) {
|
|
48
|
+
if (result.status === 'rejected')
|
|
49
|
+
throw result.reason;
|
|
50
|
+
return result.value;
|
|
51
|
+
}
|
|
45
52
|
/**
|
|
46
53
|
* Fetches and enriches open PRs from GitHub for the configured user.
|
|
47
54
|
*
|
|
@@ -196,7 +203,8 @@ export class PRMonitor {
|
|
|
196
203
|
debug(MODULE, `Could not cross-check viewer login: ${errorMessage(err)}`);
|
|
197
204
|
}
|
|
198
205
|
}
|
|
199
|
-
|
|
206
|
+
const searchTruncated = totalCount > SEARCH_API_RESULT_CAP;
|
|
207
|
+
if (searchTruncated) {
|
|
200
208
|
warnings.push(`GitHub Search API returned ${totalCount} PRs for @${searchUsername}, ` +
|
|
201
209
|
`but results are capped at ${SEARCH_API_RESULT_CAP}. ` +
|
|
202
210
|
`Showing the ${SEARCH_API_RESULT_CAP} most recently updated PRs.`);
|
|
@@ -298,7 +306,12 @@ export class PRMonitor {
|
|
|
298
306
|
return 0;
|
|
299
307
|
return a.status === 'needs_addressing' ? -1 : 1;
|
|
300
308
|
});
|
|
301
|
-
return
|
|
309
|
+
return {
|
|
310
|
+
prs,
|
|
311
|
+
failures,
|
|
312
|
+
...(warnings.length > 0 && { warnings }),
|
|
313
|
+
...(searchTruncated && { searchTruncated: true }),
|
|
314
|
+
};
|
|
302
315
|
}
|
|
303
316
|
/**
|
|
304
317
|
* Fetch detailed information for a single PR via the REST enrichment path.
|
|
@@ -552,6 +565,28 @@ export class PRMonitor {
|
|
|
552
565
|
const config = this.stateManager.getState().config;
|
|
553
566
|
return fetchRecentlyClosedPRsImpl(this.octokit, config, days);
|
|
554
567
|
}
|
|
568
|
+
/**
|
|
569
|
+
* Login of the account that closed a PR (#1863), or undefined when GitHub
|
|
570
|
+
* reports none. The Search API items behind `fetchRecentlyClosedPRs` carry
|
|
571
|
+
* no `closed_by`, so this is one `issues.get` per PR (PRs are issues to
|
|
572
|
+
* that endpoint). Lets the daily run act only on PRs the user closed
|
|
573
|
+
* themselves, not ones a maintainer or bot closed.
|
|
574
|
+
*
|
|
575
|
+
* @throws {ValidationError} If `prUrl` is not a GitHub PR or issue URL
|
|
576
|
+
* @throws Octokit errors (404 when the PR is gone, rate limit, auth) unchanged
|
|
577
|
+
*/
|
|
578
|
+
async fetchPRClosedBy(prUrl) {
|
|
579
|
+
const parsed = parseGitHubUrl(prUrl);
|
|
580
|
+
if (!parsed) {
|
|
581
|
+
throw new ValidationError(`Invalid PR URL format: ${prUrl}`);
|
|
582
|
+
}
|
|
583
|
+
const { data } = await this.octokit.issues.get({
|
|
584
|
+
owner: parsed.owner,
|
|
585
|
+
repo: parsed.repo,
|
|
586
|
+
issue_number: parsed.number,
|
|
587
|
+
});
|
|
588
|
+
return data.closed_by?.login ?? undefined;
|
|
589
|
+
}
|
|
555
590
|
/**
|
|
556
591
|
* Fetch PRs merged in the last N days.
|
|
557
592
|
* @param days - Lookback window in days (default: 7)
|
|
@@ -561,6 +596,81 @@ export class PRMonitor {
|
|
|
561
596
|
const config = this.stateManager.getState().config;
|
|
562
597
|
return fetchRecentlyMergedPRsImpl(this.octokit, config, days);
|
|
563
598
|
}
|
|
599
|
+
/**
|
|
600
|
+
* Everything the merged-PR notes selection reads for one PR (#1861): issue
|
|
601
|
+
* comments, reviews, inline review comments and commits, each paginated.
|
|
602
|
+
* Four calls per PR (more past 100 items). `truncatedLists` names the
|
|
603
|
+
* lists that hit the pagination cap; the lists arrive oldest-first, so it
|
|
604
|
+
* is the newest activity (including the user's own reply) that would be
|
|
605
|
+
* missing from those.
|
|
606
|
+
*
|
|
607
|
+
* The four calls run together; when more than one fails, a rate-limit or
|
|
608
|
+
* auth error is rethrown ahead of the others so the run stops instead of
|
|
609
|
+
* reporting a 404 that the throttled call never got to verify.
|
|
610
|
+
*
|
|
611
|
+
* @throws {ValidationError} If `prUrl` is not a GitHub PR URL
|
|
612
|
+
* @throws Octokit errors (404 when the PR is gone, rate limit, auth) unchanged
|
|
613
|
+
*/
|
|
614
|
+
async fetchMergedPRActivity(prUrl) {
|
|
615
|
+
const parsed = parseGitHubUrl(prUrl);
|
|
616
|
+
if (!parsed || parsed.type !== 'pull') {
|
|
617
|
+
throw new ValidationError(`Invalid PR URL format: ${prUrl}`);
|
|
618
|
+
}
|
|
619
|
+
const { owner, repo, number } = parsed;
|
|
620
|
+
const settled = await Promise.allSettled([
|
|
621
|
+
paginateAllDetailed((page) => this.octokit.issues.listComments({ owner, repo, page, issue_number: number, per_page: 100 })),
|
|
622
|
+
paginateAllDetailed((page) => this.octokit.pulls.listReviews({ owner, repo, page, pull_number: number, per_page: 100 })),
|
|
623
|
+
paginateAllDetailed((page) => this.octokit.pulls.listReviewComments({ owner, repo, page, pull_number: number, per_page: 100 })),
|
|
624
|
+
paginateAllDetailed((page) => this.octokit.pulls.listCommits({ owner, repo, page, pull_number: number, per_page: 100 })),
|
|
625
|
+
]);
|
|
626
|
+
rethrowRejections(settled);
|
|
627
|
+
const comments = fulfilledValue(settled[0]);
|
|
628
|
+
const reviews = fulfilledValue(settled[1]);
|
|
629
|
+
const reviewComments = fulfilledValue(settled[2]);
|
|
630
|
+
const commits = fulfilledValue(settled[3]);
|
|
631
|
+
const truncatedLists = [];
|
|
632
|
+
if (comments.truncated)
|
|
633
|
+
truncatedLists.push('comments');
|
|
634
|
+
if (reviews.truncated)
|
|
635
|
+
truncatedLists.push('reviews');
|
|
636
|
+
if (reviewComments.truncated)
|
|
637
|
+
truncatedLists.push('review comments');
|
|
638
|
+
if (commits.truncated)
|
|
639
|
+
truncatedLists.push('commits');
|
|
640
|
+
return {
|
|
641
|
+
truncatedLists,
|
|
642
|
+
comments: comments.items,
|
|
643
|
+
reviews: reviews.items,
|
|
644
|
+
reviewComments: reviewComments.items,
|
|
645
|
+
commits: commits.items,
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Open PRs the configured user reviewed or commented on but did not
|
|
650
|
+
* author (#1857); see `fetchReviewedOpenPRs` in reviewed-prs-fetch.ts for the searches,
|
|
651
|
+
* the exclusions and the cap warnings.
|
|
652
|
+
*/
|
|
653
|
+
async fetchReviewedOpenPRs() {
|
|
654
|
+
return fetchReviewedOpenPRsImpl(this.octokit, this.stateManager.getState().config);
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* The PR, comments, reviews, inline comments and commits the review
|
|
658
|
+
* follow-up scan reads for one reviewed PR (#1857); five calls, a
|
|
659
|
+
* rate-limit or auth error rethrown ahead of any other. See
|
|
660
|
+
* `fetchReviewedPRActivity` in reviewed-prs-fetch.ts.
|
|
661
|
+
*/
|
|
662
|
+
async fetchReviewedPRActivity(prUrl) {
|
|
663
|
+
return fetchReviewedPRActivityImpl(this.octokit, prUrl);
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Whether `base` is still an ancestor of `head` in the PR's repository
|
|
667
|
+
* (#1857): `ahead` / `identical` yes, `behind` / `diverged` no (rebase or
|
|
668
|
+
* force-push), `missing` when GitHub no longer has `base`. See
|
|
669
|
+
* `fetchCompareStatus` in reviewed-prs-fetch.ts.
|
|
670
|
+
*/
|
|
671
|
+
async fetchCompareStatus(prUrl, base, head) {
|
|
672
|
+
return fetchCompareStatusImpl(this.octokit, prUrl, base, head);
|
|
673
|
+
}
|
|
564
674
|
/**
|
|
565
675
|
* Generate a daily digest from fetched PRs.
|
|
566
676
|
* @param prs - All open PRs (active + shelved)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub fetches behind the review follow-ups phase (#1857): the two
|
|
3
|
+
* reviewed-PR searches, the per-PR activity fetch and the compare call.
|
|
4
|
+
* Extracted from `PRMonitor` like github-stats.ts, so pr-monitor.ts stays
|
|
5
|
+
* readable; `PRMonitor` exposes thin wrappers that supply the Octokit
|
|
6
|
+
* instance and the config.
|
|
7
|
+
*/
|
|
8
|
+
import type { Octokit } from '@octokit/rest';
|
|
9
|
+
import type { ReviewedPRActivity, ReviewedPRActivityList, ReviewedPRRef } from './reviewed-prs.js';
|
|
10
|
+
/**
|
|
11
|
+
* Search pages read per reviewed-PR query. Same ceiling as the PR count
|
|
12
|
+
* searches: the Search API gets unreliable (500s, ECONNRESET) past page 3,
|
|
13
|
+
* and 300 reviewed PRs per query is far more than a run should enrich.
|
|
14
|
+
*/
|
|
15
|
+
export declare const REVIEWED_PR_SEARCH_MAX_PAGES = 3;
|
|
16
|
+
/**
|
|
17
|
+
* GitHub lists at most this many commits for a pull request, however many
|
|
18
|
+
* pages are asked for; past it the last page comes back short, so
|
|
19
|
+
* `paginateAllDetailed` cannot tell on its own. The commit list is cut when
|
|
20
|
+
* it reaches this count or does not end at the PR's head.
|
|
21
|
+
*/
|
|
22
|
+
export declare const PR_COMMITS_LIST_MAX = 250;
|
|
23
|
+
/** Result of `PRMonitor.fetchReviewedOpenPRs`. */
|
|
24
|
+
export interface ReviewedPRSearchResult {
|
|
25
|
+
/** Deduplicated across both searches and sorted most recently updated first. */
|
|
26
|
+
prs: ReviewedPRRef[];
|
|
27
|
+
/**
|
|
28
|
+
* Per search: one entry when its results were cut by the page cap or a
|
|
29
|
+
* failed page, plus one when GitHub flagged a page as incomplete.
|
|
30
|
+
*/
|
|
31
|
+
warnings: string[];
|
|
32
|
+
}
|
|
33
|
+
/** Outcome of `PRMonitor.fetchCompareStatus`. */
|
|
34
|
+
export type CompareStatus = 'ahead' | 'behind' | 'diverged' | 'identical' | 'missing';
|
|
35
|
+
/** The config fields the search reads. */
|
|
36
|
+
export interface ReviewedPRSearchConfig {
|
|
37
|
+
githubUsername: string;
|
|
38
|
+
untrackedOrgs?: string[];
|
|
39
|
+
excludeRepos?: string[];
|
|
40
|
+
excludeOrgs?: string[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Open PRs the configured user reviewed or commented on but did not author:
|
|
44
|
+
* `is:pr is:open reviewed-by:<user> -author:<user>` plus the same with
|
|
45
|
+
* `commenter:` (a review left as a plain comment), merged, deduplicated by
|
|
46
|
+
* URL and sorted most recently updated first across both searches, so a
|
|
47
|
+
* per-run cap downstream drops the quietest PRs whichever search found
|
|
48
|
+
* them. Each search reads up to {@link REVIEWED_PR_SEARCH_MAX_PAGES} pages
|
|
49
|
+
* and records one warning when more results exist beyond the pages read,
|
|
50
|
+
* one when a page failed (the pages before it are kept and the other search
|
|
51
|
+
* still runs), and one when GitHub flagged a page as incomplete. Dropped
|
|
52
|
+
* without a warning, like every other PR list: PRs in the user's own repos,
|
|
53
|
+
* in `untrackedOrgs`, in `excludeRepos` or `excludeOrgs`, and anything the
|
|
54
|
+
* search returned that is not a pull request or that the user authored
|
|
55
|
+
* after all.
|
|
56
|
+
*
|
|
57
|
+
* @throws {ConfigurationError} If no GitHub username is configured
|
|
58
|
+
* @throws Octokit rate-limit and auth errors unchanged
|
|
59
|
+
*/
|
|
60
|
+
export declare function fetchReviewedOpenPRs(octokit: Octokit, config: ReviewedPRSearchConfig): Promise<ReviewedPRSearchResult>;
|
|
61
|
+
/**
|
|
62
|
+
* Everything the review follow-up scan reads for one PR: the PR itself
|
|
63
|
+
* (head SHA, state, author), issue comments, reviews, inline review
|
|
64
|
+
* comments and commits, the lists paginated. Five calls per PR (more past
|
|
65
|
+
* 100 items). `truncatedLists` names the lists that hit the pagination cap;
|
|
66
|
+
* they arrive oldest-first, so the newest activity would be missing. The
|
|
67
|
+
* commit list is also reported cut when it reaches GitHub's own
|
|
68
|
+
* {@link PR_COMMITS_LIST_MAX} or its last entry is not the PR's head: past
|
|
69
|
+
* 250 commits GitHub returns a short final page, which looks complete.
|
|
70
|
+
*
|
|
71
|
+
* The five calls run together; when more than one fails, a rate-limit or
|
|
72
|
+
* auth error is rethrown ahead of the others.
|
|
73
|
+
*
|
|
74
|
+
* @throws {ValidationError} If `prUrl` is not a GitHub PR URL
|
|
75
|
+
* @throws Octokit errors (404 when the PR is gone, rate limit, auth) unchanged
|
|
76
|
+
*/
|
|
77
|
+
export declare function fetchReviewedPRActivity(octokit: Octokit, prUrl: string): Promise<ReviewedPRActivity & {
|
|
78
|
+
truncatedLists: ReviewedPRActivityList[];
|
|
79
|
+
}>;
|
|
80
|
+
/**
|
|
81
|
+
* How `head` relates to `base` in the PR's repository: `ahead` or
|
|
82
|
+
* `identical` means `base` is an ancestor of `head` and `<base>...<head>`
|
|
83
|
+
* shows exactly what changed since; `behind` or `diverged` means the branch
|
|
84
|
+
* was rebased or force-pushed. A 404 (GitHub no longer has `base`, as after
|
|
85
|
+
* a force-push once the old commits are collected) is reported as
|
|
86
|
+
* `missing`. One call; the commit list is not requested.
|
|
87
|
+
*
|
|
88
|
+
* @throws {ValidationError} If `prUrl` is not a GitHub PR URL
|
|
89
|
+
* @throws Octokit errors other than 404 (rate limit, auth, 5xx) unchanged
|
|
90
|
+
*/
|
|
91
|
+
export declare function fetchCompareStatus(octokit: Octokit, prUrl: string, base: string, head: string): Promise<CompareStatus>;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub fetches behind the review follow-ups phase (#1857): the two
|
|
3
|
+
* reviewed-PR searches, the per-PR activity fetch and the compare call.
|
|
4
|
+
* Extracted from `PRMonitor` like github-stats.ts, so pr-monitor.ts stays
|
|
5
|
+
* readable; `PRMonitor` exposes thin wrappers that supply the Octokit
|
|
6
|
+
* instance and the config.
|
|
7
|
+
*/
|
|
8
|
+
import { rethrowRejections } from './concurrency.js';
|
|
9
|
+
import { ConfigurationError, ValidationError, describeError, getHttpStatusCode, isRateLimitOrAuthError, } from './errors.js';
|
|
10
|
+
import { debug, warn } from './logger.js';
|
|
11
|
+
import { paginateAllDetailed } from './pagination.js';
|
|
12
|
+
import { isOwnRepo, isUntrackedOrg, parseGitHubUrl } from './urls.js';
|
|
13
|
+
const MODULE = 'reviewed-prs';
|
|
14
|
+
/**
|
|
15
|
+
* Search pages read per reviewed-PR query. Same ceiling as the PR count
|
|
16
|
+
* searches: the Search API gets unreliable (500s, ECONNRESET) past page 3,
|
|
17
|
+
* and 300 reviewed PRs per query is far more than a run should enrich.
|
|
18
|
+
*/
|
|
19
|
+
export const REVIEWED_PR_SEARCH_MAX_PAGES = 3;
|
|
20
|
+
const SEARCH_PER_PAGE = 100;
|
|
21
|
+
/**
|
|
22
|
+
* GitHub lists at most this many commits for a pull request, however many
|
|
23
|
+
* pages are asked for; past it the last page comes back short, so
|
|
24
|
+
* `paginateAllDetailed` cannot tell on its own. The commit list is cut when
|
|
25
|
+
* it reaches this count or does not end at the PR's head.
|
|
26
|
+
*/
|
|
27
|
+
export const PR_COMMITS_LIST_MAX = 250;
|
|
28
|
+
/** The two searches behind the reviewed-PR list, with the label used in cap warnings. */
|
|
29
|
+
const REVIEWED_PR_SEARCHES = [
|
|
30
|
+
{ qualifier: 'reviewed-by', label: 'reviewed' },
|
|
31
|
+
{ qualifier: 'commenter', label: 'commented on' },
|
|
32
|
+
];
|
|
33
|
+
/** Value of a settled promise known to have fulfilled (the caller already rethrew any rejection). */
|
|
34
|
+
function fulfilledValue(result) {
|
|
35
|
+
if (result.status === 'rejected')
|
|
36
|
+
throw result.reason;
|
|
37
|
+
return result.value;
|
|
38
|
+
}
|
|
39
|
+
function parsePRUrl(prUrl) {
|
|
40
|
+
const parsed = parseGitHubUrl(prUrl);
|
|
41
|
+
if (!parsed || parsed.type !== 'pull') {
|
|
42
|
+
throw new ValidationError(`Invalid PR URL format: ${prUrl}`);
|
|
43
|
+
}
|
|
44
|
+
return parsed;
|
|
45
|
+
}
|
|
46
|
+
/** The repo-level exclusions, resolved once per search run. */
|
|
47
|
+
class ReviewedPRFilter {
|
|
48
|
+
config;
|
|
49
|
+
usernameLower;
|
|
50
|
+
excludedRepos;
|
|
51
|
+
excludedOrgs;
|
|
52
|
+
constructor(config) {
|
|
53
|
+
this.config = config;
|
|
54
|
+
this.usernameLower = config.githubUsername.toLowerCase();
|
|
55
|
+
this.excludedRepos = new Set((config.excludeRepos ?? []).map((repo) => repo.toLowerCase()));
|
|
56
|
+
this.excludedOrgs = new Set((config.excludeOrgs ?? []).map((org) => org.toLowerCase()));
|
|
57
|
+
}
|
|
58
|
+
isRepoExcluded(owner, repo) {
|
|
59
|
+
const ownerLower = owner.toLowerCase();
|
|
60
|
+
if (isOwnRepo(owner, this.config.githubUsername) || isUntrackedOrg(owner, this.config.untrackedOrgs))
|
|
61
|
+
return true;
|
|
62
|
+
return this.excludedRepos.has(repo.toLowerCase()) || this.excludedOrgs.has(ownerLower);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The ref for a search item, or undefined when it is dropped: not a pull
|
|
66
|
+
* request, an unparseable URL (warned), authored by the user after all,
|
|
67
|
+
* or in an own, untracked or excluded repo or org.
|
|
68
|
+
*/
|
|
69
|
+
toRef(item) {
|
|
70
|
+
if (!item.pull_request)
|
|
71
|
+
return undefined;
|
|
72
|
+
const parsed = parseGitHubUrl(item.html_url);
|
|
73
|
+
if (!parsed || parsed.type !== 'pull') {
|
|
74
|
+
warn(MODULE, `Skipping reviewed PR with unparseable URL: ${item.html_url}`);
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
const author = item.user?.login ?? '';
|
|
78
|
+
const repo = `${parsed.owner}/${parsed.repo}`;
|
|
79
|
+
if (author.toLowerCase() === this.usernameLower || this.isRepoExcluded(parsed.owner, repo))
|
|
80
|
+
return undefined;
|
|
81
|
+
return { repo, author, url: item.html_url, number: parsed.number, title: item.title, updatedAt: item.updated_at };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Read one search page by page, most recently updated first, up to
|
|
86
|
+
* {@link REVIEWED_PR_SEARCH_MAX_PAGES}. A page that fails ends the search
|
|
87
|
+
* with what was read so far and the failure recorded; a rate-limit or auth
|
|
88
|
+
* error propagates instead.
|
|
89
|
+
*/
|
|
90
|
+
async function searchPages(octokit, q) {
|
|
91
|
+
const result = { items: [], totalCount: 0, pagesRead: 0, incomplete: false };
|
|
92
|
+
for (let page = 1; page <= REVIEWED_PR_SEARCH_MAX_PAGES; page++) {
|
|
93
|
+
let data;
|
|
94
|
+
try {
|
|
95
|
+
({ data } = await octokit.search.issuesAndPullRequests({
|
|
96
|
+
q,
|
|
97
|
+
page,
|
|
98
|
+
sort: 'updated',
|
|
99
|
+
order: 'desc',
|
|
100
|
+
per_page: SEARCH_PER_PAGE,
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (isRateLimitOrAuthError(error))
|
|
105
|
+
throw error;
|
|
106
|
+
result.failure = { page, error };
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
result.pagesRead = page;
|
|
110
|
+
result.totalCount = data.total_count;
|
|
111
|
+
if (data.incomplete_results)
|
|
112
|
+
result.incomplete = true;
|
|
113
|
+
result.items.push(...data.items);
|
|
114
|
+
if (data.items.length < SEARCH_PER_PAGE || result.items.length >= result.totalCount)
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
/** Why a search did not cover every result: a failed page, else the page cap; undefined when it did. */
|
|
120
|
+
function coverageWarning(subject, pages) {
|
|
121
|
+
if (pages.failure) {
|
|
122
|
+
return (`GitHub search for ${subject} failed on page ${pages.failure.page} (${describeError(pages.failure.error)}); ` +
|
|
123
|
+
`only the ${pages.items.length} result(s) from the ${pages.pagesRead} page(s) before it were read this run.`);
|
|
124
|
+
}
|
|
125
|
+
if (pages.items.length < pages.totalCount) {
|
|
126
|
+
return (`GitHub Search API reports ${pages.totalCount} ${subject}, but only the ${pages.items.length} most recently ` +
|
|
127
|
+
`updated were read (${pages.pagesRead} page(s) of ${SEARCH_PER_PAGE}). Older reviewed PRs are not checked this run.`);
|
|
128
|
+
}
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
/** The warnings one search earned: incomplete coverage (failed page or page cap), and an incomplete page. */
|
|
132
|
+
function searchWarnings(label, pages) {
|
|
133
|
+
const subject = `open PRs you ${label} (not authored)`;
|
|
134
|
+
const messages = [];
|
|
135
|
+
const coverage = coverageWarning(subject, pages);
|
|
136
|
+
if (coverage !== undefined)
|
|
137
|
+
messages.push(coverage);
|
|
138
|
+
if (pages.incomplete) {
|
|
139
|
+
messages.push(`GitHub Search API returned incomplete results for ${subject} (the search timed out server-side); ` +
|
|
140
|
+
`some reviewed PRs may be missing this run.`);
|
|
141
|
+
}
|
|
142
|
+
return messages;
|
|
143
|
+
}
|
|
144
|
+
/** Most recently updated first; an unreadable `updatedAt` sorts last. */
|
|
145
|
+
function byUpdatedDesc(a, b) {
|
|
146
|
+
return (Date.parse(b.updatedAt) || 0) - (Date.parse(a.updatedAt) || 0);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Open PRs the configured user reviewed or commented on but did not author:
|
|
150
|
+
* `is:pr is:open reviewed-by:<user> -author:<user>` plus the same with
|
|
151
|
+
* `commenter:` (a review left as a plain comment), merged, deduplicated by
|
|
152
|
+
* URL and sorted most recently updated first across both searches, so a
|
|
153
|
+
* per-run cap downstream drops the quietest PRs whichever search found
|
|
154
|
+
* them. Each search reads up to {@link REVIEWED_PR_SEARCH_MAX_PAGES} pages
|
|
155
|
+
* and records one warning when more results exist beyond the pages read,
|
|
156
|
+
* one when a page failed (the pages before it are kept and the other search
|
|
157
|
+
* still runs), and one when GitHub flagged a page as incomplete. Dropped
|
|
158
|
+
* without a warning, like every other PR list: PRs in the user's own repos,
|
|
159
|
+
* in `untrackedOrgs`, in `excludeRepos` or `excludeOrgs`, and anything the
|
|
160
|
+
* search returned that is not a pull request or that the user authored
|
|
161
|
+
* after all.
|
|
162
|
+
*
|
|
163
|
+
* @throws {ConfigurationError} If no GitHub username is configured
|
|
164
|
+
* @throws Octokit rate-limit and auth errors unchanged
|
|
165
|
+
*/
|
|
166
|
+
export async function fetchReviewedOpenPRs(octokit, config) {
|
|
167
|
+
const username = config.githubUsername;
|
|
168
|
+
if (!username) {
|
|
169
|
+
throw new ConfigurationError('No GitHub username configured. Run setup first.');
|
|
170
|
+
}
|
|
171
|
+
const filter = new ReviewedPRFilter(config);
|
|
172
|
+
const prs = [];
|
|
173
|
+
const seen = new Set();
|
|
174
|
+
const warnings = [];
|
|
175
|
+
for (const { qualifier, label } of REVIEWED_PR_SEARCHES) {
|
|
176
|
+
const pages = await searchPages(octokit, `is:pr is:open is:public ${qualifier}:${username} -author:${username}`);
|
|
177
|
+
for (const item of pages.items) {
|
|
178
|
+
if (seen.has(item.html_url))
|
|
179
|
+
continue;
|
|
180
|
+
seen.add(item.html_url);
|
|
181
|
+
const ref = filter.toRef(item);
|
|
182
|
+
if (ref)
|
|
183
|
+
prs.push(ref);
|
|
184
|
+
}
|
|
185
|
+
for (const message of searchWarnings(label, pages)) {
|
|
186
|
+
warnings.push(message);
|
|
187
|
+
warn(MODULE, message);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
prs.sort(byUpdatedDesc);
|
|
191
|
+
debug(MODULE, `Found ${prs.length} open PRs reviewed by @${username}`);
|
|
192
|
+
return { prs, warnings };
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Everything the review follow-up scan reads for one PR: the PR itself
|
|
196
|
+
* (head SHA, state, author), issue comments, reviews, inline review
|
|
197
|
+
* comments and commits, the lists paginated. Five calls per PR (more past
|
|
198
|
+
* 100 items). `truncatedLists` names the lists that hit the pagination cap;
|
|
199
|
+
* they arrive oldest-first, so the newest activity would be missing. The
|
|
200
|
+
* commit list is also reported cut when it reaches GitHub's own
|
|
201
|
+
* {@link PR_COMMITS_LIST_MAX} or its last entry is not the PR's head: past
|
|
202
|
+
* 250 commits GitHub returns a short final page, which looks complete.
|
|
203
|
+
*
|
|
204
|
+
* The five calls run together; when more than one fails, a rate-limit or
|
|
205
|
+
* auth error is rethrown ahead of the others.
|
|
206
|
+
*
|
|
207
|
+
* @throws {ValidationError} If `prUrl` is not a GitHub PR URL
|
|
208
|
+
* @throws Octokit errors (404 when the PR is gone, rate limit, auth) unchanged
|
|
209
|
+
*/
|
|
210
|
+
export async function fetchReviewedPRActivity(octokit, prUrl) {
|
|
211
|
+
const { owner, repo, number } = parsePRUrl(prUrl);
|
|
212
|
+
const settled = await Promise.allSettled([
|
|
213
|
+
octokit.pulls.get({ owner, repo, pull_number: number }),
|
|
214
|
+
paginateAllDetailed((page) => octokit.issues.listComments({ owner, repo, page, issue_number: number, per_page: 100 })),
|
|
215
|
+
paginateAllDetailed((page) => octokit.pulls.listReviews({ owner, repo, page, pull_number: number, per_page: 100 })),
|
|
216
|
+
paginateAllDetailed((page) => octokit.pulls.listReviewComments({ owner, repo, page, pull_number: number, per_page: 100 })),
|
|
217
|
+
paginateAllDetailed((page) => octokit.pulls.listCommits({ owner, repo, page, pull_number: number, per_page: 100 })),
|
|
218
|
+
]);
|
|
219
|
+
rethrowRejections(settled);
|
|
220
|
+
const pr = fulfilledValue(settled[0]).data;
|
|
221
|
+
const comments = fulfilledValue(settled[1]);
|
|
222
|
+
const reviews = fulfilledValue(settled[2]);
|
|
223
|
+
const reviewComments = fulfilledValue(settled[3]);
|
|
224
|
+
const commits = fulfilledValue(settled[4]);
|
|
225
|
+
const truncatedLists = [];
|
|
226
|
+
if (comments.truncated)
|
|
227
|
+
truncatedLists.push('comments');
|
|
228
|
+
if (reviews.truncated)
|
|
229
|
+
truncatedLists.push('reviews');
|
|
230
|
+
if (reviewComments.truncated)
|
|
231
|
+
truncatedLists.push('review comments');
|
|
232
|
+
const isCommitListCut = commits.items.length >= PR_COMMITS_LIST_MAX || commits.items.at(-1)?.sha !== pr.head.sha;
|
|
233
|
+
if (isCommitListCut || commits.truncated)
|
|
234
|
+
truncatedLists.push('commits');
|
|
235
|
+
return {
|
|
236
|
+
truncatedLists,
|
|
237
|
+
pr: { headSha: pr.head.sha, state: pr.state, author: pr.user?.login, title: pr.title },
|
|
238
|
+
comments: comments.items,
|
|
239
|
+
reviews: reviews.items,
|
|
240
|
+
reviewComments: reviewComments.items,
|
|
241
|
+
commits: commits.items,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* How `head` relates to `base` in the PR's repository: `ahead` or
|
|
246
|
+
* `identical` means `base` is an ancestor of `head` and `<base>...<head>`
|
|
247
|
+
* shows exactly what changed since; `behind` or `diverged` means the branch
|
|
248
|
+
* was rebased or force-pushed. A 404 (GitHub no longer has `base`, as after
|
|
249
|
+
* a force-push once the old commits are collected) is reported as
|
|
250
|
+
* `missing`. One call; the commit list is not requested.
|
|
251
|
+
*
|
|
252
|
+
* @throws {ValidationError} If `prUrl` is not a GitHub PR URL
|
|
253
|
+
* @throws Octokit errors other than 404 (rate limit, auth, 5xx) unchanged
|
|
254
|
+
*/
|
|
255
|
+
export async function fetchCompareStatus(octokit, prUrl, base, head) {
|
|
256
|
+
const { owner, repo } = parsePRUrl(prUrl);
|
|
257
|
+
try {
|
|
258
|
+
const { data } = await octokit.repos.compareCommitsWithBasehead({
|
|
259
|
+
owner,
|
|
260
|
+
repo,
|
|
261
|
+
basehead: `${base}...${head}`,
|
|
262
|
+
per_page: 1,
|
|
263
|
+
});
|
|
264
|
+
return data.status;
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
if (getHttpStatusCode(error) === 404)
|
|
268
|
+
return 'missing';
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
}
|