From 5331c85409743ce4a6616746f87d6ab5bbbf38e8 Mon Sep 17 00:00:00 2001 From: Junghwan Park Date: Sat, 30 Apr 2022 03:14:55 +0900 Subject: [PATCH 1/5] Add site.github.public_repositories[].contributors --- lib/jekyll-github-metadata/repository.rb | 1 + spec/integration_spec.rb | 8 ++++++++ spec/spec_helpers/stub_helper.rb | 1 + 3 files changed, 10 insertions(+) diff --git a/lib/jekyll-github-metadata/repository.rb b/lib/jekyll-github-metadata/repository.rb index 821d8f3..16ad485 100644 --- a/lib/jekyll-github-metadata/repository.rb +++ b/lib/jekyll-github-metadata/repository.rb @@ -119,6 +119,7 @@ def owner_public_repositories } 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).each { |r| r[:contributors] = c.contributors(r[:full_name], options) } end) end diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 49cb6b5..b41344d 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -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) + end + it "calls all the stubs" do stubs.each do |stub| expect(stub).to have_been_requested diff --git a/spec/spec_helpers/stub_helper.rb b/spec/spec_helpers/stub_helper.rb index 04d14f3..62711f4 100644 --- a/spec/spec_helpers/stub_helper.rb +++ b/spec/spec_helpers/stub_helper.rb @@ -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") } stubs end From a9089ccd3860278b67503ed5edbda3d7d147aa2e Mon Sep 17 00:00:00 2001 From: Junghwan Park Date: Sat, 30 Apr 2022 07:28:07 +0900 Subject: [PATCH 2/5] apply review to reduce unnecessary API call Co-authored-by: Parker Moore <237985+parkr@users.noreply.github.com> --- lib/jekyll-github-metadata/repository.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/jekyll-github-metadata/repository.rb b/lib/jekyll-github-metadata/repository.rb index 16ad485..1e4864c 100644 --- a/lib/jekyll-github-metadata/repository.rb +++ b/lib/jekyll-github-metadata/repository.rb @@ -118,8 +118,10 @@ 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).each { |r| r[:contributors] = c.contributors(r[:full_name], options) } + c.list_repos(owner, options).each do |r| + r[:releases] = c.releases(r[:full_name]) + r[:contributors] = c.contributors(r[:full_name], options) + end end) end From 67d9c57ae137e4b866b6ebe868120cb25c7f715f Mon Sep 17 00:00:00 2001 From: Junghwan Park Date: Tue, 3 May 2022 22:22:01 +0900 Subject: [PATCH 3/5] apply @parkr's review that changes to load only when using Value --- lib/jekyll-github-metadata/repository.rb | 7 ++++--- lib/jekyll-github-metadata/sanitizer.rb | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/jekyll-github-metadata/repository.rb b/lib/jekyll-github-metadata/repository.rb index 1e4864c..c8716f2 100644 --- a/lib/jekyll-github-metadata/repository.rb +++ b/lib/jekyll-github-metadata/repository.rb @@ -118,9 +118,10 @@ 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 do |r| - r[:releases] = c.releases(r[:full_name]) - r[:contributors] = c.contributors(r[:full_name], options) + 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 diff --git a/lib/jekyll-github-metadata/sanitizer.rb b/lib/jekyll-github-metadata/sanitizer.rb index edaf554..0a993d3 100644 --- a/lib/jekyll-github-metadata/sanitizer.rb +++ b/lib/jekyll-github-metadata/sanitizer.rb @@ -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 @@ -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) @@ -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. From 342657c6a1adecf6a2f6a7b67c820b05b722080e Mon Sep 17 00:00:00 2001 From: Junghwan Park Date: Wed, 4 May 2022 09:13:49 +0900 Subject: [PATCH 4/5] removed spec codes which cause Rubocop failure --- spec/integration_spec.rb | 8 -------- spec/spec_helpers/stub_helper.rb | 1 - 2 files changed, 9 deletions(-) diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index b41344d..49cb6b5 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -42,14 +42,6 @@ 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) - end - it "calls all the stubs" do stubs.each do |stub| expect(stub).to have_been_requested diff --git a/spec/spec_helpers/stub_helper.rb b/spec/spec_helpers/stub_helper.rb index 62711f4..04d14f3 100644 --- a/spec/spec_helpers/stub_helper.rb +++ b/spec/spec_helpers/stub_helper.rb @@ -23,7 +23,6 @@ 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") } stubs end From a2afb1dbc9f8ffe1a60b9db436de91d95fed3ecc Mon Sep 17 00:00:00 2001 From: Junghwan Park Date: Thu, 5 May 2022 08:34:46 +0900 Subject: [PATCH 5/5] resurrected spec codes and re-applied review --- spec/integration_spec.rb | 7 +++++++ spec/spec_helpers/stub_helper.rb | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 49cb6b5..c7dd85a 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -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 diff --git a/spec/spec_helpers/stub_helper.rb b/spec/spec_helpers/stub_helper.rb index 04d14f3..c61c413 100644 --- a/spec/spec_helpers/stub_helper.rb +++ b/spec/spec_helpers/stub_helper.rb @@ -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