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
|
|
|
|
2023-04-06 14:17:48 +02:00
|
|
|
if __name__ == "__main__":
|
2021-11-06 19:06:34 +01:00
|
|
|
# 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
|
2023-04-06 14:17:48 +02: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:
|
2023-04-06 14:17:48 +02:00
|
|
|
gitlab = GitlabAPI(
|
|
|
|
config["gitlab"]["url"],
|
|
|
|
config["gitlab"]["token"],
|
|
|
|
config["gitlab"]["assignee"],
|
|
|
|
)
|
2021-11-08 18:07:50 +01:00
|
|
|
|
|
|
|
# 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-08 17:35:45 +01:00
|
|
|
if gitlab_tasks:
|
2023-04-06 13:40:05 +02:00
|
|
|
missing_gitlab_tasks = utils.get_missing_tasks(tasks, gitlab_tasks)
|
2021-11-08 17:35:45 +01:00
|
|
|
|
|
|
|
if mantishub_tasks:
|
2023-04-06 13:40:05 +02:00
|
|
|
missing_mantis_tasks = utils.get_missing_tasks(tasks, mantishub_tasks)
|
2021-11-06 20:07:57 +01:00
|
|
|
|
2023-04-06 13:40:05 +02:00
|
|
|
if missing_gitlab_tasks or missing_mantis_tasks:
|
|
|
|
if missing_gitlab_tasks:
|
2023-04-06 14:17:48 +02:00
|
|
|
todoist.create_tasks(
|
|
|
|
missing_gitlab_tasks,
|
|
|
|
[
|
|
|
|
"gitlab",
|
|
|
|
],
|
|
|
|
)
|
2023-04-06 13:40:05 +02:00
|
|
|
if missing_mantis_tasks:
|
2023-04-06 14:17:48 +02:00
|
|
|
todoist.create_tasks(
|
|
|
|
missing_mantis_tasks,
|
|
|
|
[
|
|
|
|
"mantis",
|
|
|
|
],
|
|
|
|
)
|
2021-11-06 20:57:22 +01:00
|
|
|
exit(0)
|
2021-11-06 20:54:28 +01:00
|
|
|
print("Nothing new to add.")
|