Skip to content

Commit

Permalink
First pass at adding notifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
kostajh committed Feb 26, 2013
1 parent 00b6f78 commit 8b258b3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bugwarrior/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ def pull():
issues = aggregate_issues(config)

# Stuff them in the taskwarrior db as necessary
synchronize(issues)
synchronize(issues, config)
except:
log.name('command').trace('error').critical('oh noes')
18 changes: 15 additions & 3 deletions bugwarrior/db.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from twiggy import log

from taskw import TaskWarrior
from bugwarrior.notifications import send_notification


MARKUP = "(bw)"


def synchronize(issues):
def synchronize(issues, conf):
tw = TaskWarrior()

if conf.get('general', 'notifications'):
notify = True
else:
notify = False

# Load info about the task database
tasks = tw.load_tasks()
is_bugwarrior_task = lambda task: \
Expand Down Expand Up @@ -43,6 +47,8 @@ def synchronize(issues):
"Adding task {0}",
issue['description'].encode("utf-8")
)
if notify:
send_notification(issue, 'Created', conf)
tw.task_add(**issue)

# Update any issues that may have had new properties added. These are
Expand All @@ -60,6 +66,8 @@ def synchronize(issues):
key,
upstream_issue['description'].encode("utf-8"),
)
if notify:
send_notification(upstream_issue, 'Updated', conf)
task[key] = upstream_issue[key]
id, task = tw.task_update(task)

Expand All @@ -69,4 +77,8 @@ def synchronize(issues):
"Completing task {0}",
task['description'].encode("utf-8"),
)
if notify:
send_notification(task, 'Completed', conf)

tw.task_done(uuid=task['uuid'])
send_notification("New: %d, Completed: %d" % (len(new_issues), len(done_tasks)), 'bw_finished', conf)
39 changes: 39 additions & 0 deletions bugwarrior/notifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from twiggy import log
import subprocess
import datetime

def send_notification(issue, crud, conf):
notify_binary = conf.get('general', 'notifications')
if notify_binary == 'pync':
from pync import Notifier
if crud == 'bw_finished':
Notifier.notify('Bugwarrior finished querying for new issues.', title="Bugwarrior", subtitle=issue)
return
command = []
message = issue['description'].encode("utf-8")
title_text = "%s task: %s" % (crud, issue['description'].encode("utf-8")[:20])
subtitle_text = ''
due = ''
tags = ''
priority = ''
if 'project' in issue:
project = "Proj: " + issue['project']
if 'due' in issue:
due = "Due: " + str(issue['due'])
if 'tags' in issue:
tags = "Tags: " + ', '.join(issue['tags'])
if 'priority' in issue:
priority = "Pri: " + issue['priority']
if project != '':
subtitle_text += project + " "
if priority != '':
subtitle_text += priority + " "
if due != '':
subtitle_text += due + " "
if tags != '':
subtitle_text += tags + " "
if 'uuid' in issue:
execute_cmd = 'task %s' % issue['uuid']
else:
execute_cmd = 'task list'
Notifier.notify(message, title=title_text, subtitle=subtitle_text, execute=execute_cmd)

0 comments on commit 8b258b3

Please sign in to comment.