1
Fork 0

Improve logging, by using logging

This commit is contained in:
Jake Howard 2020-01-19 20:02:13 +00:00
parent 7b0a1d0f16
commit 1189578a66
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 18 additions and 8 deletions

View file

@ -2,3 +2,4 @@ pygithub==1.45
python-dateutil==2.8.1
todoist-python==8.1.1
urlextract==0.14.0
coloredlogs==10.0

View file

@ -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:

View file

@ -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()

View file

@ -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))