-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontribute.py
130 lines (108 loc) · 4.91 KB
/
contribute.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
#!/usr/bin/env python
import argparse
import errno
import os
import stat
import shutil
from datetime import datetime
from datetime import timedelta
from random import randint
from subprocess import Popen
import sys
# NUM = 366
def remove_readonly(func, path, excinfo):
os.chmod(path, stat.S_IWRITE)
func(path)
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
# if os.path.exists(directory):
# shutil.rmtree(directory, onerror=remove_readonly)
# os.mkdir(directory)
# os.chdir(directory)
# run(['git', 'init'])
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])
if args.start_date is None:
NUM = args.days_ago
start_date = curr_date.replace(hour=20, minute=0) - timedelta(NUM)
else:
start_date = datetime.strptime(args.start_date, "%Y/%m/%d, %H:%M:%S")
NUM = (curr_date.replace(hour=20, minute=0) - start_date).days
for day in (start_date + timedelta(n) for n in range(NUM)):
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(), 'history.md'), 'a') as file:
file.write(message(date) + '\n\n')
run(['git', 'add', '.'])
run(['git', 'commit', '-m', '"%s"' % message(date),
'--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
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=7,
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, default="GameDev5916",
help="""Overrides user.name git config.
If not specified, the global config is used.""")
parser.add_argument('-ue', '--user_email', type=str, required=False, default="rostyslavhan903@gmail.com",
help="""Overrides user.email git config.
If not specified, the global config is used.""")
parser.add_argument('-da', '--days_ago', type=int, required=False, default=25,
help="""Show them if you want to contribute a few days in advance.""")
parser.add_argument('-sd', '--start_date', type=str, required=False,
help="""Start Date.""")
return parser.parse_args(argsval)
if __name__ == "__main__":
main()