Class: Dependabot::MetadataFinders::Base::ChangelogPruner
- Inherits:
-
Object
- Object
- Dependabot::MetadataFinders::Base::ChangelogPruner
- Defined in:
- lib/dependabot/metadata_finders/base/changelog_pruner.rb
Instance Attribute Summary collapse
-
#changelog_text ⇒ Object
readonly
Returns the value of attribute changelog_text.
-
#dependency ⇒ Object
readonly
Returns the value of attribute dependency.
Instance Method Summary collapse
- #includes_new_version? ⇒ Boolean
- #includes_previous_version? ⇒ Boolean
-
#initialize(dependency:, changelog_text:) ⇒ ChangelogPruner
constructor
A new instance of ChangelogPruner.
- #pruned_text ⇒ Object
Constructor Details
#initialize(dependency:, changelog_text:) ⇒ ChangelogPruner
Returns a new instance of ChangelogPruner.
11 12 13 14 |
# File 'lib/dependabot/metadata_finders/base/changelog_pruner.rb', line 11 def initialize(dependency:, changelog_text:) @dependency = dependency @changelog_text = changelog_text end |
Instance Attribute Details
#changelog_text ⇒ Object (readonly)
Returns the value of attribute changelog_text.
9 10 11 |
# File 'lib/dependabot/metadata_finders/base/changelog_pruner.rb', line 9 def changelog_text @changelog_text end |
#dependency ⇒ Object (readonly)
Returns the value of attribute dependency.
9 10 11 |
# File 'lib/dependabot/metadata_finders/base/changelog_pruner.rb', line 9 def dependency @dependency end |
Instance Method Details
#includes_new_version? ⇒ Boolean
16 17 18 |
# File 'lib/dependabot/metadata_finders/base/changelog_pruner.rb', line 16 def includes_new_version? !new_version_changelog_line.nil? end |
#includes_previous_version? ⇒ Boolean
20 21 22 |
# File 'lib/dependabot/metadata_finders/base/changelog_pruner.rb', line 20 def includes_previous_version? !old_version_changelog_line.nil? end |
#pruned_text ⇒ Object
24 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 |
# File 'lib/dependabot/metadata_finders/base/changelog_pruner.rb', line 24 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").sub(/\n*\z/, "") end |