Skip to content

Commit

Permalink
Merge pull request #5 from paveg/503-handling
Browse files Browse the repository at this point in the history
503 handling
  • Loading branch information
leonhartX authored Aug 1, 2018
2 parents a66a8e2 + 1c19bb9 commit 48056ae
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
danger-lgtm (1.0.1)
danger-lgtm (1.0.2)
danger-plugin-api (~> 1.0)

GEM
Expand All @@ -19,7 +19,7 @@ GEM
colored2 (3.1.2)
cork (0.3.0)
colored2 (~> 3.1)
danger (5.6.2)
danger (5.6.4)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored2 (~> 3.1)
Expand Down
2 changes: 1 addition & 1 deletion lib/lgtm/gem_version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Lgtm
VERSION = '1.0.1'.freeze
VERSION = '1.0.2'.freeze
end
16 changes: 13 additions & 3 deletions lib/lgtm/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def check_lgtm(image_url: nil, https_image_only: false)

private

# returns "<h1 align="center">LGTM</h1>" when ServiceTemporarilyUnavailable.
def fetch_image_url(https_image_only: false)
lgtm_post_url = process_request(RANDOM_LGTM_POST_URL)['location']

return unless lgtm_post_url
lgtm_post_response = process_request(lgtm_post_url) do |req|
req['Accept'] = 'application/json'
end
Expand All @@ -67,8 +67,18 @@ def process_request(url)
end
end

def lgtm_post_url
lgtm_post_req = process_request(RANDOM_LGTM_POST_URL)
return if lgtm_post_req.code == '503'
lgtm_post_req['location']
end

def markdown_template(image_url)
"<p align='center'><img src='#{image_url}' alt='LGTM' /></p>"
if image_url.nil?
"<h1 align='center'>LGTM</h1>"
else
"<p align='center'><img src='#{image_url}' alt='LGTM' /></p>"
end
end
end
end
15 changes: 13 additions & 2 deletions spec/lgtm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,24 @@ module Danger
expect(@dangerfile.status_report[:markdowns].length).to eq(1)
end

it 'lgtm with default url is OverQuota' do
allow(Net::HTTP).to receive(:start).and_return(mock(code: '503'))

@lgtm.check_lgtm

expect(@dangerfile.status_report[:markdowns][0].message)
.to eq("<h1 align='center'>LGTM</h1>")
end

def mock(request_url: 'https://lgtm.in/p/sSuI4hm0q',
actual_image_url: 'https://example.com/image.jpg')
actual_image_url: 'https://example.com/image.jpg',
code: '302')
double(
:[] => request_url,
body: JSON.generate(
actualImageUrl: actual_image_url
)
),
code: code
)
end

Expand Down

0 comments on commit 48056ae

Please sign in to comment.