Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline annotation creation such that each issue instance is created only once #140

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bugwarrior/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 5 additions & 4 deletions bugwarrior/services/activecollab.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,14 @@ 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 []
comments = self._comments(issue)
if comments is None:
return []

issue_obj = self.get_issue_for_record(issue)
return self.build_annotations(
((
c['user'],
Expand Down Expand Up @@ -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
9 changes: 5 additions & 4 deletions bugwarrior/services/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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
10 changes: 5 additions & 5 deletions bugwarrior/services/bz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
16 changes: 10 additions & 6 deletions bugwarrior/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ 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(
((
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):
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions bugwarrior/services/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
11 changes: 6 additions & 5 deletions bugwarrior/services/trac.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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