Skip to content

Commit

Permalink
Adding tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Coddington authored and coddingtonbear committed Mar 5, 2014
1 parent cde5c2e commit 09685d6
Show file tree
Hide file tree
Showing 26 changed files with 792 additions and 215 deletions.
105 changes: 52 additions & 53 deletions bugwarrior/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ Create a ``~/.bugwarriorrc`` file with the following contents.
# a one-line Jinja template like the below; in addition to the default
# taskwarrior issue properties (project, priority, due, etc), the
# following properties are available for Github issues:
# - github_title: The title of the issue in Github
# - github_url: This issue or pull request's URL.
# - github_pr: The pull request # of the pull request in Github.
# - github_issue: The issue # of this issue in Github.
# - github_type: The type of github entry this is ('pull_request' or 'issue')
#description_template = {% if type == 'pull_request' %}PR #{{ github_pr }}{% else %}Issue #{{ github_issue }}{% endif %}: {{ github_title }}
# - githubtitle: The title of the issue in Github
# - githuburl: This issue or pull request's URL.
# - githubnumber: The pull request # or issue # in Github.
# - githubtype: The type of github entry this is ('pullrequest' or 'issue')
#description_template = {% if type == 'pull_request' %}PR #{{ githubpr }}{% else %}Issue #{{ githubissue }}{% endif %}: {{ githubtitle }}

# I want taskwarrior to include issues from all my repos, except these
# two because they're spammy or something.
Expand Down Expand Up @@ -134,10 +133,10 @@ Create a ``~/.bugwarriorrc`` file with the following contents.
# a one-line Jinja template like the below; in addition to the default
# taskwarrior issue properties (project, priority, due, etc), the
# following properties are available for Bitbucket issues:
# - bitbucket_title
# - bitbucket_url
# - bitbucket_id
#description_template = #{{ bitbucket_id }}: {{ bitbucket_title }}
# - bitbuckettitle
# - bitbucketurl
# - bitbucketid
#description_template = #{{ bitbucketid }}: {{ bitbuckettitle }}

# Here's another bitbucket one. Here we want to scrape the issues from repos of
# another user, but only include them in the taskwarrior db if they're assigned
Expand Down Expand Up @@ -167,10 +166,10 @@ Create a ``~/.bugwarriorrc`` file with the following contents.
# a one-line Jinja template like the below; in addition to the default
# taskwarrior issue properties (project, priority, due, etc), the
# following properties are available for Trac issues:
# - trac_summary
# - trac_url
# - trac_number
#description_template = #{{ trac_number }}: {{ trac_summary }}
# - tracsummary
# - tracurl
# - tracnumber
#description_template = #{{ tracnumber }}: {{ tracsummary }}

# Here's an example of a bugzilla target. This will scrape every ticket
# 1) that is not closed and 2) that [email protected] is either the
Expand All @@ -188,9 +187,9 @@ Create a ``~/.bugwarriorrc`` file with the following contents.
# a one-line Jinja template like the below; in addition to the default
# taskwarrior issue properties (project, priority, due, etc), the
# following properties are available for Bugzilla issues:
# - bugzilla_url
# - bugzilla_summary
#description_template = {{ bugzilla_summary }}
# - bugzillaurl
# - bugzillasummary
#description_template = {{ bugzillasummary }}

# Here's an example of a megaplan target.
[my_megaplan]
Expand All @@ -207,10 +206,10 @@ Create a ``~/.bugwarriorrc`` file with the following contents.
# a one-line Jinja template like the below; in addition to the default
# taskwarrior issue properties (project, priority, due, etc), the
# following properties are available for Megaplan issues:
# - megaplan_url
# - megaplan_id
# - megaplan_title
#description_template = #{{ megaplan_id }}: {{ megaplan_title }}
# - megaplanurl
# - megaplanid
# - megaplantitle
#description_template = #{{ megaplanid }}: {{ megaplantitle }}

# Here's an example of a jira project. The ``jira-python`` module is
# a bit particular, and jira deployments, like Bugzilla, tend to be
Expand All @@ -233,10 +232,10 @@ Create a ``~/.bugwarriorrc`` file with the following contents.
# a one-line Jinja template like the below; in addition to the default
# taskwarrior issue properties (project, priority, due, etc), the
# following properties are available for JIRA issues:
# - jira_summary
# - jira_url
# - jira_id
#description_template = {{ jira_id }}: {{ jira_summary }}
# - jirasummary
# - jiraurl
# - jiraid
#description_template = {{ jiraid }}: {{ jirasummary }}

# Here's an example of a teamlab target.
[my_teamlab]
Expand All @@ -251,11 +250,11 @@ Create a ``~/.bugwarriorrc`` file with the following contents.
# a one-line Jinja template like the below; in addition to the default
# taskwarrior issue properties (project, priority, due, etc), the
# following properties are available for Teamlab issues:
# - teamlab_url
# - teamlab_id
# - teamlab_title
# - teamlab_projectowner_id
#description_template = #{{ teamlab_id }}: {{ teamlab_title }}
# - teamlaburl
# - teamlabid
# - teamlabtitle
# - teamlabprojectowner_id
#description_template = #{{ teamlabid }}: {{ teamlabtitle }}

# Here's an example of a redmine target.
[my_redmine]
Expand All @@ -269,10 +268,10 @@ Create a ``~/.bugwarriorrc`` file with the following contents.
# a one-line Jinja template like the below; in addition to the default
# taskwarrior issue properties (project, priority, due, etc), the
# following properties are available for Redmine issues:
# - redmine_url
# - redmine_subject
# - redmine_id
#description_template = #{{ redmine_id }}: {{ redmine_subject }}
# - redmineurl
# - redminesubject
# - redmineid
#description_template = #{{ redmineid }}: {{ redminesubject }}

# Here's an example of an activecollab3 target. This is only valid for
# activeCollab 3.x, see below for activeCollab 2.x.
Expand All @@ -299,16 +298,16 @@ Create a ``~/.bugwarriorrc`` file with the following contents.
# a one-line Jinja template like the below; in addition to the default
# taskwarrior issue properties (project, priority, due, etc), the
# following properties are available for ActiveCollab3 issues:
# - ac3_body
# - ac3_name
# - ac3_permalink
# - ac3_task_id
# - ac3_id
# - ac3_project_id
# - ac3_type
# - ac3_created_on
# - ac3_created_by_id
#description_template = #{{ac3_id}} - {% if ac3_name %}{{ ac3_name }}{% else %}{{ ac3_body }}{% endif %}
# - ac3body
# - ac3name
# - ac3permalink
# - ac3taskid
# - ac3id
# - ac3projectid
# - ac3type
# - ac3createdon
# - ac3createdbyid
#description_template = #{{ac3id}} - {% if ac3name %}{{ ac3name }}{% else %}{{ ac3body }}{% endif %}

# Here's an example of an activecollab2 target. Note that this will only work
# with ActiveCollab 2.x - see above for 3.x.
Expand Down Expand Up @@ -340,15 +339,15 @@ Create a ``~/.bugwarriorrc`` file with the following contents.
# a one-line Jinja template like the below; in addition to the default
# taskwarrior issue properties (project, priority, due, etc), the
# following properties are available for ActiveCollab2 issues:
# - ac2_body
# - ac2_name
# - ac2_permalink
# - ac2_ticket_id
# - ac2_project_id
# - ac2_type
# - ac2_created_on
# - ac2_created_by_id
#description_template = #{{ac2_ticket_id}} - {% if ac2_name %}{{ ac2_name }}{% else %}{{ ac2_body }}{% endif %}
# - ac2body
# - ac2name
# - ac2permalink
# - ac2ticketid
# - ac2projectid
# - ac2type
# - ac2createdon
# - ac2createdbyid
#description_template = #{{ac2ticketid}} - {% if ac2name %}{{ ac2name }}{% else %}{{ ac2body }}{% endif %}

.. example
Expand Down
43 changes: 29 additions & 14 deletions bugwarrior/db.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import copy
import re
import warnings

import six
from twiggy import log
from taskw import TaskWarriorShellout
from taskw.utils import get_annotation_value

from bugwarrior.config import asbool, NoOptionError
from bugwarrior.notifications import send_notification
Expand Down Expand Up @@ -36,16 +38,15 @@ def tasks_differ(left, right):
if set(left) - set(right):
return True
for k in left:
if k == 'annotations':
left[k] = [v['description'] for v in left[k]]
right[k] = [v['description'] for v in right[k]]
if k in ('annotations', 'urgency', ):
continue
if (
isinstance(left[k], (list, tuple))
and isinstance(right[k], (list, tuple))
):
left[k] = set(left[k])
right[k] = set(right[k])
if left[k] != right[k]:
if str(left[k]) != str(right[k]):
return True
return False

Expand Down Expand Up @@ -80,14 +81,15 @@ def find_local_uuid(tw, keys, issue, legacy_matching=True):
possibilities = possibilities | set([
task['uuid'] for task in results
])
for key in keys:
if key in issue:
results = tw.filter_tasks({
key: issue[key]
})
possibilities = possibilities | set([
task['uuid'] for task in results
])
for service, key_list in six.iteritems(keys):
for key in key_list:
if key in issue:
results = tw.filter_tasks({
key: issue[key]
})
possibilities = possibilities | set([
task['uuid'] for task in results
])
if len(possibilities) == 1:
return possibilities.pop()
if len(possibilities) > 1:
Expand Down Expand Up @@ -164,6 +166,7 @@ def _bool_option(section, option, default):
task_copy = copy.deepcopy(task)

# Handle merging annotations
annotations_changed = False
for annotation in [
a['description'] for a in task.get('annotations', [])
]:
Expand All @@ -176,6 +179,7 @@ def _bool_option(section, option, default):
) == 0:
found = True
if not found:
annotations_changed = True
issue_dict['annotations'].append(annotation)

# Merging tags, too
Expand All @@ -186,7 +190,7 @@ def _bool_option(section, option, default):
issue_dict['tags'].append(tag)

task.update(issue_dict)
if tasks_differ(task_copy, task):
if tasks_differ(task_copy, task) or annotations_changed:
issue_updates['changed'].append(task)
else:
issue_updates['existing'].append(task)
Expand Down Expand Up @@ -216,7 +220,7 @@ def _bool_option(section, option, default):
tw.task_update(issue)

for issue in issue_updates['closed']:
task_info = tw.get(uuid=issue)
task_info = tw.get_task(uuid=issue)
log.name('db').info(
"Completing task {0}",
task_info
Expand Down Expand Up @@ -258,6 +262,17 @@ def build_uda_list(targets):
targets_udas.update(SERVICES[target].ISSUE_CLASS.UDAS)
for name, uda_attributes in six.iteritems(targets_udas):
for attrib, value in six.iteritems(uda_attributes):
if '_' in name:
warnings.warn(
"Service '%s' has defined a potentially invalid UDA "
"named '%s'. As of the time of this writing, UDAs "
"must be alphanumeric, and may not contain "
"underscores." % (
target,
name,
),
RuntimeWarning
)
uda_output.append(
(
'uda.%s.%s' % (name, attrib, ),
Expand Down
27 changes: 22 additions & 5 deletions bugwarrior/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
from bugwarrior.db import MARKUP


# Semaphores for process completion status
# Sentinels for process completion status
SERVICE_FINISHED_OK = object()
SERVICE_FINISHED_ERROR = object()


class IssueService(object):
""" Abstract base class for each service """
ISSUE_CLASS = None
CONFIG_PREFIX = ''

def __init__(self, config, target):
self.config = config
Expand All @@ -35,8 +36,27 @@ def __init__(self, config, target):
)
else:
self.description_template = None
if config.has_option(self.target, 'default_priority'):
self.default_priority = config.get(self.target, 'default_priority')
else:
self.default_priority = 'M'
log.name(target).info("Working on [{0}]", self.target)

def config_get_default(self, key, default=None):
try:
return self.config_get(key)
except:
return default

def config_get(self, key=None):
return self.config.get(self.target, self._get_key(key))

def _get_key(self, key):
return '%s.%s' % (
self.CONFIG_PREFIX,
key
)

def get_service_metadata(self):
return {}

Expand Down Expand Up @@ -69,10 +89,7 @@ def build_annotations(self, annotations):
@classmethod
def validate_config(cls, config, target):
""" Validate generic options for a particular target """

cls.default_priority = 'M'
if config.has_option(target, 'default_priority'):
cls.default_priority = config.get(target, 'default_priority')
pass

def include(self, issue):
""" Return true if the issue in question should be included """
Expand Down
Loading

0 comments on commit 09685d6

Please sign in to comment.