()
| 84 | } |
| 85 | |
| 86 | async function getFrequentlyModifiedFiles(): Promise<string[]> { |
| 87 | if (process.env.NODE_ENV === 'test') return [] |
| 88 | if (env.platform === 'win32') return [] |
| 89 | if (!(await getIsGit())) return [] |
| 90 | |
| 91 | try { |
| 92 | // Collect frequently-modified files, preferring the user's own commits. |
| 93 | const userEmail = await getGitEmail() |
| 94 | |
| 95 | const logArgs = [ |
| 96 | 'log', |
| 97 | '-n', |
| 98 | '1000', |
| 99 | '--pretty=format:', |
| 100 | '--name-only', |
| 101 | '--diff-filter=M', |
| 102 | ] |
| 103 | |
| 104 | const counts = new Map<string, number>() |
| 105 | const tallyInto = (stdout: string) => { |
| 106 | for (const line of stdout.split('\n')) { |
| 107 | const f = line.trim() |
| 108 | if (f) counts.set(f, (counts.get(f) ?? 0) + 1) |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | if (userEmail) { |
| 113 | const { stdout } = await execFileNoThrowWithCwd( |
| 114 | 'git', |
| 115 | [...logArgs, `--author=${userEmail}`], |
| 116 | { cwd: getCwd() }, |
| 117 | ) |
| 118 | tallyInto(stdout) |
| 119 | } |
| 120 | |
| 121 | // Fall back to all authors if the user's own history is thin. |
| 122 | if (counts.size < 10) { |
| 123 | const { stdout } = await execFileNoThrowWithCwd(gitExe(), logArgs, { |
| 124 | cwd: getCwd(), |
| 125 | }) |
| 126 | tallyInto(stdout) |
| 127 | } |
| 128 | |
| 129 | const sorted = Array.from(counts.entries()) |
| 130 | .sort((a, b) => b[1] - a[1]) |
| 131 | .map(([p]) => p) |
| 132 | |
| 133 | return pickDiverseCoreFiles(sorted, 5) |
| 134 | } catch (err) { |
| 135 | logError(err as Error) |
| 136 | return [] |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | const ONE_WEEK_IN_MS = 7 * 24 * 60 * 60 * 1000 |
| 141 |
no test coverage detected