From ae37b82258e9948e5576c82e350c64ed7bd5b920 Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Wed, 2 Jan 2019 17:00:49 -0800 Subject: [PATCH 1/2] Expose User/Org information under site.github.owner --- lib/jekyll-github-metadata/client.rb | 1 + lib/jekyll-github-metadata/metadata_drop.rb | 1 + lib/jekyll-github-metadata/repository.rb | 4 ++++ spec/spec_helpers/integration_helper.rb | 1 + 4 files changed, 7 insertions(+) diff --git a/lib/jekyll-github-metadata/client.rb b/lib/jekyll-github-metadata/client.rb index 0950d66..d2a6aa9 100644 --- a/lib/jekyll-github-metadata/client.rb +++ b/lib/jekyll-github-metadata/client.rb @@ -12,6 +12,7 @@ class Client API_CALLS = Set.new(%w( repository organization + user repository? pages contributors diff --git a/lib/jekyll-github-metadata/metadata_drop.rb b/lib/jekyll-github-metadata/metadata_drop.rb index 4a5bb17..b870689 100644 --- a/lib/jekyll-github-metadata/metadata_drop.rb +++ b/lib/jekyll-github-metadata/metadata_drop.rb @@ -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 diff --git a/lib/jekyll-github-metadata/repository.rb b/lib/jekyll-github-metadata/repository.rb index b4315b8..243c980 100644 --- a/lib/jekyll-github-metadata/repository.rb +++ b/lib/jekyll-github-metadata/repository.rb @@ -62,6 +62,10 @@ def repo_pages_info_opts end end + def owner_metadata + memoize_value :@owner_metadata, Value.new(proc { |c| c.organization(owner) || c.user(owner) }) + end + def owner_url "#{Pages.github_url}/#{owner}" end diff --git a/spec/spec_helpers/integration_helper.rb b/spec/spec_helpers/integration_helper.rb index 1778cd3..2e893eb 100644 --- a/spec/spec_helpers/integration_helper.rb +++ b/spec/spec_helpers/integration_helper.rb @@ -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", From b293337fc7b72f8144dba6ab623ac328b9862782 Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Mon, 7 Jan 2019 16:40:59 -0800 Subject: [PATCH 2/2] Restrict User/Org object to only include whitelisted fields --- lib/jekyll-github-metadata/repository.rb | 56 +++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/lib/jekyll-github-metadata/repository.rb b/lib/jekyll-github-metadata/repository.rb index 243c980..d56595f 100644 --- a/lib/jekyll-github-metadata/repository.rb +++ b/lib/jekyll-github-metadata/repository.rb @@ -62,8 +62,62 @@ 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| c.organization(owner) || c.user(owner) }) + 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