Class: Dependabot::MetadataFinders::Base::ChangelogFinder

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

Constant Summary collapse

CHANGELOG_NAMES =

Earlier entries are preferred

%w(
  changelog news changes history release whatsnew
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, dependency:, credentials:, suggested_changelog_url: nil) ⇒ ChangelogFinder

Returns a new instance of ChangelogFinder.



27
28
29
30
31
32
33
# File 'lib/dependabot/metadata_finders/base/changelog_finder.rb', line 27

def initialize(source:, dependency:, credentials:,
               suggested_changelog_url: nil)
  @source = source
  @dependency = dependency
  @credentials = credentials
  @suggested_changelog_url = suggested_changelog_url
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



25
26
27
# File 'lib/dependabot/metadata_finders/base/changelog_finder.rb', line 25

def credentials
  @credentials
end

#dependencyObject (readonly)

Returns the value of attribute dependency.



25
26
27
# File 'lib/dependabot/metadata_finders/base/changelog_finder.rb', line 25

def dependency
  @dependency
end

#sourceObject (readonly)

Returns the value of attribute source.



25
26
27
# File 'lib/dependabot/metadata_finders/base/changelog_finder.rb', line 25

def source
  @source
end

#suggested_changelog_urlObject (readonly)

Returns the value of attribute suggested_changelog_url.



25
26
27
# File 'lib/dependabot/metadata_finders/base/changelog_finder.rb', line 25

def suggested_changelog_url
  @suggested_changelog_url
end

Instance Method Details

#changelog_textObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/dependabot/metadata_finders/base/changelog_finder.rb', line 39

def changelog_text
  return unless full_changelog_text

  pruned_text = ChangelogPruner.new(
    dependency: dependency,
    changelog_text: full_changelog_text
  ).pruned_text

  return pruned_text unless changelog.name.end_with?(".rst")

  begin
    PandocRuby.convert(
      pruned_text,
      from: :rst,
      to: :markdown,
      wrap: :none,
      timeout: 10
    )
  rescue Errno::ENOENT => e
    raise unless e.message == "No such file or directory - pandoc"

    # If pandoc isn't installed just return the rst
    pruned_text
  rescue RuntimeError => e
    raise unless e.message.include?("Pandoc timed out")

    pruned_text
  end
end

#changelog_urlObject



35
36
37
# File 'lib/dependabot/metadata_finders/base/changelog_finder.rb', line 35

def changelog_url
  changelog&.html_url
end

#upgrade_guide_textObject



73
74
75
76
77
# File 'lib/dependabot/metadata_finders/base/changelog_finder.rb', line 73

def upgrade_guide_text
  return unless upgrade_guide

  @upgrade_guide_text ||= fetch_file_text(upgrade_guide)
end

#upgrade_guide_urlObject



69
70
71
# File 'lib/dependabot/metadata_finders/base/changelog_finder.rb', line 69

def upgrade_guide_url
  upgrade_guide&.html_url
end