Class: Gemstar::RemoteRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/gemstar/remote_repository.rb

Instance Method Summary collapse

Constructor Details

#initialize(repository_uri) ⇒ RemoteRepository

Returns a new instance of RemoteRepository.



5
6
7
# File 'lib/gemstar/remote_repository.rb', line 5

def initialize(repository_uri)
  @repository_uri = repository_uri
end

Instance Method Details

#find_main_branch(cache_only: false, force_refresh: false) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gemstar/remote_repository.rb', line 9

def find_main_branch(cache_only: false, force_refresh: false)
  # Attempt loading .gitignore (assumed to be present in all repos) from either
  # main or master branch:
  %w[main master].each do |branch|
    cache_key = "gitignore-#{@repository_uri}-#{branch}"

    if cache_only
      content = Cache.peek(cache_key)
      return [branch] unless content.nil?

      next
    end

    Cache.fetch(cache_key, force: force_refresh) do
      content = begin
                  URI.open("#{@repository_uri}/#{branch}/.gitignore", read_timeout: 8)&.read
                rescue
                  nil
                end
      return [branch] unless content.nil?
    end
  end

  # No .gitignore found, have to search for changelogs in both branches:
  %w[main master]
end