From 28e9824cadd50005e6425d7250aaa74e184b165e Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 1 Mar 2020 12:57:13 +0000 Subject: [PATCH] Also check PR reviews --- todoist_github/tasks/prs_to_review.py | 15 +++++++++++++++ todoist_github/utils/__init__.py | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/todoist_github/tasks/prs_to_review.py b/todoist_github/tasks/prs_to_review.py index f60f25e..6a713ea 100644 --- a/todoist_github/tasks/prs_to_review.py +++ b/todoist_github/tasks/prs_to_review.py @@ -1,9 +1,11 @@ import logging from todoist_github.clients import github, todoist +from todoist_github.utils import get_my_review from todoist_github.utils.todoist import ( get_project_for_issue, get_relevant_todoist_tasks, + is_task_completed, pr_to_task_name, ) @@ -27,6 +29,7 @@ def prs_to_review(): if not task: continue tasks_actioned.append(task["id"]) + pr = issue.as_pull_request() if task["content"] != pr_to_task_name(issue): logging.info("Updating issue name for '%s'", issue.title) 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"]: logging.info("Updating project for '%s'", issue.title) 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() diff --git a/todoist_github/utils/__init__.py b/todoist_github/utils/__init__.py index ff5c412..45e0848 100644 --- a/todoist_github/utils/__init__.py +++ b/todoist_github/utils/__init__.py @@ -3,6 +3,7 @@ from typing import Optional from urllib.parse import urlparse from github.Issue import Issue +from github.PullRequest import PullRequest from urlextract import URLExtract 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}" ) 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