gistory 0.1.7 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: d0a07bc173fd96849fa0660f4641d9945896f3329ec3cc467be6ceb4383a75eb
4
- data.tar.gz: cee8b211779dc04c1f0d11af49496aaf3745d4763e618ef74cb3ca88f09b016a
2
+ SHA1:
3
+ metadata.gz: 2d3139f7b6f07fd2b6de135eb63c8ada4baaa1c4
4
+ data.tar.gz: 95de85e6a6f1b4809295db975d33449d12dd23cd
5
5
  SHA512:
6
- metadata.gz: ad8f8841415791d29292e5ab2ad7057d763e5fc59de7fa7cf42e574aea9a959241ac7e526e062a9dc9863974e15ee52b3aef96be5567c625de9ff5b44dea96e2
7
- data.tar.gz: cacb17ab10b572b74bf760ab98690e55afa6d93f6de207df04bc2774e1d924db8eb533bbacc1a660e0d9ec17556fe54aa6031f0132eaaac25c249221a07a0893
6
+ metadata.gz: f8eae6a6a4b52a452b45f837594646b8a57c6aa4f101c86612b56462a1234025355861c8a6fe0bb22de55c54908c9d422c15634c92c0c22b5ed52b6c5f6ebb21
7
+ data.tar.gz: cb9c8bd90a5f722217a792b4b3890394894ed23a242d95e1453470ab408f86ba83c145364a8c2f47367552900635ad56d9299809ee64ff76f179ea35f29538b6
@@ -11,6 +11,7 @@ require 'gistory/errors'
11
11
  require 'gistory/commit'
12
12
  require 'gistory/version_change'
13
13
  require 'gistory/git_repo'
14
+ require 'gistory/lockfile_parser'
14
15
  require 'gistory/change_log'
15
16
 
16
17
  module Gistory
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler'
4
-
5
3
  module Gistory
6
4
  class ChangeLog
7
- LOCKFILE = 'Gemfile.lock'.freeze
5
+ LOCKFILE = 'Gemfile.lock'
8
6
 
9
7
  def initialize(repo:)
10
8
  @repo = repo
@@ -18,37 +16,35 @@ module Gistory
18
16
  return [] if lockfile_changes.empty?
19
17
 
20
18
  previous_commit = lockfile_changes.shift
21
- previous_gem_spec = gem_spec_at_commit_hash(previous_commit.short_hash, gem_name)
19
+ previous_gem_spec = gem_version_at_commit_hash(previous_commit.short_hash, gem_name)
22
20
  # only one change to the lockfile was found and the gem was not there
23
21
  return [] if previous_gem_spec.nil?
24
22
 
25
23
  lockfile_changes.each do |current_commit|
26
- current_gem_spec = gem_spec_at_commit_hash(current_commit.short_hash, gem_name)
24
+ current_gem_spec = gem_version_at_commit_hash(current_commit.short_hash, gem_name)
27
25
 
28
26
  # we reached the end, the gem didn't exist back then
29
27
  # TODO: what if it was added then removed and then added again?
30
28
  break if current_gem_spec.nil?
31
29
 
32
- if current_gem_spec.version.to_s != previous_gem_spec.version.to_s
33
- version_changes << VersionChange.new(commit: previous_commit, version: previous_gem_spec.version)
30
+ if current_gem_spec != previous_gem_spec
31
+ version_changes << VersionChange.new(commit: previous_commit, version: previous_gem_spec)
34
32
  end
35
33
 
36
34
  previous_gem_spec = current_gem_spec
37
35
  previous_commit = current_commit
38
36
  end
39
37
 
40
- version_changes << VersionChange.new(commit: previous_commit, version: previous_gem_spec.version)
38
+ version_changes << VersionChange.new(commit: previous_commit, version: previous_gem_spec)
41
39
 
42
40
  version_changes
43
41
  end
44
42
 
45
43
  private
46
44
 
47
- def gem_spec_at_commit_hash(commit_hash, gem_name)
45
+ def gem_version_at_commit_hash(commit_hash, gem_name)
48
46
  lockfile_content = @repo.file_content_at_commit(commit_hash, LOCKFILE)
49
- lockfile = Bundler::LockfileParser.new(lockfile_content)
50
- gem_spec = lockfile.specs.find { |spec| spec.name == gem_name }
51
- gem_spec
47
+ LockfileParser.new(lockfile_content: lockfile_content).gem_version(gem_name)
52
48
  end
53
49
  end
54
50
  end
@@ -18,8 +18,8 @@ module Gistory
18
18
  parse_gem_name
19
19
  @io.error("extra parameters ignored: #{@args}") unless @args.count.zero?
20
20
  @config
21
- rescue OptionParser::InvalidOption => err
22
- raise(Gistory::ParserError, err.message)
21
+ rescue OptionParser::InvalidOption => e
22
+ raise(Gistory::ParserError, e.message)
23
23
  end
24
24
 
25
25
  def to_s
@@ -14,11 +14,11 @@ module Gistory
14
14
  parser = Cli::ArgParser.new(args: @args, io: @io)
15
15
  config = parser.parse
16
16
  history(repo, config.gem_name)
17
- rescue Gistory::ParserError => error
18
- @io.error error.message
17
+ rescue Gistory::ParserError => e
18
+ @io.error e.message
19
19
  @io.puts parser
20
- rescue Gistory::Error => error
21
- @io.error error.message
20
+ rescue Gistory::Error => e
21
+ @io.error e.message
22
22
  end
23
23
 
24
24
  private
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+
5
+ module Gistory
6
+ class LockfileParser
7
+ def initialize(lockfile_content:)
8
+ @lockfile_content = lockfile_content
9
+ end
10
+
11
+ def gem_version(gem_name)
12
+ lockfile = Bundler::LockfileParser.new(@lockfile_content)
13
+ gem_spec = lockfile.specs.find { |spec| spec.name == gem_name }
14
+ gem_spec ? gem_spec.version.to_s : nil
15
+ rescue Bundler::LockfileError => _e
16
+ # bundler could not parse the lockfile
17
+ # f.i. it could have been committed with merge conflicts
18
+ # try to parse it with a regex
19
+ # gem version looks like " byebug (9.0.6)"
20
+ # TODO: what if the gem was in the merge conflict?
21
+ regexp = /\n\s{4}#{gem_name} \((?<version>.+)\)\n/
22
+ matches = @lockfile_content.match(regexp)
23
+ matches ? matches[:version] : nil
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gistory
4
- VERSION = '0.1.7'.freeze
4
+ VERSION = '0.1.8'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gistory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Medina
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-29 00:00:00.000000000 Z
11
+ date: 2019-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,6 +97,7 @@ files:
97
97
  - lib/gistory/configuration.rb
98
98
  - lib/gistory/errors.rb
99
99
  - lib/gistory/git_repo.rb
100
+ - lib/gistory/lockfile_parser.rb
100
101
  - lib/gistory/version.rb
101
102
  - lib/gistory/version_change.rb
102
103
  homepage: https://www.github.com/serch/gistory
@@ -119,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  version: '0'
120
121
  requirements: []
121
122
  rubyforge_project:
122
- rubygems_version: 2.7.8
123
+ rubygems_version: 2.6.14.1
123
124
  signing_key:
124
125
  specification_version: 4
125
126
  summary: 'Gistory: Know exactly when a gem was updated in your Gemfile.lock'