Skip to content

Commit

Permalink
Merge pull request #166 from djmitche/normalize-github-tags
Browse files Browse the repository at this point in the history
Github tag should be normalized to taskwarrior tags
  • Loading branch information
ralphbean committed Dec 1, 2014
2 parents 03a3231 + 177d69b commit 84a0845
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
5 changes: 4 additions & 1 deletion bugwarrior/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class GithubIssue(Issue):
}
UNIQUE_KEY = (URL, TYPE,)

def _normalize_label_to_tag(self, label):
return re.sub(r'[^a-zA-Z0-9]', '_', label)

def to_taskwarrior(self):
milestone = self.record['milestone']
if milestone:
Expand Down Expand Up @@ -97,7 +100,7 @@ def get_tags(self):

for label_dict in self.record.get('labels', []):
context.update({
'label': label_dict['name']
'label': self._normalize_label_to_tag(label_dict['name'])
})
tags.append(
label_template.render(context)
Expand Down
67 changes: 37 additions & 30 deletions tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,56 @@ class TestGithubIssue(ServiceTest):
'github.password': 'arbitrary_password',
'github.username': 'arbitrary_username',
}
arbitrary_created = (
datetime.datetime.utcnow() - datetime.timedelta(hours=1)
).replace(tzinfo=pytz.UTC)
arbitrary_updated = datetime.datetime.utcnow().replace(tzinfo=pytz.UTC)
arbitrary_issue = {
'title': 'Hallo',
'html_url': 'http://whanot.com/',
'number': 10,
'body': 'Something',
'milestone': {'id': 'alpha'},
'created_at': arbitrary_created.isoformat(),
'updated_at': arbitrary_updated.isoformat(),
}
arbitrary_extra = {
'project': 'one',
'type': 'issue',
'annotations': [],
}

def setUp(self):
self.service = self.get_mock_service(GithubService)

def test_to_taskwarrior(self):
arbitrary_created = (
datetime.datetime.utcnow() - datetime.timedelta(hours=1)
).replace(tzinfo=pytz.UTC)
arbitrary_updated = datetime.datetime.utcnow().replace(tzinfo=pytz.UTC)
arbitrary_issue = {
'title': 'Hallo',
'html_url': 'http://whanot.com/',
'number': 10,
'body': 'Something',
'milestone': {'id': 'alpha'},
'created_at': arbitrary_created.isoformat(),
'updated_at': arbitrary_updated.isoformat(),
}
arbitrary_extra = {
'project': 'one',
'type': 'issue',
'annotations': [],
}
def test_normalize_label_to_tag(self):
issue = self.service.get_issue_for_record(
self.arbitrary_issue,
self.arbitrary_extra
)
self.assertEqual(issue._normalize_label_to_tag('needs work'),
'needs_work')

def test_to_taskwarrior(self):
issue = self.service.get_issue_for_record(
arbitrary_issue,
arbitrary_extra
self.arbitrary_issue,
self.arbitrary_extra
)

expected_output = {
'project': arbitrary_extra['project'],
'project': self.arbitrary_extra['project'],
'priority': self.service.default_priority,
'annotations': [],
'tags': [],

issue.URL: arbitrary_issue['html_url'],
issue.TYPE: arbitrary_extra['type'],
issue.TITLE: arbitrary_issue['title'],
issue.NUMBER: arbitrary_issue['number'],
issue.UPDATED_AT: arbitrary_updated,
issue.CREATED_AT: arbitrary_created,
issue.BODY: arbitrary_issue['body'],
issue.MILESTONE: arbitrary_issue['milestone']['id'],
issue.URL: self.arbitrary_issue['html_url'],
issue.TYPE: self.arbitrary_extra['type'],
issue.TITLE: self.arbitrary_issue['title'],
issue.NUMBER: self.arbitrary_issue['number'],
issue.UPDATED_AT: self.arbitrary_updated,
issue.CREATED_AT: self.arbitrary_created,
issue.BODY: self.arbitrary_issue['body'],
issue.MILESTONE: self.arbitrary_issue['milestone']['id'],
}
actual_output = issue.to_taskwarrior()

Expand Down

0 comments on commit 84a0845

Please sign in to comment.