Add assigned github issues to todoist
This commit is contained in:
parent
9bc321fe1b
commit
fec37dd294
2 changed files with 63 additions and 2 deletions
|
@ -1,10 +1,13 @@
|
|||
import asyncio
|
||||
|
||||
from apscheduler.schedulers.blocking import BlockingScheduler
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
|
||||
from .todoist_assigned_issues import todoist_assigned_issues
|
||||
|
||||
|
||||
def create_scheduler():
|
||||
scheduler = BlockingScheduler()
|
||||
scheduler = AsyncIOScheduler()
|
||||
scheduler.add_job(todoist_assigned_issues, 'interval', minutes=15)
|
||||
return scheduler
|
||||
|
||||
|
||||
|
|
58
actioner/scheduler/todoist_assigned_issues.py
Normal file
58
actioner/scheduler/todoist_assigned_issues.py
Normal file
|
@ -0,0 +1,58 @@
|
|||
from typing import Dict
|
||||
|
||||
from github import Issue
|
||||
|
||||
from actioner.clients import github, todoist
|
||||
|
||||
REPOS = {
|
||||
'srobo/tasks': 2190856871,
|
||||
'srobo/core-team-minutes': 2190856871
|
||||
}
|
||||
|
||||
|
||||
def get_issue_link(issue: Issue) -> str:
|
||||
return "[#{id}]({url})".format(
|
||||
id=issue.number,
|
||||
url=issue.html_url
|
||||
)
|
||||
|
||||
|
||||
def issue_to_task_name(issue: Issue) -> str:
|
||||
return get_issue_link(issue) + ": " + issue.title
|
||||
|
||||
|
||||
def get_existing_task(tasks: Dict[int, str], issue: Issue):
|
||||
issue_link = get_issue_link(issue)
|
||||
for task_id, task_title in tasks.items():
|
||||
if issue_link in task_title:
|
||||
return task_id
|
||||
return None
|
||||
|
||||
|
||||
def todoist_assigned_issues():
|
||||
me = github.get_user()
|
||||
todoist.projects.sync()
|
||||
todoist.items.sync()
|
||||
for repo_name, project_id in REPOS.items():
|
||||
existing_tasks = {item['id']: item['content'] for item in todoist.state['items'] if item['project_id'] == project_id}
|
||||
repo = github.get_repo(repo_name)
|
||||
for issue in repo.get_issues(assignee=me.login):
|
||||
existing_task_id = get_existing_task(existing_tasks, issue)
|
||||
if existing_task_id is None:
|
||||
existing_task_id = todoist.items.add(
|
||||
issue_to_task_name(issue),
|
||||
project_id
|
||||
)['id']
|
||||
existing_task = todoist.items.get_by_id(existing_task_id)
|
||||
existing_task.update(
|
||||
content=issue_to_task_name(issue)
|
||||
)
|
||||
if issue.milestone and issue.milestone.due_on:
|
||||
existing_task.update(date_string=issue.milestone.due_on.strftime("%d/%m/%Y"))
|
||||
|
||||
for issue in repo.get_issues(assignee=me.login, state='closed'):
|
||||
existing_task_id = get_existing_task(existing_tasks, issue)
|
||||
if existing_task_id is not None:
|
||||
todoist.items.complete([existing_task_id])
|
||||
|
||||
todoist.commit()
|
Reference in a new issue