Class: Gitingest::RepositoryFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/gitingest/repository_fetcher.rb

Constant Summary collapse

MAX_FILES =
1000

Instance Method Summary collapse

Constructor Details

#initialize(client, repository, branch = :default, exclusion_filter = nil) ⇒ RepositoryFetcher

Returns a new instance of RepositoryFetcher.



9
10
11
12
13
14
# File 'lib/gitingest/repository_fetcher.rb', line 9

def initialize(client, repository, branch = :default, exclusion_filter = nil)
  @client = client
  @repository = repository
  @branch = branch
  @exclusion_filter = exclusion_filter
end

Instance Method Details

#fetchObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gitingest/repository_fetcher.rb', line 16

def fetch
  validate_repository_access
  repo_tree = @client.tree(@repository, @branch, recursive: true)

  files = repo_tree.tree.select do |item|
    item.type == "blob" && !@exclusion_filter&.excluded?(item.path)
  end

  if files.size > MAX_FILES
    # We might want to warn here, but for now we just truncate
    files = files.first(MAX_FILES)
  end

  files
rescue Octokit::Unauthorized
  raise "Authentication error: Invalid or expired GitHub token."
rescue Octokit::NotFound
  raise "Repository not found: '#{@repository}' or branch '#{@branch}' doesn't exist or is private."
rescue Octokit::Error => e
  raise "Error accessing repository: #{e.message}"
end