compare_linker 1.2.1 → 1.3.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: 4bd91ee90fc917c5cae680d6d5c3316b142d95d2
4
- data.tar.gz: 7b594db9f42c2a2b854308395884b514e58d7f63
3
+ metadata.gz: 82c24082c7f1e558330f73e82641d3bb89170a06
4
+ data.tar.gz: a1f100bf18a6bf9a1c1e3b0742334cb508b0f18b
5
5
  SHA512:
6
- metadata.gz: 514183f5e9ff8ed40cddf123857048296b2b04e4833f57cadbd02b787ab97ecb286892fd3ee002e1db7bec80a71d13cbf7e43a058811b8f7bbf0c4b2421043cc
7
- data.tar.gz: 82673469c08f0e6905479c30acf6f896c2c3f0c4ea8abe7105995fd4435c93bfddf7f8c3948fe694fe6e9176945ec445bf994f16df53fbe0208fc0683d18a782
6
+ metadata.gz: 50591bfabe3b54b10fe058e5130b3a56a971254322b5d9334b24b1caf08c824ba7a9f3931bc7c93946177e80dd5af507e1108fe2b7bee3a9194b51ca0fbdd4c7
7
+ data.tar.gz: be7eb5a92eb8d282309d583d6f2beffc5e736cfc52d0f1ae18e78cdc33e0226dda03ac7c74d3d10535c75c3d78386fcabfd472cd8692a3c674cccd1c6d121be1
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.3.0
3
4
  - 2.2.0
4
5
  - 2.1.0
5
6
  - 2.0.0
data/README.md CHANGED
@@ -1,4 +1,14 @@
1
- # Compare Linker [![Build Status][travis-badge]][travis-link] [![Gem Version][gem-badge]][gem-link]
1
+ # Compare Linker
2
+
3
+ [![Travis Status](https://img.shields.io/travis/masutaka/compare_linker.svg?maxAge=2592000)][travisci]
4
+ [![License](https://img.shields.io/github/license/masutaka/compare_linker.svg?maxAge=2592000?style=flat-square)][license]
5
+ [![Gem](https://img.shields.io/gem/v/compare_linker.svg?maxAge=2592000?style=flat-square)][gem-link]
6
+
7
+ [travisci]: https://travis-ci.org/masutaka/compare_linker
8
+ [license]: https://github.com/masutaka/compare_linker/blob/master/LICENSE.txt
9
+ [gem-link]: http://badge.fury.io/rb/compare_linker
10
+
11
+ ## Description
2
12
 
3
13
  Create GitHub's compare view URLs for pull request from diff of `Gemfile.lock` (and post comment to pull request).
4
14
 
@@ -6,6 +16,22 @@ Create GitHub's compare view URLs for pull request from diff of `Gemfile.lock` (
6
16
 
7
17
  [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.
8
18
 
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'compare_linker'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install compare_linker
34
+
9
35
  ## Usage
10
36
 
11
37
  ```ruby
@@ -19,13 +45,16 @@ comment = compare_linker.make_compare_links.to_a.join("\n")
19
45
  compare_linker.add_comment('masutaka/compare_linker', '17', comment)
20
46
  ```
21
47
 
22
- ## Rack app for listening GitHub Webhook
48
+ ## Development
23
49
 
24
- There's rack application for Compare Linker with GitHub's Webhook.
50
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
51
 
26
- https://github.com/kyanny/compare_linker_rack_app
52
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
27
53
 
28
- [travis-badge]: https://travis-ci.org/masutaka/compare_linker.svg?branch=master
29
- [travis-link]: https://travis-ci.org/masutaka/compare_linker
30
- [gem-badge]: https://badge.fury.io/rb/compare_linker.svg
31
- [gem-link]: http://badge.fury.io/rb/compare_linker
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/masutaka/compare_linker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,13 @@
1
+ # Gem name: GitHub repository
2
+
3
+ actioncable: rails/rails
4
+ actionmailer: rails/rails
5
+ actionpack: rails/rails
6
+ actionview: rails/rails
7
+ activejob: rails/rails
8
+ activemodel: rails/rails
9
+ activerecord: rails/rails
10
+ activesupport: rails/rails
11
+ capistrano: capistrano/capistrano
12
+ railties: rails/rails
13
+ serverspec: mizzy/serverspec
@@ -2,19 +2,21 @@ require "octokit"
2
2
  require_relative "compare_linker/formatter/base"
3
3
  require_relative "compare_linker/formatter/text"
4
4
  require_relative "compare_linker/formatter/markdown"
5
+ require_relative "compare_linker/gem_dictionary"
5
6
  require_relative "compare_linker/github_link_finder"
6
7
  require_relative "compare_linker/github_tag_finder"
7
8
  require_relative "compare_linker/lockfile_comparator"
8
9
  require_relative "compare_linker/lockfile_fetcher"
9
10
 
10
11
  class CompareLinker
11
- attr_reader :repo_full_name, :pr_number, :compare_links
12
+ attr_reader :repo_full_name, :pr_number, :compare_links, :gem_dictionary
12
13
  attr_accessor :formatter, :octokit
13
14
 
14
15
  def initialize(repo_full_name, pr_number)
15
16
  @repo_full_name = repo_full_name
16
17
  @pr_number = pr_number
17
18
  @octokit ||= Octokit::Client.new(access_token: ENV["OCTOKIT_ACCESS_TOKEN"])
19
+ @gem_dictionary = GemDictionary.new
18
20
  @formatter = Formatter::Text.new
19
21
  end
20
22
 
@@ -30,18 +32,18 @@ class CompareLinker
30
32
  comparator.compare(old_lockfile, new_lockfile)
31
33
  @compare_links = comparator.updated_gems.map { |gem_name, gem_info|
32
34
  if gem_info[:owner].nil?
33
- finder = GithubLinkFinder.new(octokit)
35
+ finder = GithubLinkFinder.new(octokit, gem_dictionary)
34
36
  finder.find(gem_name)
37
+ gem_info[:homepage_uri] = finder.homepage_uri
35
38
  if finder.repo_owner.nil?
36
- gem_info[:homepage_uri] = finder.homepage_uri
37
39
  formatter.format(gem_info)
38
40
  else
39
41
  gem_info[:repo_owner] = finder.repo_owner
40
42
  gem_info[:repo_name] = finder.repo_name
41
43
 
42
- tag_finder = GithubTagFinder.new(octokit)
43
- old_tag = tag_finder.find(finder.repo_full_name, gem_info[:old_ver])
44
- new_tag = tag_finder.find(finder.repo_full_name, gem_info[:new_ver])
44
+ tag_finder = GithubTagFinder.new(octokit, gem_name, finder.repo_full_name)
45
+ old_tag = tag_finder.find(gem_info[:old_ver])
46
+ new_tag = tag_finder.find(gem_info[:new_ver])
45
47
 
46
48
  if old_tag && new_tag
47
49
  gem_info[:old_tag] = old_tag.name
@@ -9,7 +9,7 @@ class CompareLinker
9
9
  end
10
10
 
11
11
  def to_ver(tag)
12
- tag.sub(/\Av/, '')
12
+ return $1 if tag =~ /(\d+(?:\.\d+)+)\z/
13
13
  end
14
14
  end
15
15
  end
@@ -9,15 +9,49 @@ class CompareLinker
9
9
  text = "* [ ] "
10
10
  text += case
11
11
  when g.owner && g.old_rev && g.new_rev
12
- "#{g.gem_name}: https://github.com/#{g.owner}/#{g.gem_name}/compare/#{g.old_rev}...#{g.new_rev}"
12
+ "[%s](%s): [`%s...%s`](%s)" % [
13
+ g.gem_name,
14
+ github_url(g.owner, g.gem_name),
15
+ g.old_rev,
16
+ g.new_rev,
17
+ github_compare_url(g.owner, g.gem_name, g.old_rev, g.new_rev),
18
+ ]
19
+ when g.homepage_uri && g.old_tag && g.new_tag
20
+ "[%s](%s): [`%s...%s`](%s)" % [
21
+ g.gem_name,
22
+ github_url(g.repo_owner, g.repo_name),
23
+ g.old_ver,
24
+ g.new_ver,
25
+ github_compare_url(g.repo_owner, g.repo_name, g.old_tag, g.new_tag),
26
+ ]
13
27
  when g.homepage_uri
14
- "[#{g.gem_name}](#{g.homepage_uri}): #{g.old_ver} => #{g.new_ver}"
28
+ "[%s](%s): `%s...%s`" % [
29
+ g.gem_name,
30
+ g.homepage_uri,
31
+ g.old_ver,
32
+ g.new_ver,
33
+ ]
15
34
  when g.old_tag && g.new_tag
16
- "#{g.gem_name}: https://github.com/#{g.repo_owner}/#{g.repo_name}/compare/#{g.old_tag}...#{g.new_tag}"
35
+ "[%s](%s): [`%s...%s`](%s)" % [
36
+ g.gem_name,
37
+ github_url(g.repo_owner, g.repo_name),
38
+ g.old_ver,
39
+ g.new_ver,
40
+ github_compare_url(g.repo_owner, g.repo_name, g.old_tag, g.new_tag),
41
+ ]
17
42
  when g.repo_owner && g.repo_name
18
- "[#{g.gem_name}](https://github.com/#{g.repo_owner}/#{g.repo_name}): #{g.old_ver} => #{g.new_ver}"
43
+ "[%s](%s): `%s...%s`" % [
44
+ g.gem_name,
45
+ github_url(g.repo_owner, g.repo_name),
46
+ g.old_ver,
47
+ g.new_ver,
48
+ ]
19
49
  else
20
- "#{g.gem_name}: (link not found) #{g.old_ver} => #{g.new_ver}"
50
+ "%s: (link not found) `%s...%s`" % [
51
+ g.gem_name,
52
+ g.old_ver,
53
+ g.new_ver,
54
+ ]
21
55
  end
22
56
 
23
57
  if downgrade?(g.old_ver, g.new_ver, g.old_tag, g.new_tag)
@@ -26,6 +60,16 @@ class CompareLinker
26
60
 
27
61
  text
28
62
  end
63
+
64
+ private
65
+
66
+ def github_url(repo_owner, repo_name)
67
+ "https://github.com/#{repo_owner}/#{repo_name}"
68
+ end
69
+
70
+ def github_compare_url(repo_owner, repo_name, old_tag, new_tag)
71
+ "#{github_url(repo_owner, repo_name)}/compare/#{old_tag}...#{new_tag}"
72
+ end
29
73
  end
30
74
  end
31
75
  end
@@ -9,14 +9,16 @@ class CompareLinker
9
9
  text = case
10
10
  when g.owner && g.old_rev && g.new_rev
11
11
  "#{g.gem_name}: https://github.com/#{g.owner}/#{g.gem_name}/compare/#{g.old_rev}...#{g.new_rev}"
12
+ when g.homepage_uri && g.old_tag && g.new_tag
13
+ "#{g.gem_name} (#{g.homepage_uri}): https://github.com/#{g.repo_owner}/#{g.repo_name}/compare/#{g.old_tag}...#{g.new_tag}"
12
14
  when g.homepage_uri
13
- "#{g.gem_name} (#{g.homepage_uri}): #{g.old_ver} => #{g.new_ver}"
15
+ "#{g.gem_name} (#{g.homepage_uri}): #{g.old_ver}...#{g.new_ver}"
14
16
  when g.old_tag && g.new_tag
15
17
  "#{g.gem_name}: https://github.com/#{g.repo_owner}/#{g.repo_name}/compare/#{g.old_tag}...#{g.new_tag}"
16
18
  when g.repo_owner && g.repo_name
17
- "#{g.gem_name}: https://github.com/#{g.repo_owner}/#{g.repo_name} #{g.old_ver} => #{g.new_ver}"
19
+ "#{g.gem_name}: https://github.com/#{g.repo_owner}/#{g.repo_name} #{g.old_ver}...#{g.new_ver}"
18
20
  else
19
- "#{g.gem_name} (link not found): #{g.old_ver} => #{g.new_ver}"
21
+ "#{g.gem_name} (link not found): #{g.old_ver}...#{g.new_ver}"
20
22
  end
21
23
 
22
24
  if downgrade?(g.old_ver, g.new_ver, g.old_tag, g.new_tag)
@@ -0,0 +1,32 @@
1
+ require "yaml"
2
+
3
+ class CompareLinker
4
+ class GemDictionary
5
+ attr_reader :file, :rubygems
6
+
7
+ def initialize
8
+ @file = File.join(__dir__, '../../data/rubygems.yml')
9
+ end
10
+
11
+ # Look gem info up from Dictionary
12
+ #
13
+ # @param gem_name [String]
14
+ # @return [Array<String>] [repo_owner, repo_name]
15
+ # @return [Array<NilClass>] cannot look up
16
+ def lookup(gem_name)
17
+ repo_full_name = rubygems[gem_name]
18
+
19
+ if repo_full_name
20
+ repo_full_name.split("/")
21
+ else
22
+ [nil, nil]
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def rubygems
29
+ @rubygems ||= YAML.load(IO.read(file))
30
+ end
31
+ end
32
+ end
@@ -4,10 +4,11 @@ require "net/http"
4
4
 
5
5
  class CompareLinker
6
6
  class GithubLinkFinder
7
- attr_reader :octokit, :repo_owner, :repo_name, :homepage_uri
7
+ attr_reader :octokit, :gem_dictionary, :repo_owner, :repo_name, :homepage_uri
8
8
 
9
- def initialize(octokit)
9
+ def initialize(octokit, gem_dictionary)
10
10
  @octokit = octokit
11
+ @gem_dictionary = gem_dictionary
11
12
  end
12
13
 
13
14
  def find(gem_name)
@@ -23,6 +24,7 @@ class CompareLinker
23
24
  if github_url = redirect_url(github_url)
24
25
  _, @repo_owner, @repo_name = github_url.match(%r!github\.com/([^/]+)/([^/]+)!).to_a
25
26
  else
27
+ @repo_owner, @repo_name = gem_dictionary.lookup(gem_info["name"])
26
28
  @homepage_uri = gem_info["homepage_uri"]
27
29
  end
28
30
 
@@ -1,18 +1,32 @@
1
1
  class CompareLinker
2
2
  class GithubTagFinder
3
- attr_reader :octokit
3
+ attr_reader :octokit, :gem_name, :repo_full_name
4
4
 
5
- def initialize(octokit)
5
+ def initialize(octokit, gem_name, repo_full_name)
6
6
  @octokit = octokit
7
+ @gem_name = gem_name
8
+ @repo_full_name = repo_full_name
7
9
  end
8
10
 
9
- def find(repo_full_name, gem_version)
10
- tags = octokit.tags(repo_full_name)
11
+ def find(gem_version)
12
+ tags = auto_paginate { octokit.tags(repo_full_name) }
11
13
  if tags
12
14
  tags.find { |tag|
13
- tag.name == gem_version || tag.name == "v#{gem_version}"
15
+ tag.name == gem_version ||
16
+ tag.name == "v#{gem_version}" ||
17
+ tag.name == "#{gem_name}-#{gem_version}"
14
18
  }
15
19
  end
16
20
  end
21
+
22
+ private
23
+
24
+ def auto_paginate
25
+ original = octokit.auto_paginate
26
+ octokit.auto_paginate = true
27
+ yield
28
+ ensure
29
+ octokit.auto_paginate = original
30
+ end
17
31
  end
18
32
  end
@@ -1,3 +1,3 @@
1
1
  class CompareLinker
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe CompareLinker::GemDictionary do
4
+ describe "#lookup" do
5
+ context 'given a gem name included in the dictionary' do
6
+ subject { described_class.new.lookup('serverspec') }
7
+ it { is_expected.to eq %w(mizzy serverspec) }
8
+ end
9
+
10
+ context 'given a gem name not included in the dictionary' do
11
+ subject { described_class.new.lookup('not_exist') }
12
+ it { is_expected.to eq [nil, nil] }
13
+ end
14
+ end
15
+ end
@@ -2,8 +2,9 @@ require "spec_helper"
2
2
 
3
3
  describe CompareLinker::GithubLinkFinder do
4
4
  let(:octokit) { double.as_null_object }
5
+ let(:gem_dictionary) { double.as_null_object }
5
6
 
6
- subject { described_class.new(octokit) }
7
+ subject { described_class.new(octokit, gem_dictionary) }
7
8
 
8
9
 
9
10
  describe "#find" do
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.2.1
4
+ version: 1.3.0
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-11-29 00:00:00.000000000 Z
11
+ date: 2016-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -95,11 +95,13 @@ files:
95
95
  - README.md
96
96
  - Rakefile
97
97
  - compare_linker.gemspec
98
+ - data/rubygems.yml
98
99
  - guides/jenkins_setup_guide.md
99
100
  - lib/compare_linker.rb
100
101
  - lib/compare_linker/formatter/base.rb
101
102
  - lib/compare_linker/formatter/markdown.rb
102
103
  - lib/compare_linker/formatter/text.rb
104
+ - lib/compare_linker/gem_dictionary.rb
103
105
  - lib/compare_linker/github_link_finder.rb
104
106
  - lib/compare_linker/github_tag_finder.rb
105
107
  - lib/compare_linker/lockfile_comparator.rb
@@ -111,6 +113,7 @@ files:
111
113
  - spec/fixtures/coffee-script-source.json
112
114
  - spec/fixtures/rails.json
113
115
  - spec/fixtures/web_translate_it.json
116
+ - spec/lib/compare_linker/gem_dictionary_spec.rb
114
117
  - spec/lib/compare_linker/github_link_finder_spec.rb
115
118
  - spec/spec_helper.rb
116
119
  - spec/support/load_fixture.rb
@@ -134,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
137
  version: '0'
135
138
  requirements: []
136
139
  rubyforge_project:
137
- rubygems_version: 2.4.8
140
+ rubygems_version: 2.5.1
138
141
  signing_key:
139
142
  specification_version: 4
140
143
  summary: Create GitHub's compare view URLs for pull request
@@ -142,6 +145,7 @@ test_files:
142
145
  - spec/fixtures/coffee-script-source.json
143
146
  - spec/fixtures/rails.json
144
147
  - spec/fixtures/web_translate_it.json
148
+ - spec/lib/compare_linker/gem_dictionary_spec.rb
145
149
  - spec/lib/compare_linker/github_link_finder_spec.rb
146
150
  - spec/spec_helper.rb
147
151
  - spec/support/load_fixture.rb