lib/gistory/change_log.rb in gistory-0.1.7 vs lib/gistory/change_log.rb in gistory-0.1.8
- old
+ new
@@ -1,12 +1,10 @@
# frozen_string_literal: true
-require 'bundler'
-
module Gistory
class ChangeLog
- LOCKFILE = 'Gemfile.lock'.freeze
+ LOCKFILE = 'Gemfile.lock'
def initialize(repo:)
@repo = repo
end
@@ -16,39 +14,37 @@
# no lockfile found or no changes to the lockfile found
return [] if lockfile_changes.empty?
previous_commit = lockfile_changes.shift
- previous_gem_spec = gem_spec_at_commit_hash(previous_commit.short_hash, gem_name)
+ previous_gem_spec = gem_version_at_commit_hash(previous_commit.short_hash, gem_name)
# only one change to the lockfile was found and the gem was not there
return [] if previous_gem_spec.nil?
lockfile_changes.each do |current_commit|
- current_gem_spec = gem_spec_at_commit_hash(current_commit.short_hash, gem_name)
+ current_gem_spec = gem_version_at_commit_hash(current_commit.short_hash, gem_name)
# we reached the end, the gem didn't exist back then
# TODO: what if it was added then removed and then added again?
break if current_gem_spec.nil?
- if current_gem_spec.version.to_s != previous_gem_spec.version.to_s
- version_changes << VersionChange.new(commit: previous_commit, version: previous_gem_spec.version)
+ if current_gem_spec != previous_gem_spec
+ version_changes << VersionChange.new(commit: previous_commit, version: previous_gem_spec)
end
previous_gem_spec = current_gem_spec
previous_commit = current_commit
end
- version_changes << VersionChange.new(commit: previous_commit, version: previous_gem_spec.version)
+ version_changes << VersionChange.new(commit: previous_commit, version: previous_gem_spec)
version_changes
end
private
- def gem_spec_at_commit_hash(commit_hash, gem_name)
+ def gem_version_at_commit_hash(commit_hash, gem_name)
lockfile_content = @repo.file_content_at_commit(commit_hash, LOCKFILE)
- lockfile = Bundler::LockfileParser.new(lockfile_content)
- gem_spec = lockfile.specs.find { |spec| spec.name == gem_name }
- gem_spec
+ LockfileParser.new(lockfile_content: lockfile_content).gem_version(gem_name)
end
end
end