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

Expose User/Org information under site.github.owner #151

Merged
merged 2 commits into from
Jan 16, 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
1 change: 1 addition & 0 deletions lib/jekyll-github-metadata/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Client
API_CALLS = Set.new(%w(
repository
organization
user
repository?
pages
contributors
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll-github-metadata/metadata_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def keys
def_delegator :repository, :organization_public_members, :organization_members
def_delegator :repository, :name, :project_title
def_delegator :repository, :tagline, :project_tagline
def_delegator :repository, :owner_metadata, :owner
def_delegator :repository, :owner, :owner_name
def_delegator :repository, :owner_url, :owner_url
def_delegator :repository, :owner_gravatar_url, :owner_gravatar_url
Expand Down
58 changes: 58 additions & 0 deletions lib/jekyll-github-metadata/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,64 @@ def repo_pages_info_opts
end
end

# Whitelisted keys for Organizations and Users
WHITELISTED_ORGANIZATION_KEYS = Set.new([
:login,
:id,
:node_id,
:url,
:avatar_url,
:description,
:name,
:company,
:blog,
:location,
:email,
:is_verified,
:has_organization_projects,
:has_repository_projects,
:public_repos,
:public_gists,
:followers,
:following,
:html_url,
:created_at,
:type,
:collaborators,
])

WHITELISTED_USER_KEYS = Set.new([
:login,
:id,
:node_id,
:avatar_url,
:html_url,
:type,
:site_admin,
:name,
:company,
:blog,
:location,
:bio,
:public_repos,
:public_gists,
:followers,
:following,
:created_at,
:updated_at,
])

def owner_metadata
memoize_value :@owner_metadata, Value.new(proc { |c|
org = c.organization(owner)
if org
org.to_h.select { |k, _| WHITELISTED_ORGANIZATION_KEYS.include? k }
else
c.user(owner).to_h.select { |k, _| WHITELISTED_USER_KEYS.include? k }
end
})
end

def owner_url
"#{Pages.github_url}/#{owner}"
end
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helpers/integration_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def expected_values
"build_revision" => %r![a-f0-9]{40}!,
"project_title" => "github-metadata",
"project_tagline" => ":octocat: `site.github`",
"owner" => Regexp.new('"login"=>"jekyll", "id"=>3083652'),
"owner_name" => "jekyll",
"owner_url" => "https://github.com/jekyll",
"owner_gravatar_url" => "https://github.com/jekyll.png",
Expand Down