todoist_interface/todoist_interface/gitlab.py

49 lines
1.3 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:
2023-04-06 14:45:33 +02:00
content = "[{title}]({url})".format(title=issue["title"], url=issue["web_url"])
tasks.append(
{
"content": content,
"label_ids": [
2158782094,
],
}
)
2021-12-29 11:10:56 +01:00
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
2023-04-06 14:45:33 +02:00
url = (
self.url
+ "issues?assignee_username="
+ assignee
+ "&state=opened&scope=all"
)
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)