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

70 lines
1.6 KiB
Python
Raw Normal View History

2019-11-22 15:03:21 +01:00
#!/usr/bin/env python3
2019-12-12 12:08:04 +01:00
import json
import os
from pathlib import Path
2019-11-22 15:03:21 +01:00
import sys
2019-11-22 20:12:37 +01:00
from commands import MergeRequests, UpdateAssignees, Comments, Merge, Test
2020-04-03 14:10:37 +02:00
from gitlab_provider import Gitlab
2019-11-30 17:48:29 +01:00
from kontr_emails import Parser
2019-11-22 15:03:21 +01:00
COMMANDS = {
"mrs": MergeRequests,
"update-assignees": UpdateAssignees,
"comments": Comments,
"merge": Merge,
"test": Test,
2019-11-22 15:03:21 +01:00
}
2019-11-23 16:51:21 +01:00
def print_usage():
2019-12-12 12:08:04 +01:00
print(f"{sys.argv[0]} <command>")
2019-11-30 17:48:29 +01:00
print()
print("Commands:")
2019-11-23 16:51:21 +01:00
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")
2019-12-12 12:08:04 +01:00
# 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:
2019-12-12 12:15:52 +01:00
config = json.load(config_file)
config["token"] = os.getenv("GITLAB_FI_TOKEN")
return config
2019-11-23 16:51:21 +01:00
2019-11-22 15:03:21 +01:00
def main():
2019-12-12 12:08:04 +01:00
config = load_config()
if len(sys.argv) != 2 or sys.argv[1] not in COMMANDS:
2019-11-23 16:51:21 +01:00
print_usage()
2019-11-22 15:03:21 +01:00
exit(2)
2020-04-03 14:10:37 +02:00
details = config["homeworks"][config["homework"]]
2020-06-08 17:39:36 +02:00
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,
)()
2019-11-22 15:03:21 +01:00
if __name__ == "__main__":
main()