-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-test.py
131 lines (111 loc) · 5.29 KB
/
git-test.py
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python
import argparse
import os
from datetime import datetime
from datetime import timedelta
from random import randint
from subprocess import Popen
import sys
def main(def_args=sys.argv[1:]):
args = arguments(def_args)
curr_date = datetime.now()
directory = 'repository-' + curr_date.strftime('%Y-%m-%d-%H-%M-%S')
repository = args.repository
user_name = args.user_name
user_email = args.user_email
if repository is not None:
start = repository.rfind('/') + 1
end = repository.rfind('.')
directory = repository[start:end]
no_weekends = args.no_weekends
frequency = args.frequency
days_before = args.days_before
if days_before < 0:
sys.exit('days_before must not be negative')
days_after = args.days_after
if days_after < 0:
sys.exit('days_after must not be negative')
os.mkdir(directory)
os.chdir(directory)
if user_name is not None:
run(['git', 'config', 'user.name', user_name])
if user_email is not None:
run(['git', 'config', 'user.email', user_email])
start_date = curr_date.replace(hour=20, minute=0) - timedelta(days_before)
for day in (start_date + timedelta(n) for n
in range(days_before + days_after)):
if (not no_weekends or day.weekday() < 5) \
and randint(0, 100) < frequency:
for commit_time in (day + timedelta(minutes=m)
for m in range(contributions_per_day(args))):
contribute(commit_time)
if repository is not None:
run(['git', 'remote', 'add', 'origin', repository])
run(['git', 'branch', '-M', 'main'])
run(['git', 'push', '-u', 'origin', 'main'])
print('\nRepository generation ' +
'\x1b[6;30;42mcompleted successfully\x1b[0m!')
def contribute(date):
with open(os.path.join(os.getcwd(), 'README.md'), 'a') as file:
file.write(message(date) + '\n\n')
run(['git', 'add', '.'])
messageCommit = input(date.strftime('Commit message at %d -%m -%Y %H:%M :'))
run(['git', 'commit', '-m', '"%s"' % messageCommit,
'--date', date.strftime('"%Y-%m-%d %H:%M:%S"')])
def run(commands):
Popen(commands).wait()
def message(date):
return date.strftime('Contribution: %Y-%m-%d %H:%M')
def contributions_per_day(args):
max_c = args.max_commits
if max_c > 20:
max_c = 20
if max_c < 1:
max_c = 1
##fixed to 5 commits per day
# max_c = 5
return randint(1, max_c)
def arguments(argsval):
parser = argparse.ArgumentParser()
parser.add_argument('-nw', '--no_weekends',
required=False, action='store_true', default=False,
help="""do not commit on weekends""")
parser.add_argument('-mc', '--max_commits', type=int, default=10,
required=False, help="""Defines the maximum amount of
commits a day the script can make. Accepts a number
from 1 to 20. If N is specified the script commits
from 1 to N times a day. The exact number of commits
is defined randomly for each day. The default value
is 10.""")
parser.add_argument('-fr', '--frequency', type=int, default=80,
required=False, help="""Percentage of days when the
script performs commits. If N is specified, the script
will commit N%% of days in a year. The default value
is 80.""")
parser.add_argument('-r', '--repository', type=str, required=False,
help="""A link on an empty non-initialized remote git
repository. If specified, the script pushes the changes
to the repository. The link is accepted in SSH or HTTPS
format. For example: git@github.com:user/repo.git or
https://github.com/user/repo.git""")
parser.add_argument('-un', '--user_name', type=str, required=False,
help="""Overrides user.name git config.
If not specified, the global config is used.""")
parser.add_argument('-ue', '--user_email', type=str, required=False,
help="""Overrides user.email git config.
If not specified, the global config is used.""")
parser.add_argument('-db', '--days_before', type=int, default=365,
required=False, help="""Specifies the number of days
before the current date when the script will start
adding commits. For example: if it is set to 30 the
first commit date will be the current date minus 30
days.""")
parser.add_argument('-da', '--days_after', type=int, default=0,
required=False, help="""Specifies the number of days
after the current date until which the script will be
adding commits. For example: if it is set to 30 the
last commit will be on a future date which is the
current date plus 30 days.""")
return parser.parse_args(argsval)
if __name__ == "__main__":
main()