@oss-autopilot/core 3.42.5 → 3.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-pre-action.js +8 -3
- package/dist/cli-registry.js +428 -27
- package/dist/cli.bundle.cjs +212 -156
- package/dist/commands/check-integration.js +5 -1
- package/dist/commands/cleanup.d.ts +80 -0
- package/dist/commands/cleanup.js +334 -0
- package/dist/commands/comments.d.ts +14 -1
- package/dist/commands/comments.js +17 -5
- package/dist/commands/config.d.ts +2 -0
- package/dist/commands/config.js +63 -6
- package/dist/commands/daily-dismiss-filter.d.ts +7 -0
- package/dist/commands/daily-dismiss-filter.js +17 -1
- package/dist/commands/daily-ledger.d.ts +150 -0
- package/dist/commands/daily-ledger.js +248 -0
- package/dist/commands/daily-recent-prs.d.ts +26 -0
- package/dist/commands/daily-recent-prs.js +55 -0
- package/dist/commands/daily-render.d.ts +2 -1
- package/dist/commands/daily-render.js +4 -1
- package/dist/commands/daily.d.ts +5 -1
- package/dist/commands/daily.js +83 -93
- package/dist/commands/dashboard-cache.d.ts +2 -0
- package/dist/commands/dashboard-cache.js +33 -8
- package/dist/commands/dashboard-data.js +113 -69
- package/dist/commands/dashboard-gist-sync.js +3 -1
- package/dist/commands/dashboard-lifecycle.d.ts +36 -8
- package/dist/commands/dashboard-lifecycle.js +132 -39
- package/dist/commands/dashboard-process.d.ts +49 -1
- package/dist/commands/dashboard-process.js +111 -12
- package/dist/commands/dashboard-server.js +89 -23
- package/dist/commands/detect-formatters.js +1 -0
- package/dist/commands/dismiss.js +11 -7
- package/dist/commands/doctor.d.ts +15 -1
- package/dist/commands/doctor.js +66 -5
- package/dist/commands/draft.d.ts +77 -0
- package/dist/commands/draft.js +218 -0
- package/dist/commands/eval.js +1 -0
- package/dist/commands/fork-prune.d.ts +58 -0
- package/dist/commands/fork-prune.js +247 -0
- package/dist/commands/guidelines.d.ts +69 -2
- package/dist/commands/guidelines.js +158 -14
- package/dist/commands/index.d.ts +29 -4
- package/dist/commands/index.js +20 -3
- package/dist/commands/issue-thread.d.ts +46 -0
- package/dist/commands/issue-thread.js +123 -0
- package/dist/commands/ledger-backfill.d.ts +9 -0
- package/dist/commands/ledger-backfill.js +44 -1
- package/dist/commands/list-mark-done.d.ts +2 -1
- package/dist/commands/list-mark-done.js +3 -1
- package/dist/commands/list-move-tier.d.ts +2 -1
- package/dist/commands/list-move-tier.js +3 -1
- package/dist/commands/local-repos.js +10 -5
- package/dist/commands/locate-issue-list.d.ts +40 -17
- package/dist/commands/locate-issue-list.js +148 -88
- package/dist/commands/move.js +7 -1
- package/dist/commands/overnight-handoff.d.ts +17 -7
- package/dist/commands/overnight-handoff.js +36 -14
- package/dist/commands/overnight-push-prep.d.ts +14 -8
- package/dist/commands/overnight-push-prep.js +107 -35
- package/dist/commands/overnight-tool-rules.d.ts +54 -0
- package/dist/commands/overnight-tool-rules.js +217 -0
- package/dist/commands/overnight.d.ts +5 -6
- package/dist/commands/overnight.js +61 -140
- package/dist/commands/parse-list.js +7 -1
- package/dist/commands/policy.d.ts +90 -0
- package/dist/commands/policy.js +276 -0
- package/dist/commands/pr-create.d.ts +48 -0
- package/dist/commands/pr-create.js +200 -0
- package/dist/commands/pr-preflight.d.ts +69 -0
- package/dist/commands/pr-preflight.js +348 -0
- package/dist/commands/repo-vet.d.ts +9 -0
- package/dist/commands/repo-vet.js +36 -11
- package/dist/commands/scout-bridge.js +18 -8
- package/dist/commands/search.js +7 -0
- package/dist/commands/setup.d.ts +3 -3
- package/dist/commands/setup.js +160 -48
- package/dist/commands/skip-add.js +10 -1
- package/dist/commands/startup.d.ts +12 -3
- package/dist/commands/startup.js +82 -49
- package/dist/commands/state-cmd.d.ts +2 -0
- package/dist/commands/state-cmd.js +5 -1
- package/dist/commands/stats.js +1 -0
- package/dist/commands/status.js +6 -0
- package/dist/commands/strategy.js +1 -0
- package/dist/commands/validation.d.ts +5 -0
- package/dist/commands/validation.js +5 -0
- package/dist/commands/vet-list.d.ts +6 -0
- package/dist/commands/vet-list.js +26 -1
- package/dist/commands/vet.d.ts +20 -0
- package/dist/commands/vet.js +133 -2
- package/dist/commands/work.d.ts +4 -0
- package/dist/commands/work.js +34 -11
- package/dist/core/__fixtures__/prompt-injection-payloads.js +31 -0
- package/dist/core/anti-llm-policy.d.ts +3 -0
- package/dist/core/anti-llm-policy.js +3 -0
- package/dist/core/auth.js +2 -0
- package/dist/core/ci-analysis.d.ts +7 -2
- package/dist/core/ci-analysis.js +76 -21
- package/dist/core/commit-date.d.ts +45 -0
- package/dist/core/commit-date.js +45 -0
- package/dist/core/compliance-score.d.ts +3 -0
- package/dist/core/compliance-score.js +13 -9
- package/dist/core/config-registry.d.ts +27 -2
- package/dist/core/config-registry.js +94 -7
- package/dist/core/contributing.d.ts +2 -3
- package/dist/core/contributing.js +2 -3
- package/dist/core/daily-logic.d.ts +30 -5
- package/dist/core/daily-logic.js +68 -19
- package/dist/core/errors.d.ts +37 -3
- package/dist/core/errors.js +54 -5
- package/dist/core/fork-prune.d.ts +149 -0
- package/dist/core/fork-prune.js +333 -0
- package/dist/core/gist-health.d.ts +15 -3
- package/dist/core/gist-health.js +8 -0
- package/dist/core/gist-state-store.d.ts +24 -4
- package/dist/core/gist-state-store.js +98 -51
- package/dist/core/github-stats.d.ts +110 -16
- package/dist/core/github-stats.js +295 -110
- package/dist/core/http-cache.d.ts +0 -10
- package/dist/core/http-cache.js +0 -19
- package/dist/core/index.d.ts +13 -6
- package/dist/core/index.js +16 -6
- package/dist/core/issue-conversation.d.ts +8 -2
- package/dist/core/issue-conversation.js +31 -12
- package/dist/core/local-config.d.ts +95 -0
- package/dist/core/local-config.js +270 -0
- package/dist/core/merged-pr-notes.d.ts +2 -2
- package/dist/core/pacing.d.ts +41 -0
- package/dist/core/pacing.js +115 -0
- package/dist/core/pagination.d.ts +55 -0
- package/dist/core/pagination.js +59 -0
- package/dist/core/paths.d.ts +7 -0
- package/dist/core/paths.js +9 -0
- package/dist/core/pr-assembly.d.ts +2 -0
- package/dist/core/pr-assembly.js +6 -2
- package/dist/core/pr-graphql.d.ts +53 -4
- package/dist/core/pr-graphql.js +87 -14
- package/dist/core/pr-monitor.d.ts +35 -12
- package/dist/core/pr-monitor.js +110 -26
- package/dist/core/pr-preflight.d.ts +154 -0
- package/dist/core/pr-preflight.js +753 -0
- package/dist/core/pr-quality-rubric.d.ts +0 -6
- package/dist/core/pr-quality-rubric.js +0 -8
- package/dist/core/pr-template.d.ts +2 -0
- package/dist/core/pr-template.js +5 -1
- package/dist/core/prose-script.d.ts +72 -0
- package/dist/core/prose-script.js +223 -0
- package/dist/core/repo-policy.d.ts +111 -0
- package/dist/core/repo-policy.js +428 -0
- package/dist/core/repo-score-manager.d.ts +66 -0
- package/dist/core/repo-score-manager.js +140 -1
- package/dist/core/review-analysis.d.ts +49 -21
- package/dist/core/review-analysis.js +89 -15
- package/dist/core/reviewed-prs-fetch.js +11 -29
- package/dist/core/reviewed-prs.js +8 -15
- package/dist/core/stale-data.d.ts +78 -0
- package/dist/core/stale-data.js +153 -0
- package/dist/core/state-persistence.d.ts +62 -27
- package/dist/core/state-persistence.js +338 -119
- package/dist/core/state-schema.d.ts +152 -210
- package/dist/core/state-schema.js +232 -80
- package/dist/core/state.d.ts +81 -8
- package/dist/core/state.js +239 -46
- package/dist/core/status-determination.js +32 -12
- package/dist/core/strategy.js +3 -1
- package/dist/core/types.d.ts +22 -1
- package/dist/core/types.js +1 -0
- package/dist/core/untrusted-content.d.ts +30 -11
- package/dist/core/untrusted-content.js +95 -42
- package/dist/core/urls.d.ts +33 -0
- package/dist/core/urls.js +94 -0
- package/dist/dashboard/assets/chart-panel-B-nLVgzQ.js +3 -0
- package/dist/dashboard/assets/index-5IvMGokL.js +55 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/formatters/json.d.ts +432 -10
- package/dist/formatters/json.js +156 -1
- package/package.json +6 -6
- package/dist/core/ci-enforced-tools.d.ts +0 -35
- package/dist/core/ci-enforced-tools.js +0 -109
- package/dist/core/comment-decision.d.ts +0 -79
- package/dist/core/comment-decision.js +0 -82
- package/dist/core/extraction-categories.d.ts +0 -55
- package/dist/core/extraction-categories.js +0 -108
- package/dist/core/follow-up-history.d.ts +0 -40
- package/dist/core/follow-up-history.js +0 -71
- package/dist/core/issue-effort.d.ts +0 -29
- package/dist/core/issue-effort.js +0 -47
- package/dist/core/maintainer-hints.d.ts +0 -23
- package/dist/core/maintainer-hints.js +0 -36
- package/dist/core/workflow-state.d.ts +0 -56
- package/dist/core/workflow-state.js +0 -101
- package/dist/dashboard/assets/chart-panel-DPKNBUts.js +0 -3
- package/dist/dashboard/assets/index-B25bZOYX.js +0 -55
|
@@ -17,30 +17,31 @@ export interface ReviewComment {
|
|
|
17
17
|
in_reply_to_id?: number;
|
|
18
18
|
pull_request_review_id?: number | null;
|
|
19
19
|
}
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
* Groups reviews by user, keeping each user's latest verdict, then checks
|
|
23
|
-
* for CHANGES_REQUESTED or APPROVED states.
|
|
24
|
-
*
|
|
25
|
-
* Only APPROVED, CHANGES_REQUESTED and DISMISSED change a reviewer's standing
|
|
26
|
-
* verdict on GitHub. COMMENTED is also what GitHub records for every inline
|
|
27
|
-
* reply, so it must not overwrite an earlier verdict from the same reviewer.
|
|
28
|
-
*
|
|
29
|
-
* Bot-authored reviews (e.g. an AI review bot posting APPROVE) are ignored so a
|
|
30
|
-
* bot alone never reads as maintainer approval or a changes request (#1840).
|
|
31
|
-
*/
|
|
32
|
-
export declare function determineReviewDecision(reviews: Array<{
|
|
20
|
+
/** The review fields the verdict helpers read. */
|
|
21
|
+
type VerdictReview = {
|
|
33
22
|
state?: string | null;
|
|
23
|
+
submitted_at?: string | null;
|
|
34
24
|
user?: {
|
|
35
25
|
login?: string;
|
|
36
26
|
type?: string | null;
|
|
37
27
|
} | null;
|
|
38
|
-
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Determine review decision from reviews list: changes requested when any
|
|
31
|
+
* reviewer's standing verdict ({@link standingVerdicts}) is CHANGES_REQUESTED,
|
|
32
|
+
* otherwise approved when any is APPROVED.
|
|
33
|
+
*/
|
|
34
|
+
export declare function determineReviewDecision(reviews: VerdictReview[]): ReviewDecision;
|
|
35
|
+
/**
|
|
36
|
+
* When `login`'s standing approval (see {@link standingVerdicts}) was
|
|
37
|
+
* submitted, or undefined when that account has no standing APPROVED verdict.
|
|
38
|
+
* Logins compare case-insensitively. Lets the status logic tell whether the
|
|
39
|
+
* author of an unanswered comment approved at or after writing it (#1920).
|
|
40
|
+
*/
|
|
41
|
+
export declare function getStandingApprovalDate(reviews: VerdictReview[], login: string | undefined): string | undefined;
|
|
39
42
|
/**
|
|
40
43
|
* Get the date of the latest CHANGES_REQUESTED review (from any human reviewer).
|
|
41
44
|
* Used to detect needs_changes status when review feedback is in inline comments.
|
|
42
|
-
* Bot reviews are skipped (#1840): a bot re-reviewing every push would otherwise
|
|
43
|
-
* move the date past the author's fix commit.
|
|
44
45
|
*/
|
|
45
46
|
export declare function getLatestChangesRequestedDate(reviews: Array<{
|
|
46
47
|
state?: string | null;
|
|
@@ -50,6 +51,21 @@ export declare function getLatestChangesRequestedDate(reviews: Array<{
|
|
|
50
51
|
type?: string | null;
|
|
51
52
|
} | null;
|
|
52
53
|
}>): string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* The head commit the latest CHANGES_REQUESTED review (from any human
|
|
56
|
+
* reviewer) was submitted against. A head moved onto a new parent since then
|
|
57
|
+
* was rebased, not amended, so its new committer date says nothing about the
|
|
58
|
+
* review (#2042).
|
|
59
|
+
*/
|
|
60
|
+
export declare function getChangesRequestedCommitSha(reviews: Array<{
|
|
61
|
+
state?: string | null;
|
|
62
|
+
submitted_at?: string | null;
|
|
63
|
+
user?: {
|
|
64
|
+
login?: string;
|
|
65
|
+
type?: string | null;
|
|
66
|
+
} | null;
|
|
67
|
+
commit_id?: string | null;
|
|
68
|
+
}>): string | undefined;
|
|
53
69
|
/**
|
|
54
70
|
* Check if all inline comments in a COMMENTED review are self-replies.
|
|
55
71
|
* A self-reply is when an author replies to their own earlier inline comment.
|
|
@@ -86,12 +102,19 @@ export declare function getFirstMaintainerResponseAt(comments: Array<ActorFields
|
|
|
86
102
|
* Check if there are unresponded comments from maintainers.
|
|
87
103
|
* Combines issue comments and review comments into a timeline,
|
|
88
104
|
* then finds maintainer comments after the user's last comment.
|
|
105
|
+
*
|
|
106
|
+
* Whose items count (#1921): every review from another human, and every issue
|
|
107
|
+
* comment from another human except a passer-by's. A passer-by is an account
|
|
108
|
+
* whose association is NONE, FIRST_TIMER, FIRST_TIME_CONTRIBUTOR or MANNEQUIN
|
|
109
|
+
* ({@link NO_STANDING_ASSOCIATIONS}) and that has submitted no review (in any
|
|
110
|
+
* state) and no inline review comment on this PR. So an OWNER, MEMBER,
|
|
111
|
+
* COLLABORATOR or CONTRIBUTOR always counts, anyone who reviewed the PR counts
|
|
112
|
+
* whatever their association, and an issue comment with no association data
|
|
113
|
+
* counts: missing a maintainer costs more than surfacing a passer-by. This is
|
|
114
|
+
* deliberately wider than {@link isMaintainerEngagement}, which drives the
|
|
115
|
+
* dormancy clock.
|
|
89
116
|
*/
|
|
90
|
-
export declare function checkUnrespondedComments(comments: Array<{
|
|
91
|
-
user?: {
|
|
92
|
-
login?: string;
|
|
93
|
-
type?: string | null;
|
|
94
|
-
} | null;
|
|
117
|
+
export declare function checkUnrespondedComments(comments: Array<ActorFields & {
|
|
95
118
|
body?: string | null;
|
|
96
119
|
created_at: string;
|
|
97
120
|
}>, reviews: Array<{
|
|
@@ -106,6 +129,11 @@ export declare function checkUnrespondedComments(comments: Array<{
|
|
|
106
129
|
}>, reviewComments: ReviewComment[], username: string): {
|
|
107
130
|
hasUnrespondedComment: boolean;
|
|
108
131
|
lastMaintainerComment?: FetchedPR['lastMaintainerComment'];
|
|
132
|
+
/** Every unanswered maintainer item, oldest first; the last one is `lastMaintainerComment`. */
|
|
133
|
+
unrespondedComments: Array<{
|
|
134
|
+
author: string;
|
|
135
|
+
createdAt: string;
|
|
136
|
+
}>;
|
|
109
137
|
};
|
|
110
138
|
/** A non-comment PR event: a commit, force-push, review request or label. */
|
|
111
139
|
export interface ActivityEvent {
|
|
@@ -9,9 +9,8 @@ function isBotReview(review) {
|
|
|
9
9
|
return isBotAuthor(review.user?.login ?? '', review.user?.type);
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* for CHANGES_REQUESTED or APPROVED states.
|
|
12
|
+
* Each human reviewer's standing verdict: their latest APPROVED or
|
|
13
|
+
* CHANGES_REQUESTED review, dropped again by a later DISMISSED one.
|
|
15
14
|
*
|
|
16
15
|
* Only APPROVED, CHANGES_REQUESTED and DISMISSED change a reviewer's standing
|
|
17
16
|
* verdict on GitHub. COMMENTED is also what GitHub records for every inline
|
|
@@ -20,11 +19,7 @@ function isBotReview(review) {
|
|
|
20
19
|
* Bot-authored reviews (e.g. an AI review bot posting APPROVE) are ignored so a
|
|
21
20
|
* bot alone never reads as maintainer approval or a changes request (#1840).
|
|
22
21
|
*/
|
|
23
|
-
|
|
24
|
-
if (reviews.length === 0) {
|
|
25
|
-
return 'review_required';
|
|
26
|
-
}
|
|
27
|
-
// Group reviews by user, keeping each user's latest verdict
|
|
22
|
+
function standingVerdicts(reviews) {
|
|
28
23
|
const latestByUser = new Map();
|
|
29
24
|
for (const review of reviews) {
|
|
30
25
|
const login = review.user?.login;
|
|
@@ -35,10 +30,18 @@ export function determineReviewDecision(reviews) {
|
|
|
35
30
|
latestByUser.delete(login);
|
|
36
31
|
}
|
|
37
32
|
else if (state === 'APPROVED' || state === 'CHANGES_REQUESTED') {
|
|
38
|
-
latestByUser.set(login,
|
|
33
|
+
latestByUser.set(login, review);
|
|
39
34
|
}
|
|
40
35
|
}
|
|
41
|
-
|
|
36
|
+
return Array.from(latestByUser.values());
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Determine review decision from reviews list: changes requested when any
|
|
40
|
+
* reviewer's standing verdict ({@link standingVerdicts}) is CHANGES_REQUESTED,
|
|
41
|
+
* otherwise approved when any is APPROVED.
|
|
42
|
+
*/
|
|
43
|
+
export function determineReviewDecision(reviews) {
|
|
44
|
+
const states = standingVerdicts(reviews).map((review) => review.state);
|
|
42
45
|
if (states.includes('CHANGES_REQUESTED')) {
|
|
43
46
|
return 'changes_requested';
|
|
44
47
|
}
|
|
@@ -48,22 +51,52 @@ export function determineReviewDecision(reviews) {
|
|
|
48
51
|
return 'review_required';
|
|
49
52
|
}
|
|
50
53
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
54
|
+
* When `login`'s standing approval (see {@link standingVerdicts}) was
|
|
55
|
+
* submitted, or undefined when that account has no standing APPROVED verdict.
|
|
56
|
+
* Logins compare case-insensitively. Lets the status logic tell whether the
|
|
57
|
+
* author of an unanswered comment approved at or after writing it (#1920).
|
|
58
|
+
*/
|
|
59
|
+
export function getStandingApprovalDate(reviews, login) {
|
|
60
|
+
const wanted = login?.toLowerCase();
|
|
61
|
+
if (!wanted)
|
|
62
|
+
return undefined;
|
|
63
|
+
const approval = standingVerdicts(reviews).find((review) => review.state === 'APPROVED' && review.user?.login?.toLowerCase() === wanted);
|
|
64
|
+
return approval?.submitted_at ?? undefined;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The latest CHANGES_REQUESTED review (from any human reviewer).
|
|
53
68
|
* Bot reviews are skipped (#1840): a bot re-reviewing every push would otherwise
|
|
54
69
|
* move the date past the author's fix commit.
|
|
55
70
|
*/
|
|
56
|
-
|
|
71
|
+
function getLatestChangesRequestedReview(reviews) {
|
|
57
72
|
let latest;
|
|
73
|
+
let latestAt;
|
|
58
74
|
for (const review of reviews) {
|
|
59
75
|
if (review.state !== 'CHANGES_REQUESTED' || isBotReview(review))
|
|
60
76
|
continue;
|
|
61
|
-
if (review.submitted_at && (!
|
|
62
|
-
latest = review
|
|
77
|
+
if (review.submitted_at && (!latestAt || review.submitted_at > latestAt)) {
|
|
78
|
+
latest = review;
|
|
79
|
+
latestAt = review.submitted_at;
|
|
63
80
|
}
|
|
64
81
|
}
|
|
65
82
|
return latest;
|
|
66
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the date of the latest CHANGES_REQUESTED review (from any human reviewer).
|
|
86
|
+
* Used to detect needs_changes status when review feedback is in inline comments.
|
|
87
|
+
*/
|
|
88
|
+
export function getLatestChangesRequestedDate(reviews) {
|
|
89
|
+
return getLatestChangesRequestedReview(reviews)?.submitted_at ?? undefined;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The head commit the latest CHANGES_REQUESTED review (from any human
|
|
93
|
+
* reviewer) was submitted against. A head moved onto a new parent since then
|
|
94
|
+
* was rebased, not amended, so its new committer date says nothing about the
|
|
95
|
+
* review (#2042).
|
|
96
|
+
*/
|
|
97
|
+
export function getChangesRequestedCommitSha(reviews) {
|
|
98
|
+
return getLatestChangesRequestedReview(reviews)?.commit_id ?? undefined;
|
|
99
|
+
}
|
|
67
100
|
/**
|
|
68
101
|
* Check if all inline comments in a COMMENTED review are self-replies.
|
|
69
102
|
* A self-reply is when an author replies to their own earlier inline comment.
|
|
@@ -135,15 +168,50 @@ export function getFirstMaintainerResponseAt(comments, reviews, username) {
|
|
|
135
168
|
}
|
|
136
169
|
return earliest;
|
|
137
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Associations GitHub reports for an account with no tie to the repository.
|
|
173
|
+
* CONTRIBUTOR is not one of them: an outside token sees a maintainer whose
|
|
174
|
+
* organization membership is private as CONTRIBUTOR.
|
|
175
|
+
*/
|
|
176
|
+
const NO_STANDING_ASSOCIATIONS = new Set([
|
|
177
|
+
'NONE',
|
|
178
|
+
'FIRST_TIMER',
|
|
179
|
+
'FIRST_TIME_CONTRIBUTOR',
|
|
180
|
+
'MANNEQUIN',
|
|
181
|
+
]);
|
|
182
|
+
/** Lower-cased logins of everyone who submitted a review, in any state, or an inline review comment on the PR. */
|
|
183
|
+
function prReviewers(reviews, reviewComments) {
|
|
184
|
+
const logins = new Set();
|
|
185
|
+
for (const list of [reviews, reviewComments]) {
|
|
186
|
+
for (const item of list) {
|
|
187
|
+
const login = item.user?.login;
|
|
188
|
+
if (login)
|
|
189
|
+
logins.add(login.toLowerCase());
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return logins;
|
|
193
|
+
}
|
|
138
194
|
/**
|
|
139
195
|
* Check if there are unresponded comments from maintainers.
|
|
140
196
|
* Combines issue comments and review comments into a timeline,
|
|
141
197
|
* then finds maintainer comments after the user's last comment.
|
|
198
|
+
*
|
|
199
|
+
* Whose items count (#1921): every review from another human, and every issue
|
|
200
|
+
* comment from another human except a passer-by's. A passer-by is an account
|
|
201
|
+
* whose association is NONE, FIRST_TIMER, FIRST_TIME_CONTRIBUTOR or MANNEQUIN
|
|
202
|
+
* ({@link NO_STANDING_ASSOCIATIONS}) and that has submitted no review (in any
|
|
203
|
+
* state) and no inline review comment on this PR. So an OWNER, MEMBER,
|
|
204
|
+
* COLLABORATOR or CONTRIBUTOR always counts, anyone who reviewed the PR counts
|
|
205
|
+
* whatever their association, and an issue comment with no association data
|
|
206
|
+
* counts: missing a maintainer costs more than surfacing a passer-by. This is
|
|
207
|
+
* deliberately wider than {@link isMaintainerEngagement}, which drives the
|
|
208
|
+
* dormancy clock.
|
|
142
209
|
*/
|
|
143
210
|
export function checkUnrespondedComments(comments, reviews, reviewComments, username) {
|
|
144
211
|
// Combine comments and reviews into a timeline
|
|
145
212
|
const timeline = [];
|
|
146
213
|
const usernameLower = username.toLowerCase();
|
|
214
|
+
const reviewers = prReviewers(reviews, reviewComments);
|
|
147
215
|
for (const comment of comments) {
|
|
148
216
|
const author = comment.user?.login || 'unknown';
|
|
149
217
|
timeline.push({
|
|
@@ -152,6 +220,7 @@ export function checkUnrespondedComments(comments, reviews, reviewComments, user
|
|
|
152
220
|
body: comment.body || '',
|
|
153
221
|
createdAt: comment.created_at,
|
|
154
222
|
isUser: author.toLowerCase() === usernameLower,
|
|
223
|
+
isPasserBy: NO_STANDING_ASSOCIATIONS.has(comment.author_association ?? '') && !reviewers.has(author.toLowerCase()),
|
|
155
224
|
});
|
|
156
225
|
}
|
|
157
226
|
for (const review of reviews) {
|
|
@@ -196,6 +265,7 @@ export function checkUnrespondedComments(comments, reviews, reviewComments, user
|
|
|
196
265
|
}
|
|
197
266
|
// Find maintainer comments after the user's last comment
|
|
198
267
|
let lastMaintainerComment;
|
|
268
|
+
const unrespondedComments = [];
|
|
199
269
|
for (const item of timeline) {
|
|
200
270
|
if (item.isUser)
|
|
201
271
|
continue; // Skip user's own comments
|
|
@@ -203,6 +273,8 @@ export function checkUnrespondedComments(comments, reviews, reviewComments, user
|
|
|
203
273
|
continue; // Skip deleted/null accounts
|
|
204
274
|
if (isBotAuthor(item.author, item.userType))
|
|
205
275
|
continue; // Skip bots
|
|
276
|
+
if (item.isPasserBy)
|
|
277
|
+
continue; // Skip accounts with no tie to the repository or the PR (#1921)
|
|
206
278
|
// Skip pure acknowledgments here, not after the loop, so a later "thanks"
|
|
207
279
|
// does not clear an earlier unanswered request (#1916). A review with
|
|
208
280
|
// inline comments is never skipped: those carry feedback beyond the
|
|
@@ -212,6 +284,7 @@ export function checkUnrespondedComments(comments, reviews, reviewComments, user
|
|
|
212
284
|
continue;
|
|
213
285
|
const itemTime = new Date(item.createdAt);
|
|
214
286
|
if (!lastUserCommentTime || itemTime > lastUserCommentTime) {
|
|
287
|
+
unrespondedComments.push({ author: item.author, createdAt: item.createdAt });
|
|
215
288
|
lastMaintainerComment = {
|
|
216
289
|
author: item.author,
|
|
217
290
|
body: item.body.slice(0, 200) + (item.body.length > 200 ? '...' : ''),
|
|
@@ -222,6 +295,7 @@ export function checkUnrespondedComments(comments, reviews, reviewComments, user
|
|
|
222
295
|
return {
|
|
223
296
|
hasUnrespondedComment: !!lastMaintainerComment,
|
|
224
297
|
lastMaintainerComment,
|
|
298
|
+
unrespondedComments,
|
|
225
299
|
};
|
|
226
300
|
}
|
|
227
301
|
/**
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { rethrowRejections } from './concurrency.js';
|
|
9
9
|
import { ConfigurationError, ValidationError, describeError, getHttpStatusCode, isRateLimitOrAuthError, } from './errors.js';
|
|
10
10
|
import { debug, warn } from './logger.js';
|
|
11
|
-
import { paginateAllDetailed } from './pagination.js';
|
|
11
|
+
import { paginateAllDetailed, searchAllPages } from './pagination.js';
|
|
12
12
|
import { isOwnRepo, isUntrackedOrg, parseGitHubUrl } from './urls.js';
|
|
13
13
|
const MODULE = 'reviewed-prs';
|
|
14
14
|
/**
|
|
@@ -83,38 +83,20 @@ class ReviewedPRFilter {
|
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* Read one search page by page, most recently updated first, up to
|
|
86
|
-
* {@link REVIEWED_PR_SEARCH_MAX_PAGES}. A page that fails
|
|
87
|
-
* with what was read so far and the failure recorded
|
|
86
|
+
* {@link REVIEWED_PR_SEARCH_MAX_PAGES} (`searchAllPages`). A page that fails
|
|
87
|
+
* ends the search with what was read so far and the failure recorded, the
|
|
88
|
+
* first page included: the other search still runs. A rate-limit or auth
|
|
88
89
|
* error propagates instead.
|
|
89
90
|
*/
|
|
90
91
|
async function searchPages(octokit, q) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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;
|
|
92
|
+
try {
|
|
93
|
+
return await searchAllPages((page) => octokit.search.issuesAndPullRequests({ q, page, sort: 'updated', order: 'desc', per_page: SEARCH_PER_PAGE }), REVIEWED_PR_SEARCH_MAX_PAGES, SEARCH_PER_PAGE);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (isRateLimitOrAuthError(error))
|
|
97
|
+
throw error;
|
|
98
|
+
return { items: [], totalCount: 0, pagesRead: 0, incomplete: false, truncated: true, failure: { page: 1, error } };
|
|
116
99
|
}
|
|
117
|
-
return result;
|
|
118
100
|
}
|
|
119
101
|
/** Why a search did not cover every result: a failed page, else the page cap; undefined when it did. */
|
|
120
102
|
function coverageWarning(subject, pages) {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
* and `PRMonitor.fetchCompareStatus`; orchestration, the compare call, the
|
|
30
30
|
* dismiss check and the warnings live in commands/daily-reviewed-prs.ts.
|
|
31
31
|
*/
|
|
32
|
+
import { commitDateOf } from './commit-date.js';
|
|
32
33
|
import { isBotAuthor, isQuoteReplyTo, isReactionOnlyComment, proseWithoutCode } from './comment-utils.js';
|
|
33
34
|
import { debug } from './logger.js';
|
|
34
35
|
const MODULE = 'reviewed-prs';
|
|
@@ -124,20 +125,6 @@ function scanUser(entries, usernameLower) {
|
|
|
124
125
|
}
|
|
125
126
|
return user;
|
|
126
127
|
}
|
|
127
|
-
/**
|
|
128
|
-
* The date a commit was pushed under: the committer date when the author
|
|
129
|
-
* also committed it (their own amend or rebase moved it, which is the
|
|
130
|
-
* force-push case this feature exists for), the author date when someone
|
|
131
|
-
* else rewrote it (a maintainer's rebase does not make the author's old
|
|
132
|
-
* work new). Either falls back to the other when missing.
|
|
133
|
-
*/
|
|
134
|
-
function commitDateOf(entry) {
|
|
135
|
-
const authorDate = entry.commit.author?.date;
|
|
136
|
-
const committerDate = entry.commit.committer?.date;
|
|
137
|
-
const login = entry.author?.login?.toLowerCase();
|
|
138
|
-
const isOwnRewrite = login !== undefined && entry.committer?.login?.toLowerCase() === login;
|
|
139
|
-
return isOwnRewrite ? (committerDate ?? authorDate) : (authorDate ?? committerDate);
|
|
140
|
-
}
|
|
141
128
|
/** More than one parent: an "Update branch" or upstream merge, which carries no new work of its own. */
|
|
142
129
|
function isMergeCommit(entry) {
|
|
143
130
|
return (entry.parents?.length ?? 0) > 1;
|
|
@@ -146,7 +133,13 @@ function isMergeCommit(entry) {
|
|
|
146
133
|
function toDatedCommit(entry, usernameLower) {
|
|
147
134
|
if (isMergeCommit(entry))
|
|
148
135
|
return undefined;
|
|
149
|
-
|
|
136
|
+
// Committer date only for the author's own amend or rebase (the force-push case this feature exists for).
|
|
137
|
+
const date = commitDateOf({
|
|
138
|
+
authorDate: entry.commit.author?.date,
|
|
139
|
+
committerDate: entry.commit.committer?.date,
|
|
140
|
+
authorLogin: entry.author?.login,
|
|
141
|
+
committerLogin: entry.committer?.login,
|
|
142
|
+
});
|
|
150
143
|
const atMs = parseMs(date);
|
|
151
144
|
if (!date || atMs === undefined)
|
|
152
145
|
return undefined;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retention for the rejected state copies under `~/.oss-autopilot` (#1956).
|
|
3
|
+
*
|
|
4
|
+
* {@link preserveRejected} keeps a file that failed validation as
|
|
5
|
+
* `<name>.json.rejected-<ms>` beside it so the user can recover it by hand:
|
|
6
|
+
* `state.json` (state-persistence.ts), `state-cache.json`
|
|
7
|
+
* (gist-state-store.ts) and `local-config.json` (local-config.ts). Nothing
|
|
8
|
+
* reads them back, and one bad night can write dozens.
|
|
9
|
+
*
|
|
10
|
+
* Kept: the newest {@link REJECTED_KEEP} of each kind, the oldest of each kind
|
|
11
|
+
* (the first copy of an incident is the one most likely to hold the state
|
|
12
|
+
* from before it), and every copy younger than {@link REJECTED_MIN_AGE_DAYS}.
|
|
13
|
+
* Only direct children of the data
|
|
14
|
+
* directory named like what {@link preserveRejected} writes are considered,
|
|
15
|
+
* and only regular files: a symlink or a directory with a matching name is
|
|
16
|
+
* left alone.
|
|
17
|
+
*/
|
|
18
|
+
export declare const REJECTED_KEEP = 5;
|
|
19
|
+
export declare const REJECTED_MIN_AGE_DAYS = 7;
|
|
20
|
+
export declare const DAY_MS: number;
|
|
21
|
+
/** `cleanup` keeps a worktree touched within this many days (commands/cleanup.ts). */
|
|
22
|
+
export declare const WORKTREE_MIN_AGE_DAYS = 14;
|
|
23
|
+
/** Directory names the overnight preparer gives its worktrees: `<owner>-<repo>-<n>`, `...-issue-<n>`. */
|
|
24
|
+
export declare const WORKTREE_NAME: RegExp;
|
|
25
|
+
/** True when `child`, with every symlink resolved, sits strictly inside `parent`. */
|
|
26
|
+
export declare function isInside(parent: string, child: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Rejected copies in `dataDir` that retention no longer covers, in no order.
|
|
29
|
+
* Read-only. Throws on an unreadable directory; a missing one is empty.
|
|
30
|
+
*/
|
|
31
|
+
export declare function staleRejectedCopies(dataDir: string, now?: number): string[];
|
|
32
|
+
export interface StaleDataCounts {
|
|
33
|
+
/** Directories under `worktrees/` named like the overnight preparer's; not judged, so not all removable. */
|
|
34
|
+
worktrees: number;
|
|
35
|
+
/**
|
|
36
|
+
* Those whose own mtime is at least {@link WORKTREE_MIN_AGE_DAYS} days old:
|
|
37
|
+
* an upper bound by age only. `cleanup` also checks the index's mtime and
|
|
38
|
+
* that the worktree is clean and pushed, so it may remove fewer.
|
|
39
|
+
*/
|
|
40
|
+
oldWorktrees: number;
|
|
41
|
+
/** Rejected state copies past retention. */
|
|
42
|
+
rejected: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Counts for `doctor` and `startup` from directory listings only: no Git runs,
|
|
46
|
+
* so nothing a worktree's config names is executed. Which worktrees `cleanup`
|
|
47
|
+
* would remove is its own (slower) dry run. Throws on an unreadable directory.
|
|
48
|
+
*/
|
|
49
|
+
export declare function countStaleData(dataDir: string, now?: number): StaleDataCounts;
|
|
50
|
+
/** How {@link preserveRejected} keeps the rejected file. */
|
|
51
|
+
export type RejectedCopySource =
|
|
52
|
+
/** Copy the file; the copy keeps its mode. */
|
|
53
|
+
'copy'
|
|
54
|
+
/** Rename the file out of the way, so the next write cannot overwrite it. */
|
|
55
|
+
| 'move'
|
|
56
|
+
/** Write this text instead (owner-only), for content that was never on disk. */
|
|
57
|
+
| {
|
|
58
|
+
content: string;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Keep a file that failed validation as `<filePath>.rejected-<ms>` for
|
|
62
|
+
* recovery by hand, then prune its directory's rejected copies past retention
|
|
63
|
+
* ({@link pruneRejectedCopies}, which never throws). Returns the copy's path.
|
|
64
|
+
* Throws when the copy cannot be made; callers report that their own way.
|
|
65
|
+
*/
|
|
66
|
+
export declare function preserveRejected(filePath: string, source: RejectedCopySource): string;
|
|
67
|
+
export interface PruneResult {
|
|
68
|
+
/** Paths deleted (or, from a dry run, the paths that would be). */
|
|
69
|
+
removed: string[];
|
|
70
|
+
errors: string[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Delete what {@link staleRejectedCopies} lists. Never throws: it runs beside
|
|
74
|
+
* state loading and the overnight run, and a failed prune must not fail
|
|
75
|
+
* either. Every failure, and every prune that deleted something, is logged at
|
|
76
|
+
* warn, so an automatic delete always leaves a trace.
|
|
77
|
+
*/
|
|
78
|
+
export declare function pruneRejectedCopies(dataDir: string, now?: number): PruneResult;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retention for the rejected state copies under `~/.oss-autopilot` (#1956).
|
|
3
|
+
*
|
|
4
|
+
* {@link preserveRejected} keeps a file that failed validation as
|
|
5
|
+
* `<name>.json.rejected-<ms>` beside it so the user can recover it by hand:
|
|
6
|
+
* `state.json` (state-persistence.ts), `state-cache.json`
|
|
7
|
+
* (gist-state-store.ts) and `local-config.json` (local-config.ts). Nothing
|
|
8
|
+
* reads them back, and one bad night can write dozens.
|
|
9
|
+
*
|
|
10
|
+
* Kept: the newest {@link REJECTED_KEEP} of each kind, the oldest of each kind
|
|
11
|
+
* (the first copy of an incident is the one most likely to hold the state
|
|
12
|
+
* from before it), and every copy younger than {@link REJECTED_MIN_AGE_DAYS}.
|
|
13
|
+
* Only direct children of the data
|
|
14
|
+
* directory named like what {@link preserveRejected} writes are considered,
|
|
15
|
+
* and only regular files: a symlink or a directory with a matching name is
|
|
16
|
+
* left alone.
|
|
17
|
+
*/
|
|
18
|
+
import * as fs from 'node:fs';
|
|
19
|
+
import path from 'node:path';
|
|
20
|
+
import { errorMessage } from './errors.js';
|
|
21
|
+
import { warn } from './logger.js';
|
|
22
|
+
const MODULE = 'stale-data';
|
|
23
|
+
export const REJECTED_KEEP = 5;
|
|
24
|
+
export const REJECTED_MIN_AGE_DAYS = 7;
|
|
25
|
+
export const DAY_MS = 24 * 60 * 60 * 1000;
|
|
26
|
+
/** `cleanup` keeps a worktree touched within this many days (commands/cleanup.ts). */
|
|
27
|
+
export const WORKTREE_MIN_AGE_DAYS = 14;
|
|
28
|
+
/** Directory names the overnight preparer gives its worktrees: `<owner>-<repo>-<n>`, `...-issue-<n>`. */
|
|
29
|
+
export const WORKTREE_NAME = /^[\w.-]+-\d+$/;
|
|
30
|
+
/** `<kind>.json.rejected-<ms>`, the name {@link preserveRejected} gives any `<kind>.json`. */
|
|
31
|
+
const REJECTED_PATTERN = /^([\w-]+)\.json\.rejected-(\d+)$/;
|
|
32
|
+
/** True when `child`, with every symlink resolved, sits strictly inside `parent`. */
|
|
33
|
+
export function isInside(parent, child) {
|
|
34
|
+
const rel = path.relative(fs.realpathSync(parent), fs.realpathSync(child));
|
|
35
|
+
return rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel);
|
|
36
|
+
}
|
|
37
|
+
function readRejectedCopy(dataDir, name) {
|
|
38
|
+
const match = REJECTED_PATTERN.exec(name);
|
|
39
|
+
if (!match)
|
|
40
|
+
return null;
|
|
41
|
+
const file = path.join(dataDir, name);
|
|
42
|
+
const stat = fs.lstatSync(file);
|
|
43
|
+
if (!stat.isFile() || !isInside(dataDir, file))
|
|
44
|
+
return null;
|
|
45
|
+
return { file, kind: match[1], lastTouchedMs: Math.max(Number(match[2]), stat.mtimeMs) };
|
|
46
|
+
}
|
|
47
|
+
/** One unreadable entry (a file that vanished mid-scan) is skipped, not fatal. */
|
|
48
|
+
function tryReadRejectedCopy(dataDir, name) {
|
|
49
|
+
try {
|
|
50
|
+
return readRejectedCopy(dataDir, name);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
warn(MODULE, `Skipping ${name} in ${dataDir}: ${errorMessage(err)}`);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** A total order, so copies with equal timestamps still rank: by time, then by name. */
|
|
58
|
+
function isNewer(a, b) {
|
|
59
|
+
if (a.kind !== b.kind || a.lastTouchedMs < b.lastTouchedMs)
|
|
60
|
+
return false;
|
|
61
|
+
return a.lastTouchedMs > b.lastTouchedMs || a.file.localeCompare(b.file) > 0;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Rejected copies in `dataDir` that retention no longer covers, in no order.
|
|
65
|
+
* Read-only. Throws on an unreadable directory; a missing one is empty.
|
|
66
|
+
*/
|
|
67
|
+
export function staleRejectedCopies(dataDir, now = Date.now()) {
|
|
68
|
+
if (!fs.existsSync(dataDir))
|
|
69
|
+
return [];
|
|
70
|
+
const copies = [];
|
|
71
|
+
for (const name of fs.readdirSync(dataDir)) {
|
|
72
|
+
const copy = tryReadRejectedCopy(dataDir, name);
|
|
73
|
+
if (copy)
|
|
74
|
+
copies.push(copy);
|
|
75
|
+
}
|
|
76
|
+
const cutoff = now - REJECTED_MIN_AGE_DAYS * DAY_MS;
|
|
77
|
+
// ponytail: O(n^2) rank instead of a sort; n is a handful of files.
|
|
78
|
+
const isCovered = (copy) => copy.lastTouchedMs >= cutoff ||
|
|
79
|
+
copies.filter((other) => isNewer(other, copy)).length < REJECTED_KEEP ||
|
|
80
|
+
copies.every((other) => !isNewer(copy, other));
|
|
81
|
+
return copies.filter((copy) => !isCovered(copy)).map((copy) => copy.file);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Counts for `doctor` and `startup` from directory listings only: no Git runs,
|
|
85
|
+
* so nothing a worktree's config names is executed. Which worktrees `cleanup`
|
|
86
|
+
* would remove is its own (slower) dry run. Throws on an unreadable directory.
|
|
87
|
+
*/
|
|
88
|
+
export function countStaleData(dataDir, now = Date.now()) {
|
|
89
|
+
const root = path.join(dataDir, 'worktrees');
|
|
90
|
+
const hasRoot = fs.existsSync(root) && fs.lstatSync(root).isDirectory();
|
|
91
|
+
const entries = hasRoot ? fs.readdirSync(root, { withFileTypes: true }) : [];
|
|
92
|
+
const worktrees = entries.filter((entry) => entry.isDirectory() && WORKTREE_NAME.test(entry.name));
|
|
93
|
+
const cutoff = now - WORKTREE_MIN_AGE_DAYS * DAY_MS;
|
|
94
|
+
const old = worktrees.filter((entry) => fs.lstatSync(path.join(root, entry.name)).mtimeMs <= cutoff);
|
|
95
|
+
return {
|
|
96
|
+
worktrees: worktrees.length,
|
|
97
|
+
oldWorktrees: old.length,
|
|
98
|
+
rejected: staleRejectedCopies(dataDir, now).length,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Keep a file that failed validation as `<filePath>.rejected-<ms>` for
|
|
103
|
+
* recovery by hand, then prune its directory's rejected copies past retention
|
|
104
|
+
* ({@link pruneRejectedCopies}, which never throws). Returns the copy's path.
|
|
105
|
+
* Throws when the copy cannot be made; callers report that their own way.
|
|
106
|
+
*/
|
|
107
|
+
export function preserveRejected(filePath, source) {
|
|
108
|
+
const rejectedPath = `${filePath}.rejected-${Date.now()}`;
|
|
109
|
+
if (source === 'copy')
|
|
110
|
+
fs.copyFileSync(filePath, rejectedPath);
|
|
111
|
+
else if (source === 'move')
|
|
112
|
+
fs.renameSync(filePath, rejectedPath);
|
|
113
|
+
else
|
|
114
|
+
fs.writeFileSync(rejectedPath, source.content, { encoding: 'utf8', mode: 0o600 });
|
|
115
|
+
pruneRejectedCopies(path.dirname(rejectedPath));
|
|
116
|
+
return rejectedPath;
|
|
117
|
+
}
|
|
118
|
+
function didRemove(file, errors) {
|
|
119
|
+
try {
|
|
120
|
+
fs.unlinkSync(file);
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
errors.push(`Could not delete rejected state copy ${file}: ${errorMessage(err)}`);
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
function listStale(dataDir, now, errors) {
|
|
129
|
+
try {
|
|
130
|
+
return staleRejectedCopies(dataDir, now);
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
errors.push(`Could not prune rejected state copies in ${dataDir}: ${errorMessage(err)}`);
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Delete what {@link staleRejectedCopies} lists. Never throws: it runs beside
|
|
139
|
+
* state loading and the overnight run, and a failed prune must not fail
|
|
140
|
+
* either. Every failure, and every prune that deleted something, is logged at
|
|
141
|
+
* warn, so an automatic delete always leaves a trace.
|
|
142
|
+
*/
|
|
143
|
+
export function pruneRejectedCopies(dataDir, now = Date.now()) {
|
|
144
|
+
const errors = [];
|
|
145
|
+
const removed = listStale(dataDir, now, errors).filter((file) => didRemove(file, errors));
|
|
146
|
+
for (const error of errors)
|
|
147
|
+
warn(MODULE, error);
|
|
148
|
+
if (removed.length > 0) {
|
|
149
|
+
const names = removed.map((file) => path.basename(file)).join(', ');
|
|
150
|
+
warn(MODULE, `Pruned ${removed.length} rejected state copy(ies) from ${dataDir}, keeping the newest ${REJECTED_KEEP} and the oldest of each kind and all younger than ${REJECTED_MIN_AGE_DAYS} days: ${names}`);
|
|
151
|
+
}
|
|
152
|
+
return { removed, errors };
|
|
153
|
+
}
|