Class: Gemstar::Commands::Diff

Inherits:
Command
  • Object
show all
Defined in:
lib/gemstar/commands/diff.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Diff

Returns a new instance of Diff.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gemstar/commands/diff.rb', line 27

def initialize(options)
  super

  @debug_gem_regex = Regexp.new(options[:debug_gem_regex] || ENV["GEMSTAR_DEBUG_GEM_REGEX"] || ".*")

  @since = normalize_since(options[:since])
  @from = options[:from] || "HEAD"
  @to = options[:to]
  @lockfile = options[:lockfile] || "Gemfile.lock"
  @output_format = normalize_output_format(options[:format] || options[:output_format])
  @output_file = options[:output_file] || default_output_file
  @project = options[:project] ? Gemstar::Project.from_cli_argument(options[:project]) : nil
  @ecosystem = normalize_ecosystem(options[:ecosystem])
  @considered_commits = []
  @since_cutoff_commit = nil

  @git_repo = project ? project.git_repo : Gemstar::GitRepo.new(File.dirname(@lockfile))
  @from = resolve_since_commit if since
end

Instance Attribute Details

#considered_commitsObject (readonly)

Returns the value of attribute considered_commits.



24
25
26
# File 'lib/gemstar/commands/diff.rb', line 24

def considered_commits
  @considered_commits
end

#ecosystemObject (readonly)

Returns the value of attribute ecosystem.



22
23
24
# File 'lib/gemstar/commands/diff.rb', line 22

def ecosystem
  @ecosystem
end

#failedObject (readonly)

Returns the value of attribute failed.



13
14
15
# File 'lib/gemstar/commands/diff.rb', line 13

def failed
  @failed
end

#fromObject (readonly)

Returns the value of attribute from.



14
15
16
# File 'lib/gemstar/commands/diff.rb', line 14

def from
  @from
end

#git_repoObject (readonly)

Returns the value of attribute git_repo.



17
18
19
# File 'lib/gemstar/commands/diff.rb', line 17

def git_repo
  @git_repo
end

#lockfileObject (readonly)

Returns the value of attribute lockfile.



16
17
18
# File 'lib/gemstar/commands/diff.rb', line 16

def lockfile
  @lockfile
end

#lockfile_full_pathObject (readonly)

Returns the value of attribute lockfile_full_path.



18
19
20
# File 'lib/gemstar/commands/diff.rb', line 18

def lockfile_full_path
  @lockfile_full_path
end

#output_fileObject (readonly)

Returns the value of attribute output_file.



19
20
21
# File 'lib/gemstar/commands/diff.rb', line 19

def output_file
  @output_file
end

#output_formatObject (readonly)

Returns the value of attribute output_format.



20
21
22
# File 'lib/gemstar/commands/diff.rb', line 20

def output_format
  @output_format
end

#projectObject (readonly)

Returns the value of attribute project.



21
22
23
# File 'lib/gemstar/commands/diff.rb', line 21

def project
  @project
end

#sinceObject (readonly)

Returns the value of attribute since.



23
24
25
# File 'lib/gemstar/commands/diff.rb', line 23

def since
  @since
end

#since_cutoff_commitObject (readonly)

Returns the value of attribute since_cutoff_commit.



25
26
27
# File 'lib/gemstar/commands/diff.rb', line 25

def since_cutoff_commit
  @since_cutoff_commit
end

#toObject (readonly)

Returns the value of attribute to.



15
16
17
# File 'lib/gemstar/commands/diff.rb', line 15

def to
  @to
end

#updatesObject (readonly)

Returns the value of attribute updates.



12
13
14
# File 'lib/gemstar/commands/diff.rb', line 12

def updates
  @updates
end

Instance Method Details

#format_commit(commit, fallback_revision:) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/gemstar/commands/diff.rb', line 126

def format_commit(commit, fallback_revision:)
  return fallback_revision.to_s if commit.nil?

  date = commit[:authored_at].to_s.split("T").first
  label = [commit[:short_sha] || commit[:id], commit[:subject]].compact.join(" ")
  date.empty? ? label : "#{label} (#{date})"
end

#project_nameObject



142
143
144
145
146
# File 'lib/gemstar/commands/diff.rb', line 142

def project_name
  return project.name if project

  Pathname.getwd.basename.to_s
end

#runObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gemstar/commands/diff.rb', line 47

def run
  project ? run_project_diff : run_lockfile_diff
  @considered_commits = collect_considered_commits

  rendered_output = output_renderer.render_diff(self)
  File.write(output_file, rendered_output)
  puts "✅ Changelog report created: #{output_file_url}"

  if failed.any?
    puts "\n⚠️ The following gems failed to process:"
    failed.each { |gem, msg| puts "  - #{gem}: #{msg}" }
  end
end