From 1189578a66c852326a613be9fc3c9ac68cfd0f66 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 19 Jan 2020 20:02:13 +0000 Subject: [PATCH] Improve logging, by using `logging` --- requirements.txt | 1 + todoist_github/cli.py | 9 ++++++++- todoist_github/tasks/assigned_issues.py | 11 ++++++----- todoist_github/tasks/prs_to_review.py | 5 +++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index 6d37547..8edbe90 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ pygithub==1.45 python-dateutil==2.8.1 todoist-python==8.1.1 urlextract==0.14.0 +coloredlogs==10.0 diff --git a/todoist_github/cli.py b/todoist_github/cli.py index 9e4cf16..78f7b79 100755 --- a/todoist_github/cli.py +++ b/todoist_github/cli.py @@ -2,6 +2,8 @@ import argparse import time +import coloredlogs +import logging from .tasks import ALL_TASKS @@ -14,11 +16,16 @@ def get_args(): def run_tasks(): for task in ALL_TASKS: - print("Executing", task.__name__) + logging.info("Executing %s", task.__name__) task() def main(): + coloredlogs.install( + level=logging.INFO, + fmt="%(asctime)s %(levelname)s %(message)s", + datefmt="%H:%M:%S", + ) args = get_args() run_tasks() if args.interval: diff --git a/todoist_github/tasks/assigned_issues.py b/todoist_github/tasks/assigned_issues.py index 799592a..8daf477 100644 --- a/todoist_github/tasks/assigned_issues.py +++ b/todoist_github/tasks/assigned_issues.py @@ -1,4 +1,5 @@ import datetime +import logging from dateutil.relativedelta import relativedelta @@ -21,19 +22,19 @@ def assigned_issues(): for assigned_issue in me.get_issues(state="all", since=relevant_since): task = todoist_tasks.get(assigned_issue.html_url) if not task and assigned_issue.state == "open": - print("creating", assigned_issue) + logging.info("Creating '%s'", assigned_issue.title) task = todoist.items.add(issue_to_task_name(assigned_issue)) if not task: continue tasks_actioned.append(task["id"]) if assigned_issue.state == "closed" and not is_task_completed(task): - print("completing", assigned_issue) + logging.info("Completing '%s'", assigned_issue.title) task.complete() elif assigned_issue.state == "open" and is_task_completed(task): - print("uncompleting task", assigned_issue) + logging.info("Uncompleting task '%s'", assigned_issue.title) task.uncomplete() if task["content"] != issue_to_task_name(assigned_issue): - print("updating issue name for", assigned_issue) + logging.info("Updating issue name for '%s'", assigned_issue.title) task.update(content=issue_to_task_name(assigned_issue)) if assigned_issue.milestone and assigned_issue.milestone.due_on: task.update( @@ -50,5 +51,5 @@ def assigned_issues(): issue = get_issue(me, org, repo, issue_number) me_assigned = me.login in {assignee.login for assignee in issue.assignees} if not me_assigned: - print("Deleting", issue) + logging.warn("Deleting '%s'", issue.title) task.delete() diff --git a/todoist_github/tasks/prs_to_review.py b/todoist_github/tasks/prs_to_review.py index 5784dfe..ec81c40 100644 --- a/todoist_github/tasks/prs_to_review.py +++ b/todoist_github/tasks/prs_to_review.py @@ -1,5 +1,6 @@ from todoist_github.clients import github, todoist from todoist_github.utils.todoist import get_relevant_todoist_tasks, pr_to_task_name +import logging SEARCH_STRING = "is:pr review-requested:{username} archived:false" @@ -12,11 +13,11 @@ def prs_to_review(): for issue in github.search_issues(search_string): task = relevant_tasks.get(issue.html_url) if not task and issue.state == "open": - print("Creating", issue) + logging.info("Creating '%s'", issue.title) 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) + logging.info("Updating issue name for '%s'", issue.title) task.update(content=pr_to_task_name(issue))