Class: Dependabot::MetadataFinders::Base::ChangelogPruner

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/metadata_finders/base/changelog_pruner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependency:, changelog_text:) ⇒ ChangelogPruner

Returns a new instance of ChangelogPruner.



12
13
14
15
# File 'lib/dependabot/metadata_finders/base/changelog_pruner.rb', line 12

def initialize(dependency:, changelog_text:)
  @dependency = dependency
  @changelog_text = changelog_text
end

Instance Attribute Details

#changelog_textObject (readonly)

Returns the value of attribute changelog_text.



10
11
12
# File 'lib/dependabot/metadata_finders/base/changelog_pruner.rb', line 10

def changelog_text
  @changelog_text
end

#dependencyObject (readonly)

Returns the value of attribute dependency.



10
11
12
# File 'lib/dependabot/metadata_finders/base/changelog_pruner.rb', line 10

def dependency
  @dependency
end

Instance Method Details

#includes_new_version?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/dependabot/metadata_finders/base/changelog_pruner.rb', line 17

def includes_new_version?
  !new_version_changelog_line.nil?
end

#includes_previous_version?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/dependabot/metadata_finders/base/changelog_pruner.rb', line 21

def includes_previous_version?
  !old_version_changelog_line.nil?
end

#pruned_textObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dependabot/metadata_finders/base/changelog_pruner.rb', line 25

def pruned_text
  changelog_lines = changelog_text.split("\n")

  slice_range =
    if old_version_changelog_line && new_version_changelog_line
      if old_version_changelog_line < new_version_changelog_line
        Range.new(old_version_changelog_line, -1)
      else
        Range.new(new_version_changelog_line,
                  old_version_changelog_line - 1)
      end
    elsif old_version_changelog_line
      return if old_version_changelog_line.zero?

      # Assumes changelog is in descending order
      Range.new(0, old_version_changelog_line - 1)
    elsif new_version_changelog_line
      # Assumes changelog is in descending order
      Range.new(new_version_changelog_line, -1)
    else
      return unless changelog_contains_relevant_versions?

      # If the changelog contains any relevant versions, return it in
      # full. We could do better here by fully parsing the changelog
      Range.new(0, -1)
    end

  changelog_lines.slice(slice_range).join("\n").rstrip
end