From e91636fd4407ab91f7ee0e3b6c7046a84c318cc8 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Mon, 25 Aug 2014 20:37:22 -0700 Subject: [PATCH 1/7] Adding functionality allowing one to update extra post-object-creation. --- bugwarrior/services/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bugwarrior/services/__init__.py b/bugwarrior/services/__init__.py index 798c731ae..21195464e 100644 --- a/bugwarrior/services/__init__.py +++ b/bugwarrior/services/__init__.py @@ -253,6 +253,9 @@ def __init__(self, foreign_record, origin=None, extra=None): self._origin = origin if origin else {} self._extra = extra if extra else {} + def update_extra(self, extra): + self._extra.update(extra) + def to_taskwarrior(self): """ Transform a foreign record into a taskwarrior dictionary.""" raise NotImplementedError() From 2a9f1b8fae6013e914d951854d46c514dedddc09 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Mon, 25 Aug 2014 20:38:02 -0700 Subject: [PATCH 2/7] Only create JiraIssue instance once. --- bugwarrior/services/jira.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bugwarrior/services/jira.py b/bugwarrior/services/jira.py index 16bfcb96d..3d1817bc6 100644 --- a/bugwarrior/services/jira.py +++ b/bugwarrior/services/jira.py @@ -158,13 +158,12 @@ def validate_config(cls, config, target): IssueService.validate_config(config, target) - def annotations(self, issue): + def annotations(self, issue, issue_obj): comments = self.jira.comments(issue.key) if not comments: return [] else: - issue_obj = self.get_issue_for_record(issue.raw) return self.build_annotations( (( comment.author.name, @@ -181,11 +180,13 @@ def issues(self): jira_version = self.config.getint(self.target, 'jira.version') for case in cases: + issue = self.get_issue_for_record(case.raw) extra = { 'jira_version': jira_version, } if jira_version > 4: extra.update({ - 'annotations': self.annotations(case) + 'annotations': self.annotations(case, issue) }) - yield self.get_issue_for_record(case.raw, extra) + issue.update_extra(extra) + yield issue From 3ef7e3f5b3dfbe7fc65497b76b5aab1d8fc7f210 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Mon, 25 Aug 2014 20:42:37 -0700 Subject: [PATCH 3/7] Only create ActivecollabIssue instance once. --- bugwarrior/services/activecollab.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bugwarrior/services/activecollab.py b/bugwarrior/services/activecollab.py index 69214c0b1..bb089a73c 100644 --- a/bugwarrior/services/activecollab.py +++ b/bugwarrior/services/activecollab.py @@ -199,7 +199,7 @@ def get_owner(self, issue): if issue['assignee_id']: return issue['assignee_id'] - def annotations(self, issue): + def annotations(self, issue, issue_obj): if 'type' not in issue: # Subtask return [] @@ -207,7 +207,6 @@ def annotations(self, issue): if comments is None: return [] - issue_obj = self.get_issue_for_record(issue) return self.build_annotations( (( c['user'], @@ -246,7 +245,9 @@ def issues(self): log.name(self.target).debug(" Found {0} total", task_count) log.name(self.target).debug(" Pruned down to {0}", len(issues)) for issue in issues: + issue_obj = self.get_issue_for_record(issue) extra = { - 'annotations': self.annotations(issue) + 'annotations': self.annotations(issue, issue_obj) } - yield self.get_issue_for_record(issue, extra) + issue_obj.update_extra(extra) + yield issue_obj From e63745500d13b8c50064ec37934d60258c9b456b Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Mon, 25 Aug 2014 20:43:57 -0700 Subject: [PATCH 4/7] Only create BitbucketIssue instance once. --- bugwarrior/services/bitbucket.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bugwarrior/services/bitbucket.py b/bugwarrior/services/bitbucket.py index 155e2d3e3..2cacae339 100644 --- a/bugwarrior/services/bitbucket.py +++ b/bugwarrior/services/bitbucket.py @@ -105,11 +105,10 @@ def pull(self, tag): response = self.get_data('/repositories/%s/issues/' % tag) return [(tag, issue) for issue in response['issues']] - def get_annotations(self, tag, issue): + def get_annotations(self, tag, issue, issue_obj): response = self.get_data( '/repositories/%s/issues/%i/comments' % (tag, issue['local_id']) ) - issue_obj = self.get_issue_for_record(issue) return self.build_annotations( (( comment['author_info']['username'], @@ -140,11 +139,13 @@ def issues(self): log.name(self.target).debug(" Pruned down to {0}", len(issues)) for tag, issue in issues: + issue_obj = self.get_issue_for_record(issue) extras = { 'project': tag.split('/')[1], 'url': self.BASE_URL + '/'.join( issue['resource_uri'].split('/')[3:] ).replace('issues', 'issue'), - 'annotations': self.get_annotations(tag, issue) + 'annotations': self.get_annotations(tag, issue, issue_obj) } - yield self.get_issue_for_record(issue, extras) + issue_obj.update_extra(extras) + yield issue_obj From 8c572587cd2dd0716cdb00bf1ef5bef120eda049 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Mon, 25 Aug 2014 20:44:30 -0700 Subject: [PATCH 5/7] Only create BugzillaIssue instance once. --- bugwarrior/services/bz.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bugwarrior/services/bz.py b/bugwarrior/services/bz.py index 3d9bfbf5c..7bbc8c59d 100644 --- a/bugwarrior/services/bz.py +++ b/bugwarrior/services/bz.py @@ -114,9 +114,7 @@ def get_owner(self, issue): # used by this IssueService. raise NotImplementedError - def annotations(self, tag, issue): - - issue_obj = self.get_issue_for_record(issue) + def annotations(self, tag, issue, issue_obj): base_url = "https://%s/show_bug.cgi?id=" % self.base_uri long_url = base_url + six.text_type(issue['id']) url = issue_obj.get_processed_url(long_url) @@ -190,11 +188,13 @@ def issues(self): # Build a url for each issue base_url = "https://%s/show_bug.cgi?id=" % (self.base_uri) for tag, issue in issues: + issue_obj = self.get_issue_for_record(issue) extra = { 'url': base_url + six.text_type(issue['id']), - 'annotations': self.annotations(tag, issue), + 'annotations': self.annotations(tag, issue, issue_obj), } - yield self.get_issue_for_record(issue, extra) + issue_obj.update_extra(extra) + yield issue_obj def _get_bug_attr(bug, attr): From 2ca1ec0edfb533874e1911c397b35aaf47a4e525 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Mon, 25 Aug 2014 20:46:53 -0700 Subject: [PATCH 6/7] Only create GithubIssue instance once. --- bugwarrior/services/github.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/bugwarrior/services/github.py b/bugwarrior/services/github.py index 74ec7da11..dc8b8447f 100644 --- a/bugwarrior/services/github.py +++ b/bugwarrior/services/github.py @@ -188,7 +188,7 @@ def _comments(self, tag, number): user, repo = tag.split('/') return githubutils.get_comments(user, repo, number, auth=self.auth) - def annotations(self, tag, issue): + def annotations(self, tag, issue, issue_obj): url = issue['html_url'] comments = self._comments(tag, issue['number']) return self.build_annotations( @@ -196,7 +196,7 @@ def annotations(self, tag, issue): c['user']['login'], c['body'], ) for c in comments), - self.get_issue_for_record(issue).get_processed_url(url) + issue_obj.get_processed_url(url) ) def _reqs(self, tag): @@ -271,20 +271,24 @@ def issues(self): issues = [i for i in issues if not i[1]['html_url'] in request_urls] for tag, issue in issues: + issue_obj = self.get_issue_for_record(issue) extra = { 'project': tag.split('/')[1], 'type': 'issue', - 'annotations': self.annotations(tag, issue) + 'annotations': self.annotations(tag, issue, issue_obj) } - yield self.get_issue_for_record(issue, extra) + issue_obj.update_extra(extra) + yield issue_obj for tag, request in requests: + issue_obj = self.get_issue_for_record(request) extra = { 'project': tag.split('/')[1], 'type': 'pull_request', - 'annotations': self.annotations(tag, request) + 'annotations': self.annotations(tag, request, issue_obj) } - yield self.get_issue_for_record(request, extra) + issue_obj.update_extra(extra) + yield issue_obj @classmethod def validate_config(cls, config, target): From 61ed88f76e2314631f372256ec80d18b72a48e86 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Mon, 25 Aug 2014 20:49:15 -0700 Subject: [PATCH 7/7] Only create TracIssue instance once. --- bugwarrior/services/trac.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bugwarrior/services/trac.py b/bugwarrior/services/trac.py index 1d09babd0..fa9ae15e4 100644 --- a/bugwarrior/services/trac.py +++ b/bugwarrior/services/trac.py @@ -91,15 +91,14 @@ def validate_config(cls, config, target): IssueService.validate_config(config, target) - def annotations(self, tag, issue): + def annotations(self, tag, issue, issue_obj): annotations = [] changelog = self.trac.server.ticket.changeLog(issue['number']) for time, author, field, oldvalue, newvalue, permament in changelog: if field == 'comment': annotations.append((author, newvalue, )) - url = issue['url'] - url = self.get_issue_for_record(issue).get_processed_url(url) + url = issue_obj.get_processed_url(issue['url']) return self.build_annotations(annotations, url) def get_owner(self, issue): @@ -122,8 +121,10 @@ def issues(self): log.name(self.target).debug(" Pruned down to {0}", len(issues)) for project, issue in issues: + issue_obj = self.get_issue_for_record(issue) extra = { - 'annotations': self.annotations(project, issue), + 'annotations': self.annotations(project, issue, issue_obj), 'project': project, } - yield self.get_issue_for_record(issue, extra) + issue_obj.update_extra(extra) + yield issue_obj