danger-lgtm 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2003b650eca71ba9c3c9ac91b86eda29757349c7
4
- data.tar.gz: 9d258b59a6f6f0ab638f556ae7b91b7b4cf11563
3
+ metadata.gz: 6bc0f25e9ef746b8ee1c128835654931a5132527
4
+ data.tar.gz: 2edec9d0cf6c6239e955b01399bb169a6c17bb61
5
5
  SHA512:
6
- metadata.gz: 48166fec2e2aa69503e71431839aacb146864505efb2cf26297b9d2fcf36823b9dab78b7b42c94da1dee51a394a44c92de810f91a9ee1fc4419066cc23f4473f
7
- data.tar.gz: 2309634a33d3d73baf5a429ac054bbcd4d01f4d27234b7187f336e3fa41d80226569707ddffe9d79e1ad0b4eb2fd8b70db2a3a956e887eac60be632a3180a4f3
6
+ metadata.gz: c098b0a77f69c05182d694ebb0092a88caf2be72c2e7665f4d11d307cd250592760316b477fc36cac93908c8f2b47b6e0d51d223e4e02abdd3f8b83f2d9dd068
7
+ data.tar.gz: 1f05eccca2427dbafcb0d1f289be41137f131c3925037b19d706ec0239b00d87ab5fc73b9824b27de54774e0bdb38e3ce3720a952d6d9fd8b9731d720ced3206
@@ -5,8 +5,7 @@ cache:
5
5
 
6
6
  rvm:
7
7
  - 2.0
8
- - 2.1.3
9
8
  - 2.3.1
10
9
 
11
10
  script:
12
- - bundle exec rake spec
11
+ - bundle exec rake spec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-lgtm (0.2.0)
4
+ danger-lgtm (1.0.0)
5
5
  danger-plugin-api (~> 1.0)
6
6
 
7
7
  GEM
@@ -19,7 +19,7 @@ GEM
19
19
  colored2 (3.1.2)
20
20
  cork (0.3.0)
21
21
  colored2 (~> 3.1)
22
- danger (5.2.2)
22
+ danger (5.1.1)
23
23
  claide (~> 1.0)
24
24
  claide-plugins (>= 0.9.2)
25
25
  colored2 (~> 3.1)
@@ -107,8 +107,8 @@ GEM
107
107
  faraday (~> 0.8, < 1.0)
108
108
  shellany (0.0.1)
109
109
  slop (3.6.0)
110
- terminal-table (1.8.0)
111
- unicode-display_width (~> 1.1, >= 1.1.1)
110
+ terminal-table (1.7.3)
111
+ unicode-display_width (~> 1.1.1)
112
112
  thor (0.19.4)
113
113
  unicode-display_width (1.1.3)
114
114
  yard (0.9.8)
data/README.md CHANGED
@@ -20,6 +20,10 @@ Also you can specify a image url to post with `image_url`
20
20
 
21
21
  lgtm.check_lgtm image_url: 'https://yourimage'
22
22
 
23
+ If you want a https image only, you can use `https_image_only` option
24
+
25
+ lgtm.check_lgtm https_image_only: true
26
+
23
27
  ## Development
24
28
 
25
29
  1. Clone this repo
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lgtm
4
- VERSION = '0.2.0'.freeze
4
+ VERSION = '1.0.0'.freeze
5
5
  end
@@ -16,20 +16,21 @@ module Danger
16
16
  # @tags lgtm, github
17
17
  #
18
18
  class DangerLgtm < Plugin
19
- RANDOM_LGTM_POST_URL = 'http://lgtm.in/g'.freeze
19
+ RANDOM_LGTM_POST_URL = 'https://lgtm.in/g'.freeze
20
20
 
21
21
  # Check status report, say lgtm if no violations
22
- # Generates a `markdown` of a lgtm iamge.
22
+ # Generates a `markdown` of a lgtm image.
23
23
  #
24
24
  # @param [image_url] lgtm image url
25
+ # @param [https_image_only] fetching https image only if true
25
26
  #
26
27
  # @return [void]
27
28
  #
28
- def check_lgtm(image_url: nil)
29
+ def check_lgtm(image_url: nil, https_image_only: false)
29
30
  return unless status_report[:errors].length.zero? &&
30
31
  status_report[:warnings].length.zero?
31
32
 
32
- image_url ||= fetch_image_url
33
+ image_url ||= fetch_image_url(https_image_only: https_image_only)
33
34
 
34
35
  markdown(
35
36
  markdown_template(image_url)
@@ -38,7 +39,7 @@ module Danger
38
39
 
39
40
  private
40
41
 
41
- def fetch_image_url
42
+ def fetch_image_url(https_image_only: false)
42
43
  lgtm_post_url = process_request(RANDOM_LGTM_POST_URL)['location']
43
44
 
44
45
  lgtm_post_response = process_request(lgtm_post_url) do |req|
@@ -47,7 +48,11 @@ module Danger
47
48
 
48
49
  lgtm_post = JSON.parse(lgtm_post_response.body)
49
50
 
50
- lgtm_post['actualImageUrl']
51
+ url = lgtm_post['actualImageUrl']
52
+ if https_image_only && URI.parse(url).scheme != 'https'
53
+ return fetch_image_url(https_image_only: true)
54
+ end
55
+ url
51
56
  end
52
57
 
53
58
  def process_request(url)
@@ -57,7 +62,9 @@ module Danger
57
62
 
58
63
  yield req if block_given?
59
64
 
60
- Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) }
65
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
66
+ http.request(req)
67
+ end
61
68
  end
62
69
 
63
70
  def markdown_template(image_url)
@@ -25,14 +25,17 @@ module Danger
25
25
  expect(@dangerfile.status_report[:markdowns].length).to eq(1)
26
26
  end
27
27
 
28
- it 'pick random pic from lgtm.in' do
29
- mock = double(
30
- :[] => 'https://lgtm.in/p/sSuI4hm0q',
28
+ def mock(request_url: 'https://lgtm.in/p/sSuI4hm0q',
29
+ actual_image_url: 'https://example.com/image.jpg')
30
+ double(
31
+ :[] => request_url,
31
32
  body: JSON.generate(
32
- actualImageUrl: 'https://example.com/image.jpg'
33
+ actualImageUrl: actual_image_url
33
34
  )
34
35
  )
36
+ end
35
37
 
38
+ it 'pick random pic from lgtm.in' do
36
39
  allow(Net::HTTP).to receive(:start).and_return(mock)
37
40
 
38
41
  @lgtm.check_lgtm
@@ -41,6 +44,15 @@ module Danger
41
44
  .to match(%r{https:\/\/example.com\/image.jpg})
42
45
  end
43
46
 
47
+ it 'pick random pic from lgtm.in with https_image_only option' do
48
+ allow(Net::HTTP).to receive(:start).and_return(mock)
49
+
50
+ @lgtm.check_lgtm https_image_only: true
51
+
52
+ expect(@dangerfile.status_report[:markdowns][0].message)
53
+ .to match(%r{https:\/\/example.com\/image.jpg})
54
+ end
55
+
44
56
  it 'use given url' do
45
57
  @lgtm.check_lgtm image_url: 'http://imgur.com/Irk2wyX.jpg'
46
58
  expect(@dangerfile.status_report[:markdowns][0].message)
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: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - leonhartX
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-02 00:00:00.000000000 Z
11
+ date: 2017-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  version: '0'
194
194
  requirements: []
195
195
  rubyforge_project:
196
- rubygems_version: 2.6.11
196
+ rubygems_version: 2.5.1
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: Danger Plugin used to post LGTM iamge when there is no violations