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