Skip to content

Commit

Permalink
Fix pycontribs#93: ability to retrieve custom fields by their JQL names.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorin Sbarnea committed Oct 11, 2015
1 parent 2dddaf2 commit 0ad3c35
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ def __init__(self, server=None, options=None, basic_auth=None, oauth=None, jwt=N
self._check_update_()
JIRA.checked_version = True

# TODO: check if this works with non-admin accounts
self._fields = {}
for f in self.fields():
for name in f['clauseNames']:
self._fields[name] = f['id']

def _check_update_(self):
# check if the current version of the library is outdated
try:
Expand Down Expand Up @@ -1571,6 +1577,21 @@ def search_issues(self, jql_str, startAt=0, maxResults=50, validate_query=True,
if fields is None:
fields = []

if isinstance(fields, basestring):
if "," in fields:
fields = fields.split(",")
else:
fields = [fields]

# this will translate JQL field names to REST API Name
# most people do know the JQL names so this will help them use the API easier
untranslate = {} # use to add friendly aliases when we get the results back
if self._fields:
for i, field in enumerate(fields):
if field in self._fields:
untranslate[self._fields[field]] = fields[i]
fields[i] = self._fields[field]

# If None is passed as parameter, this fetch all issues from the query
if not maxResults:
maxResults = maxi
Expand Down Expand Up @@ -1601,6 +1622,13 @@ def search_issues(self, jql_str, startAt=0, maxResults=50, validate_query=True,
resource['issues']]
issues.extend(issue_batch)
cnt = len(issue_batch)

if untranslate:
for i in issues:
for k, v in untranslate.iteritems():
if k in i.raw['fields']:
i.raw['fields'][v] = i.raw['fields'][k]

return ResultList(issues, total)

# Security levels
Expand Down
2 changes: 1 addition & 1 deletion jira/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# 1) we don't load dependencies by storing it in __init__.py
# 2) we can import it in setup.py for the same reason
# 3) we can import it into the jira module
__version__ = '1.0.1'
__version__ = '1.0.3'

0 comments on commit 0ad3c35

Please sign in to comment.