Skip to content
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 new attributes to return for users and repositories #158

Merged
merged 2 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/jekyll-github-metadata/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def repo_pages_info_opts
:public_gists,
:followers,
:following,
:hireable,
:created_at,
:updated_at,
])
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions spec/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@
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)
end

it "returns the fork count" do
expect(repo.forks_count).to eq(4)
end
end

context "hubot.github.com" do
let(:nwo) { "github/hubot.github.com" }
let!(:stub) { stub_api("/repos/#{nwo}/pages", "hubot_repo_pages") }
Expand Down