Skip to content

Commit

Permalink
Adding ability to sanitize output for jinja templating (#79)
Browse files Browse the repository at this point in the history
* Adding ability to sanitize output for jinja templating
  • Loading branch information
cwilson21 authored Apr 23, 2024
1 parent a4de384 commit 0785da7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## 3.1.0
- Add new feature to ``jira.get_issue`` to allow for stripping of Jinja templating artifacts from resulting output. (Removes instances of {{ }} from results.)

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
issues when trying to use that output anywhere else in a workflow as it cannot find the `code` variable in the context.


## 3.0.1

- Fixed bug with `update_dashboard` action sending the wrong payload.
Expand Down
15 changes: 13 additions & 2 deletions actions/get_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@
class GetJiraIssueAction(BaseJiraAction):
def run(self, issue_key, include_comments=False, include_attachments=False,
include_customfields=False, include_components=False, include_subtasks=False,
include_links=False):
include_links=False, sanitize_formatting=False):
issue = self._client.issue(issue_key)
result = to_issue_dict(issue=issue, include_comments=include_comments,
include_attachments=include_attachments,
include_customfields=include_customfields,
include_components=include_components,
include_subtasks=include_subtasks,
include_links=include_links)
return result

def strip_braces(data):
if isinstance(data, dict):
return {k: strip_braces(v) for k, v in data.items()}
elif isinstance(data, list):
return [strip_braces(element) for element in data]
elif isinstance(data, str):
return data.replace("{{", "").replace("}}", "")
else:
return data

return strip_braces(result) if sanitize_formatting else result
5 changes: 5 additions & 0 deletions actions/get_issue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ parameters:
description: True to include linked issues.
required: true
default: false
sanitize_formatting:
type: boolean
description: When set to true removes jinja template artifacts.
required: true
default: false
2 changes: 1 addition & 1 deletion pack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ keywords:
- issues
- ticket management
- project management
version: 3.0.1
version: 3.1.0
python_versions:
- "3"
author: StackStorm, Inc.
Expand Down

0 comments on commit 0785da7

Please sign in to comment.