todoist_interface/todoist_interface/__main__.py

57 lines
1.7 KiB
Python
Raw Normal View History

2021-11-06 19:06:34 +01:00
import settings
from todoist import TodoistAPI
2021-11-06 19:42:04 +01:00
from gitlab import GitlabAPI
2021-11-06 21:27:27 +01:00
from mantishub import MantishubAPI
2021-11-06 20:07:57 +01:00
import utils
2021-11-06 19:06:34 +01:00
if __name__ == '__main__':
# initialise the settings
2021-11-06 19:34:33 +01:00
config = settings.read_config("todoist_interface.yml")
2021-11-06 19:06:34 +01:00
2021-11-06 20:07:57 +01:00
# initialise Todoist and Gitlab
2021-11-06 19:06:34 +01:00
todoist = TodoistAPI(config['todoist']['token'])
2021-11-06 20:07:57 +01:00
2021-11-08 18:07:50 +01:00
# Setup the todoist tasks
2021-11-06 21:28:48 +01:00
tasks = []
2021-11-08 17:35:45 +01:00
2021-11-08 18:07:50 +01:00
# Gitlab
gitlab_labeled_tasks = []
2021-11-08 17:35:45 +01:00
gitlab_tasks = []
2021-11-08 18:07:50 +01:00
if "gitlab" in config:
gitlab = GitlabAPI(config["gitlab"]["url"],
config["gitlab"]["token"],
config["gitlab"]["assignee"])
# Get the Gitlab tasks
gitlab_tasks = gitlab.get_issues()
# Get the Todoist tasks labeled gitlab
gitlab_labeled_tasks = todoist.get_get_tasks_by_filter("@gitlab")
if gitlab_labeled_tasks:
tasks.extend(gitlab_labeled_tasks)
# Mantishub
mantis_labeled_tasks = []
mantishub_tasks = []
if "mantishub" in config:
mantishub = MantishubAPI(config["mantishub"]["token"])
# Get the Mantishub tasks
mantishub_tasks = mantishub.get_tickets()
# Get the Todoist tasks labeled mantishub
mantis_labeled_tasks = todoist.get_get_tasks_by_filter("@mantis")
if mantis_labeled_tasks:
tasks.extend(mantis_labeled_tasks)
# Check if there are any tasks to add to Todoist
2021-11-06 21:27:27 +01:00
missing_tasks = []
2021-11-08 17:35:45 +01:00
if gitlab_tasks:
2021-11-08 17:56:15 +01:00
missing_tasks.extend(utils.get_missing_tasks(tasks, gitlab_tasks))
2021-11-08 17:35:45 +01:00
if mantishub_tasks:
2021-11-08 17:56:15 +01:00
missing_tasks.extend(utils.get_missing_tasks(tasks, mantishub_tasks))
2021-11-06 20:07:57 +01:00
2021-11-06 20:48:30 +01:00
if missing_tasks:
todoist.create_tasks(missing_tasks)
2021-11-06 20:57:22 +01:00
exit(0)
2021-11-06 20:54:28 +01:00
print("Nothing new to add.")