diff --git a/lib/jekyll-github-metadata/client.rb b/lib/jekyll-github-metadata/client.rb index aab378b..29c882e 100644 --- a/lib/jekyll-github-metadata/client.rb +++ b/lib/jekyll-github-metadata/client.rb @@ -95,6 +95,9 @@ def save_from_errors(default = false) rescue Faraday::ConnectionFailed, Octokit::TooManyRequests => e GitHubMetadata.log :warn, e.message default + rescue Octokit::Forbidden => e + GitHubMetadata.log :warn, "#{e.message} This is a limitation of the GitHub API." + default rescue Octokit::NotFound default end diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 7ab97f2..c05c31f 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -39,6 +39,23 @@ end.to raise_error(described_class::BadCredentialsError) end + it "warns and returns false when contributors list is too large" do + stub_request(:get, url("/repos/jekyll/github-metadata/contributors?per_page=100")) + .with(:headers => request_headers.merge( + "Authorization" => "token #{token}" + )) + .to_return( + :status => 403, + :headers => WebMockHelper::RESPONSE_HEADERS, + :body => webmock_data("contributors_forbidden") + ) + logger_output = StringIO.new + Jekyll::GitHubMetadata.logger = Logger.new(logger_output) + result = subject.contributors("jekyll/github-metadata") + expect(result).to be(false) + expect(logger_output.string).to include("This is a limitation of the GitHub API") + end + it "supresses network accesses if requested" do WebMock.disable_net_connect! diff --git a/spec/webmock/api_get_contributors_forbidden.json b/spec/webmock/api_get_contributors_forbidden.json new file mode 100644 index 0000000..3f89d7a --- /dev/null +++ b/spec/webmock/api_get_contributors_forbidden.json @@ -0,0 +1,4 @@ +{ + "message": "The history or contributor list is too large to list contributors for this repository via the API.", + "documentation_url": "https://docs.github.com/rest/repos/repos#list-repository-contributors" +}