Skip to content

Commit

Permalink
Merge pull request #68 from nikolavp/jira4-fixes
Browse files Browse the repository at this point in the history
Make the jira service version 4 compatible
  • Loading branch information
ralphbean committed Jun 7, 2013
2 parents 3eb477c + e144f5b commit 9c000d8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
4 changes: 4 additions & 0 deletions bugwarrior/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ Create a ``~/.bugwarriorrc`` file with the following contents.
jira.password = OMG_LULZ
jira.query = assignee = ralph and status != closed and status != resolved
jira.project_prefix = Programming.
# Set this to your jira major version. We currently support only jira version
# 4 and 5(the default). You can find your particular version in the footer at
# the dashboard.
jira.version = 5

# Here's an example of a teamlab target.
[my_teamlab]
Expand Down
54 changes: 44 additions & 10 deletions bugwarrior/services/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def __init__(self, *args, **kw):
self.target, 'jira.project_prefix', '')
self.jira = JIRA(
options={
'server': self.config.get(self.target, 'jira.base_uri')
'server': self.config.get(self.target, 'jira.base_uri'),
'rest_api_version': 'latest',
},
basic_auth=(
self.username,
Expand Down Expand Up @@ -75,12 +76,27 @@ def annotations(self, issue):

return dict(annotations)

def issues(self):
cases = self.jira.search_issues(self.query, maxResults=-1)

log.name(self.target).debug(" Found {0} total.", len(cases))

return [dict(
def __convert_for_jira4(self,issue):
print(issue.key)
class IssueWrapper:
pass
#print(self.jira.issue(issue.key).fields.summary.value)
#print(self.jira.issue(issue.key).fields.summary)
new_issue = self.jira.issue(issue.key)
result = IssueWrapper()
fields = IssueWrapper()
fields.__dict__ = {
'summary': new_issue.fields.summary.value,
'priority': new_issue.fields.priority.name,
}
result.__dict__ = {
'key': issue.key,
'fields': fields,
}
return result

def __issue(self, case, jira_version):
result = dict(
description=self.description(
title=case.fields.summary,
url=self.url + '/browse/' + case.key,
Expand All @@ -90,6 +106,24 @@ def issues(self):
priority=self.priorities.get(
get_priority(case.fields.priority),
self.default_priority,
),
**self.annotations(case.key)
) for case in cases]
)
)
if jira_version != 4:
result.update(self.annotations(case.key))
return result

def issues(self):
cases = self.jira.search_issues(self.query, maxResults=-1)

jira_version = 5 # Default version number
if self.config.has_option(self.target, 'jira.version'):
jira_version = self.config.getint(self.target, 'jira.version')
if jira_version == 4:
# Convert for older jira versions that don't support the new API
cases = [self.__convert_for_jira4(case) for case in cases]


log.name(self.target).debug(" Found {0} total.", len(cases))


return [self.__issue(case, jira_version) for case in cases]

0 comments on commit 9c000d8

Please sign in to comment.