forked from sindresorhus/awesome-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-repo-age.js
40 lines (33 loc) · 1001 Bytes
/
git-repo-age.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import {execa} from 'execa';
import {lintRule} from 'unified-lint-rule';
const oneDay = 24 * 60 * 60 * 1000;
const minGitRepoAgeDays = 30;
const minGitRepoAgeMs = minGitRepoAgeDays * oneDay;
const gitRepoAgeRule = lintRule('remark-lint:awesome-git-repo-age', async (ast, file) => {
const {dirname} = file;
try {
const {stdout: firstCommitHash} = await execa('git', [
'rev-list',
'--max-parents=0',
'HEAD',
], {
cwd: dirname,
});
const {stdout: firstCommitDate} = await execa('git', [
'show',
'-s',
'--format=%ci',
firstCommitHash,
], {
cwd: dirname,
});
const date = new Date(firstCommitDate);
const now = new Date();
if (now - date < minGitRepoAgeMs) {
file.message(`Git repository must be at least ${minGitRepoAgeDays} days old`);
}
} catch {
file.message('Awesome list must reside in a valid deep-cloned Git repository (see https://github.com/sindresorhus/awesome-lint#tip for more information)');
}
});
export default gitRepoAgeRule;