more changes

This commit is contained in:
Andreas Zweili 2021-11-08 17:35:45 +01:00
parent 0385d75afb
commit 5e35a1c443
5 changed files with 44 additions and 12 deletions

View File

@ -3,4 +3,6 @@ from todoist_interface.gitlab import GitlabAPI
def test_gitlab_init():
gitlab = GitlabAPI("url", "token", "assignee")
assert gitlab.url == "url" and gitlab.token == "token"
assert (gitlab.url == "url"
and gitlab.token == "token"
and gitlab.assignee == "assignee")

View File

@ -0,0 +1,16 @@
from todoist_interface.mantishub import MantishubAPI
def test_mantishub_init():
mantishub = MantishubAPI("mantistoken")
assert mantishub.token == "mantistoken"
def test_mantishub_get_tickets():
mantishub = MantishubAPI("mantistoken")
tickets = mantishub.get_tickets()
assert len(tickets) > 0
def test_convert_to_todoist():
assert False

View File

@ -18,15 +18,26 @@ if __name__ == '__main__':
# Get the Todoist tasks
tasks = []
tasks.append(todoist.get_get_tasks_by_filter("@gitlab"))
tasks.append(todoist.get_get_tasks_by_filter("@mantis"))
gitlab_labeled_tasks = todoist.get_get_tasks_by_filter("@gitlab")
if gitlab_labeled_tasks:
tasks.append(gitlab_labeled_tasks)
mantis_labeled_tasks = todoist.get_get_tasks_by_filter("@mantis")
if mantis_labeled_tasks:
tasks.append(mantis_labeled_tasks)
# Get the Gitlab issues
gitlab_tasks = gitlab.get_issues()
# gitlab_tasks = gitlab.get_issues()
gitlab_tasks = []
mantishub_tasks = mantishub.get_tickets()
missing_tasks = []
missing_tasks.append(utils.get_missing_tasks(tasks, gitlab_tasks))
missing_tasks.append(utils.get_missing_tasks(tasks, mantishub_tasks))
if gitlab_tasks:
missing_tasks.append(utils.get_missing_tasks(tasks, gitlab_tasks))
if mantishub_tasks:
missing_tasks.append(utils.get_missing_tasks(tasks, mantishub_tasks))
if missing_tasks:
todoist.create_tasks(missing_tasks)

View File

@ -12,14 +12,14 @@ class MantishubAPI:
self.url + "issues?filter_id=assigned",
headers={"Authorization": self.token})
tickets = response.json()
return self.convert_to_todoist(tickets)
return self.convert_to_todoist(tickets["issues"])
def convert_to_todoist(self, tickets):
# TODO: add a function to convert mantis priority to todoist priority
# TODO: add a function to create the url
tasks = []
for ticket in tickets:
url = "https:mantishub.com"
url = ("https://contria.mantishub.io/view.php?id="
+ str(ticket["id"]))
content = "[{title}]({url})".format(title=ticket["summary"],
url=url)
tasks.append({"content": content, "label_ids": [2158784659, ]})

View File

@ -6,8 +6,11 @@ def get_missing_tasks(tasks, issues_to_check):
:return: A list of tasks not in Todoist
"""
missing_tasks = []
for issue in issues_to_check:
if issue["content"] not in [t["content"] for t in tasks]:
missing_tasks.append(issue)
if tasks:
for issue in issues_to_check:
if issue["content"] not in [t["content"] for t in tasks]:
missing_tasks.append(issue)
else:
missing_tasks = issues_to_check
return missing_tasks