-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
47 lines (40 loc) · 1.5 KB
/
main.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
const simpleGit = require('simple-git');
// Function to make a commit and push for a specific date
async function makeCommit(date, commits) {
const git = simpleGit();
const dateString = date.toISOString();
// Set the environment variable GIT_AUTHOR_DATE and GIT_COMMITTER_DATE
// to the specified date before making the commit
process.env['GIT_AUTHOR_DATE'] = dateString;
process.env['GIT_COMMITTER_DATE'] = dateString;
try {
// Make the commits
const commit = commits[Math.floor(Math.random() * commits.length)];
await git.add('./*').commit(commit, {'--allow-empty': null});
// Push the commits to the remote repository
await git.push();
console.log(`Committed and pushed ${commits.length} commits for ${dateString} successfully!`);
} catch (err) {
console.error(`Failed to commit and push for ${dateString}:`, err);
}
}
// Function to make commits and push for a date range
async function makeCommitsForDateRange(startDate, endDate, commits) {
const currentDate = new Date(startDate);
while (currentDate <= endDate) {
await makeCommit(currentDate, commits);
// Increment the current date by one day
currentDate.setDate(currentDate.getDate() + 1);
}
}
// Usage example
const startDate = new Date('2022-12-09T12:00:00Z');
const endDate = new Date('2022-12-10T12:00:00Z');
const commits = [
'Creted serverless.yml',
'Created apis',
'Added authorizer',
'Added dynamodb',
'Set configuration'
];
makeCommitsForDateRange(startDate, endDate, commits);