Skip to content
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

Adding ability to sanitize output for jinja templating #79

Merged
merged 8 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading