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 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
8 changes: 8 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
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")
expect(subject["public_repositories"].first["contributors"].first["id"]).to eql(237985)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rubocop is failing on this line. I think it's unnecessary so I'd recommend that you remove this line.

end

it "calls all the stubs" do
stubs.each do |stub|
expect(stub).to have_been_requested
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helpers/stub_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def stub_all_api_requests

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 { |r| stubs << stub_api("/repos/#{r["full_name"]}/contributors?per_page=100", "repo_contributors") }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Rubocop:

Style/CombinableLoops: Combine this loop with the previous loop.


stubs
end
Expand Down