Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions lib/fbe/unmask_repos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,18 @@ def Fbe.unmask_repos( # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticCompl
repos.reject! { |r| re.match?(r) }
end
repos.uniq!(&:downcase)
repos.reject! do |repo|
octo.repository(repo)[:archived]
rescue Octokit::NotFound => e
loog.warn("Repository #{repo.inspect} is absent, dropping it: #{e.message}")
true
rescue Octokit::Deprecated, Octokit::Forbidden, Octokit::ServerError, Octokit::Unauthorized,
Faraday::ConnectionFailed, Faraday::TimeoutError, Fbe::OffQuota => e
loog.warn("Cannot tell whether #{repo.inspect} is archived, assuming it is not: #{e.message}")
false
end
repos =
repos.filter_map do |repo|
r = octo.repository(repo)
r[:archived] ? nil : (r[:full_name] || repo)
rescue Octokit::NotFound => e
loog.warn("Repository #{repo.inspect} is absent, dropping it: #{e.message}")
nil
rescue Octokit::Deprecated, Octokit::Forbidden, Octokit::ServerError, Octokit::Unauthorized,
Faraday::ConnectionFailed, Faraday::TimeoutError, Fbe::OffQuota => e
loog.warn("Cannot tell whether #{repo.inspect} is archived, assuming it is not: #{e.message}")
repo
end
raise(Fbe::Error, "No repos found matching: #{options.repositories.inspect}") if repos.empty?
repos.shuffle!
loog.debug("Scanning #{repos.size} repositories: #{repos.joined}...")
Expand Down
19 changes: 19 additions & 0 deletions test/fbe/test_unmask_repos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,25 @@ def test_does_not_raise_off_quota_regardless_of_quota_aware
assert_equal(['foo/bar'], list, 'the repo is not kept when the quota check itself is off-quota')
end

def test_returns_canonical_case_for_exact_and_wildcard_masks
WebMock.disable_net_connect!
stub_request(:get, 'https://api.github.com/rate_limit').to_return(
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
)
stub_request(:get, 'https://api.github.com/repos/ZEROCRACY/FBE').to_return(
body: '{"full_name":"zerocracy/fbe"}', headers: { 'Content-Type' => 'application/json' }
)
stub_request(:get, 'https://api.github.com/orgs/zerocracy/repos?per_page=100&type=all').to_return(
body: '[{"full_name":"zerocracy/fbe"}]', headers: { 'Content-Type' => 'application/json' }
)
stub_request(:get, 'https://api.github.com/repos/zerocracy/fbe').to_return(
body: '{"full_name":"zerocracy/fbe","archived":false}', headers: { 'Content-Type' => 'application/json' }
)
options = Judges::Options.new({ 'repositories' => 'ZEROCRACY/FBE,zerocracy/*' })
list = Fbe.unmask_repos(options:, global: {}, loog: Loog::NULL)
assert_equal(['zerocracy/fbe'], list, "expected canonical case, got #{list.inspect}")
end

def test_live_usage
skip('Run it only manually, since it touches GitHub API')
opts = Judges::Options.new({ 'repositories' => 'zerocracy/*,-zerocracy/judges-action,zerocracy/datum' })
Expand Down
Loading