Restructure PR code to prevent unnecessary task creation
This commit is contained in:
parent
deb87104bb
commit
23fee6adee
1 changed files with 30 additions and 29 deletions
|
@ -41,12 +41,8 @@ def todoist_repo_prs():
|
||||||
|
|
||||||
if pr.state == "closed" and existing_task_id:
|
if pr.state == "closed" and existing_task_id:
|
||||||
my_review = get_my_review(me, pr)
|
my_review = get_my_review(me, pr)
|
||||||
if (
|
if pr.merged and my_review and my_review.state == "APPROVED":
|
||||||
pr.merged
|
if not is_task_completed(todoist.items.get_by_id(existing_task_id)):
|
||||||
and my_review
|
|
||||||
and my_review.state == "APPROVED"
|
|
||||||
and not is_task_completed(existing_task_id)
|
|
||||||
):
|
|
||||||
logger.info("Completing task to review '{}'".format(pr.title))
|
logger.info("Completing task to review '{}'".format(pr.title))
|
||||||
todoist.items.complete([existing_task_id])
|
todoist.items.complete([existing_task_id])
|
||||||
else:
|
else:
|
||||||
|
@ -54,27 +50,32 @@ def todoist_repo_prs():
|
||||||
todoist.items.delete([existing_task_id])
|
todoist.items.delete([existing_task_id])
|
||||||
|
|
||||||
elif pr.state == "open":
|
elif pr.state == "open":
|
||||||
if existing_task_id is None:
|
|
||||||
logger.info("Creating task to review '{}'".format(pr.title))
|
|
||||||
existing_task_id = todoist.items.add(
|
|
||||||
pr_to_task_name(pr), project_id
|
|
||||||
)["id"]
|
|
||||||
|
|
||||||
existing_task = todoist.items.get_by_id(existing_task_id)
|
|
||||||
my_review = get_my_review(me, pr)
|
my_review = get_my_review(me, pr)
|
||||||
if existing_task_id and my_review:
|
|
||||||
if my_review.commit_id == pr.head.sha and not is_task_completed(
|
if existing_task_id:
|
||||||
existing_task
|
existing_task = todoist.items.get_by_id(existing_task_id)
|
||||||
):
|
task_completed = is_task_completed(existing_task)
|
||||||
|
if my_review:
|
||||||
|
if my_review.commit_id == pr.head.sha and not task_completed:
|
||||||
logger.info(
|
logger.info(
|
||||||
"Completing task to review '{}', because I already did it".format(
|
"Completing task to review '{}', because I already did it".format(
|
||||||
pr.title
|
pr.title
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
todoist.items.complete([existing_task_id])
|
todoist.items.complete([existing_task_id])
|
||||||
elif is_task_completed(existing_task):
|
elif task_completed:
|
||||||
logger.info("Re-opening task to review '{}'".format(pr.title))
|
logger.info(
|
||||||
|
"Re-opening task to review '{}'".format(pr.title)
|
||||||
|
)
|
||||||
todoist.items.uncomplete([existing_task_id])
|
todoist.items.uncomplete([existing_task_id])
|
||||||
|
continue
|
||||||
|
elif my_review and my_review.commit_id != pr.head.sha:
|
||||||
|
logger.info("Creating task to review '{}'".format(pr.title))
|
||||||
|
existing_task_id = todoist.items.add(
|
||||||
|
pr_to_task_name(pr), project_id
|
||||||
|
)["id"]
|
||||||
|
if existing_task_id is not None:
|
||||||
|
existing_task = todoist.items.get_by_id(existing_task_id)
|
||||||
existing_task.update(content=pr_to_task_name(pr))
|
existing_task.update(content=pr_to_task_name(pr))
|
||||||
if pr.milestone and pr.milestone.due_on:
|
if pr.milestone and pr.milestone.due_on:
|
||||||
existing_task.update(
|
existing_task.update(
|
||||||
|
|
Reference in a new issue