From a4d6531793655941c4bd13e6d6842c1e83263de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20=C5=81yp?= Date: Mon, 2 Sep 2024 11:03:53 +0200 Subject: [PATCH] Return right away if file is missing --- .../actions/asana_upload_action.rb | 17 ++++++++--------- spec/asana_upload_action_spec.rb | 1 + 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/fastlane/plugin/ddg_apple_automation/actions/asana_upload_action.rb b/lib/fastlane/plugin/ddg_apple_automation/actions/asana_upload_action.rb index 2ae4eb1..319ae39 100644 --- a/lib/fastlane/plugin/ddg_apple_automation/actions/asana_upload_action.rb +++ b/lib/fastlane/plugin/ddg_apple_automation/actions/asana_upload_action.rb @@ -13,18 +13,17 @@ def self.run(params) begin file = File.open(file_name) + url = Helper::DdgAppleAutomationHelper::ASANA_API_URL + "/tasks/#{task_id}/attachments" + response = HTTParty.post(url, + headers: { 'Authorization' => "Bearer #{token}" }, + body: { file: file }) + + unless response.success? + UI.user_error!("Failed to upload file to Asana task: (#{response.code} #{response.message})") + end rescue Errno::ENOENT UI.user_error!("Failed to open file: #{file_name}") end - - url = Helper::DdgAppleAutomationHelper::ASANA_API_URL + "/tasks/#{task_id}/attachments" - response = HTTParty.post(url, - headers: { 'Authorization' => "Bearer #{token}" }, - body: { file: file }) - - unless response.success? - UI.user_error!("Failed to upload file to Asana task: (#{response.code} #{response.message})") - end end def self.description diff --git a/spec/asana_upload_action_spec.rb b/spec/asana_upload_action_spec.rb index 2dea25d..fabc7d8 100644 --- a/spec/asana_upload_action_spec.rb +++ b/spec/asana_upload_action_spec.rb @@ -24,6 +24,7 @@ it "shows error if file does not exist" do allow(HTTParty).to receive(:post).and_return(double(success?: true)) expect(Fastlane::UI).to receive(:user_error!).with("Failed to open file: path/to/file.txt") + expect(HTTParty).not_to receive(:post) test_action("12345", "path/to/file.txt") end end