From 362b0aefe6101feee504fbc2d9790183f706d4d5 Mon Sep 17 00:00:00 2001 From: Justin Kenyon Date: Mon, 28 Jan 2019 15:40:01 -0600 Subject: [PATCH 1/2] Add new attributes to return for users and repos This commit: - Adds `hireable` to the whitelisted attributes available on the `owner` hash. - Adds decorator methods for `stargazers_count` and `forks_count` to the `Repository` object. Why? - This will allow users of this gem to access more useful information from users and repositories. --- lib/jekyll-github-metadata/repository.rb | 9 +++++++++ spec/repository_spec.rb | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/jekyll-github-metadata/repository.rb b/lib/jekyll-github-metadata/repository.rb index d56595f..cbdaa43 100644 --- a/lib/jekyll-github-metadata/repository.rb +++ b/lib/jekyll-github-metadata/repository.rb @@ -105,6 +105,7 @@ def repo_pages_info_opts :public_gists, :followers, :following, + :hireable, :created_at, :updated_at, ]) @@ -237,6 +238,14 @@ def url_without_path uri.dup.tap { |u| u.path = "" }.to_s end + def stargazers_count + repo_pages_info["stargazers_count"] || 0 + end + + def forks_count + repo_pages_info["forks_count"] || 0 + end + private def memoize_value(var_name, value) diff --git a/spec/repository_spec.rb b/spec/repository_spec.rb index 560fc53..ec0f0bd 100644 --- a/spec/repository_spec.rb +++ b/spec/repository_spec.rb @@ -39,6 +39,14 @@ it "respects the source branch" do expect(repo.git_ref).to eql("master") end + + it "returns the stargazers_count" do + expect(repo.stargazers_count).to eq(22) + end + + it "returns the fork count" do + expect(repo.forks_count).to eq(4) + end end context "hubot.github.com" do From 8b621118ad31a07f2d756923407977543c7968bf Mon Sep 17 00:00:00 2001 From: Justin Kenyon Date: Mon, 28 Jan 2019 22:16:11 -0600 Subject: [PATCH 2/2] update test to request with correct headers --- spec/repository_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/repository_spec.rb b/spec/repository_spec.rb index ec0f0bd..23aa6c3 100644 --- a/spec/repository_spec.rb +++ b/spec/repository_spec.rb @@ -39,6 +39,17 @@ it "respects the source branch" do expect(repo.git_ref).to eql("master") end + end + + context "repository information" do + let(:nwo) { "jekyll/jekyll" } + let!(:stub) do + stub_api( + "/repos/#{nwo}/pages", + "repo", + "Accept" => "application/vnd.github.v3+json" + ) + end it "returns the stargazers_count" do expect(repo.stargazers_count).to eq(22)