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

Use owner name as site title for User and Organization sites. #197

Merged
merged 2 commits into from
Aug 3, 2021
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/metadata_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def keys
def_delegator :repository, :tagline, :project_tagline
def_delegator :repository, :owner_metadata, :owner
def_delegator :repository, :owner, :owner_name
def_delegator :repository, :owner_display_name, :owner_display_name
def_delegator :repository, :owner_url, :owner_url
def_delegator :repository, :owner_gravatar_url, :owner_gravatar_url
def_delegator :repository, :repository_url, :repository_url
Expand Down
4 changes: 4 additions & 0 deletions lib/jekyll-github-metadata/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def repo_pages_info_opts
end
end

def owner_display_name
owner_metadata.name
mattr- marked this conversation as resolved.
Show resolved Hide resolved
end

def owner_metadata
@owner_metadata ||= Jekyll::GitHubMetadata::Owner.new(owner)
end
Expand Down
8 changes: 7 additions & 1 deletion lib/jekyll-github-metadata/site_github_munger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ def add_title_and_description_fallbacks!
msg << "Jekyll GitHub Metadata will not set site.title to the repository's name."
Jekyll::GitHubMetadata.log :warn, msg
else
site.config["title"] ||= Value.new("title", proc { |_c, r| r.name })
site.config["title"] ||= Value.new("title", proc { |_context, repository|
if repository.project_page?
repository.name
else
repository.owner_display_name || repository.owner
end
})
end
site.config["description"] ||= Value.new("description", proc { |_c, r| r.tagline })
end
Expand Down
58 changes: 58 additions & 0 deletions spec/site_github_munger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,64 @@
end
end

context "generating repo for user with displayname" do
before(:each) do
ENV["JEKYLL_ENV"] = "production"
ENV["PAGES_REPO_NWO"] = "jekyllbot/jekyllbot.github.io"
stub_api("/repos/jekyllbot/jekyllbot.github.io", "user_site")
stub_api_404("/orgs/jekyllbot")
stub_api("/users/jekyllbot", "user_with_displayname")
subject.munge!
end

it "sets title to user's displayname" do
expect(site.config["title"]).to eql("Jekyll Bot")
end
end

context "generating repo for user without displayname" do
before(:each) do
ENV["JEKYLL_ENV"] = "production"
ENV["PAGES_REPO_NWO"] = "jekyllbot/jekyllbot.github.io"
stub_api("/repos/jekyllbot/jekyllbot.github.io", "user_site")
stub_api_404("/orgs/jekyllbot")
stub_api("/users/jekyllbot", "user_without_displayname")
subject.munge!
end

it "sets title to user's login" do
expect(site.config["title"]).to eql("jekyllbot")
end
end

context "generating repo for org with displayname" do
before(:each) do
ENV["JEKYLL_ENV"] = "production"
ENV["PAGES_REPO_NWO"] = "jekyll/jekyll.github.io"
stub_api("/repos/jekyll/jekyll.github.io", "repo")
stub_api("/orgs/jekyll", "org",)
subject.munge!
end

it "sets title to org's displayname" do
expect(site.config["title"]).to eql("Jekyll")
end
end

context "generating repo for org without displayname" do
before(:each) do
ENV["JEKYLL_ENV"] = "production"
ENV["PAGES_REPO_NWO"] = "jekyll/jekyll.github.io"
stub_api("/repos/jekyll/jekyll.github.io", "repo")
stub_api("/orgs/jekyll", "org_without_displayname",)
subject.munge!
end

it "sets title to org's login" do
expect(site.config["title"]).to eql("jekyll")
end
end

context "with a client with no credentials" do
before(:each) do
Jekyll::GitHubMetadata.client = Jekyll::GitHubMetadata::Client.new(:access_token => "")
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 @@ -17,6 +17,7 @@ def expected_values
"project_tagline" => ":octocat: `site.github`",
"owner" => Regexp.new('"html_url"=>"https://github.com/jekyll",\s+"id"=>3083652'),
"owner_name" => "jekyll",
"owner_display_name" => "Jekyll",
"owner_url" => "https://github.com/jekyll",
"owner_gravatar_url" => "https://github.com/jekyll.png",
"repository_url" => "https://github.com/jekyll/github-metadata",
Expand Down
30 changes: 30 additions & 0 deletions spec/webmock/api_get_org_without_displayname.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"login": "jekyll",
"id": 3083652,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjMwODM2NTI=",
"url": "https://api.github.com/orgs/jekyll",
"repos_url": "https://api.github.com/orgs/jekyll/repos",
"events_url": "https://api.github.com/orgs/jekyll/events",
"hooks_url": "https://api.github.com/orgs/jekyll/hooks",
"issues_url": "https://api.github.com/orgs/jekyll/issues",
"members_url": "https://api.github.com/orgs/jekyll/members{/member}",
"public_members_url": "https://api.github.com/orgs/jekyll/public_members{/member}",
"avatar_url": "https://avatars0.githubusercontent.com/u/3083652?v=4",
"description": "Jekyll is a blog-aware, static site generator in Ruby.",
"name": null,
"company": null,
"blog": "https://jekyllrb.com",
"location": null,
"email": "",
"is_verified": true,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 50,
"public_gists": 0,
"followers": 0,
"following": 0,
"html_url": "https://github.com/jekyll",
"created_at": "2012-12-19T19:37:35Z",
"updated_at": "2019-01-27T15:27:32Z",
"type": "Organization"
}
103 changes: 103 additions & 0 deletions spec/webmock/api_get_user_site.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"id": 50212532,
"node_id": "MDEwOlJlcG9zaXRvcnk1MDIxMjUzMg==",
"name": "github-pages-site",
"full_name": "jekyllbot/github-pages-site",
"private": false,
"owner": {
"login": "jekyllbot",
"id": 6166343,
"node_id": "MDQ6VXNlcjYxNjYzNDM=",
"avatar_url": "https://avatars.githubusercontent.com/u/6166343?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jekyllbot",
"html_url": "https://github.com/jekyllbot",
"followers_url": "https://api.github.com/users/jekyllbot/followers",
"following_url": "https://api.github.com/users/jekyllbot/following{/other_user}",
"gists_url": "https://api.github.com/users/jekyllbot/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jekyllbot/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jekyllbot/subscriptions",
"organizations_url": "https://api.github.com/users/jekyllbot/orgs",
"repos_url": "https://api.github.com/users/jekyllbot/repos",
"events_url": "https://api.github.com/users/jekyllbot/events{/privacy}",
"received_events_url": "https://api.github.com/users/jekyllbot/received_events",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/jekyllbot/github-pages-site",
"description": "Example GitHub Pages Site",
"fork": false,
"url": "https://api.github.com/repos/jekyllbot/github-pages-site",
"forks_url": "https://api.github.com/repos/jekyllbot/github-pages-site/forks",
"keys_url": "https://api.github.com/repos/jekyllbot/github-pages-site/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/jekyllbot/github-pages-site/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/jekyllbot/github-pages-site/teams",
"hooks_url": "https://api.github.com/repos/jekyllbot/github-pages-site/hooks",
"issue_events_url": "https://api.github.com/repos/jekyllbot/github-pages-site/issues/events{/number}",
"events_url": "https://api.github.com/repos/jekyllbot/github-pages-site/events",
"assignees_url": "https://api.github.com/repos/jekyllbot/github-pages-site/assignees{/user}",
"branches_url": "https://api.github.com/repos/jekyllbot/github-pages-site/branches{/branch}",
"tags_url": "https://api.github.com/repos/jekyllbot/github-pages-site/tags",
"blobs_url": "https://api.github.com/repos/jekyllbot/github-pages-site/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/jekyllbot/github-pages-site/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/jekyllbot/github-pages-site/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/jekyllbot/github-pages-site/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/jekyllbot/github-pages-site/statuses/{sha}",
"languages_url": "https://api.github.com/repos/jekyllbot/github-pages-site/languages",
"stargazers_url": "https://api.github.com/repos/jekyllbot/github-pages-site/stargazers",
"contributors_url": "https://api.github.com/repos/jekyllbot/github-pages-site/contributors",
"subscribers_url": "https://api.github.com/repos/jekyllbot/github-pages-site/subscribers",
"subscription_url": "https://api.github.com/repos/jekyllbot/github-pages-site/subscription",
"commits_url": "https://api.github.com/repos/jekyllbot/github-pages-site/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/jekyllbot/github-pages-site/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/jekyllbot/github-pages-site/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/jekyllbot/github-pages-site/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/jekyllbot/github-pages-site/contents/{+path}",
"compare_url": "https://api.github.com/repos/jekyllbot/github-pages-site/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/jekyllbot/github-pages-site/merges",
"archive_url": "https://api.github.com/repos/jekyllbot/github-pages-site/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/jekyllbot/github-pages-site/downloads",
"issues_url": "https://api.github.com/repos/jekyllbot/github-pages-site/issues{/number}",
"pulls_url": "https://api.github.com/repos/jekyllbot/github-pages-site/pulls{/number}",
"milestones_url": "https://api.github.com/repos/jekyllbot/github-pages-site/milestones{/number}",
"notifications_url": "https://api.github.com/repos/jekyllbot/github-pages-site/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/jekyllbot/github-pages-site/labels{/name}",
"releases_url": "https://api.github.com/repos/jekyllbot/github-pages-site/releases{/id}",
"deployments_url": "https://api.github.com/repos/jekyllbot/github-pages-site/deployments",
"created_at": "2016-01-22T22:53:40Z",
"updated_at": "2017-07-13T20:03:10Z",
"pushed_at": "2016-11-20T00:18:58Z",
"git_url": "git://github.com/jekyllbot/github-pages-site.git",
"ssh_url": "[email protected]:jekyllbot/github-pages-site.git",
"clone_url": "https://github.com/jekyllbot/github-pages-site.git",
"svn_url": "https://github.com/jekyllbot/github-pages-site",
"homepage": "https://jekyllbot.github.io/github-pages-site/",
"size": 16,
"stargazers_count": 6,
"watchers_count": 6,
"language": "JavaScript",
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": false,
"has_pages": true,
"forks_count": 6,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": {
"key": "mit",
"name": "MIT License",
"spdx_id": "MIT",
"url": "https://api.github.com/licenses/mit",
"node_id": "MDc6TGljZW5zZTEz"
},
"forks": 6,
"open_issues": 0,
"watchers": 6,
"default_branch": "gh-pages",
"temp_clone_token": null,
"network_count": 6,
"subscribers_count": 1
}
33 changes: 33 additions & 0 deletions spec/webmock/api_get_user_with_displayname.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"login": "jekyllbot",
"id": 6166343,
"node_id": "MDQ6VXNlcjYxNjYzNDM=",
"avatar_url": "https://avatars0.githubusercontent.com/u/6166343?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jekyllbot",
"html_url": "https://github.com/jekyllbot",
"followers_url": "https://api.github.com/users/jekyllbot/followers",
"following_url": "https://api.github.com/users/jekyllbot/following{/other_user}",
"gists_url": "https://api.github.com/users/jekyllbot/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jekyllbot/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jekyllbot/subscriptions",
"organizations_url": "https://api.github.com/users/jekyllbot/orgs",
"repos_url": "https://api.github.com/users/jekyllbot/repos",
"events_url": "https://api.github.com/users/jekyllbot/events{/privacy}",
"received_events_url": "https://api.github.com/users/jekyllbot/received_events",
"type": "User",
"site_admin": false,
"name": "Jekyll Bot",
"company": null,
"blog": "https://github.com/parkr/auto-reply",
"location": null,
"email": null,
"hireable": null,
"bio": "I help make working with @jekyll fun and easy.",
"public_repos": 2,
"public_gists": 0,
"followers": 68,
"following": 0,
"created_at": "2013-12-12T02:49:00Z",
"updated_at": "2017-12-05T21:23:41Z"
}
33 changes: 33 additions & 0 deletions spec/webmock/api_get_user_without_displayname.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"login": "jekyllbot",
"id": 6166343,
"node_id": "MDQ6VXNlcjYxNjYzNDM=",
"avatar_url": "https://avatars0.githubusercontent.com/u/6166343?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jekyllbot",
"html_url": "https://github.com/jekyllbot",
"followers_url": "https://api.github.com/users/jekyllbot/followers",
"following_url": "https://api.github.com/users/jekyllbot/following{/other_user}",
"gists_url": "https://api.github.com/users/jekyllbot/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jekyllbot/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jekyllbot/subscriptions",
"organizations_url": "https://api.github.com/users/jekyllbot/orgs",
"repos_url": "https://api.github.com/users/jekyllbot/repos",
"events_url": "https://api.github.com/users/jekyllbot/events{/privacy}",
"received_events_url": "https://api.github.com/users/jekyllbot/received_events",
"type": "User",
"site_admin": false,
"name": null,
"company": null,
"blog": "https://github.com/parkr/auto-reply",
"location": null,
"email": null,
"hireable": null,
"bio": "I help make working with @jekyll fun and easy.",
"public_repos": 2,
"public_gists": 0,
"followers": 68,
"following": 0,
"created_at": "2013-12-12T02:49:00Z",
"updated_at": "2017-12-05T21:23:41Z"
}