Class: GemChangelogDiff::ChangelogParser

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_changelog_diff/changelog_parser.rb

Overview

Parses CHANGELOG.md files from GitHub repos as a fallback source.

Constant Summary collapse

CONTENTS_URL =
"https://api.github.com/repos/%<repo>s/contents/%<path>s"
FILENAMES =
%w[CHANGELOG.md CHANGES.md History.md NEWS.md].freeze
VERSION_HEADING =
/^##\s+\[?v?(\d+[^\]\s]+)/

Instance Method Summary collapse

Constructor Details

#initialize(cache: nil) ⇒ ChangelogParser

Returns a new instance of ChangelogParser.



13
14
15
# File 'lib/gem_changelog_diff/changelog_parser.rb', line 13

def initialize(cache: nil)
  @cache = cache
end

Instance Method Details

#entries_between(repo, current_version, newest_version) ⇒ Array<Hash>

Parses changelog entries between two versions from a repo's changelog file.

Parameters:

  • repo (String)

    GitHub "owner/repo" slug

  • current_version (String)

    currently locked version (exclusive)

  • newest_version (String)

    target version (inclusive)

Returns:

  • (Array<Hash>)

    release hashes with :tag_name, :name, :published_at, :body

Raises:



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gem_changelog_diff/changelog_parser.rb', line 23

def entries_between(repo, current_version, newest_version)
  content = fetch_changelog(repo)
  return [] unless content

  parse_entries(content, current_version, newest_version)
rescue SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH,
       Errno::ETIMEDOUT, Errno::ECONNRESET,
       Net::OpenTimeout, Net::ReadTimeout,
       OpenSSL::SSL::SSLError => e
  raise NetworkError, "GitHub API request failed: #{e.message}"
end