Skip to content

Commit

Permalink
Adding option allowing one to import github labels as tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
coddingtonbear committed Mar 7, 2014
1 parent 79b3220 commit 1f2cbf8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
10 changes: 10 additions & 0 deletions bugwarrior/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ Create a ``~/.bugwarriorrc`` file with the following contents.
github.login = ralphbean
github.password = OMG_LULZ

# Pull-in github labels as tags?
github.import_labels_as_tags = True

# Template to use for generating the tag name from the github label
# will receive, as context, all task fields by name, as well as a
# context variable named `label` containing the github label name.
# This can be used (as is below) to prefix a label with 'github_'.
# By default, the label is converted into a tag name without changes.
#github.label_template = github_{{label}}

# This is the same thing, but for bitbucket. Each target entry must have a
# 'service' attribute which must be one of the supported services (like
# 'github', 'bitbucket', 'trac', etc...).
Expand Down
11 changes: 7 additions & 4 deletions bugwarrior/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ def __init__(self, config, target):

log.name(target).info("Working on [{0}]", self.target)

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

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

def _get_key(self, key):
return '%s.%s' % (
Expand Down
40 changes: 37 additions & 3 deletions bugwarrior/services/github.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from jinja2 import Template
import six
from twiggy import log

from bugwarrior.config import die, get_service_password
from bugwarrior.config import asbool, die, get_service_password
from bugwarrior.services import IssueService, Issue

from . import githubutils
Expand Down Expand Up @@ -37,13 +39,33 @@ def to_taskwarrior(self):
'project': self.extra['project'],
'priority': self.origin['default_priority'],
'annotations': self.extra.get('annotations', []),
'tags': self.get_tags(),

self.URL: self.record['html_url'],
self.TYPE: self.extra['type'],
self.TITLE: self.record['title'],
self.NUMBER: self.record['number'],
}

def get_tags(self):
tags = []

if not self.origin['import_labels_as_tags']:
return tags

context = self.record.copy()
label_template = Template(self.origin['label_template'])

for label_dict in self.record.get('labels', []):
context.update({
'label': label_dict['name']
})
tags.append(
label_template.render(context)
)

return tags

def get_default_description(self):
return self.build_default_description(
title=self.record['title'],
Expand Down Expand Up @@ -72,20 +94,32 @@ def __init__(self, *args, **kw):
self.auth = (login, password)

self.exclude_repos = []
self.include_repos = []

if self.config_get_default('exclude_repos', None):
self.exclude_repos = [
item.strip() for item in
self.config_get('exclude_repos').strip().split(',')
]

self.include_repos = []
if self.config_get_default('include_repos', None):
self.include_repos = [
item.strip() for item in
self.config_get('include_repos').strip().split(',')
]

self.import_labels_as_tags = self.config_get_default(
'import_labels_as_tags', default=False, to_type=asbool
)
self.label_template = self.config_get_default(
'label_template', default='{{label}}', to_type=six.text_type
)

def get_service_metadata(self):
return {
'import_labels_as_tags': self.import_labels_as_tags,
'label_template': self.label_template,
}

def _issues(self, tag):
""" Grab all the issues """
return [
Expand Down

0 comments on commit 1f2cbf8

Please sign in to comment.