Skip to content

Commit

Permalink
Merge pull request #59 from kostajh/notifications
Browse files Browse the repository at this point in the history
Notifications
  • Loading branch information
ralphbean committed Mar 1, 2013
2 parents 1c05d2b + 03128dd commit 953adfe
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 5 deletions.
13 changes: 12 additions & 1 deletion bugwarrior/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ Create a ``~/.bugwarriorrc`` file with the following contents.
# https://github.com/ralphbean/bugwarrior/issues
#multiprocessing = False

# This section is for configuring notifications when bugwarrior-pull runs,
# and when issues are created, updated, or deleted by bugwarrior-pull.
# Currently only growlnotify (v2) on Mac OS X is supported. To configure,
# first install the gntp library ("pip install gntp"). Then adjust the settings
# below.
[notifications]
# notifications = True
# backend = growlnotify
# finished_querying_sticky = False
# task_crud_sticky = True

# This is a github example. It says, "scrape every issue from every repository
# on http://github.com/ralphbean. It doesn't matter if ralphbean owns the issue
# or not."
Expand Down Expand Up @@ -250,6 +261,6 @@ Contributors
- Justin Forest (contributed support for RedMine, TeamLab, and MegaPlan, as
well as some unicode help)
- Tycho Garen (contributed support for Jira)
- Kosta Harlan (contributed support for ActiveCollab2)
- Kosta Harlan (contributed support for ActiveCollab 2.x/3.x, and notifications)
- Luke Macken (contributed some code cleaning)
- James Rowe (contributed to the docs)
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,13 +1,17 @@
from twiggy import log

from taskw import TaskWarrior
from bugwarrior.notifications import send_notification
from bugwarrior.config import asbool


MARKUP = "(bw)"


def synchronize(issues):
def synchronize(issues, conf):
tw = TaskWarrior()
if asbool(conf.get('notifications', 'notifications', 'True')):
notify = True
else:
notify = False

# Load info about the task database
tasks = tw.load_tasks()
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)
61 changes: 61 additions & 0 deletions bugwarrior/notifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import datetime
from bugwarrior.config import asbool

def _get_metadata(issue):
due = ''
tags = ''
priority = ''
metadata = ''
if 'project' in issue:
project = "Project: " + issue['project']
if 'due' in issue:
due = "Due: " + datetime.datetime.fromtimestamp(int(issue['due'])).strftime('%Y-%m-%d')
if 'tags' in issue:
tags = "Tags: " + ', '.join(issue['tags'])
if 'priority' in issue:
priority = "Priority: " + issue['priority']
if project != '':
metadata += "\n" + project
if priority != '':
metadata += "\n" + priority
if due != '':
metadata += "\n" + due
if tags != '':
metadata += "\n" + tags
return metadata

def send_notification(issue, op, conf):
notify_backend = conf.get('notifications', 'backend')

# Notifications for growlnotify on Mac OS X
if notify_backend == 'growlnotify':
import gntp.notifier
growl = gntp.notifier.GrowlNotifier(
applicationName = "Bugwarrior",
notifications = ["New Updates", "New Messages"],
defaultNotifications = ["New Messages"],
)
growl.register()
if op == 'bw_finished':
growl.notify(
noteType = "New Messages",
title = "Bugwarrior",
description = "Finished querying for new issues.\n%s" % issue,
sticky = asbool(conf.get('notifications', 'finished_querying_sticky', 'True')),
icon = "https://upload.wikimedia.org/wikipedia/en/5/59/Taskwarrior_logo.png",
priority = 1,
)
return
message = "%s task: %s" % (op, issue['description'].encode("utf-8"))
metadata = _get_metadata(issue)
if metadata is not None:
message += metadata
growl.notify(
noteType = "New Messages",
title = "Bugwarrior",
description = message,
sticky = asbool(conf.get('notifications', 'task_crud_sticky', 'True')),
icon = "https://upload.wikimedia.org/wikipedia/en/5/59/Taskwarrior_logo.png",
priority = 1,
)
return

0 comments on commit 953adfe

Please sign in to comment.