Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add site.github.public_repositories[].contributors #234

Merged
Merged
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
6 changes: 5 additions & 1 deletion lib/jekyll-github-metadata/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ def owner_public_repositories
:accept => "application/vnd.github.mercy-preview+json",
}
memoize_value :@owner_public_repositories, Value.new("owner_public_repositories", proc do |c|
c.list_repos(owner, options).each { |r| r[:releases] = c.releases(r[:full_name]) }
c.list_repos(owner, options).map do |r|
r[:releases] = Value.new("owner_public_repositories_releases", proc { c.releases(r[:full_name]) })
r[:contributors] = Value.new("owner_public_repositories_contributors", proc { c.contributors(r[:full_name]) })
r
end
end)
end

Expand Down
6 changes: 4 additions & 2 deletions lib/jekyll-github-metadata/sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Sanitizer
# resource - an Object
#
# Returns the sanitized resource.
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
def sanitize(resource)
case resource
when Array
Expand All @@ -31,6 +31,8 @@ def sanitize(resource)
nil
when String
resource
when Value
resource.render
else
if resource.respond_to?(:to_hash)
sanitize_resource(resource)
Expand All @@ -39,7 +41,7 @@ def sanitize(resource)
end
end
end
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength

# Sanitize the Sawyer Resource or Hash
# Note: the object must respond to :to_hash for this to work.
Expand Down
7 changes: 7 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
expect(subject["public_repositories"].first["releases"].first["target_commitish"]).to eql("master")
end

it "contains the correct public_repositories.contributors" do
expect(subject).to have_key("public_repositories")
expect(subject["public_repositories"].first).to have_key("contributors")
expect(subject["public_repositories"].first["contributors"].size).to eql(1)
expect(subject["public_repositories"].first["contributors"].first["login"]).to eql("parkr")
end

it "calls all the stubs" do
stubs.each do |stub|
expect(stub).to have_been_requested
Expand Down
5 changes: 4 additions & 1 deletion spec/spec_helpers/stub_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def stub_all_api_requests
}.map { |path, file| stub_api(path, file) }

owner_repos = JSON.parse(webmock_data("owner_repos"))
owner_repos.each { |r| stubs << stub_api("/repos/#{r["full_name"]}/releases?per_page=100", "repo_releases") }
owner_repos.each do |r|
stubs << stub_api("/repos/#{r["full_name"]}/releases?per_page=100", "repo_releases")
stubs << stub_api("/repos/#{r["full_name"]}/contributors?per_page=100", "repo_contributors")
end

stubs
end
Expand Down