Start pulling PR review requests
This commit is contained in:
parent
78f78cb5ea
commit
2b40d7e320
4 changed files with 46 additions and 14 deletions
|
@ -1,5 +1,6 @@
|
|||
from .assigned_issues import assigned_issues
|
||||
from .prs_to_review import prs_to_review
|
||||
|
||||
ALL_TASKS = [assigned_issues]
|
||||
ALL_TASKS = [prs_to_review, assigned_issues]
|
||||
|
||||
__all__ = ["ALL_TASKS"]
|
||||
|
|
|
@ -3,22 +3,16 @@ import datetime
|
|||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from todoist_github.clients import github, todoist
|
||||
from todoist_github.utils import get_github_issue_details, get_github_task, get_issue
|
||||
from todoist_github.utils.todoist import is_task_completed, issue_to_task_name
|
||||
|
||||
|
||||
def get_relevant_todoist_tasks():
|
||||
todoist.items.sync()
|
||||
tasks = {}
|
||||
for task in todoist.items.all():
|
||||
github_task = get_github_task(task["content"])
|
||||
if github_task:
|
||||
tasks[github_task] = task
|
||||
return tasks
|
||||
from todoist_github.utils import get_github_issue_details, get_issue
|
||||
from todoist_github.utils.todoist import (
|
||||
get_relevant_todoist_tasks,
|
||||
is_task_completed,
|
||||
issue_to_task_name,
|
||||
)
|
||||
|
||||
|
||||
def assigned_issues():
|
||||
todoist_tasks = get_relevant_todoist_tasks()
|
||||
todoist_tasks = get_relevant_todoist_tasks(todoist)
|
||||
relevant_since = datetime.datetime.now() - relativedelta(
|
||||
weeks=30
|
||||
) # TODO: Make this a sane number
|
||||
|
|
21
todoist_github/tasks/prs_to_review.py
Normal file
21
todoist_github/tasks/prs_to_review.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from todoist_github.clients import github, todoist
|
||||
from todoist_github.utils.todoist import get_relevant_todoist_tasks, pr_to_task_name
|
||||
|
||||
SEARCH_STRING = "is:pr review-requested:{username} archived:false"
|
||||
|
||||
|
||||
def prs_to_review():
|
||||
relevant_tasks = get_relevant_todoist_tasks(todoist)
|
||||
me = github.get_user()
|
||||
search_string = SEARCH_STRING.format(username=me.login)
|
||||
tasks_actioned = []
|
||||
for issue in github.search_issues(search_string):
|
||||
task = relevant_tasks.get(issue.html_url)
|
||||
if not task and issue.state == "open":
|
||||
task = todoist.items.add(pr_to_task_name(issue))
|
||||
if not task:
|
||||
continue
|
||||
tasks_actioned.append(task["id"])
|
||||
if task["content"] != pr_to_task_name(issue):
|
||||
print("updating issue name for", issue)
|
||||
task.update(content=pr_to_task_name(issue))
|
|
@ -1,5 +1,7 @@
|
|||
from github.Issue import Issue
|
||||
|
||||
from . import get_github_task
|
||||
|
||||
|
||||
def get_issue_link(issue_or_pr) -> str:
|
||||
return "[#{id}]({url})".format(id=issue_or_pr.number, url=issue_or_pr.html_url)
|
||||
|
@ -9,5 +11,19 @@ def issue_to_task_name(issue: Issue) -> str:
|
|||
return get_issue_link(issue) + ": " + issue.title
|
||||
|
||||
|
||||
def pr_to_task_name(pr) -> str:
|
||||
return f"Review {get_issue_link(pr)} : {pr.title}"
|
||||
|
||||
|
||||
def is_task_completed(task):
|
||||
return task.data.get("checked", 0)
|
||||
|
||||
|
||||
def get_relevant_todoist_tasks(todoist):
|
||||
todoist.items.sync()
|
||||
tasks = {}
|
||||
for task in todoist.items.all():
|
||||
github_task = get_github_task(task["content"])
|
||||
if github_task:
|
||||
tasks[github_task] = task
|
||||
return tasks
|
||||
|
|
Reference in a new issue