compare_linker 1.1.1 → 1.1.2

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: af95f0a2fa32ca45c3466eaea99a42a60f459ee8
4
- data.tar.gz: c326f2ce50e6ee13d95fb6902fd5485c670388cc
3
+ metadata.gz: 4057ff1e3a27a008b165f7c0a8e9c66778b3c81a
4
+ data.tar.gz: a12d3dfceac57651d84af749f494af6a8ec0bfe1
5
5
  SHA512:
6
- metadata.gz: f2658bdebc63b821bfe21fe64ac000ebcbef6ae64bf9259f694bb50dda824bcc866e2d9f12e7c308ea62b13132d3b5e49e77ae36458751471db8bb7159c41dc8
7
- data.tar.gz: 7141938c57780fee24b2e814cdc01b4fabcb21f23060969c14a9564c88d88fe95a4d5310d0c8c5ef55e688895ce4c04f19251bb105dd645ae46abb7bc52f67b4
6
+ metadata.gz: 11a2efd1e0e96eec69a7b2b9485f2680ffbac561a8f4215b3eb7c9e21b5f3a70047a183fde4ef5f35f81789a4219eab6c7629aa5244e7db4d6d0caec2397d42c
7
+ data.tar.gz: 354661c22002a122751b6e2b8d0bd2f39de82a5e47d79aab0d7eebb9b14bacbc4be4a9e3aad8987fe926ff1e5f554364521be4406660587c4ee7bab06942f30c
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
- /.bundle/config
1
+ /.bundle
2
2
  /.envrc
3
3
  /pkg
4
4
  /vendor/bundle
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.0
4
- - 2.1.0
5
- - 2.0.0
3
+ - 2.2.1
4
+ - 2.1.5
5
+ - 2.0.0-p643
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source "https://rubygems.org"
2
- ruby '2.2.0'
3
2
 
4
3
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- compare_linker (1.1.1)
4
+ compare_linker (1.1.2)
5
5
  httpclient
6
6
  octokit
7
7
 
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- Compare Linker
2
- ==============
1
+ # Compare Linker [![Build Status][travis-badge]][travis-link] [![Gem Version][gem-badge]][gem-link]
3
2
 
4
3
  Create GitHub's compare view URLs for pull request from diff of `Gemfile.lock` (and post comment to pull request).
5
4
 
@@ -7,9 +6,13 @@ Create GitHub's compare view URLs for pull request from diff of `Gemfile.lock` (
7
6
 
8
7
  [GitHub Compare View](https://github.com/blog/612-introducing-github-compare-view) rocks.But [diff of Gemfile.lock](https://github.com/kyanny/compare_linker_demo/pull/14/files) sucks. So I made Compare Linker.
9
8
 
10
- Rack app for listening GitHub Webhook
11
- -------------------------------------
9
+ ## Rack app for listening GitHub Webhook
12
10
 
13
11
  There's rack application for Compare Linker with GitHub's Webhook.
14
12
 
15
13
  https://github.com/kyanny/compare_linker_rack_app
14
+
15
+ [travis-badge]: https://travis-ci.org/masutaka/compare_linker.svg?branch=master
16
+ [travis-link]: https://travis-ci.org/masutaka/compare_linker
17
+ [gem-badge]: https://badge.fury.io/rb/compare_linker.svg
18
+ [gem-link]: http://badge.fury.io/rb/compare_linker
@@ -1,4 +1,5 @@
1
1
  require "octokit"
2
+ require_relative "compare_linker/formatter/base"
2
3
  require_relative "compare_linker/formatter/text"
3
4
  require_relative "compare_linker/formatter/markdown"
4
5
  require_relative "compare_linker/github_link_finder"
@@ -0,0 +1,16 @@
1
+ class CompareLinker
2
+ class Formatter
3
+ class Base
4
+ private
5
+
6
+ def downgrade?(old_ver, new_ver, old_tag, new_tag)
7
+ Gem::Version.new(new_ver) < Gem::Version.new(old_ver) ||
8
+ (old_tag && new_tag && Gem::Version.new(to_ver(new_tag)) < Gem::Version.new(to_ver(old_tag)))
9
+ end
10
+
11
+ def to_ver(tag)
12
+ tag.sub(/\Av/, '')
13
+ end
14
+ end
15
+ end
16
+ end
@@ -2,7 +2,7 @@ require "ostruct"
2
2
 
3
3
  class CompareLinker
4
4
  class Formatter
5
- class Markdown
5
+ class Markdown < Base
6
6
  def format(gem_info)
7
7
  g = OpenStruct.new(gem_info)
8
8
 
@@ -19,7 +19,7 @@ class CompareLinker
19
19
  "* #{g.gem_name}: (link not found) #{g.old_ver} => #{g.new_ver}"
20
20
  end
21
21
 
22
- if (g.old_tag && g.new_tag && g.new_tag.to_f < g.old_tag.to_f) || g.new_ver.to_f < g.old_ver.to_f
22
+ if downgrade?(g.old_ver, g.new_ver, g.old_tag, g.new_tag)
23
23
  text += " (downgrade)"
24
24
  end
25
25
 
@@ -2,7 +2,7 @@ require "ostruct"
2
2
 
3
3
  class CompareLinker
4
4
  class Formatter
5
- class Text
5
+ class Text < Base
6
6
  def format(gem_info)
7
7
  g = OpenStruct.new(gem_info)
8
8
 
@@ -19,7 +19,7 @@ class CompareLinker
19
19
  "#{g.gem_name} (link not found): #{g.old_ver} => #{g.new_ver}"
20
20
  end
21
21
 
22
- if (g.old_tag && g.new_tag && g.new_tag.to_f < g.old_tag.to_f) || g.new_ver.to_f < g.old_ver.to_f
22
+ if downgrade?(g.old_ver, g.new_ver, g.old_tag, g.new_tag)
23
23
  text += " (downgrade)"
24
24
  end
25
25
 
@@ -1,5 +1,6 @@
1
1
  require "json"
2
2
  require "httpclient"
3
+ require "net/http"
3
4
 
4
5
  class CompareLinker
5
6
  class GithubLinkFinder
@@ -22,6 +23,7 @@ class CompareLinker
22
23
  if github_url.nil?
23
24
  @homepage_uri = gem_info["homepage_uri"]
24
25
  else
26
+ github_url = redirect_url(github_url)
25
27
  _, @repo_owner, @repo_name = github_url.match(%r!github\.com/([^/]+)/([^/]+)!).to_a
26
28
  end
27
29
  end
@@ -29,5 +31,20 @@ class CompareLinker
29
31
  def repo_full_name
30
32
  "#{@repo_owner}/#{repo_name}"
31
33
  end
34
+
35
+ private
36
+
37
+ def redirect_url(url, limit = 5)
38
+ raise ArgumentError, 'HTTP redirect too deep' if limit <= 0
39
+ response = Net::HTTP.get_response(URI.parse(url))
40
+ case response
41
+ when Net::HTTPSuccess
42
+ url
43
+ when Net::HTTPRedirection
44
+ redirect_url(response['location'], limit - 1)
45
+ else
46
+ raise ItemNotFound
47
+ end
48
+ end
32
49
  end
33
50
  end
@@ -1,3 +1,3 @@
1
1
  class CompareLinker
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compare_linker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kensuke Nagae
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-28 00:00:00.000000000 Z
11
+ date: 2015-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -98,6 +98,7 @@ files:
98
98
  - compare_linker.gemspec
99
99
  - guides/jenkins_setup_guide.md
100
100
  - lib/compare_linker.rb
101
+ - lib/compare_linker/formatter/base.rb
101
102
  - lib/compare_linker/formatter/markdown.rb
102
103
  - lib/compare_linker/formatter/text.rb
103
104
  - lib/compare_linker/github_link_finder.rb