Skip to content

Commit

Permalink
Return right away if file is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceklyp committed Sep 2, 2024
1 parent fcbc848 commit a4d6531
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/asana_upload_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a4d6531

Please sign in to comment.