danger-lgtm 1.0.2 → 1.0.3
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/lgtm/error_handleable.rb +33 -0
- data/lib/lgtm/errors.rb +6 -0
- data/lib/lgtm/gem_version.rb +1 -1
- data/lib/lgtm/plugin.rb +9 -6
- data/spec/lgtm_spec.rb +53 -52
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96b81a57a626da94dcb035e081a9102303204040
|
4
|
+
data.tar.gz: f8c73962d2b81e6b4f4558004179fd03fcac0237
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f42e21763b4d6bcfb20714948f6fd6517ab550bf94897e03cfb9033ec94e85246004d2d8f152c795cc7cf3e16d273d25434611296b0e29b9899f31b12ad4cc7a
|
7
|
+
data.tar.gz: 62b287ebaf3d065b402829e06fec6cb395045032b5ab66ae2636b4715ca2326f095fbd02c8eae3195c86adab4600733762ac0e64f6e1c43473df7a889204f8b3
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,33 @@
|
|
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
|
data/lib/lgtm/errors.rb
ADDED
data/lib/lgtm/gem_version.rb
CHANGED
data/lib/lgtm/plugin.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
require 'uri'
|
4
4
|
require 'json'
|
5
5
|
require 'net/http'
|
6
|
+
require './lib/lgtm/errors'
|
7
|
+
require './lib/lgtm/error_handleable'
|
6
8
|
|
7
9
|
module Danger
|
8
10
|
# Lgtm let danger say lgtm when there is no violations.
|
@@ -16,13 +18,14 @@ module Danger
|
|
16
18
|
# @tags lgtm, github
|
17
19
|
#
|
18
20
|
class DangerLgtm < Plugin
|
21
|
+
include ::Lgtm::ErrorHandleable
|
19
22
|
RANDOM_LGTM_POST_URL = 'https://lgtm.in/g'.freeze
|
20
23
|
|
21
24
|
# Check status report, say lgtm if no violations
|
22
25
|
# Generates a `markdown` of a lgtm image.
|
23
26
|
#
|
24
|
-
# @param
|
25
|
-
# @param
|
27
|
+
# @param [String] image_url lgtm image url
|
28
|
+
# @param [Boolean] https_image_only https image only if true
|
26
29
|
#
|
27
30
|
# @return [void]
|
28
31
|
#
|
@@ -41,7 +44,6 @@ module Danger
|
|
41
44
|
|
42
45
|
# returns "<h1 align="center">LGTM</h1>" when ServiceTemporarilyUnavailable.
|
43
46
|
def fetch_image_url(https_image_only: false)
|
44
|
-
return unless lgtm_post_url
|
45
47
|
lgtm_post_response = process_request(lgtm_post_url) do |req|
|
46
48
|
req['Accept'] = 'application/json'
|
47
49
|
end
|
@@ -53,6 +55,7 @@ module Danger
|
|
53
55
|
return fetch_image_url(https_image_only: true)
|
54
56
|
end
|
55
57
|
url
|
58
|
+
rescue ::Lgtm::Errors::UnexpectedError; nil
|
56
59
|
end
|
57
60
|
|
58
61
|
def process_request(url)
|
@@ -68,9 +71,9 @@ module Danger
|
|
68
71
|
end
|
69
72
|
|
70
73
|
def lgtm_post_url
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
+
res = process_request(RANDOM_LGTM_POST_URL)
|
75
|
+
validate_response(res)
|
76
|
+
res['location']
|
74
77
|
end
|
75
78
|
|
76
79
|
def markdown_template(image_url)
|
data/spec/lgtm_spec.rb
CHANGED
@@ -2,72 +2,73 @@
|
|
2
2
|
|
3
3
|
require File.expand_path('spec_helper', __dir__)
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
before do
|
16
|
-
@dangerfile = testing_dangerfile
|
17
|
-
@lgtm = @dangerfile.lgtm
|
18
|
-
end
|
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
|
19
15
|
|
20
|
-
|
21
|
-
|
16
|
+
it 'should be a plugin' do
|
17
|
+
expect(Danger::DangerLgtm.new(nil)).to be_a(Danger::Plugin)
|
18
|
+
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
describe '#check_lgtm' do
|
21
|
+
subject do
|
22
|
+
lgtm.check_lgtm(
|
23
|
+
https_image_only: https_image_only,
|
24
|
+
image_url: image_url
|
25
|
+
)
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
let(:dangerfile) { testing_dangerfile }
|
29
|
+
let(:lgtm) { dangerfile.lgtm }
|
30
|
+
let(:https_image_only) { false } # default false
|
31
|
+
let(:image_url) {} # default nil
|
30
32
|
|
31
|
-
|
33
|
+
shared_examples 'returns correctly message' do
|
34
|
+
it do
|
35
|
+
allow(Net::HTTP).to receive(:start).and_return(mock)
|
36
|
+
is_expected
|
32
37
|
|
33
|
-
expect(
|
34
|
-
.to
|
38
|
+
expect(dangerfile.status_report[:markdowns][0].message)
|
39
|
+
.to match(expected_message)
|
35
40
|
end
|
41
|
+
end
|
36
42
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
:[] => request_url,
|
42
|
-
body: JSON.generate(
|
43
|
-
actualImageUrl: actual_image_url
|
44
|
-
),
|
45
|
-
code: code
|
46
|
-
)
|
43
|
+
context 'with Dangerfile' do
|
44
|
+
it 'when no violation' do
|
45
|
+
is_expected
|
46
|
+
expect(dangerfile.status_report[:markdowns].length).to eq(1)
|
47
47
|
end
|
48
48
|
|
49
|
-
it '
|
50
|
-
allow(
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
.to match(%r{https:\/\/example.com\/image.jpg})
|
49
|
+
it 'lgtm with errors' do
|
50
|
+
allow(lgtm).to receive(:validate_response)
|
51
|
+
.and_raise(::Lgtm::Errors::UnexpectedError)
|
52
|
+
is_expected
|
53
|
+
expect(dangerfile.status_report[:markdowns][0].message)
|
54
|
+
.to eq("<h1 align='center'>LGTM</h1>")
|
56
55
|
end
|
57
56
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
context 'pick random pic from lgtm.in' do
|
58
|
+
let(:expected_message) { %r{https:\/\/example.com\/image.jpg} }
|
59
|
+
it_behaves_like 'returns correctly message'
|
60
|
+
end
|
62
61
|
|
63
|
-
|
64
|
-
|
62
|
+
context 'pick random pic from lgtm.in with https_image_only option' do
|
63
|
+
let(:https_image_only) { true }
|
64
|
+
let(:expected_message) { %r{https:\/\/example.com\/image.jpg} }
|
65
|
+
it_behaves_like 'returns correctly message'
|
65
66
|
end
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
context 'use given url' do
|
69
|
+
let(:image_url) { 'http://imgur.com/Irk2wyX.jpg' }
|
70
|
+
let(:expected_message) { %r{http:\/\/imgur\.com\/Irk2wyX\.jpg} }
|
71
|
+
it_behaves_like 'returns correctly message'
|
71
72
|
end
|
72
73
|
end
|
73
74
|
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.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- leonhartX
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -169,6 +169,8 @@ files:
|
|
169
169
|
- danger-lgtm.gemspec
|
170
170
|
- lib/danger_lgtm.rb
|
171
171
|
- lib/danger_plugin.rb
|
172
|
+
- lib/lgtm/error_handleable.rb
|
173
|
+
- lib/lgtm/errors.rb
|
172
174
|
- lib/lgtm/gem_version.rb
|
173
175
|
- lib/lgtm/plugin.rb
|
174
176
|
- spec/lgtm_spec.rb
|