Skip to content

Commit

Permalink
Add site.github.public_repositories[].contributors (#234)
Browse files Browse the repository at this point in the history
Merge pull request 234
  • Loading branch information
9bow committed May 5, 2022
1 parent f3b27ce commit 421dd6e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
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

0 comments on commit 421dd6e

Please sign in to comment.