Skip to content

Commit

Permalink
feat(yegor256#228): fetch_contents
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Jul 1, 2024
1 parent 0a8ea92 commit 85a0af1
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions steps/discover-repos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,24 @@ def cooldown(opts, found)
sleep opts[:pause]
end

def files_in_repo(github, repo, ref, path = '')
begin
contents = github.contents(repo, { path: path, ref: ref })
count = 0
contents.each do |content|
if content[:type] == 'file'
count += 1
elsif content[:type] == 'dir'
count += files_in_repo(github, repo, ref, content[:path])
end
def fetch_contents(github, repo, ref, path)
contents = github.contents(repo, { path: path, ref: ref })
count = 0
contents.each do |content|
if content[:type] == 'file'
count += 1
elsif content[:type] == 'dir'
count += fetch_contents(github, repo, ref, content[:path])
end
count
rescue Octokit::NotFound
puts "There is no contents inside #{repo}"
count
end
count
end

def files_in_repo(github, repo, ref, path = '')
fetch_contents(github, repo, ref, path)
rescue Octokit::NotFound
puts "There is no contents inside #{repo}"
0
end

puts 'Not searching GitHub API, using mock repos' if opts[:dry]
Expand Down

0 comments on commit 85a0af1

Please sign in to comment.