danger-lgtm 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +14 -7
- data/Gemfile.lock +24 -18
- data/danger-lgtm.gemspec +3 -1
- data/lib/danger_lgtm.rb +1 -1
- data/lib/lgtm/network.rb +57 -0
- data/lib/lgtm/plugin.rb +77 -46
- data/lib/lgtm/{gem_version.rb → version.rb} +1 -1
- data/spec/lgtm_spec.rb +36 -44
- data/spec/spec_helper.rb +20 -0
- metadata +5 -7
- data/lib/lgtm/error_handleable.rb +0 -33
- data/lib/lgtm/errors.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cd172e647a8512ec42e6c9f93ad239417e2fe26dadabc3d74a674e54666e3ba0
|
4
|
+
data.tar.gz: f20897b8e4ac857e7e9e0a26ad108233947eb170bdd6606ef0a04a510c12cbba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bf3c8c8f2b68ec72202b93a903c358edd8383d60e43e578d65be5f47762e9521b16d9d635b7dbbf8adb60cb868d8beeaea08d1ae7df6dfbd8eeab94766da205
|
7
|
+
data.tar.gz: 16814ecd00a3dd8fa55fedd10a869bc4e47f8ca1b41452f036d05efabf97d367a3c1d3d4943e61e01b0961981d0eb7b824efd33f487075d2aa91b1c013d5b981
|
data/.travis.yml
CHANGED
@@ -1,11 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
- bundle
|
1
|
+
---
|
2
|
+
|
3
|
+
sudo: false
|
5
4
|
|
5
|
+
language: ruby
|
6
6
|
rvm:
|
7
|
-
- 2.
|
8
|
-
- 2.
|
7
|
+
- 2.3
|
8
|
+
- 2.4
|
9
|
+
- 2.5
|
10
|
+
- 2.6
|
11
|
+
|
12
|
+
before_install:
|
13
|
+
- travis_retry gem install bundler --no-document -v 1.17.3
|
14
|
+
|
15
|
+
cache: bundler
|
9
16
|
|
10
17
|
script:
|
11
|
-
|
18
|
+
- bundle exec rake spec
|
data/Gemfile.lock
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
danger-lgtm (1.0
|
4
|
+
danger-lgtm (1.1.0)
|
5
5
|
danger-plugin-api (~> 1.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
addressable (2.
|
11
|
-
public_suffix (>= 2.0.2, <
|
10
|
+
addressable (2.7.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
12
|
ast (2.4.0)
|
13
|
-
claide (1.0.
|
13
|
+
claide (1.0.3)
|
14
14
|
claide-plugins (0.9.2)
|
15
15
|
cork
|
16
16
|
nap
|
@@ -19,28 +19,30 @@ GEM
|
|
19
19
|
colored2 (3.1.2)
|
20
20
|
cork (0.3.0)
|
21
21
|
colored2 (~> 3.1)
|
22
|
-
danger (
|
22
|
+
danger (6.2.2)
|
23
23
|
claide (~> 1.0)
|
24
24
|
claide-plugins (>= 0.9.2)
|
25
25
|
colored2 (~> 3.1)
|
26
26
|
cork (~> 0.1)
|
27
27
|
faraday (~> 0.9)
|
28
|
-
faraday-http-cache (~>
|
29
|
-
git (~> 1)
|
30
|
-
kramdown (~>
|
28
|
+
faraday-http-cache (~> 2.0)
|
29
|
+
git (~> 1.6)
|
30
|
+
kramdown (~> 2.0)
|
31
|
+
kramdown-parser-gfm (~> 1.0)
|
31
32
|
no_proxy_fix
|
32
33
|
octokit (~> 4.7)
|
33
34
|
terminal-table (~> 1)
|
34
35
|
danger-plugin-api (1.0.0)
|
35
36
|
danger (> 2.0)
|
36
37
|
diff-lcs (1.3)
|
37
|
-
faraday (0.
|
38
|
+
faraday (0.17.3)
|
38
39
|
multipart-post (>= 1.2, < 3)
|
39
|
-
faraday-http-cache (
|
40
|
+
faraday-http-cache (2.0.0)
|
40
41
|
faraday (~> 0.8)
|
41
42
|
ffi (1.9.18)
|
42
43
|
formatador (0.2.5)
|
43
|
-
git (1.
|
44
|
+
git (1.6.0)
|
45
|
+
rchardet (~> 1.8)
|
44
46
|
guard (2.14.1)
|
45
47
|
formatador (>= 0.2.4)
|
46
48
|
listen (>= 2.7, < 4.0)
|
@@ -56,20 +58,23 @@ GEM
|
|
56
58
|
guard-compat (~> 1.1)
|
57
59
|
rspec (>= 2.99.0, < 4.0)
|
58
60
|
jaro_winkler (1.5.1)
|
59
|
-
kramdown (1.
|
61
|
+
kramdown (2.1.0)
|
62
|
+
kramdown-parser-gfm (1.1.0)
|
63
|
+
kramdown (~> 2.0)
|
60
64
|
listen (3.0.7)
|
61
65
|
rb-fsevent (>= 0.9.3)
|
62
66
|
rb-inotify (>= 0.9.7)
|
63
67
|
lumberjack (1.0.11)
|
64
68
|
method_source (0.8.2)
|
65
|
-
multipart-post (2.
|
69
|
+
multipart-post (2.1.1)
|
66
70
|
nap (1.1.0)
|
67
71
|
nenv (0.3.0)
|
68
72
|
no_proxy_fix (0.1.2)
|
69
73
|
notiffany (0.1.1)
|
70
74
|
nenv (~> 0.1)
|
71
75
|
shellany (~> 0.0)
|
72
|
-
octokit (4.
|
76
|
+
octokit (4.16.0)
|
77
|
+
faraday (>= 0.9)
|
73
78
|
sawyer (~> 0.8.0, >= 0.5.3)
|
74
79
|
open4 (1.3.4)
|
75
80
|
parallel (1.12.1)
|
@@ -80,12 +85,13 @@ GEM
|
|
80
85
|
coderay (~> 1.1.0)
|
81
86
|
method_source (~> 0.8.1)
|
82
87
|
slop (~> 3.4)
|
83
|
-
public_suffix (
|
88
|
+
public_suffix (4.0.3)
|
84
89
|
rainbow (3.0.0)
|
85
90
|
rake (10.5.0)
|
86
91
|
rb-fsevent (0.9.8)
|
87
92
|
rb-inotify (0.9.8)
|
88
93
|
ffi (>= 0.5.0)
|
94
|
+
rchardet (1.8.0)
|
89
95
|
rspec (3.5.0)
|
90
96
|
rspec-core (~> 3.5.0)
|
91
97
|
rspec-expectations (~> 3.5.0)
|
@@ -108,9 +114,9 @@ GEM
|
|
108
114
|
ruby-progressbar (~> 1.7)
|
109
115
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
110
116
|
ruby-progressbar (1.9.0)
|
111
|
-
sawyer (0.8.
|
112
|
-
addressable (>= 2.3.5
|
113
|
-
faraday (
|
117
|
+
sawyer (0.8.2)
|
118
|
+
addressable (>= 2.3.5)
|
119
|
+
faraday (> 0.8, < 2.0)
|
114
120
|
shellany (0.0.1)
|
115
121
|
slop (3.6.0)
|
116
122
|
terminal-table (1.8.0)
|
data/danger-lgtm.gemspec
CHANGED
data/lib/danger_lgtm.rb
CHANGED
data/lib/lgtm/network.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lgtm
|
4
|
+
# Network is module of HTTP communication
|
5
|
+
module Network
|
6
|
+
class NetworkError < StandardError; end
|
7
|
+
|
8
|
+
# process_request Send HTTP request
|
9
|
+
#
|
10
|
+
# @param [URI] uri Request uri
|
11
|
+
#
|
12
|
+
# @return [Net::HTTP] HTTP response
|
13
|
+
#
|
14
|
+
def process_request(uri)
|
15
|
+
request = Net::HTTP::Get.new(uri)
|
16
|
+
connection = Net::HTTP.start(uri.hostname, uri.port, use_ssl: https?(uri))
|
17
|
+
|
18
|
+
connection
|
19
|
+
.request(request)
|
20
|
+
.tap(&method(:validate_response!))
|
21
|
+
end
|
22
|
+
|
23
|
+
# parse_redirect_location Parse redirect location from response
|
24
|
+
#
|
25
|
+
# @param [Net::HTTP] response HTTP response
|
26
|
+
#
|
27
|
+
# @return [String] Redirect location
|
28
|
+
#
|
29
|
+
def parse_redirect_location(response)
|
30
|
+
response['location']
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# validate_response! Validates HTTP response
|
36
|
+
#
|
37
|
+
# @param [Net::HTTP] response Net::HTTP response
|
38
|
+
#
|
39
|
+
# @raise NetworkError
|
40
|
+
#
|
41
|
+
# @return [nil]
|
42
|
+
#
|
43
|
+
def validate_response!(response)
|
44
|
+
raise NetworkError, response.message if response.is_a?(Net::HTTPError)
|
45
|
+
end
|
46
|
+
|
47
|
+
# https? Check that uri use HTTPS scheme
|
48
|
+
#
|
49
|
+
# @param [URI] uri Test uri
|
50
|
+
#
|
51
|
+
# @return [Boolean] Result of check
|
52
|
+
#
|
53
|
+
def https?(uri)
|
54
|
+
uri.instance_of?(URI::HTTPS)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/lgtm/plugin.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'uri'
|
4
|
-
require 'json'
|
5
4
|
require 'net/http'
|
6
|
-
|
7
|
-
require_relative '
|
5
|
+
|
6
|
+
require_relative 'network'
|
8
7
|
|
9
8
|
module Danger
|
10
9
|
# Lgtm let danger say lgtm when there is no violations.
|
@@ -18,70 +17,102 @@ module Danger
|
|
18
17
|
# @tags lgtm, github
|
19
18
|
#
|
20
19
|
class DangerLgtm < Plugin
|
21
|
-
include ::Lgtm::
|
22
|
-
|
20
|
+
include ::Lgtm::Network
|
21
|
+
|
22
|
+
LGTM_URL = 'https://www.lgtm.app'.freeze
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
RANDOM_POST_PATH = '/g'.freeze
|
25
|
+
POST_CONTENT_PATH = '/p'.freeze
|
26
|
+
|
27
|
+
# check_lgtm Comment LGTM markdown if report has no violations
|
26
28
|
#
|
27
|
-
# @param [String] image_url
|
28
|
-
# @param [Boolean] https_image_only
|
29
|
+
# @param [String] image_url LGTM image url
|
30
|
+
# @param [Boolean] https_image_only Use only secure url
|
29
31
|
#
|
30
|
-
# @return [
|
32
|
+
# @return [nil]
|
31
33
|
#
|
32
34
|
def check_lgtm(image_url: nil, https_image_only: false)
|
33
|
-
return
|
34
|
-
|
35
|
-
|
36
|
-
image_url ||= fetch_image_url(https_image_only: https_image_only)
|
35
|
+
return if status_report[:errors].any?
|
36
|
+
return if status_report[:warnings].any?
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
if image_url
|
39
|
+
comment image_url
|
40
|
+
else
|
41
|
+
comment fetch_image_url(https_image_only)
|
42
|
+
end
|
41
43
|
end
|
42
44
|
|
43
45
|
private
|
44
46
|
|
45
|
-
#
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
# comment Place markdown comment
|
48
|
+
#
|
49
|
+
# @param [Boolean] url LGTM image url
|
50
|
+
#
|
51
|
+
# @return [nil]
|
52
|
+
#
|
53
|
+
def comment(url)
|
54
|
+
if url.nil?
|
55
|
+
markdown("<h1 align='center'>LGTM</h1>")
|
56
|
+
else
|
57
|
+
markdown("<p align='center'><img src='#{url}' alt='LGTM' /></p>")
|
49
58
|
end
|
59
|
+
end
|
50
60
|
|
51
|
-
|
61
|
+
# fetch_image_url Fetch LGTM image url from https://www.lgtm.app
|
62
|
+
#
|
63
|
+
# @param [Boolean] reject_insecure_url Eeturn only secure url
|
64
|
+
#
|
65
|
+
# @return [String] LGTM image url
|
66
|
+
#
|
67
|
+
def fetch_image_url(reject_insecure_url = false)
|
68
|
+
post_id = fetch_randon_post_id
|
69
|
+
return if post_id.empty?
|
52
70
|
|
53
|
-
|
54
|
-
if
|
55
|
-
return fetch_image_url(https_image_only: true)
|
56
|
-
end
|
57
|
-
url
|
58
|
-
rescue ::Lgtm::Errors::UnexpectedError; nil
|
59
|
-
end
|
71
|
+
post_content_url = fetch_post_content_url(post_id)
|
72
|
+
return if post_content_url.empty?
|
60
73
|
|
61
|
-
|
62
|
-
|
74
|
+
return fetch_image_url(reject_insecure_url) if retry?(reject_insecure_url,
|
75
|
+
post_content_url)
|
63
76
|
|
64
|
-
|
77
|
+
post_content_url
|
78
|
+
rescue ::Lgtm::Network::NetworkError => e
|
79
|
+
$stdout.puts e.message
|
80
|
+
end
|
65
81
|
|
66
|
-
|
82
|
+
# fetch_randon_post_id Fetch renadon LGTM post url from https://www.lgtm.app
|
83
|
+
#
|
84
|
+
# @return [String] LGTM post url
|
85
|
+
#
|
86
|
+
def fetch_randon_post_id
|
87
|
+
uri = URI.join(LGTM_URL, RANDOM_POST_PATH)
|
88
|
+
response = process_request(uri)
|
89
|
+
location = parse_redirect_location(response)
|
67
90
|
|
68
|
-
|
69
|
-
http.request(req)
|
70
|
-
end
|
91
|
+
location.split('/').last
|
71
92
|
end
|
72
93
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
94
|
+
# fetch_post_content_url Fetch LGTM image url from https://www.lgtm.app
|
95
|
+
#
|
96
|
+
# @param [String] post_id LGTM post identifier
|
97
|
+
#
|
98
|
+
# @return [String] LGTM image url
|
99
|
+
#
|
100
|
+
def fetch_post_content_url(post_id)
|
101
|
+
uri = URI.join(LGTM_URL, POST_CONTENT_PATH, post_id)
|
102
|
+
response = process_request(uri)
|
103
|
+
|
104
|
+
parse_redirect_location(response)
|
77
105
|
end
|
78
106
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
107
|
+
# retry? Check should be image url requested again
|
108
|
+
#
|
109
|
+
# @param [Boolean] reject_insecure_url Return only secure url
|
110
|
+
# @param [String] url LGTM image url
|
111
|
+
#
|
112
|
+
# @return [Boolean] should be image url requested again
|
113
|
+
#
|
114
|
+
def retry?(reject_insecure_url, url)
|
115
|
+
reject_insecure_url && https?(URI.parse(url))
|
85
116
|
end
|
86
117
|
end
|
87
118
|
end
|
data/spec/lgtm_spec.rb
CHANGED
@@ -3,71 +3,63 @@
|
|
3
3
|
require File.expand_path('spec_helper', __dir__)
|
4
4
|
|
5
5
|
describe Danger::DangerLgtm do
|
6
|
-
def mock(request_url: 'https://lgtm.in/p/sSuI4hm0q',
|
7
|
-
actual_image_url: 'https://example.com/image.jpg')
|
8
|
-
double(
|
9
|
-
:[] => request_url,
|
10
|
-
body: JSON.generate(
|
11
|
-
actualImageUrl: actual_image_url
|
12
|
-
)
|
13
|
-
)
|
14
|
-
end
|
15
|
-
|
16
6
|
it 'should be a plugin' do
|
17
7
|
expect(Danger::DangerLgtm.new(nil)).to be_a(Danger::Plugin)
|
18
8
|
end
|
19
9
|
|
20
10
|
describe '#check_lgtm' do
|
21
|
-
|
22
|
-
|
23
|
-
https_image_only: https_image_only,
|
24
|
-
image_url: image_url
|
25
|
-
)
|
11
|
+
shared_examples 'returns correctly message' do
|
12
|
+
it { expect(markdowns.first.message).to match(/#{image_url}/) }
|
26
13
|
end
|
27
14
|
|
28
|
-
let(:dangerfile) { testing_dangerfile }
|
29
15
|
let(:lgtm) { dangerfile.lgtm }
|
30
|
-
let(:
|
31
|
-
let(:image_url) {} # default nil
|
16
|
+
let(:dangerfile) { testing_dangerfile }
|
32
17
|
|
33
|
-
|
34
|
-
|
35
|
-
allow(Net::HTTP).to receive(:start).and_return(mock)
|
36
|
-
is_expected
|
18
|
+
let(:https_only) { false }
|
19
|
+
let(:image_url) { nil }
|
37
20
|
|
38
|
-
|
39
|
-
|
40
|
-
|
21
|
+
let(:connection_mock) { double('Connection', request: response) }
|
22
|
+
|
23
|
+
subject(:markdowns) do
|
24
|
+
dangerfile.status_report[:markdowns]
|
41
25
|
end
|
42
26
|
|
43
|
-
context 'with
|
44
|
-
|
45
|
-
|
46
|
-
|
27
|
+
context 'with HTTP errors' do
|
28
|
+
let(:message) { 'Hello World!' }
|
29
|
+
let(:response) { failure_response_mock(message) }
|
30
|
+
|
31
|
+
it 'handles error' do
|
32
|
+
expect($stdout).to receive(:puts).with(message)
|
33
|
+
|
34
|
+
allow(Net::HTTP).to receive(:start).and_return(connection_mock)
|
35
|
+
lgtm.check_lgtm(https_image_only: https_only, image_url: image_url)
|
36
|
+
|
37
|
+
expect(markdowns.first.message).to eq("<h1 align='center'>LGTM</h1>")
|
47
38
|
end
|
39
|
+
end
|
48
40
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
is_expected
|
53
|
-
expect(dangerfile.status_report[:markdowns][0].message)
|
54
|
-
.to eq("<h1 align='center'>LGTM</h1>")
|
41
|
+
context 'without HTTP errors' do
|
42
|
+
before do
|
43
|
+
allow(Net::HTTP).to receive(:start).and_return(connection_mock)
|
55
44
|
end
|
56
45
|
|
57
|
-
|
58
|
-
|
59
|
-
it_behaves_like 'returns correctly message'
|
46
|
+
before do
|
47
|
+
lgtm.check_lgtm(https_image_only: https_only, image_url: image_url)
|
60
48
|
end
|
61
49
|
|
62
|
-
context '
|
63
|
-
let(:
|
64
|
-
let(:
|
50
|
+
context 'with passed image url' do
|
51
|
+
let(:lgtm_image) { 'https://example.com/image1.jpg' }
|
52
|
+
let(:image_url) { 'https://example.com/image2.jpg' }
|
53
|
+
let(:response) { success_response_mock(lgtm_image) }
|
54
|
+
|
65
55
|
it_behaves_like 'returns correctly message'
|
66
56
|
end
|
67
57
|
|
68
|
-
context '
|
69
|
-
let(:
|
70
|
-
let(:
|
58
|
+
context 'without passed image url' do
|
59
|
+
let(:lgtm_image) { 'https://example.com/image.jpg' }
|
60
|
+
let(:image_url) { 'https://example.com/image.jpg' }
|
61
|
+
let(:response) { success_response_mock(lgtm_image) }
|
62
|
+
|
71
63
|
it_behaves_like 'returns correctly message'
|
72
64
|
end
|
73
65
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -59,3 +59,23 @@ def testing_dangerfile
|
|
59
59
|
env = Danger::EnvironmentManager.new(testing_env)
|
60
60
|
Danger::Dangerfile.new(env, testing_ui)
|
61
61
|
end
|
62
|
+
|
63
|
+
# Failute response mock
|
64
|
+
def failure_response_mock(message)
|
65
|
+
mock = double('Response')
|
66
|
+
|
67
|
+
allow(mock).to receive(:is_a?).with(Net::HTTPError).and_return(true)
|
68
|
+
allow(mock).to receive(:message).and_return(message)
|
69
|
+
|
70
|
+
mock
|
71
|
+
end
|
72
|
+
|
73
|
+
# Success response mock
|
74
|
+
def success_response_mock(url)
|
75
|
+
mock = double('Response')
|
76
|
+
|
77
|
+
allow(mock).to receive(:is_a?).with(Net::HTTPError).and_return(false)
|
78
|
+
allow(mock).to receive(:[]).with('location').and_return(url)
|
79
|
+
|
80
|
+
mock
|
81
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-lgtm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- leonhartX
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -169,10 +169,9 @@ files:
|
|
169
169
|
- danger-lgtm.gemspec
|
170
170
|
- lib/danger_lgtm.rb
|
171
171
|
- lib/danger_plugin.rb
|
172
|
-
- lib/lgtm/
|
173
|
-
- lib/lgtm/errors.rb
|
174
|
-
- lib/lgtm/gem_version.rb
|
172
|
+
- lib/lgtm/network.rb
|
175
173
|
- lib/lgtm/plugin.rb
|
174
|
+
- lib/lgtm/version.rb
|
176
175
|
- spec/lgtm_spec.rb
|
177
176
|
- spec/spec_helper.rb
|
178
177
|
homepage: https://github.com/leonhartX/danger-lgtm
|
@@ -194,8 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
193
|
- !ruby/object:Gem::Version
|
195
194
|
version: '0'
|
196
195
|
requirements: []
|
197
|
-
|
198
|
-
rubygems_version: 2.5.2.3
|
196
|
+
rubygems_version: 3.1.2
|
199
197
|
signing_key:
|
200
198
|
specification_version: 4
|
201
199
|
summary: Danger Plugin used to post LGTM iamge when there is no violations
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Lgtm
|
2
|
-
# ErrorHandleable is module of error handling
|
3
|
-
module ErrorHandleable
|
4
|
-
# 4xx http status.
|
5
|
-
CLIENT_ERRORS = [
|
6
|
-
Net::HTTPBadRequest,
|
7
|
-
Net::HTTPForbidden,
|
8
|
-
Net::HTTPNotFound
|
9
|
-
].freeze
|
10
|
-
# 5xx http status.
|
11
|
-
SERVER_ERRORS = [
|
12
|
-
Net::HTTPInternalServerError,
|
13
|
-
Net::HTTPBadGateway,
|
14
|
-
Net::HTTPServiceUnavailable,
|
15
|
-
Net::HTTPGatewayTimeOut
|
16
|
-
].freeze
|
17
|
-
|
18
|
-
# validate_response is response validating
|
19
|
-
#
|
20
|
-
# @param [Net::HTTPxxx] response Net::HTTP responses
|
21
|
-
# @raise ::Lgtm::Errors::UnexpectedError
|
22
|
-
# @return [void]
|
23
|
-
#
|
24
|
-
def validate_response(response)
|
25
|
-
case response
|
26
|
-
when *SERVER_ERRORS
|
27
|
-
raise ::Lgtm::Errors::UnexpectedError
|
28
|
-
when *CLIENT_ERRORS
|
29
|
-
raise ::Lgtm::Errors::UnexpectedError
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|