Class: LockDiff::DiffInfo

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/lock_diff/diff_info.rb

Constant Summary collapse

UPGRADE =
'upgrade'
DOWNGRADE =
'downgrade'
DELETE =
'delete'
NEW =
'new'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(old_package:, new_package:) ⇒ DiffInfo

Returns a new instance of DiffInfo.



13
14
15
16
# File 'lib/lock_diff/diff_info.rb', line 13

def initialize(old_package:, new_package:)
  @old_package = old_package
  @new_package = new_package
end

Instance Attribute Details

#new_packageObject (readonly)

Returns the value of attribute new_package.



10
11
12
# File 'lib/lock_diff/diff_info.rb', line 10

def new_package
  @new_package
end

#old_packageObject (readonly)

Returns the value of attribute old_package.



10
11
12
# File 'lib/lock_diff/diff_info.rb', line 10

def old_package
  @old_package
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/lock_diff/diff_info.rb', line 18

def changed?
  @old_package.different?(@new_package)
end

#changelog_nameObject



77
78
79
# File 'lib/lock_diff/diff_info.rb', line 77

def changelog_name
  File.basename(changelog_url)
end

#changelog_urlObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/lock_diff/diff_info.rb', line 59

def changelog_url
  @changelog_url ||= begin
    ref =
      case status
      when UPGRADE, NEW
        @new_package.ref
      when DOWNGRADE, DELETE
        nil # default branch(master)
      end

    Github::ChangelogUrlFinder.new(
      repository: package.repository,
      github_url: package.github_url,
      ref: ref
    ).call
  end
end

#commits_urlObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/lock_diff/diff_info.rb', line 81

def commits_url
  return unless package.github_url
  old_ref = @old_package.ref
  new_ref = @new_package.ref
  commits_url =
    case status
    when UPGRADE
      "compare/#{old_ref}...#{new_ref}" if old_ref && new_ref
    when DOWNGRADE
      "compare/#{new_ref}...#{old_ref}" if old_ref && new_ref
    when DELETE
      "commits/#{old_ref}" if old_ref
    when NEW
      "commits/#{new_ref}" if new_ref
    end

  "#{package.github_url}/#{commits_url}" if commits_url
end

#commits_url_textObject



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/lock_diff/diff_info.rb', line 100

def commits_url_text
  case status
  when UPGRADE
    "#{@old_package.version_str}...#{@new_package.version_str}"
  when DOWNGRADE
    "#{@new_package.version_str}...#{@old_package.version_str}"
  when DELETE
    "#{@old_package.version_str}"
  when NEW
    "#{@new_package.version_str}"
  end
end

#packageObject



37
38
39
40
41
42
43
44
# File 'lib/lock_diff/diff_info.rb', line 37

def package
  case status
  when UPGRADE, NEW
    @new_package
  when DOWNGRADE, DELETE
    @old_package
  end
end

#statusObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lock_diff/diff_info.rb', line 22

def status
  case
  when @old_package.version && @new_package.version
    if @old_package.version < @new_package.version
      UPGRADE
    else
      DOWNGRADE
    end
  when @old_package.version
    DELETE
  when @new_package.version
    NEW
  end
end

#status_emojiObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/lock_diff/diff_info.rb', line 46

def status_emoji
  case status
  when UPGRADE
    ':chart_with_upwards_trend:'
  when DOWNGRADE
    ':chart_with_downwards_trend:'
  when DELETE
    ':x:'
  when NEW
    ':new:'
  end
end