todoist_interface/todoist_interface/gitlab.py

39 lines
1.2 KiB
Python
Raw Normal View History

2021-11-06 20:07:57 +01:00
import requests
2021-12-29 11:10:56 +01:00
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, "label_ids": [2158782094, ]})
return tasks
2021-11-06 19:42:04 +01:00
class GitlabAPI:
2021-11-06 21:27:27 +01:00
def __init__(self, url: str, token: str, assignee: str) -> None:
2021-11-06 19:42:04 +01:00
self.url = url
self.token = token
2021-11-06 21:27:27 +01:00
self.assignee = assignee
2021-11-06 20:07:57 +01:00
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
2021-11-09 09:28:51 +01:00
+ 'issues?assignee_username='
2021-11-06 20:07:57 +01:00
+ assignee
2021-11-09 10:50:24 +01:00
+ '&state=opened&scope=all')
2021-11-09 09:28:51 +01:00
response = requests.get(url, headers={'PRIVATE-TOKEN': self.token}, verify=False)
2021-11-06 20:07:57 +01:00
issues = response.json()
return issues
2021-11-06 21:27:27 +01:00
def get_issues(self) -> list:
issues = self.get_issues_by_assignee(self.assignee)
2021-12-29 11:10:56 +01:00
return convert_to_todoist(issues)