diff --git a/lib/lgtm/plugin.rb b/lib/lgtm/plugin.rb
index 875b60d..a5f3bc4 100644
--- a/lib/lgtm/plugin.rb
+++ b/lib/lgtm/plugin.rb
@@ -39,11 +39,9 @@ def check_lgtm(image_url: nil, https_image_only: false)
private
+ # returns "
LGTM
" 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 "LGTM
" 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
@@ -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?
"LGTM
"
diff --git a/spec/lgtm_spec.rb b/spec/lgtm_spec.rb
index 678625b..889beb2 100644
--- a/spec/lgtm_spec.rb
+++ b/spec/lgtm_spec.rb
@@ -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("LGTM
")
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(