-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
111 lines (96 loc) · 3.07 KB
/
index.js
File metadata and controls
111 lines (96 loc) · 3.07 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import jsonfile from "jsonfile";
import moment from "moment";
import simpleGit from "simple-git";
import random from "random";
import { CONFIG } from "./config.js";
const path = "./data.json";
const git = simpleGit();
const startDate = moment(`${CONFIG.year}-01-01`);
const endDate = moment(`${CONFIG.year}-12-31`);
const makeCommitsForDay = async (date, commitsCount) => {
for (let i = 0; i < commitsCount; i++) {
const commitDate = date.clone()
.hour(random.int(8, 20))
.minute(random.int(0, 59))
.second(random.int(0, 59));
const data = { date: commitDate.format() };
await jsonfile.writeFile(path, data);
await git.add(path);
await git.commit(`Commit on ${commitDate.format()}`, { "--date": commitDate.format() });
}
};
const run = async () => {
let totalCommits = 0;
const allDays = [];
for (let date = startDate.clone(); date.isSameOrBefore(endDate); date.add(1, "day")) {
allDays.push(date.clone());
}
const commitsDistribution = {
0: 95,
1: 85,
2: 105,
3: 100,
4: 90,
5: 75,
6: 65,
7: 55,
8: 95,
9: 100,
10: 95,
11: 80
};
for (const month in commitsDistribution) {
let monthCommitsLeft = commitsDistribution[month];
const daysInMonth = allDays.filter(d => d.month() === parseInt(month));
const activeDays = daysInMonth.filter(() => random.bool(CONFIG.activeDaysPercentage));
for (let i = 0; i < activeDays.length; i++) {
if (monthCommitsLeft <= 0) break;
const date = activeDays[i];
const isWeekend = [0, 6].includes(date.day());
const isSummer = [5, 6, 7].includes(date.month());
const isWinterHolidays = (date.month() === 11 && date.date() >= 20) || (date.month() === 0 && date.date() <= 10);
let commitsForDay;
if (isSummer) {
if (isWeekend) {
commitsForDay = random.int(0, 1);
} else {
if (Math.random() < 0.8) {
commitsForDay = random.int(1, 2);
} else {
commitsForDay = random.int(2, 4);
}
}
} else if (isWinterHolidays) {
commitsForDay = random.int(0, 1);
} else if (isWeekend) {
if (Math.random() < 0.6) {
commitsForDay = random.int(0, 1);
} else {
commitsForDay = random.int(1, 3);
}
} else {
const rand = Math.random();
if (rand < 0.3) {
commitsForDay = random.int(1, 3);
} else if (rand < 0.7) {
commitsForDay = random.int(3, 6);
} else {
commitsForDay = random.int(6, 10);
}
}
commitsForDay = Math.min(commitsForDay, monthCommitsLeft);
if (commitsForDay > 0) {
monthCommitsLeft -= commitsForDay;
await makeCommitsForDay(date, commitsForDay);
totalCommits += commitsForDay;
}
if (CONFIG.pushOnSunday && date.day() === 0) {
await git.push("origin", "main");
}
}
}
await git.push("origin", "main");
console.log(`Total commits made: ${totalCommits}`);
console.log(`Target was: ${CONFIG.targetCommits}`);
};
run().catch(console.error);