todoist_interface/todoist_interface/gitlab.py

38 lines
1.2 KiB
Python

import requests
class GitlabAPI:
def __init__(self, url: str, token: str, assignee: str) -> None:
self.url = url
self.token = token
self.assignee = assignee
def get_issues_by_assignee(self, assignee: str) -> list:
"""
Get all issues assigned to a specific user
:param assignee: The username of the assignee
:return: A list of issues assigned to the user
"""
# Get all issues assigned to the user
url = (self.url
+ '/api/v4/issues?assignee_username='
+ assignee
+ '&state=opened')
response = requests.get(url, headers={'PRIVATE-TOKEN': self.token})
issues = response.json()
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)