-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit.js
47 lines (40 loc) · 1.6 KB
/
commit.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
41
42
43
44
45
46
47
const simpleGit = require('simple-git');
const git = simpleGit();
const fs = require('fs');
const path = require('path');
const startDate = new Date('2024-01-06');
const endDate = new Date('2024-06-30');
const commitMessage = 'initial commit';
const maxCommitsPerDay = 3;
const minCommitsPerDay = 0;
const minDaysPerWeek = 0;
const maxDaysPerWeek = 3;
const randomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
const isWeekend = (date) => date.getDay() === 0 || date.getDay() === 6;
const makeCommits = async () => {
let currentDate = new Date(startDate);
while (currentDate <= endDate) {
if (!isWeekend(currentDate)) {
const commitDaysThisWeek = randomInt(minDaysPerWeek, maxDaysPerWeek);
for (let i = 0; i < commitDaysThisWeek && currentDate <= endDate; i++) {
if (isWeekend(currentDate)) {
currentDate.setDate(currentDate.getDate() + 1);
continue;
}
const commitsToday = randomInt(minCommitsPerDay, maxCommitsPerDay);
for (let j = 0; j < commitsToday; j++) {
const filePath = path.join(__dirname, 'file.txt');
fs.writeFileSync(filePath, `${commitMessage} ${currentDate}`);
await git.add(filePath);
await git.commit(commitMessage, filePath, { '--date': currentDate.toISOString() });
}
currentDate.setDate(currentDate.getDate() + 1);
}
} else {
currentDate.setDate(currentDate.getDate() + 1);
}
}
};
makeCommits()
.then(() => console.log('Fake commits generated successfully.'))
.catch((err) => console.error('Error generating fake commits:', err));