add a class for Mantishub
This commit is contained in:
parent
da9fc60e60
commit
d6daa604e6
|
@ -6,4 +6,5 @@ def test_settings():
|
||||||
assert (config["gitlab"]["token"] == "gitlabtoken"
|
assert (config["gitlab"]["token"] == "gitlabtoken"
|
||||||
and config["gitlab"]["url"] == "https://gitlab.example.com/api/v4/"
|
and config["gitlab"]["url"] == "https://gitlab.example.com/api/v4/"
|
||||||
and config["todoist"]["token"] == "todoisttoken"
|
and config["todoist"]["token"] == "todoisttoken"
|
||||||
and config["gitlab"]["assignee"] == "muster")
|
and config["gitlab"]["assignee"] == "muster"
|
||||||
|
and config["mantishub"]["token"] == "mantistoken")
|
||||||
|
|
|
@ -5,3 +5,6 @@ gitlab:
|
||||||
|
|
||||||
todoist:
|
todoist:
|
||||||
token: "todoisttoken"
|
token: "todoisttoken"
|
||||||
|
|
||||||
|
mantishub:
|
||||||
|
token: "mantistoken"
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import settings
|
import settings
|
||||||
from todoist import TodoistAPI
|
from todoist import TodoistAPI
|
||||||
from gitlab import GitlabAPI
|
from gitlab import GitlabAPI
|
||||||
|
from mantishub import MantishubAPI
|
||||||
|
from todoist_interface import mantishub
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -10,16 +12,21 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
# initialise Todoist and Gitlab
|
# initialise Todoist and Gitlab
|
||||||
todoist = TodoistAPI(config['todoist']['token'])
|
todoist = TodoistAPI(config['todoist']['token'])
|
||||||
gitlab = GitlabAPI(config["gitlab"]["url"], config["gitlab"]["token"])
|
gitlab = GitlabAPI(config["gitlab"]["url"],
|
||||||
|
config["gitlab"]["token"],
|
||||||
|
config["gitlab"]["assignee"])
|
||||||
|
mantishub = MantishubAPI(config["mantishub"]["token"])
|
||||||
|
|
||||||
# Get the Todoist tasks
|
# Get the Todoist tasks
|
||||||
tasks = todoist.get_get_tasks_by_filter("@gitlab")
|
tasks = todoist.get_get_tasks_by_filter("@gitlab")
|
||||||
|
|
||||||
# Get the Gitlab issues
|
# Get the Gitlab issues
|
||||||
issues = gitlab.get_issues_by_assignee("zweili")
|
gitlab_tasks = gitlab.get_issues()
|
||||||
|
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))
|
||||||
|
|
||||||
# Create a list of issues that are not in Todoist
|
|
||||||
missing_tasks = utils.get_missing_tasks(tasks, issues)
|
|
||||||
if missing_tasks:
|
if missing_tasks:
|
||||||
todoist.create_tasks(missing_tasks)
|
todoist.create_tasks(missing_tasks)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
|
@ -2,9 +2,10 @@ import requests
|
||||||
|
|
||||||
|
|
||||||
class GitlabAPI:
|
class GitlabAPI:
|
||||||
def __init__(self, url: str, token: str) -> None:
|
def __init__(self, url: str, token: str, assignee: str) -> None:
|
||||||
self.url = url
|
self.url = url
|
||||||
self.token = token
|
self.token = token
|
||||||
|
self.assignee = assignee
|
||||||
|
|
||||||
def get_issues_by_assignee(self, assignee: str) -> list:
|
def get_issues_by_assignee(self, assignee: str) -> list:
|
||||||
"""
|
"""
|
||||||
|
@ -22,3 +23,15 @@ class GitlabAPI:
|
||||||
issues = response.json()
|
issues = response.json()
|
||||||
|
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
|
def convert_to_todoist(issues):
|
||||||
|
tasks = []
|
||||||
|
for issue in issues:
|
||||||
|
content = "[{title}]({url})".format(title=issue["title"],
|
||||||
|
url=issue["web_url"])
|
||||||
|
tasks.append({"content": content})
|
||||||
|
return tasks
|
||||||
|
|
||||||
|
def get_issues(self) -> list:
|
||||||
|
issues = self.get_issues_by_assignee(self.assignee)
|
||||||
|
return self.convert_to_todoist(issues)
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
class MantishubAPI:
|
||||||
|
url = "https://contria.mantishub.io/api/rest/"
|
||||||
|
|
||||||
|
def __init__(self, token: str):
|
||||||
|
self.token = token
|
||||||
|
|
||||||
|
def get_tickets(self):
|
||||||
|
response = requests.get(
|
||||||
|
self.url + "issues?filter_id=assigned",
|
||||||
|
headers={"Authorization": self.token})
|
||||||
|
tickets = response.json()
|
||||||
|
return self.convert_to_todoist(tickets)
|
||||||
|
|
||||||
|
def convert_to_todoist(self, tickets):
|
||||||
|
for ticket in tickets:
|
||||||
|
print(ticket)
|
||||||
|
tasks = []
|
||||||
|
return tasks
|
|
@ -7,9 +7,7 @@ def get_missing_tasks(tasks, issues_to_check):
|
||||||
"""
|
"""
|
||||||
missing_tasks = []
|
missing_tasks = []
|
||||||
for issue in issues_to_check:
|
for issue in issues_to_check:
|
||||||
content = "[{title}]({url})".format(title=issue["title"],
|
if issue["content"] not in [t["content"] for t in tasks]:
|
||||||
url=issue["web_url"])
|
missing_tasks.append(issue)
|
||||||
if content not in [t["content"] for t in tasks]:
|
|
||||||
missing_tasks.append({"content": content})
|
|
||||||
|
|
||||||
return missing_tasks
|
return missing_tasks
|
||||||
|
|
Loading…
Reference in New Issue