Class: GemMaintainer::ChangelogFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_maintainer/changelog_fetcher.rb

Overview

Fetches the changelog URL for a gem. Strategy (mirrors bin/gem-changelog logic):

1. changelog_uri from RubyGems metadata
2. source_code_uri — search GitHub for a changelog file
3. homepage_uri    — search GitHub for a changelog file
4. Locally installed gem directory

Constant Summary collapse

RUBYGEMS_API =
"https://rubygems.org/api/v1/gems/%s.json"
CHANGELOG_FILES =
%w[CHANGELOG.md CHANGELOG.txt CHANGELOG CHANGES.md CHANGES History.md].freeze
GITHUB_BRANCHES =
%w[main master].freeze

Instance Method Summary collapse

Instance Method Details

#fetch(gem_name) ⇒ Object



19
20
21
22
23
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
# File 'lib/gem_maintainer/changelog_fetcher.rb', line 19

def fetch(gem_name)
   = (gem_name)
  return nil unless 

  changelog_uri  = ["changelog_uri"]
  source_code_uri = ["source_code_uri"]
  homepage_uri   = ["homepage_uri"]

  # 1. Explicit changelog_uri
  if changelog_uri && !changelog_uri.empty?
    return changelog_uri if url_exists?(changelog_uri)
  end

  # 2. source_code_uri → GitHub search
  if source_code_uri && source_code_uri.include?("github.com")
    url = find_github_changelog(source_code_uri)
    return url if url
  end

  # 3. homepage_uri → GitHub search
  if homepage_uri && homepage_uri.include?("github.com")
    url = find_github_changelog(homepage_uri)
    return url if url
  end

  # 4. Locally installed gem
  local = find_local_changelog(gem_name)
  return local if local

  # Fallback: RubyGems page
  "https://rubygems.org/gems/#{gem_name}"
end