Skip to content

Commit 18f8fb9

Browse files
committed
Merge pull request #37 from jekyll/smarter-url-scheme
Properly calculate the url scheme
2 parents b196362 + 1f32300 commit 18f8fb9

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

lib/jekyll-github-metadata/pages.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class << self
1212
'SUBDOMAIN_ISOLATION' => 'false'.freeze
1313
}.freeze
1414

15+
# Whether the GitHub instance supports HTTPS
16+
# Note: this will be the same as how sites are served in Enterprise,
17+
# but may be different from how sites are served on GitHub.com.
18+
# See Repository#url_scheme
1519
def ssl?
1620
env_var('SSL') == 'true' || test?
1721
end

lib/jekyll-github-metadata/repository.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,17 @@ def primary?
106106
end
107107
end
108108

109+
# In enterprise, the site's scheme will be the same as the instance's
110+
# In dotcom, this will be `https` for GitHub-owned sites that end with
111+
# `.github.com` and will be `http` for all other sites.
112+
# Note: This is not the same as *instance*'s scheme, which may differ
109113
def url_scheme
110-
if domain.end_with?(".github.com".freeze)
111-
"https".freeze
112-
elsif cname
113-
"http"
114-
else
114+
if Pages.enterprise?
115115
Pages.scheme
116+
elsif owner == 'github' && domain.end_with?('.github.com')
117+
'https'
118+
else
119+
'http'
116120
end
117121
end
118122

spec/repository_spec.rb

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,34 @@
4646
end
4747

4848
it "returns Pages.scheme for the scheme" do
49-
expect(repo.url_scheme).to eql(Jekyll::GitHubMetadata::Pages.scheme)
49+
expect(repo.url_scheme).to eql("http")
5050
end
5151

5252
it "uses Pages.scheme to determine scheme for domain" do
53-
expect(repo.pages_url).to eql("#{Jekyll::GitHubMetadata::Pages.scheme}://parkr.github.io")
53+
expect(repo.pages_url).to eql("http://parkr.github.io")
54+
end
55+
56+
context "on enterprise" do
57+
it "uses Pages.scheme to determine scheme for pages URL" do
58+
# With SSL=true
59+
with_env({
60+
"PAGES_ENV" => "enterprise",
61+
"SSL" => "true"
62+
}) do
63+
expect(Jekyll::GitHubMetadata::Pages.ssl?).to be(true)
64+
expect(Jekyll::GitHubMetadata::Pages.scheme).to eql("https")
65+
expect(repo.url_scheme).to eql("https")
66+
end
67+
68+
# With no SSL
69+
with_env({
70+
"PAGES_ENV" => "enterprise"
71+
}) do
72+
expect(Jekyll::GitHubMetadata::Pages.ssl?).to be(false)
73+
expect(Jekyll::GitHubMetadata::Pages.scheme).to eql("http")
74+
expect(repo.url_scheme).to eql("http")
75+
end
76+
end
5477
end
5578
end
5679
end

0 commit comments

Comments
 (0)