diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..24ca2d9 --- /dev/null +++ b/.vscode/launch.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/test_apis.py b/test_apis.py new file mode 100644 index 0000000..bb3203b --- /dev/null +++ b/test_apis.py @@ -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, ] + })) diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..c4f7f2e --- /dev/null +++ b/tests/conftest.py @@ -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 diff --git a/todoist_interface/__main__.py b/todoist_interface/__main__.py index 3ceda58..402eaf5 100644 --- a/todoist_interface/__main__.py +++ b/todoist_interface/__main__.py @@ -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) diff --git a/todoist_interface/todoist.py b/todoist_interface/todoist.py index 2e97fcd..3cc85fd 100644 --- a/todoist_interface/todoist.py +++ b/todoist_interface/todoist.py @@ -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, ] })) diff --git a/todoist_interface/utils.py b/todoist_interface/utils.py index cb85a25..af01099 100644 --- a/todoist_interface/utils.py +++ b/todoist_interface/utils.py @@ -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