This repository has been archived on 2023-07-17. You can view files and clone it, but cannot push or open issues or pull requests.
pushee/pushee.py

67 lines
1.7 KiB
Python
Executable file

#!/usr/bin/env python3
import json
import os
from pathlib import Path
import sys
from commands import MergeRequests, UpdateAssignees, Comments, Merge, Test
from gitlab_provider import Gitlab
from kontr_emails import Parser
COMMANDS = {
"mrs": MergeRequests,
"update-assignees": UpdateAssignees,
"comments": Comments,
"merge": Merge,
"test": Test,
}
def print_usage():
print(f"{sys.argv[0]} <command>")
print()
print("Commands:")
print("\tmrs\t\t\tFetch files and create merge requests for them")
print("\tupdate-assignees\tUpdate assignees on MRs")
print("\tcomments\t\tFetch all comments on MRs")
print("\tmerge\t\t\tMerge all MRs")
print("\ttest\t\t\tDebugging function")
# print("Format of date: %Y_%m%d_%H%M%S")
def load_config():
config_file_path = Path("~/.pushee.json").expanduser()
if not os.path.exists(config_file_path):
print("Couldn't find config file", file=sys.stderr)
exit(1)
with open(config_file_path) as config_file:
config = json.load(config_file)
config["token"] = os.getenv("GITLAB_FI_TOKEN")
return config
def main():
config = load_config()
if len(sys.argv) != 2 or sys.argv[1] not in COMMANDS:
print_usage()
exit(2)
details = config["homeworks"][config["homework"]]
submissions = Parser(
details, config["reviewer"], config["homework"]
).parse(config["homework"])
COMMANDS[sys.argv[1]](submissions, Gitlab(config["project_namespace"],
config["project_name"],
config["token"]), details)()
if __name__ == "__main__":
main()