Class: BundleUpdateInteractive::ChangelogLocator::GitHubRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/bundle_update_interactive/changelog_locator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ GitHubRepo

Returns a new instance of GitHubRepo.



22
23
24
# File 'lib/bundle_update_interactive/changelog_locator.rb', line 22

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



20
21
22
# File 'lib/bundle_update_interactive/changelog_locator.rb', line 20

def path
  @path
end

Class Method Details

.from_uris(*uris) ⇒ Object



13
14
15
16
17
18
# File 'lib/bundle_update_interactive/changelog_locator.rb', line 13

def self.from_uris(*uris)
  uris.flatten.each do |uri|
    return new(Regexp.last_match(1)) if uri&.match(GITHUB_PATTERN)
  end
  nil
end

Instance Method Details

#discover_changelog_uri(version) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bundle_update_interactive/changelog_locator.rb', line 26

def discover_changelog_uri(version)
  repo_html = fetch_repo_html(follow_redirect: true)
  return if repo_html.nil?

  changelog_path = repo_html[%r{/(#{path}/blob/[^/]+/#{FILE_PATTERN}(?:\.#{EXT_PATTERN})?)"}i, 1]
  return "https://github.com/#{changelog_path}" if changelog_path

  releases_url = "https://github.com/#{path}/releases"
  response = HTTP.get(releases_url)
  releases_url if response.success? && response.body.include?("v#{version}")
end