Skip to content

Commit 0785da7

Browse files
authored
Adding ability to sanitize output for jinja templating (#79)
* Adding ability to sanitize output for jinja templating
1 parent a4de384 commit 0785da7

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## 3.1.0
4+
- Add new feature to ``jira.get_issue`` to allow for stripping of Jinja templating artifacts from resulting output. (Removes instances of {{ }} from results.)
5+
6+
Example: You pull a jira with ``code`` block in a comment or the description. To the API that shows up as {{ code }} which is jinja Templating and will cause
7+
issues when trying to use that output anywhere else in a workflow as it cannot find the `code` variable in the context.
8+
9+
310
## 3.0.1
411

512
- Fixed bug with `update_dashboard` action sending the wrong payload.

actions/get_issue.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@
99
class GetJiraIssueAction(BaseJiraAction):
1010
def run(self, issue_key, include_comments=False, include_attachments=False,
1111
include_customfields=False, include_components=False, include_subtasks=False,
12-
include_links=False):
12+
include_links=False, sanitize_formatting=False):
1313
issue = self._client.issue(issue_key)
1414
result = to_issue_dict(issue=issue, include_comments=include_comments,
1515
include_attachments=include_attachments,
1616
include_customfields=include_customfields,
1717
include_components=include_components,
1818
include_subtasks=include_subtasks,
1919
include_links=include_links)
20-
return result
20+
21+
def strip_braces(data):
22+
if isinstance(data, dict):
23+
return {k: strip_braces(v) for k, v in data.items()}
24+
elif isinstance(data, list):
25+
return [strip_braces(element) for element in data]
26+
elif isinstance(data, str):
27+
return data.replace("{{", "").replace("}}", "")
28+
else:
29+
return data
30+
31+
return strip_braces(result) if sanitize_formatting else result

actions/get_issue.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,8 @@ parameters:
3939
description: True to include linked issues.
4040
required: true
4141
default: false
42+
sanitize_formatting:
43+
type: boolean
44+
description: When set to true removes jinja template artifacts.
45+
required: true
46+
default: false

pack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords:
66
- issues
77
- ticket management
88
- project management
9-
version: 3.0.1
9+
version: 3.1.0
1010
python_versions:
1111
- "3"
1212
author: StackStorm, Inc.

0 commit comments

Comments
 (0)