-
Notifications
You must be signed in to change notification settings - Fork 135
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
Add site.github.public_repositories[].contributors #234
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definite 👍 to the idea... wondering if we can use the Value class to improve the performance / reduce API calls if we aren't going to use these fields.
Co-authored-by: Parker Moore <[email protected]>
Thanks for your review, @parkr How about the following method? I made it work only when def owner_public_repositories
options = {
:type => "public",
:accept => "application/vnd.github.mercy-preview+json",
}
if ENV["JEKYLL_GITHUB_METADATA_DETAILS"] == true
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)
end
end)
else
memoize_value :@owner_public_repositories, Value.new("owner_public_repositories", proc { |c| c.list_repos(owner, options) })
end
end |
I was able to get this to pass on my machine with the following change: diff --git lib/jekyll-github-metadata/repository.rb lib/jekyll-github-metadata/repository.rb
index 1e4864c..9f75d2f 100644
--- lib/jekyll-github-metadata/repository.rb
+++ lib/jekyll-github-metadata/repository.rb
@@ -118,9 +118,10 @@ module Jekyll
: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 lib/jekyll-github-metadata/sanitizer.rb lib/jekyll-github-metadata/sanitizer.rb
index edaf554..0a993d3 100644
--- lib/jekyll-github-metadata/sanitizer.rb
+++ lib/jekyll-github-metadata/sanitizer.rb
@@ -16,7 +16,7 @@ module Jekyll
# 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 @@ module Jekyll
nil
when String
resource
+ when Value
+ resource.render
else
if resource.respond_to?(:to_hash)
sanitize_resource(resource)
@@ -39,7 +41,7 @@ module Jekyll
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. I don't think we want to make this an optional change – we can just load only when requested using |
Thanks for the detailed guide, @parkr! As per your guide, I wrapped the existing codes to use Anyway, please let me know if there is anything else I need to change or do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two quick rubocop failures. Thank you!
spec/spec_helpers/stub_helper.rb
Outdated
@@ -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") } |
There was a problem hiding this comment.
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.
spec/integration_spec.rb
Outdated
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) |
There was a problem hiding this comment.
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.
Thanks for reviewing this. I just removed spec related codes, and am waiting for CI results! |
@9bow Sorry, I just meant the one line, not all your specs! I like your tests. Just remove the one line I pointed out, and combine the loop you added in spec_helper with the one right above it. |
Oh, I'm sorry @parkr. I misunderstood. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
@jekyllbot: merge +minor |
Thank you very much, @parkr! |
Could you please let me know when the next release schedule is? |
v2.14.0 has been released! |
Awesome! Thanks a lot @parkr! |
I've finally rolled out this cool new feature on our site! 🎉 Again, thank you very much, @parkr! |
Hello,
After I wrote #233, I saw a merged PR about
site.github.public_repositories[].releases
(#224 by @parkr )I've never used ruby before, but with help of my friend @peniar , I made this PR. (thanks, @peniar)
Here're what I did:
First, I changed the code
lib/jekyll-github-metadata/repository.rb
in my installed gem, and check it worked.And then, I wrote some spec code referring previous PR about release, assumed that return should be like
spec/webmock/api_get_repo_contributors.json
Lastly, I tested with
bundle exec rspec spec
, and then 1 test I added failed as follows:I think the error
expected to execute 1 time but it executed 2 times
is because the line 16 inspec/spec_helpers/stub_helper.rb
conflict with line 26 which I added. However, line 15 for releases code does not conflict with line 25. :(I'm stuck here and don't know what to try or look for anymore.
If anyone could point out this PR, I would be very grateful.