gems_comparator 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 179e35a8f2b56f8a28196fa3a1ee7e3c0d2ab134
4
+ data.tar.gz: 5175435aa591c9dc67e27cd9bdfef78474936121
5
+ SHA512:
6
+ metadata.gz: 7080057f52c38165ec3ddedee35c8db20846095af04b384cd880bc12aeb53a85de1a7c2ef40ca2e5192c52e8c04c09b786bce45a820e0ac8657eca2b9365a86e
7
+ data.tar.gz: abd84ed164f6108a331c7d3d37240071cc8506f2a26b3f00242805df4946b3873b77d85bc73ef94136569efa43e3f431871317c47d1dfe7d92941362f4656898
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ DisplayCopNames: true
4
+ DisplayStyleGuide: true
5
+ ExtraDetails: true
6
+ Exclude:
7
+ - 'spec/fixtures/*'
8
+
9
+ Style/Documentation:
10
+ Enabled: false
11
+
12
+ Metrics/BlockLength:
13
+ Exclude:
14
+ - 'spec/**/*'
15
+
16
+ Metrics/LineLength:
17
+ Exclude:
18
+ - '*.gemspec'
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ - 2.4.0
6
+ before_install:
7
+ - gem update --system
8
+ - gem install bundler
9
+ notifications:
10
+ email: false
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sinsoku.listy@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ # Specify your gem's dependencies in gems_comparator.gemspec
5
+ gemspec
6
+
7
+ gem 'codecov', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 sinsoku
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # GemsComparator
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/gems_comparator.svg)](https://badge.fury.io/rb/gems_comparator)
4
+ [![Build Status](https://travis-ci.org/sinsoku/gems_comparator.svg?branch=master)](https://travis-ci.org/sinsoku/gems_comparator)
5
+ [![codecov](https://codecov.io/gh/sinsoku/gems_comparator/branch/master/graph/badge.svg)](https://codecov.io/gh/sinsoku/gems_comparator)
6
+
7
+ GemsComparator generates GitHub's compare view urls from `Gemfile.lock`
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'gems_comparator'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install gems_comparator
24
+
25
+ ## Usage
26
+
27
+ ```rb
28
+ require 'gems_comparator'
29
+
30
+ before_lockfile = File.read('before_Gemfile.lock')
31
+ after_lockfile = File.read('after_Gemfile.lock')
32
+
33
+ GemsComparator.compare(before_lockfile, after_lockfile)
34
+ #=> [{:name=>"rake", :before=>"11.3.0", :after=>"12.0.0", :homepage=>"https://github.com/ruby/rake", :github_url=>"https://github.com/ruby/rake", :compare_url=>"https://github.com/ruby/rake/compare/v11.3.0...v12.0.0"}, ...]
35
+ ```
36
+
37
+ ## Development
38
+
39
+ 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.
40
+
41
+ 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).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sinsoku/gems_comparator. 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.
46
+
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
51
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ require 'rubocop/rake_task'
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: [:rubocop, :spec]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'gems_comparator'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ action_args: asakusarb/action_args
2
+ airbrake: airbrake/airbrake
3
+ capistrano: capistrano/capistrano
4
+ coderay: rubychan/coderay
5
+ coffee-script-source: jessedoyle/coffee-script-source
6
+ concurrent-ruby: ruby-concurrency/concurrent-ruby
7
+ eventmachine: eventmachine/eventmachine
8
+ logging: TwP/logging
9
+ nokogiri: sparklemotion/nokogiri
10
+ puma: puma/puma
11
+ rack-mini-profiler: MiniProfiler/rack-mini-profiler
12
+ rails_best_practices: railsbp/rails_best_practices
13
+ sass: sass/sass
14
+ sidekiq: mperham/sidekiq
15
+ thin: macournoyer/thin
16
+ thor: erikhuda/thor
17
+ unicorn: defunkt/unicorn
18
+ uniform_notifier: flyerhzm/uniform_notifier
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'gems_comparator/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'gems_comparator'
9
+ spec.version = GemsComparator::VERSION
10
+ spec.authors = ['sinsoku']
11
+ spec.email = ['sinsoku.listy@gmail.com']
12
+
13
+ spec.summary = "A comparator for Gemfile.lock that generate the GitHub's compare view urls"
14
+ spec.description = "A comparator for Gemfile.lock that generate the GitHub's compare view urls"
15
+ spec.homepage = 'https://github.com/sinsoku/gems_comparator'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'octokit'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.13'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.0'
28
+ spec.add_development_dependency 'rubocop', '0.47.1'
29
+ spec.add_development_dependency 'webmock', '~> 2.3.2'
30
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ require 'octokit'
3
+ require 'gems_comparator/comparator'
4
+ require 'gems_comparator/config'
5
+ require 'gems_comparator/gem_info'
6
+ require 'gems_comparator/github_repository'
7
+ require 'gems_comparator/version'
8
+
9
+ module GemsComparator
10
+ def self.config
11
+ @config ||= Config.new
12
+ end
13
+
14
+ def self.configure
15
+ yield config
16
+ end
17
+
18
+ def self.compare(before_lockfile, after_lockfile)
19
+ Comparator.new(before_lockfile, after_lockfile).compare
20
+ end
21
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ module GemsComparator
3
+ class Comparator
4
+ def initialize(before_lockfile, after_lockfile)
5
+ @before_lockfile = before_lockfile
6
+ @after_lockfile = after_lockfile
7
+ end
8
+
9
+ def compare
10
+ gems = addition_gems + change_gems + deletion_gems
11
+ gems.sort_by(&:name).map(&:to_h)
12
+ end
13
+
14
+ private
15
+
16
+ def parse_lockfile(lockfile)
17
+ parser = Bundler::LockfileParser.new(lockfile)
18
+ parser.specs.map { |spec| [spec.name, spec.version] }.to_h
19
+ end
20
+
21
+ def before_gems
22
+ @before_gems ||= parse_lockfile(@before_lockfile)
23
+ end
24
+
25
+ def after_gems
26
+ @after_gems ||= parse_lockfile(@after_lockfile)
27
+ end
28
+
29
+ def addition_gems
30
+ names = after_gems.keys - before_gems.keys
31
+ names.map { |name| new_geminfo(name) }
32
+ end
33
+
34
+ def change_gems
35
+ names = before_gems.keys.select do |name|
36
+ before_gems[name] != after_gems[name]
37
+ end
38
+ names.map { |name| new_geminfo(name) }
39
+ end
40
+
41
+ def deletion_gems
42
+ names = before_gems.keys - after_gems.keys
43
+ names.map { |name| new_geminfo(name) }
44
+ end
45
+
46
+ def new_geminfo(name)
47
+ GemInfo.new(name, before_gems[name].to_s, after_gems[name].to_s)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module GemsComparator
3
+ class Config
4
+ attr_accessor :client
5
+
6
+ def initialize
7
+ @client = Octokit::Client.new
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml'
3
+
4
+ module GemsComparator
5
+ class GemInfo
6
+ GITHUB_URLS_PATH = File.join(__dir__, '../../data/github_urls.yml')
7
+
8
+ attr_reader :name, :before, :after
9
+
10
+ def initialize(name, before, after)
11
+ @name = name
12
+ @before = before
13
+ @after = after
14
+ end
15
+
16
+ def compare_url
17
+ return unless github_url
18
+
19
+ repo = GithubRepository.new(github_url)
20
+ repo.compare(before, after)
21
+ rescue => e
22
+ e.inspect
23
+ end
24
+
25
+ def github_url
26
+ if GithubRepository.repo?(homepage)
27
+ homepage
28
+ elsif github_urls.key?(name)
29
+ "https://github.com/#{github_urls[name]}"
30
+ end
31
+ end
32
+
33
+ def homepage
34
+ spec&.homepage
35
+ end
36
+
37
+ def to_h
38
+ attr_names = %i(name before after homepage github_url compare_url)
39
+ attr_names.map { |m| [m, send(m)] }.to_h
40
+ end
41
+
42
+ private
43
+
44
+ def github_urls
45
+ @github_urls ||= YAML.load_file(GITHUB_URLS_PATH)
46
+ end
47
+
48
+ def spec
49
+ @spec ||= Gem::Specification.load(spec_path)
50
+ end
51
+
52
+ def spec_path
53
+ spec_paths = [
54
+ "#{Bundler.specs_path}/#{name}-#{before}.gemspec",
55
+ "#{Bundler.specs_path}/#{name}-#{after}.gemspec"
56
+ ]
57
+ spec_paths.find { |path| File.exist?(path) }
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ module GemsComparator
3
+ class GithubRepository
4
+ def self.repo?(url)
5
+ Octokit::Repository.from_url(url)
6
+ true
7
+ rescue
8
+ false
9
+ end
10
+
11
+ def initialize(url)
12
+ @repo = Octokit::Repository.from_url(url)
13
+ end
14
+
15
+ def compare(base, head)
16
+ base_tag = find_tag(base)
17
+ head_tag = find_tag(head)
18
+
19
+ if base_tag && head_tag
20
+ "#{@repo.url}/compare/#{base_tag.name}...#{head_tag.name}"
21
+ elsif base_tag
22
+ "#{@repo.url}/compare/#{base_tag.name}...master"
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def tags
29
+ @tags ||= client.tags(@repo)
30
+ end
31
+
32
+ def find_tag(name)
33
+ tags.find { |tag| ["v#{name}", name].include?(tag.name) }
34
+ end
35
+
36
+ def client
37
+ GemsComparator.config.client
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module GemsComparator
3
+ VERSION = '0.1.0'
4
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gems_comparator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - sinsoku
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.47.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.47.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.3.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.3.2
97
+ description: A comparator for Gemfile.lock that generate the GitHub's compare view
98
+ urls
99
+ email:
100
+ - sinsoku.listy@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".travis.yml"
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - data/github_urls.yml
117
+ - gems_comparator.gemspec
118
+ - lib/gems_comparator.rb
119
+ - lib/gems_comparator/comparator.rb
120
+ - lib/gems_comparator/config.rb
121
+ - lib/gems_comparator/gem_info.rb
122
+ - lib/gems_comparator/github_repository.rb
123
+ - lib/gems_comparator/version.rb
124
+ homepage: https://github.com/sinsoku/gems_comparator
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.6.8
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: A comparator for Gemfile.lock that generate the GitHub's compare view urls
148
+ test_files: []