From 18f551ad008ed6df7c0011a694157937c74ab68d Mon Sep 17 00:00:00 2001 From: Curtis Wilson Date: Tue, 23 Apr 2024 00:59:26 -0500 Subject: [PATCH 1/8] Adding ability to sanitize output for jinja templating --- actions/get_issue.py | 19 +++++++++++++++++-- actions/get_issue.yaml | 5 +++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/actions/get_issue.py b/actions/get_issue.py index 92b61d6..7d8cbf6 100644 --- a/actions/get_issue.py +++ b/actions/get_issue.py @@ -9,7 +9,7 @@ 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, @@ -17,4 +17,19 @@ def run(self, issue_key, include_comments=False, include_attachments=False, 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 + + cleaned_issue_dict = strip_braces(issue_dict) + if sanitize_formatting: + return strip_braces(result) + else: + return result diff --git a/actions/get_issue.yaml b/actions/get_issue.yaml index e83d1ce..07339fc 100644 --- a/actions/get_issue.yaml +++ b/actions/get_issue.yaml @@ -39,3 +39,8 @@ parameters: description: True to include linked issues. required: true default: false + sanitize_formatting: + type: boolean + description: True to remove jinja template artifacts. + required: true + default: false From a26bfe91a6f4b3c6873e2ada6ece8456f737887a Mon Sep 17 00:00:00 2001 From: Curtis Wilson Date: Tue, 23 Apr 2024 01:05:38 -0500 Subject: [PATCH 2/8] Cleaning up local var not intended to be here --- actions/get_issue.py | 1 - 1 file changed, 1 deletion(-) diff --git a/actions/get_issue.py b/actions/get_issue.py index 7d8cbf6..cf18ddd 100644 --- a/actions/get_issue.py +++ b/actions/get_issue.py @@ -28,7 +28,6 @@ def strip_braces(data): else: return data - cleaned_issue_dict = strip_braces(issue_dict) if sanitize_formatting: return strip_braces(result) else: From e52f6539e3f71b2c36beb695c7c815e1e1dca17c Mon Sep 17 00:00:00 2001 From: Curtis Wilson Date: Tue, 23 Apr 2024 01:09:16 -0500 Subject: [PATCH 3/8] Updating pack/changes --- CHANGES.md | 3 +++ pack.yaml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 73fd148..1469395 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,8 @@ # Change Log +## 3.0.2 +- Add new feature to get_issue to allow for stripping of Jinja templating artifacts. + ## 3.0.1 - Fixed bug with `update_dashboard` action sending the wrong payload. diff --git a/pack.yaml b/pack.yaml index 5801e07..f240b1b 100644 --- a/pack.yaml +++ b/pack.yaml @@ -6,7 +6,7 @@ keywords: - issues - ticket management - project management -version: 3.0.1 +version: 3.0.2 python_versions: - "3" author: StackStorm, Inc. From 1d25af7008eb9c8acf1d17d6920a4dba06e7585f Mon Sep 17 00:00:00 2001 From: Curtis Wilson Date: Tue, 23 Apr 2024 12:46:15 -0500 Subject: [PATCH 4/8] Updating version, and cahnges along with fixing return statement --- CHANGES.md | 4 ++-- actions/get_issue.py | 5 +---- actions/get_issue.yaml | 2 +- pack.yaml | 2 +- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1469395..dd98173 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,7 @@ # Change Log -## 3.0.2 -- Add new feature to get_issue to allow for stripping of Jinja templating artifacts. +## 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.). ## 3.0.1 diff --git a/actions/get_issue.py b/actions/get_issue.py index cf18ddd..7f127c5 100644 --- a/actions/get_issue.py +++ b/actions/get_issue.py @@ -28,7 +28,4 @@ def strip_braces(data): else: return data - if sanitize_formatting: - return strip_braces(result) - else: - return result + return strip_braces(result) if sanitize_formatting else result \ No newline at end of file diff --git a/actions/get_issue.yaml b/actions/get_issue.yaml index 07339fc..71be829 100644 --- a/actions/get_issue.yaml +++ b/actions/get_issue.yaml @@ -41,6 +41,6 @@ parameters: default: false sanitize_formatting: type: boolean - description: True to remove jinja template artifacts. + description: When set to true removes jinja template artifacts. required: true default: false diff --git a/pack.yaml b/pack.yaml index f240b1b..e7a516c 100644 --- a/pack.yaml +++ b/pack.yaml @@ -6,7 +6,7 @@ keywords: - issues - ticket management - project management -version: 3.0.2 +version: 3.1.0 python_versions: - "3" author: StackStorm, Inc. From 1e94da6f2bf6b7cad246cff6eb1df734e25f5e4c Mon Sep 17 00:00:00 2001 From: Curtis Wilson Date: Tue, 23 Apr 2024 12:53:54 -0500 Subject: [PATCH 5/8] Updating changes wiht an example --- CHANGES.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index dd98173..5542a15 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,11 @@ # 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.). +- 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 outpu anywhere else in a workflow as it cannot find the `code` variable in the context. + ## 3.0.1 From 0955c94d69bb5df3cef615d9963642dd7e677c82 Mon Sep 17 00:00:00 2001 From: Curtis Wilson Date: Tue, 23 Apr 2024 13:00:58 -0500 Subject: [PATCH 6/8] New line EOF --- actions/get_issue.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/actions/get_issue.py b/actions/get_issue.py index 7f127c5..412114d 100644 --- a/actions/get_issue.py +++ b/actions/get_issue.py @@ -28,4 +28,5 @@ def strip_braces(data): else: return data - return strip_braces(result) if sanitize_formatting else result \ No newline at end of file + return strip_braces(result) if sanitize_formatting else result + \ No newline at end of file From 218163131e52d7a2609f7218ef24cfe3148cbfd7 Mon Sep 17 00:00:00 2001 From: Curtis Wilson Date: Tue, 23 Apr 2024 13:05:13 -0500 Subject: [PATCH 7/8] Attempt to at an empty blank line --- actions/get_issue.py | 1 - 1 file changed, 1 deletion(-) diff --git a/actions/get_issue.py b/actions/get_issue.py index 412114d..6dcbedb 100644 --- a/actions/get_issue.py +++ b/actions/get_issue.py @@ -29,4 +29,3 @@ def strip_braces(data): return data return strip_braces(result) if sanitize_formatting else result - \ No newline at end of file From 93e2c42bbe4fc2dc95042a92f2c31b1b091efbf5 Mon Sep 17 00:00:00 2001 From: Curtis Wilson Date: Tue, 23 Apr 2024 13:29:02 -0500 Subject: [PATCH 8/8] Updating mispelling on CHANGES --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 5542a15..0ecc0ff 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,7 +4,7 @@ - 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 outpu anywhere else in a workflow as it cannot find the `code` variable in the context. + 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