From 017e0fec1f16f140bbd21d6c7be0ebfa42a5c03a Mon Sep 17 00:00:00 2001 From: Dominik Kapusta Date: Thu, 12 Sep 2024 21:12:00 +0200 Subject: [PATCH] sanitize_and_replace_env_vars -> sanitize_html_and_replace_env_vars --- .../actions/asana_add_comment_action.rb | 2 +- .../actions/asana_create_action_item_action.rb | 4 ++-- .../helper/ddg_apple_automation_helper.rb | 2 +- spec/ddg_apple_automation_helper_spec.rb | 16 ++++++++-------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/fastlane/plugin/ddg_apple_automation/actions/asana_add_comment_action.rb b/lib/fastlane/plugin/ddg_apple_automation/actions/asana_add_comment_action.rb index f327ba0..d2aaa13 100644 --- a/lib/fastlane/plugin/ddg_apple_automation/actions/asana_add_comment_action.rb +++ b/lib/fastlane/plugin/ddg_apple_automation/actions/asana_add_comment_action.rb @@ -33,7 +33,7 @@ def self.run(params) template_content = Helper::DdgAppleAutomationHelper.load_file(template_file) return unless template_content - html_text = Helper::DdgAppleAutomationHelper.sanitize_and_replace_env_vars(template_content) + html_text = Helper::DdgAppleAutomationHelper.sanitize_html_and_replace_env_vars(template_content) create_story(asana_access_token, task_id, html_text: html_text) end end diff --git a/lib/fastlane/plugin/ddg_apple_automation/actions/asana_create_action_item_action.rb b/lib/fastlane/plugin/ddg_apple_automation/actions/asana_create_action_item_action.rb index 79dbd6f..7d0097f 100644 --- a/lib/fastlane/plugin/ddg_apple_automation/actions/asana_create_action_item_action.rb +++ b/lib/fastlane/plugin/ddg_apple_automation/actions/asana_create_action_item_action.rb @@ -40,8 +40,8 @@ def self.run(params) if template_name template_file = Helper::DdgAppleAutomationHelper.path_for_asset_file("asana_create_action_item/templates/#{template_name}.yml") template_content = YAML.safe_load(Helper::DdgAppleAutomationHelper.load_file(template_file)) - task_name = Helper::DdgAppleAutomationHelper.sanitize_and_replace_env_vars(template_content["name"]) - html_notes = Helper::DdgAppleAutomationHelper.sanitize_and_replace_env_vars(template_content["html_notes"]) + task_name = Helper::DdgAppleAutomationHelper.sanitize_html_and_replace_env_vars(template_content["name"]) + html_notes = Helper::DdgAppleAutomationHelper.sanitize_html_and_replace_env_vars(template_content["html_notes"]) end begin diff --git a/lib/fastlane/plugin/ddg_apple_automation/helper/ddg_apple_automation_helper.rb b/lib/fastlane/plugin/ddg_apple_automation/helper/ddg_apple_automation_helper.rb index 362e994..d8b30e8 100644 --- a/lib/fastlane/plugin/ddg_apple_automation/helper/ddg_apple_automation_helper.rb +++ b/lib/fastlane/plugin/ddg_apple_automation/helper/ddg_apple_automation_helper.rb @@ -28,7 +28,7 @@ def self.load_file(file) UI.user_error!("Error: The file '#{file}' does not exist.") end - def self.sanitize_and_replace_env_vars(content) + def self.sanitize_html_and_replace_env_vars(content) content.gsub(/\$\{(\w+)\}/) { ENV.fetch($1, '') } # replace environment variables .gsub(/\s+/, ' ') # replace multiple whitespaces with a single space .gsub(/>\s+<') # remove spaces between HTML tags diff --git a/spec/ddg_apple_automation_helper_spec.rb b/spec/ddg_apple_automation_helper_spec.rb index bad0ccf..f6ec551 100644 --- a/spec/ddg_apple_automation_helper_spec.rb +++ b/spec/ddg_apple_automation_helper_spec.rb @@ -31,39 +31,39 @@ def load_file(file) end end - describe "#sanitize_and_replace_env_vars" do + describe "#sanitize_html_and_replace_env_vars" do it "substitutes all env variables" do content = "

${ASSIGNEE_ID} is publishing ${TAG} hotfix release

" ClimateControl.modify( ASSIGNEE_ID: '12345', TAG: 'v1.0.0' ) do - expect(sanitize_and_replace_env_vars(content)).to eq("

12345 is publishing v1.0.0 hotfix release

") + expect(sanitize_html_and_replace_env_vars(content)).to eq("

12345 is publishing v1.0.0 hotfix release

") end end it "removes newlines and leading/trailing spaces" do content = " \nHello, \n\n World!\n This is a test. \n" - expect(sanitize_and_replace_env_vars(content)).to eq("Hello, World! This is a test.") + expect(sanitize_html_and_replace_env_vars(content)).to eq("Hello, World! This is a test.") end it "removes spaces between html tags" do content = "

Hello, World! This is a test.

" - expect(sanitize_and_replace_env_vars(content)).to eq("

Hello, World! This is a test.

") + expect(sanitize_html_and_replace_env_vars(content)).to eq("

Hello, World! This is a test.

") end it "replaces multiple whitespaces with a single space" do content = "

Hello, World! This is a test.

" - expect(sanitize_and_replace_env_vars(content)).to eq("

Hello, World! This is a test.

") + expect(sanitize_html_and_replace_env_vars(content)).to eq("

Hello, World! This is a test.

") end it "replaces
tags with new lines" do content = "

Hello, World!
This is a test.

" - expect(sanitize_and_replace_env_vars(content)).to eq("

Hello, World!\n This is a test.

") + expect(sanitize_html_and_replace_env_vars(content)).to eq("

Hello, World!\n This is a test.

") end - def sanitize_and_replace_env_vars(content) - Fastlane::Helper::DdgAppleAutomationHelper.sanitize_and_replace_env_vars(content) + def sanitize_html_and_replace_env_vars(content) + Fastlane::Helper::DdgAppleAutomationHelper.sanitize_html_and_replace_env_vars(content) end end end