-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcommit_assignment.py
61 lines (40 loc) · 1.52 KB
/
commit_assignment.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
""" Add the completed assignment to github repository. """
import os
from argparse import ArgumentParser
def git_commit(message):
os.system(f'git commit -m "{message}"')
def git_add(filename: str):
os.system(f'git add "{filename}"')
def commit_assignment(filename: str | None, commit_message: str | None):
# If filename not given
if filename is None:
exit()
# Check the file path
if os.path.exists(filename):
git_add(filename)
else:
exit()
# Check commit message
if commit_message:
git_commit(commit_message)
else:
git_commit(f"Added {filename.split('/')[-1]} assignment.")
def get_link_to_submit(filename: str) -> str:
github_link = 'https://github.com/arv-anshul/pw-impact-batch/blob/main/'
MONTH, DATE = filename.split('/')
link_to_answer_sheet = f'{MONTH}/{DATE}/{DATE} - Answer.ipynb'
return github_link + link_to_answer_sheet.replace(' ', r'%20')
def main():
parser = ArgumentParser()
parser.add_argument('--file-name', type=str, default=None,
help='Get the filename to add & commit.')
parser.add_argument('--commit-message', type=str, default=None,
help='Get commit message.')
# Get passed args
args = parser.parse_args()
# Finally commit the file
commit_assignment(filename=args.file_name,
commit_message=args.commit_message)
os.system('echo ' + get_link_to_submit(filename=args.file_name))
if __name__ == '__main__':
main()