Skip to content

Commit

Permalink
Pass travis.ci
Browse files Browse the repository at this point in the history
  • Loading branch information
paveg committed Jul 31, 2018
1 parent 35ceaca commit 1c19bb9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/lgtm/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +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_req = process_request(RANDOM_LGTM_POST_URL)
return if lgtm_post_req.code == '503' # returns "<h1 align="center">LGTM</h1>" when Service Temporarily Unavailable; Over Quota.
lgtm_post_url = lgtm_post_req['location']

return unless lgtm_post_url
lgtm_post_response = process_request(lgtm_post_url) do |req|
req['Accept'] = 'application/json'
end
Expand All @@ -69,6 +67,12 @@ 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)
if image_url.nil?
"<h1 align='center'>LGTM</h1>"
Expand Down
5 changes: 4 additions & 1 deletion spec/lgtm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ module Danger
@lgtm.check_lgtm
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',
code: '200')
code: '302')
double(
:[] => request_url,
body: JSON.generate(
Expand Down

0 comments on commit 1c19bb9

Please sign in to comment.