Improve logging, by using logging
This commit is contained in:
parent
7b0a1d0f16
commit
1189578a66
4 changed files with 18 additions and 8 deletions
|
@ -2,3 +2,4 @@ pygithub==1.45
|
||||||
python-dateutil==2.8.1
|
python-dateutil==2.8.1
|
||||||
todoist-python==8.1.1
|
todoist-python==8.1.1
|
||||||
urlextract==0.14.0
|
urlextract==0.14.0
|
||||||
|
coloredlogs==10.0
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import time
|
import time
|
||||||
|
import coloredlogs
|
||||||
|
import logging
|
||||||
|
|
||||||
from .tasks import ALL_TASKS
|
from .tasks import ALL_TASKS
|
||||||
|
|
||||||
|
@ -14,11 +16,16 @@ def get_args():
|
||||||
|
|
||||||
def run_tasks():
|
def run_tasks():
|
||||||
for task in ALL_TASKS:
|
for task in ALL_TASKS:
|
||||||
print("Executing", task.__name__)
|
logging.info("Executing %s", task.__name__)
|
||||||
task()
|
task()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
coloredlogs.install(
|
||||||
|
level=logging.INFO,
|
||||||
|
fmt="%(asctime)s %(levelname)s %(message)s",
|
||||||
|
datefmt="%H:%M:%S",
|
||||||
|
)
|
||||||
args = get_args()
|
args = get_args()
|
||||||
run_tasks()
|
run_tasks()
|
||||||
if args.interval:
|
if args.interval:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
|
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
|
|
||||||
|
@ -21,19 +22,19 @@ def assigned_issues():
|
||||||
for assigned_issue in me.get_issues(state="all", since=relevant_since):
|
for assigned_issue in me.get_issues(state="all", since=relevant_since):
|
||||||
task = todoist_tasks.get(assigned_issue.html_url)
|
task = todoist_tasks.get(assigned_issue.html_url)
|
||||||
if not task and assigned_issue.state == "open":
|
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))
|
task = todoist.items.add(issue_to_task_name(assigned_issue))
|
||||||
if not task:
|
if not task:
|
||||||
continue
|
continue
|
||||||
tasks_actioned.append(task["id"])
|
tasks_actioned.append(task["id"])
|
||||||
if assigned_issue.state == "closed" and not is_task_completed(task):
|
if assigned_issue.state == "closed" and not is_task_completed(task):
|
||||||
print("completing", assigned_issue)
|
logging.info("Completing '%s'", assigned_issue.title)
|
||||||
task.complete()
|
task.complete()
|
||||||
elif assigned_issue.state == "open" and is_task_completed(task):
|
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()
|
task.uncomplete()
|
||||||
if task["content"] != issue_to_task_name(assigned_issue):
|
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))
|
task.update(content=issue_to_task_name(assigned_issue))
|
||||||
if assigned_issue.milestone and assigned_issue.milestone.due_on:
|
if assigned_issue.milestone and assigned_issue.milestone.due_on:
|
||||||
task.update(
|
task.update(
|
||||||
|
@ -50,5 +51,5 @@ def assigned_issues():
|
||||||
issue = get_issue(me, org, repo, issue_number)
|
issue = get_issue(me, org, repo, issue_number)
|
||||||
me_assigned = me.login in {assignee.login for assignee in issue.assignees}
|
me_assigned = me.login in {assignee.login for assignee in issue.assignees}
|
||||||
if not me_assigned:
|
if not me_assigned:
|
||||||
print("Deleting", issue)
|
logging.warn("Deleting '%s'", issue.title)
|
||||||
task.delete()
|
task.delete()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from todoist_github.clients import github, todoist
|
from todoist_github.clients import github, todoist
|
||||||
from todoist_github.utils.todoist import get_relevant_todoist_tasks, pr_to_task_name
|
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"
|
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):
|
for issue in github.search_issues(search_string):
|
||||||
task = relevant_tasks.get(issue.html_url)
|
task = relevant_tasks.get(issue.html_url)
|
||||||
if not task and issue.state == "open":
|
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))
|
task = todoist.items.add(pr_to_task_name(issue))
|
||||||
if not task:
|
if not task:
|
||||||
continue
|
continue
|
||||||
tasks_actioned.append(task["id"])
|
tasks_actioned.append(task["id"])
|
||||||
if task["content"] != pr_to_task_name(issue):
|
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))
|
task.update(content=pr_to_task_name(issue))
|
||||||
|
|
Reference in a new issue