1
Fork 0

Also check PR reviews

This commit is contained in:
Jake Howard 2020-03-01 12:57:13 +00:00
parent 2f23b37825
commit 28e9824cad
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 22 additions and 0 deletions

View file

@ -1,9 +1,11 @@
import logging import logging
from todoist_github.clients import github, todoist from todoist_github.clients import github, todoist
from todoist_github.utils import get_my_review
from todoist_github.utils.todoist import ( from todoist_github.utils.todoist import (
get_project_for_issue, get_project_for_issue,
get_relevant_todoist_tasks, get_relevant_todoist_tasks,
is_task_completed,
pr_to_task_name, pr_to_task_name,
) )
@ -27,6 +29,7 @@ def prs_to_review():
if not task: if not task:
continue continue
tasks_actioned.append(task["id"]) tasks_actioned.append(task["id"])
pr = issue.as_pull_request()
if task["content"] != pr_to_task_name(issue): if task["content"] != pr_to_task_name(issue):
logging.info("Updating issue name for '%s'", issue.title) logging.info("Updating issue name for '%s'", issue.title)
task.update(content=pr_to_task_name(issue)) task.update(content=pr_to_task_name(issue))
@ -35,3 +38,15 @@ def prs_to_review():
if todoist_project and task["project_id"] != todoist_project["id"]: if todoist_project and task["project_id"] != todoist_project["id"]:
logging.info("Updating project for '%s'", issue.title) logging.info("Updating project for '%s'", issue.title)
task.move(project_id=todoist_project["id"]) task.move(project_id=todoist_project["id"])
my_review = get_my_review(me, pr)
if my_review:
if my_review.commit_id == pr.head.sha and not is_task_completed(task):
logging.info("Completing '%s'", issue.title)
task.complete()
elif is_task_completed(task):
logging.info("Un-completing '%s'", issue.title)
task.uncomplete()
if pr.merged and not is_task_completed(task):
logging.info("Deleting '%s'", issue.title)
task.delete()

View file

@ -3,6 +3,7 @@ from typing import Optional
from urllib.parse import urlparse from urllib.parse import urlparse
from github.Issue import Issue from github.Issue import Issue
from github.PullRequest import PullRequest
from urlextract import URLExtract from urlextract import URLExtract
GITHUB_ISSUE_PR_RE = re.compile(r"\/(.+?)\/(.+?)\/(pull|issues)\/(\d+?)$") GITHUB_ISSUE_PR_RE = re.compile(r"\/(.+?)\/(.+?)\/(pull|issues)\/(\d+?)$")
@ -38,3 +39,9 @@ def get_issue(me, org, repo, issue_num):
"GET", f"/repos/{org}/{repo}/issues/{issue_num}" "GET", f"/repos/{org}/{repo}/issues/{issue_num}"
) )
return Issue(me._requester, headers, data, completed=True) return Issue(me._requester, headers, data, completed=True)
def get_my_review(me, pr: PullRequest):
for review in pr.get_reviews().reversed:
if review.user.login == me.login:
return review