Skip to content

Commit

Permalink
Expose User/Org information under site.github.owner (#151)
Browse files Browse the repository at this point in the history
Merge pull request 151
  • Loading branch information
filbranden authored and jekyllbot committed Jan 16, 2019
1 parent dfdbfcf commit f05be64
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
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

0 comments on commit f05be64

Please sign in to comment.