gem_updater 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gem_updater/gem_file.rb +32 -8
- data/lib/gem_updater/ruby_gems_fetcher.rb +58 -9
- data/lib/gem_updater.rb +27 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8bef24cd913cd7aea6272eecf19cb98666fc6b4
|
4
|
+
data.tar.gz: 8470997ff32cfdc1ab6473cc18fbcdc4873a0725
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a305a247455c268d03570f35616bfa0a93a9cba56ff4b8d00987e24342e1f805d0a985aeec0224ecc5927d390de3e01fa48c6527009952d0a88b86f1c4fab2b
|
7
|
+
data.tar.gz: dbb800a2a74db5493e159ef70ba2b35c52aa42f49596b1ba32003e6b197690bf9f23610b5fb66480c91daa031aee297aefdedc5e22c1ba1cbee02d1f891754b7
|
data/lib/gem_updater/gem_file.rb
CHANGED
@@ -5,30 +5,54 @@ module GemUpdater
|
|
5
5
|
# GemFile is responsible for handling `Gemfile`
|
6
6
|
class GemFile
|
7
7
|
attr_accessor :changes
|
8
|
+
attr_reader :old_spec_set, :new_spec_set
|
8
9
|
|
9
10
|
def initialize
|
10
|
-
@
|
11
|
-
@changes = {}
|
11
|
+
@changes = {}
|
12
12
|
end
|
13
13
|
|
14
14
|
# Run `bundle update` to update gems.
|
15
|
-
# Then get new spec set.
|
16
15
|
def update!
|
17
16
|
puts "Updating gems..."
|
18
17
|
Bundler::CLI.start( [ 'update' ] )
|
19
|
-
@new_spec_set = Bundler.definition.specs
|
20
|
-
compute_changes
|
21
18
|
end
|
22
19
|
|
23
20
|
# Compute the diffs between two `Gemfile.lock`.
|
24
21
|
#
|
25
22
|
# @return [Hash] gems for which there are differences.
|
26
23
|
def compute_changes
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
get_spec_sets
|
25
|
+
|
26
|
+
old_spec_set.each do |old_gem|
|
27
|
+
if updated_gem = new_spec_set.find{ |new_gem| new_gem.name == old_gem.name }
|
28
|
+
unless old_gem.version == updated_gem.version
|
29
|
+
changes[ old_gem.name ] = { versions: { old: old_gem.version.to_s, new: updated_gem.version.to_s }, source: updated_gem.source }
|
30
|
+
end
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# Get the two spec sets (before and after `bundle update`)
|
38
|
+
def get_spec_sets
|
39
|
+
@old_spec_set = spec_set
|
40
|
+
reinitialize_spec_set!
|
41
|
+
@new_spec_set = spec_set
|
42
|
+
end
|
43
|
+
|
44
|
+
# Get the current spec set
|
45
|
+
#
|
46
|
+
# @return [Array] array of Bundler::LazySpecification (including gem name, version and source)
|
47
|
+
def spec_set
|
48
|
+
Bundler.locked_gems.specs
|
49
|
+
end
|
50
|
+
|
51
|
+
# Calling `Bundler.locked_gems` before or after a `bundler update`
|
52
|
+
# will return the same result.
|
53
|
+
# Use a hacky way to tell bundle we want to parse the new `Gemfile.lock`
|
54
|
+
def reinitialize_spec_set!
|
55
|
+
Bundler.remove_instance_variable( "@locked_gems" )
|
56
|
+
end
|
33
57
|
end
|
34
58
|
end
|
@@ -6,29 +6,78 @@ module GemUpdater
|
|
6
6
|
|
7
7
|
# RubyGemsFetcher is a wrapper around rubygems API.
|
8
8
|
class RubyGemsFetcher
|
9
|
+
attr_reader :gem_name, :source
|
9
10
|
|
10
11
|
# @param gem_name [String] name of the gem
|
11
|
-
|
12
|
+
# @param source [Bundler::Source] source of gem
|
13
|
+
def initialize( gem_name, source )
|
12
14
|
@gem_name = gem_name
|
15
|
+
@source = source
|
13
16
|
end
|
14
17
|
|
15
18
|
# Finds where code is hosted.
|
16
|
-
# Most likely in will be in
|
19
|
+
# Most likely in will be on rubygems, else look in other sources.
|
17
20
|
#
|
18
|
-
# @return [String] url of gem source code
|
21
|
+
# @return [String|nil] url of gem source code
|
19
22
|
def source_uri
|
20
|
-
|
23
|
+
uri_from_rubygems || uri_from_other_sources
|
21
24
|
end
|
22
25
|
|
23
26
|
private
|
24
27
|
|
25
|
-
#
|
26
|
-
# from rubygems.org.
|
28
|
+
# Ask rubygems.org for source uri of gem.
|
27
29
|
# See API: http://guides.rubygems.org/rubygems-org-api/#gem-methods
|
28
30
|
#
|
29
|
-
# @return [
|
30
|
-
def
|
31
|
-
|
31
|
+
# @return [String|nil] uri of source code
|
32
|
+
def uri_from_rubygems
|
33
|
+
return unless source.remotes.map( &:host ).include?( 'rubygems.org' )
|
34
|
+
|
35
|
+
response = begin
|
36
|
+
JSON.parse( open( "https://rubygems.org/api/v1/gems/#{gem_name}.json" ).read )
|
37
|
+
rescue OpenURI::HTTPError
|
38
|
+
end
|
39
|
+
|
40
|
+
if response
|
41
|
+
response[ "source_code_uri" ] || response[ "homepage_uri" ]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Look if gem can be found in another remote
|
46
|
+
#
|
47
|
+
# @return [String|nil] uri of source code
|
48
|
+
def uri_from_other_sources
|
49
|
+
uri = nil
|
50
|
+
source.remotes.each do |remote|
|
51
|
+
break if uri
|
52
|
+
|
53
|
+
uri = case remote.host
|
54
|
+
when 'rubygems.org' then next # already checked
|
55
|
+
when 'rails-assets.org'
|
56
|
+
uri_from_railsassets
|
57
|
+
else
|
58
|
+
puts "Source #{remote} is not supported, feel free to open a PR or an issue on https://github.com/MaximeD/gem_updater"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
uri
|
63
|
+
end
|
64
|
+
|
65
|
+
# Ask rails-assets.org for source uri of gem.
|
66
|
+
# API is at : https://rails-assets.org/packages/package_name
|
67
|
+
#
|
68
|
+
# @return [String|nil] uri of source code
|
69
|
+
def uri_from_railsassets
|
70
|
+
begin
|
71
|
+
response = JSON.parse( open( "https://rails-assets.org/packages/#{gem_name.gsub( /rails-assets-/, '' )}" ).read )
|
72
|
+
rescue JSON::ParserError
|
73
|
+
# if gem is not found, rails-assets returns a 200
|
74
|
+
# with html (instead of json) containing a 500...
|
75
|
+
rescue OpenURI::HTTPError
|
76
|
+
end
|
77
|
+
|
78
|
+
if response
|
79
|
+
response[ "url" ].gsub( /^git/, 'http' )
|
80
|
+
end
|
32
81
|
end
|
33
82
|
end
|
34
83
|
end
|
data/lib/gem_updater.rb
CHANGED
@@ -3,7 +3,11 @@ require 'gem_updater/ruby_gems_fetcher'
|
|
3
3
|
require 'gem_updater/source_page_parser'
|
4
4
|
|
5
5
|
module GemUpdater
|
6
|
+
|
7
|
+
# Updater's main responsability is to fill changes happened before and after update
|
8
|
+
# of `Gemfile`, and then format them.
|
6
9
|
class Updater
|
10
|
+
attr_accessor :gemfile
|
7
11
|
|
8
12
|
def initialize
|
9
13
|
@gemfile = GemUpdater::GemFile.new
|
@@ -14,26 +18,43 @@ module GemUpdater
|
|
14
18
|
# 1. update gemfile
|
15
19
|
# 2. find changelogs for updated gems
|
16
20
|
def update!
|
17
|
-
|
21
|
+
gemfile.update!
|
22
|
+
gemfile.compute_changes
|
23
|
+
|
18
24
|
|
19
|
-
|
20
|
-
source_uri
|
21
|
-
|
25
|
+
gemfile.changes.each do |gem_name, details|
|
26
|
+
if source_uri = find_source( gem_name, details[ :source ] )
|
27
|
+
source_page = GemUpdater::SourcePageParser.new( url: source_uri, version: details[ :versions ][ :new ] )
|
22
28
|
|
23
|
-
|
29
|
+
gemfile.changes[ gem_name ][ :changelog ] = source_page.changelog if source_page.changelog
|
30
|
+
end
|
24
31
|
end
|
25
32
|
end
|
26
33
|
|
27
34
|
# Format the diff to get human readable information
|
28
35
|
# on the gems that were updated.
|
29
36
|
def format_diff
|
30
|
-
|
37
|
+
gemfile.changes.each do |gem, details|
|
31
38
|
puts ERB.new( template, nil, '<>' ).result( binding )
|
32
39
|
end
|
33
40
|
end
|
34
41
|
|
35
42
|
private
|
36
43
|
|
44
|
+
# Find where is hosted the source of a gem
|
45
|
+
#
|
46
|
+
# @param gem [String] the name of the gem
|
47
|
+
# @param source [Bundler::Source] gem's source
|
48
|
+
# @return [String] url where gem is hosted
|
49
|
+
def find_source( gem, source )
|
50
|
+
case source
|
51
|
+
when Bundler::Source::Rubygems
|
52
|
+
GemUpdater::RubyGemsFetcher.new( gem, source ).source_uri
|
53
|
+
when Bundler::Source::Git
|
54
|
+
source.uri.gsub( /^git/, 'http' ).chomp( '.git' )
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
37
58
|
# Get the template for gem's diff.
|
38
59
|
# It can use a custom template.
|
39
60
|
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_updater
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxime Demolin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,8 +66,8 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
-
description:
|
70
|
-
|
69
|
+
description: Updates the gems of your Gemfile and fetches the links pointing to where
|
70
|
+
their changelogs are
|
71
71
|
email: akbarova.armia@gmail.com
|
72
72
|
executables:
|
73
73
|
- gem_update
|