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.



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

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.from_uris(*uris) ⇒ Object



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

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



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

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"
  releases_url if Faraday.head("#{releases_url}/tag/v#{version}").success?
end