-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
[Jira JQL] Add: support custom JIRA fields and enhance value mapping #1508
Merged
arikfr
merged 4 commits into
getredash:master
from
stefanseifert:feature/jql-custom-fields
Jan 24, 2017
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2aae497
include custom fields in JQL query results
stefanseifert 689a1aa
should set nothing instead of empty string as value when no valid lis…
stefanseifert 9126874
apply snake_case naming conventions
stefanseifert 187b557
adapt to new field mapping syntax and add unit tests
stefanseifert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,15 +26,33 @@ def to_json(self): | |
return json.dumps({'rows': self.rows, 'columns': self.columns.values()}) | ||
|
||
|
||
def parse_issue(issue): | ||
def parse_issue(issue, fieldMapping): | ||
result = OrderedDict() | ||
result['key'] = issue['key'] | ||
|
||
for k, v in issue['fields'].iteritems(): | ||
if k.startswith('customfield_'): | ||
continue | ||
|
||
if isinstance(v, dict): | ||
# if field mapping is defined optionally change output key and parsing rules for value | ||
if k in fieldMapping: | ||
mapping = fieldMapping[k] | ||
output_key = k | ||
if 'name' in mapping: | ||
output_key = mapping['name'] | ||
put_value(result, output_key, v, mapping) | ||
|
||
else: | ||
put_value(result, k, v, {}) | ||
|
||
return result | ||
|
||
|
||
def put_value(result, k, v, mapping): | ||
if isinstance(v, dict): | ||
if 'member' in mapping: | ||
result[k] = v[mapping['member']] | ||
|
||
else: | ||
# these special mapping rules are kept for backwards compatibility | ||
if 'key' in v: | ||
result['{}_key'.format(k)] = v['key'] | ||
if 'name' in v: | ||
|
@@ -45,19 +63,27 @@ def parse_issue(issue): | |
|
||
if 'watchCount' in v: | ||
result[k] = v['watchCount'] | ||
# elif isinstance(v, list): | ||
# pass | ||
else: | ||
result[k] = v | ||
|
||
elif isinstance(v, list): | ||
listValues = [] | ||
for listItem in v: | ||
if isinstance(listItem, dict): | ||
if 'member' in mapping: | ||
listValues.append(listItem[mapping['member']]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if |
||
else: | ||
listValues.append(listItem) | ||
if len(listValues) > 0: | ||
result[k] = ','.join(listValues) | ||
|
||
return result | ||
else: | ||
result[k] = v | ||
|
||
|
||
def parse_issues(data): | ||
def parse_issues(data, fieldMapping): | ||
results = ResultSet() | ||
|
||
for issue in data['issues']: | ||
results.add_row(parse_issue(issue)) | ||
results.add_row(parse_issue(issue, fieldMapping)) | ||
|
||
return results | ||
|
||
|
@@ -109,6 +135,7 @@ def run_query(self, query, user): | |
try: | ||
query = json.loads(query) | ||
query_type = query.pop('queryType', 'select') | ||
fieldMapping = query.pop('fieldMapping', {}) | ||
|
||
if query_type == 'count': | ||
query['maxResults'] = 1 | ||
|
@@ -127,7 +154,7 @@ def run_query(self, query, user): | |
if query_type == 'count': | ||
results = parse_count(data) | ||
else: | ||
results = parse_issues(data) | ||
results = parse_issues(data, fieldMapping) | ||
|
||
return results.to_json(), None | ||
except KeyboardInterrupt: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be
field_mapping
(we usesnake_case
in the Python code).