Skip to content

Gracefully fallback for domains without CNAMEs #43

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

Merged
merged 1 commit into from
Feb 17, 2016
Merged
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
5 changes: 3 additions & 2 deletions lib/github-pages-health-check/repository.rb
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ class Repository < Checkable
attr_reader :name, :owner

REPO_REGEX = %r{\A[a-z0-9_\-]+/[a-z0-9_\-\.]+\z}i

HASH_METHODS = [
:name_with_owner, :built?, :last_built, :build_duration, :build_error
].freeze
@@ -39,7 +39,7 @@ def built?
end

def build_error
last_build.error.message unless built?
last_build.error["message"] unless built?
end
alias_method :reason, :build_error

@@ -52,6 +52,7 @@ def last_built
end

def domain
return if cname.nil?
@domain ||= GitHubPages::HealthCheck::Domain.new(cname)
end

5 changes: 2 additions & 3 deletions lib/github-pages-health-check/site.rb
Original file line number Diff line number Diff line change
@@ -13,13 +13,12 @@ def initialize(repository_or_domain, access_token: nil)
end

def check!
domain.check!
repository.check! unless repository.nil?
[domain, repository].each { |check| check.check! unless check.nil? }
true
end

def to_hash
hash = domain.to_hash.dup
hash = (domain || {}).to_hash.dup
hash = hash.merge(repository.to_hash) unless repository.nil?
hash[:valid?] = valid?
hash[:reason] = reason
6 changes: 6 additions & 0 deletions spec/fixtures/pages_info_no_cname.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"url": "https://api.github.com/repos/github/pages.github.com/pages",
"status": "built",
"cname": null,
"custom_404": false
}
15 changes: 14 additions & 1 deletion spec/github_pages_health_check_repository_spec.rb
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@

context "without an access token" do
before { subject.instance_variable_set("@access_token", nil) }

it "raises an error" do
expected = GitHubPages::HealthCheck::Errors::MissingAccessTokenError
expect { subject.send(:client) }.to raise_error(expected)
@@ -130,5 +130,18 @@
expect(subject.domain.class).to eql(GitHubPages::HealthCheck::Domain)
expect(subject.domain.host).to eql("pages.github.com")
end

context "without a CNAME" do
before do
subject.instance_variable_set("@access_token", "1234")
fixture = File.read(fixture_path("pages_info_no_cname.json"))
stub_request(:get, "https://api.github.com/repos/github/pages.github.com/pages").
to_return(:status => 200, :body => fixture, :headers => {'Content-Type'=>'application/json'})
end

it "doesn't try to build the domain" do
expect(subject.domain).to be_nil
end
end
end
end
24 changes: 24 additions & 0 deletions spec/github_pages_health_check_site_spec.rb
Original file line number Diff line number Diff line change
@@ -50,6 +50,30 @@
end
end

context "with no cname" do
before do
if init_type == "repo"
fixture = File.read(fixture_path("pages_info_no_cname.json"))
stub_request(:get, "https://api.github.com/repos/github/pages.github.com/pages").
to_return(:status => 200, :body => fixture, :headers => {'Content-Type'=>'application/json'})

fixture = File.read(fixture_path("build_success.json"))
stub_request(:get, "https://api.github.com/repos/github/pages.github.com/pages/builds/latest").
to_return(:status => 200, :body => fixture, :headers => {'Content-Type'=>'application/json'})
end
end

if init_type == "repo"
it "knows it doesn't know the domain" do
expect(subject.domain).to eql(nil)
end

it "doesnt err out when it checks" do
expect(subject.check!).to eql(true)
end
end
end

context "json" do
let(:json) { JSON.parse subject.to_json }