Open History to see the last commit
1import {
2 isBotLogin,
3 isRosterMaintainer,
4} from '../../scripts/maintainer/config.ts'
5import type { ToolsetConfig } from '../../scripts/maintainer/types.ts'
6
7type SkipInput = {
8 mode: 'auto' | 'manual'
9 isDraft: boolean
10 authorLogin: string | null
11 headCommitAuthorLogin: string | null
12 headSha: string
13 alreadyReviewedSha: string | null
14 machineUserLogin: string
15 config: ToolsetConfig
16}
17
18/**
19 * Decide whether this AI review run should skip, and why.
20 *
21 * Auto mode skips drafts, bot PR authors, roster maintainers, machine-user
22 * head commits, and a head SHA that was already reviewed, in that order.
23 * Manual mode never skips.
24 */
25export function shouldSkip(input: SkipInput) {
26 if (input.mode === 'manual') {
27 return { skip: false, reason: null }
28 }
29
30 if (input.isDraft) {
31 return { skip: true, reason: 'draft' }
32 }
33
34 if (isBotLogin(input.authorLogin, input.config)) {
35 return { skip: true, reason: 'bot-author' }
36 }
37
38 if (isRosterMaintainer(input.authorLogin, input.config)) {
39 return { skip: true, reason: 'maintainer-author' }
40 }
41
42 const isBotHeadCommit =
43 input.headCommitAuthorLogin !== null &&
44 input.headCommitAuthorLogin.toLowerCase() ===
45 input.machineUserLogin.toLowerCase()
46 if (isBotHeadCommit) {
47 return { skip: true, reason: 'bot-head-commit' }
48 }
49
50 if (input.alreadyReviewedSha === input.headSha) {
51 return { skip: true, reason: 'same-sha' }
52 }
53
54 return { skip: false, reason: null }
55}