add more things

This commit is contained in:
Andreas Zweili 2021-11-06 20:48:30 +01:00
parent 3e712c8132
commit 78a01e674f
6 changed files with 60 additions and 8 deletions

15
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}

23
test_apis.py Normal file
View File

@ -0,0 +1,23 @@
import json
import requests
import uuid
if __name__ == '__main__':
# tasks = requests.get(
# "https://api.todoist.com/rest/v1/labels",
# headers={
# "Authorization": "Bearer f1d6ff420068f4323077ff3ce500d39e09713a27"
# }).json()
# print(tasks)
requests.post("https://api.todoist.com/rest/v1/tasks",
headers={
"Content-Type": "application/json",
"X-Request-Id": str(uuid.uuid4()),
"Authorization": "Bearer f1d6ff420068f4323077ff3ce500d39e09713a27"
},
data=json.dumps({
"content": "foo",
"description": "bar",
"label_id": [2158782094, ]
}))

6
tests/conftest.py Normal file
View File

@ -0,0 +1,6 @@
import json
def example_issues():
issues = json.loads('[{"state":"opened","description":"Ratione dolores corrupti mollitia soluta quia.","author":{"state":"active","id":18,"web_url":"https://gitlab.example.com/eileen.lowe","name":"Alexandra Bashirian","avatar_url":null,"username":"eileen.lowe"},"milestone":{"project_id":1,"description":"Ducimus nam enim ex consequatur cumque ratione.","state":"closed","due_date":null,"iid":2,"created_at":"2016-01-04T15:31:39.996Z","title":"v4.0","id":17,"updated_at":"2016-01-04T15:31:39.996Z"},"project_id":1,"assignees":[{"state":"active","id":1,"name":"Administrator","web_url":"https://gitlab.example.com/root","avatar_url":null,"username":"root"}],"assignee":{"state":"active","id":1,"name":"Administrator","web_url":"https://gitlab.example.com/root","avatar_url":null,"username":"root"},"type":"ISSUE","updated_at":"2016-01-04T15:31:51.081Z","closed_at":null,"closed_by":null,"id":76,"title":"Consequatur","created_at":"2016-01-04T15:31:51.081Z","moved_to_id":null,"iid":6,"labels":["foo","bar"],"upvotes":4,"downvotes":0,"merge_requests_count":0,"user_notes_count":1,"due_date":"2016-07-22","web_url":"http://gitlab.example.com/my-group/my-project/issues/6","references":{"short":"#6","relative":"my-group/my-project#6","full":"my-group/my-project#6"},"time_stats":{"time_estimate":0,"total_time_spent":0,"human_time_estimate":null,"human_total_time_spent":null},"has_tasks":true,"task_status":"10 of 15 tasks completed","confidential":false,"discussion_locked":false,"issue_type":"issue","_links":{"self":"http://gitlab.example.com/api/v4/projects/1/issues/76","notes":"http://gitlab.example.com/api/v4/projects/1/issues/76/notes","award_emoji":"http://gitlab.example.com/api/v4/projects/1/issues/76/award_emoji","project":"http://gitlab.example.com/api/v4/projects/1"},"task_completion_status":{"count":0,"completed_count":0}}]')
return issues

View File

@ -1,3 +1,4 @@
import json
import settings
from todoist import TodoistAPI
from gitlab import GitlabAPI
@ -16,9 +17,9 @@ if __name__ == '__main__':
tasks = todoist.get_get_tasks_by_filter("@gitlab")
# Get the Gitlab issues
issues = gitlab.get_issues_by_assignee("zweili")
# issues = gitlab.get_issues_by_assignee("zweili")
# Create a list of issues that are not in Todoist
missing_tasks = utils.get_missing_tasks(tasks, issues)
todoist.create_tasks(missing_tasks)
print(tasks)
if missing_tasks:
todoist.create_tasks(missing_tasks)

View File

@ -1,5 +1,6 @@
import requests
import json
import uuid
class TodoistAPI:
@ -13,18 +14,24 @@ class TodoistAPI:
Returns all tasks from todoist
"""
response = requests.get(
self.url + '/tasks',
self.url + 'tasks',
headers={'Authorization': 'Bearer ' + self.token},
params={"filter": filter})
return response.json()
def add_tasks(self, tasks: list):
def create_tasks(self, tasks: list):
"""
Adds tasks to todoist
"""
for task in tasks:
requests.post(self.url + '/tasks',
headers={'Authorization': 'Bearer ' + self.token},
requests.post(self.url + 'tasks',
headers={
"Content-Type": "application/json",
"X-Request-Id": str(uuid.uuid4()),
"Authorization": "Bearer "
+ self.token},
data=json.dumps({
"content": task["content"],
"description": task["description"],
"label_ids": [2158782094, ]
}))

View File

@ -9,6 +9,6 @@ def get_missing_tasks(tasks, issues_to_check):
for issue in issues_to_check:
if issue["title"] not in [t["content"] for t in tasks]:
missing_tasks.append({"content": issue["title"],
"url": issue["web_url"]})
"description": issue["web_url"]})
return missing_tasks