-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.mjs
More file actions
executable file
·69 lines (64 loc) · 2.02 KB
/
Copy pathscript.mjs
File metadata and controls
executable file
·69 lines (64 loc) · 2.02 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { $ } from "zx";
// commit the empty change dynamic times...
async function mockCommits(
startDate,
endDate,
count = 1,
useDynamic = false,
workdayOnly = false
) {
while (endDate - startDate > 0) {
if (workdayOnly) {
const day = startDate.getDay();
if (day === 0 || day === 6) {
startDate.setDate(startDate.getDate() + 1);
continue;
}
}
const getRandom = (count) => Math.ceil(Math.random() * count);
const execCount = useDynamic ? getRandom(count) : count;
for (let i = 0; i < execCount; i++) {
await $`git commit --allow-empty -m "mock commit (time=${i})" --date=${startDate.toString()}`;
}
startDate.setDate(startDate.getDate() + 1);
}
}
const argv = yargs(hideBin(process.argv))
.option("startDate", {
type: "string",
description:
"YYYY-MM-DD, commit start date, if you don't provide, will automatically grab the latest commit",
})
.option("count", {
type: "number",
description: "commit count per day, default is 1",
default: 1,
})
.option("useDynamic", {
type: "boolean",
description:
"enable than commit count per day will random between 1 ~ argv.count, default is false",
default: false,
})
.option("workdayOnly", {
type: "boolean",
description: "only exec commit in MON~FRI, default is false",
default: false,
})
.option("forcePush", {
type: "boolean",
description: "force push the master branch?",
default: true,
}).argv;
const { startDate, count, useDynamic, workdayOnly, forcePush } = argv;
if (startDate) {
let _startDate = new Date(startDate);
await mockCommits(_startDate, Date.now(), count, useDynamic, workdayOnly);
} else {
// using the latest commit as start, and commit until touch now
const lastCommitDate = await $`git log -1 --format=%cd `;
await mockCommits(lastCommitDate, Date.now(), count, useDynamic, workdayOnly);
}
await $`git push origin master ${forcePush ? "--force" : ""}`;