Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions contribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys


def main(def_args=sys.argv[1:]):
def main(def_args=sys.argv[1:]) -> None:
args = arguments(def_args)
curr_date = datetime.now()
directory = 'repository-' + curr_date.strftime('%Y-%m-%d-%H-%M-%S')
Expand All @@ -27,9 +27,8 @@ def main(def_args=sys.argv[1:]):
days_after = args.days_after
if days_after < 0:
sys.exit('days_after must not be negative')
os.mkdir(directory)
os.chdir(directory)
run(['git', 'init', '-b', 'main'])

chdir_to_repo(repository, directory)

if user_name is not None:
run(['git', 'config', 'user.name', user_name])
Expand All @@ -55,23 +54,40 @@ def main(def_args=sys.argv[1:]):
'\x1b[6;30;42mcompleted successfully\x1b[0m!')


def contribute(date):
def contribute(date) -> None:
with open(os.path.join(os.getcwd(), 'README.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 chdir_to_repo(repository, directory) -> None:
git_command = ['git', repository, directory]
if ".git" in os.listdir():
git_command.insert(1, 'submodule')
git_command.insert(2, 'add')
else:
git_command.insert(1, 'clone')
if directory not in os.listdir():
try:
run(git_command)
except Exception as e:
print(e)
raise Exception('Repository does not exist. Please check if the link is ssh and do your user has access to your ssh keys')
os.chdir(directory)
run(['git', 'pull'])


def run(commands):
def run(commands) -> None:
Popen(commands).wait()


def message(date):
def message(date) -> str:
return date.strftime('Contribution: %Y-%m-%d %H:%M')


def contributions_per_day(args):
def contributions_per_day(args) -> int:
max_c = args.max_commits
if max_c > 20:
max_c = 20
Expand All @@ -80,7 +96,7 @@ def contributions_per_day(args):
return randint(1, max_c)


def arguments(argsval):
def arguments(argsval) -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument('-nw', '--no_weekends',
required=False, action='store_true', default=False,
Expand Down