diff --git a/lib/jekyll-github-metadata/metadata_drop.rb b/lib/jekyll-github-metadata/metadata_drop.rb index e7be085..e1584c7 100644 --- a/lib/jekyll-github-metadata/metadata_drop.rb +++ b/lib/jekyll-github-metadata/metadata_drop.rb @@ -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 diff --git a/lib/jekyll-github-metadata/repository.rb b/lib/jekyll-github-metadata/repository.rb index 03cfeaf..fff4638 100644 --- a/lib/jekyll-github-metadata/repository.rb +++ b/lib/jekyll-github-metadata/repository.rb @@ -64,6 +64,10 @@ def repo_pages_info_opts end end + def owner_display_name + owner_metadata.name + end + def owner_metadata @owner_metadata ||= Jekyll::GitHubMetadata::Owner.new(owner) end diff --git a/lib/jekyll-github-metadata/site_github_munger.rb b/lib/jekyll-github-metadata/site_github_munger.rb index c24f55d..f6f07a0 100644 --- a/lib/jekyll-github-metadata/site_github_munger.rb +++ b/lib/jekyll-github-metadata/site_github_munger.rb @@ -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 diff --git a/spec/site_github_munger_spec.rb b/spec/site_github_munger_spec.rb index 084e68c..839542d 100644 --- a/spec/site_github_munger_spec.rb +++ b/spec/site_github_munger_spec.rb @@ -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 => "") diff --git a/spec/spec_helpers/integration_helper.rb b/spec/spec_helpers/integration_helper.rb index 10b0a11..7fd3159 100644 --- a/spec/spec_helpers/integration_helper.rb +++ b/spec/spec_helpers/integration_helper.rb @@ -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", diff --git a/spec/webmock/api_get_org_without_displayname.json b/spec/webmock/api_get_org_without_displayname.json new file mode 100644 index 0000000..f6879c5 --- /dev/null +++ b/spec/webmock/api_get_org_without_displayname.json @@ -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" +} diff --git a/spec/webmock/api_get_user_site.json b/spec/webmock/api_get_user_site.json new file mode 100644 index 0000000..889f409 --- /dev/null +++ b/spec/webmock/api_get_user_site.json @@ -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": "git@github.com: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 +} diff --git a/spec/webmock/api_get_user_with_displayname.json b/spec/webmock/api_get_user_with_displayname.json new file mode 100644 index 0000000..e813609 --- /dev/null +++ b/spec/webmock/api_get_user_with_displayname.json @@ -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" +} diff --git a/spec/webmock/api_get_user_without_displayname.json b/spec/webmock/api_get_user_without_displayname.json new file mode 100644 index 0000000..e7439de --- /dev/null +++ b/spec/webmock/api_get_user_without_displayname.json @@ -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" +}