-
Notifications
You must be signed in to change notification settings - Fork 124
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 html_url from Pages endpoint (behind preview env flag) #60
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0fd2626
Use html_url from Pages endpoint
parkr d8395a7
Add GitHubMetadata.logger, .log, and .logger= (also upgrade webmock)
parkr 4762e81
Move ApiStub to a shared location
parkr 8e2177f
Fix mixup with generated enterprise URL's
parkr 1a5d247
Add support for the preview API and test it
parkr 8c13783
Use Repository#html_url all around.
parkr File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ source 'https://rubygems.org' | |
gemspec | ||
|
||
group :test do | ||
gem "webmock" | ||
gem "webmock", "~> 2.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,26 @@ def initialize(name_with_owner) | |
@name = nwo.split("/").last | ||
end | ||
|
||
def git_ref | ||
user_page? ? 'master' : 'gh-pages' | ||
def repo_compat | ||
@repo_compat ||= Jekyll::GitHubMetadata::RepositoryCompat.new(self) | ||
end | ||
|
||
def repo_info | ||
@repo_info ||= (Value.new(proc { |c| c.repository(nwo) }).render || Hash.new) | ||
end | ||
|
||
def repo_pages_info | ||
@repo_pages_info ||= (Value.new(proc { |c| c.pages(nwo, repo_pages_info_opts) }).render || Hash.new) | ||
end | ||
|
||
def repo_pages_info_opts | ||
if Pages.repo_pages_html_url_preview? | ||
{ :accept => "application/vnd.github.mister-fantastic-preview+json" } | ||
else | ||
{} | ||
end | ||
end | ||
|
||
def language | ||
repo_info["language"] | ||
end | ||
|
@@ -86,6 +98,10 @@ def releases | |
memoize_value :@releases, Value.new(proc { |c| c.releases(nwo) }) | ||
end | ||
|
||
def git_ref | ||
user_page? ? 'master' : 'gh-pages' | ||
end | ||
|
||
def user_page? | ||
primary? | ||
end | ||
|
@@ -106,18 +122,10 @@ def primary? | |
end | ||
end | ||
|
||
# In enterprise, the site's scheme will be the same as the instance's | ||
# In dotcom, this will be `https` for GitHub-owned sites that end with | ||
# `.github.com` and will be `http` for all other sites. | ||
# Note: This is not the same as *instance*'s scheme, which may differ | ||
def url_scheme | ||
if Pages.enterprise? | ||
Pages.scheme | ||
elsif owner == 'github' && domain.end_with?('.github.com') | ||
'https' | ||
else | ||
'http' | ||
end | ||
def user_page_domains | ||
domains = [default_user_domain] | ||
domains.push "#{owner}.github.com".downcase unless Pages.enterprise? | ||
domains | ||
end | ||
|
||
def default_user_domain | ||
|
@@ -130,56 +138,25 @@ def default_user_domain | |
end | ||
end | ||
|
||
def user_page_domains | ||
domains = [default_user_domain] | ||
domains.push "#{owner}.github.com".downcase unless Pages.enterprise? | ||
domains | ||
def cname | ||
return nil unless Pages.custom_domains_enabled? | ||
repo_pages_info["cname"] | ||
end | ||
|
||
def user_domain | ||
domain = default_user_domain | ||
user_page_domains.each do |user_repo| | ||
candidate_nwo = "#{owner}/#{user_repo}" | ||
next unless Value.new(proc { |client| client.repository? candidate_nwo }).render | ||
domain = self.class.new(candidate_nwo).domain | ||
end | ||
domain | ||
end | ||
|
||
def pages_url | ||
if !Pages.custom_domains_enabled? | ||
path = user_page? ? owner : nwo | ||
if Pages.subdomain_isolation? | ||
URI.join("#{Pages.scheme}://#{Pages.pages_hostname}/", path).to_s | ||
else | ||
URI.join("#{Pages.github_url}/pages/", path).to_s | ||
end | ||
elsif cname || primary? | ||
"#{url_scheme}://#{domain}" | ||
else | ||
URI.join("#{url_scheme}://#{domain}", name).to_s | ||
end | ||
def html_url | ||
@html_url ||= (repo_pages_info["html_url"] || repo_compat.pages_url) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @benbalter as well as this. this is where it grabs the |
||
end | ||
|
||
def cname | ||
memoize_value :@cname, Value.new(proc { |c| | ||
if Pages.custom_domains_enabled? | ||
(c.pages(nwo) || {'cname' => nil})['cname'] | ||
end | ||
}) | ||
def uri | ||
@uri ||= URI(html_url) | ||
end | ||
|
||
def domain | ||
@domain ||= | ||
if !Pages.custom_domains_enabled? | ||
Pages.github_hostname | ||
elsif cname # explicit CNAME | ||
cname | ||
elsif primary? # user/org repo | ||
default_user_domain | ||
else # project repo | ||
user_domain | ||
end | ||
uri.host | ||
end | ||
|
||
def url_scheme | ||
uri.scheme | ||
end | ||
|
||
private | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module Jekyll | ||
module GitHubMetadata | ||
class RepositoryCompat | ||
attr_reader :repo | ||
|
||
def initialize(repo) | ||
@repo = repo | ||
end | ||
|
||
# In enterprise, the site's scheme will be the same as the instance's | ||
# In dotcom, this will be `https` for GitHub-owned sites that end with | ||
# `.github.com` and will be `http` for all other sites. | ||
# Note: This is not the same as *instance*'s scheme, which may differ | ||
def url_scheme | ||
if Pages.enterprise? | ||
Pages.scheme | ||
elsif repo.owner == 'github' && domain.end_with?('.github.com') | ||
'https' | ||
else | ||
'http' | ||
end | ||
end | ||
|
||
def user_domain | ||
domain = repo.default_user_domain | ||
repo.user_page_domains.each do |user_repo| | ||
candidate_nwo = "#{repo.owner}/#{user_repo}" | ||
next unless Jekyll::GitHubMetadata.client.repository?(candidate_nwo) | ||
domain = Jekyll::GitHubMetadata::Repository.new(candidate_nwo).repo_compat.domain | ||
end | ||
domain | ||
end | ||
|
||
def pages_url | ||
if !Pages.custom_domains_enabled? | ||
path = repo.user_page? ? repo.owner : repo.nwo | ||
if Pages.subdomain_isolation? | ||
URI.join("#{Pages.scheme}://#{Pages.pages_hostname}/", path).to_s | ||
else | ||
URI.join("#{Pages.github_url}/pages/", path).to_s | ||
end | ||
elsif repo.cname || repo.primary? | ||
"#{url_scheme}://#{domain}" | ||
else | ||
URI.join("#{url_scheme}://#{domain}", repo.name).to_s | ||
end | ||
end | ||
alias_method :html_url, :pages_url | ||
|
||
def domain | ||
@domain ||= | ||
if !Pages.custom_domains_enabled? | ||
Pages.github_hostname | ||
elsif repo.cname # explicit CNAME | ||
repo.cname | ||
elsif repo.primary? # user/org repo | ||
repo.default_user_domain | ||
else # project repo | ||
user_domain | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benbalter this is key.