Skip to content

Commit

Permalink
Add site.github.public_repositories[].releases (#224)
Browse files Browse the repository at this point in the history
Merge pull request 224
  • Loading branch information
parkr committed Apr 20, 2022
1 parent 314ffbf commit f3b27ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/jekyll-github-metadata/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def owner_public_repositories
:type => "public",
:accept => "application/vnd.github.mercy-preview+json",
}
memoize_value :@owner_public_repositories, Value.new("owner_public_repositories", proc { |c| c.list_repos(owner, options) })
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]) }
end)
end

def organization_public_members
Expand Down
8 changes: 8 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
end
end

it "contains the correct public_repositories.releases" do
expect(subject).to have_key("public_repositories")
expect(subject["public_repositories"].first).to have_key("releases")
expect(subject["public_repositories"].first["releases"].size).to eql(3)
expect(subject["public_repositories"].first["releases"].first["name"]).to eql("v1.1.0")
expect(subject["public_repositories"].first["releases"].first["target_commitish"]).to eql("master")
end

it "calls all the stubs" do
stubs.each do |stub|
expect(stub).to have_been_requested
Expand Down
7 changes: 6 additions & 1 deletion spec/spec_helpers/stub_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module StubHelper
# Returns all stubs created.
def stub_all_api_requests
reset_env_for_stubs
{
stubs = {
"/users/jekyll/repos?per_page=100&type=public" => "owner_repos",
"/repos/jekyll/github-metadata" => "repo",
"/orgs/jekyll" => "org",
Expand All @@ -20,6 +20,11 @@ def stub_all_api_requests
"/repos/jekyll/jekyll.github.io/pages" => "repo_pages",
"/repos/jekyll/github-metadata/releases/latest" => "latest_release",
}.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") }

stubs
end

def reset_env_for_stubs
Expand Down

0 comments on commit f3b27ce

Please sign in to comment.