Class: GitHubPages::HealthCheck::Repository

Inherits:
Checkable
  • Object
show all
Defined in:
lib/github-pages-health-check/repository.rb

Constant Summary collapse

REPO_REGEX =
%r{\A[a-z0-9_\-]+/[a-z0-9_\-\.]+\z}i.freeze
HASH_METHODS =
%i[
  name_with_owner built? last_built build_duration build_error
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Checkable

#to_hash, #to_json, #to_s, #to_s_pretty, #valid?

Constructor Details

#initialize(name_with_owner, access_token: nil) ⇒ Repository

Returns a new instance of Repository.



14
15
16
17
18
19
20
21
22
23
# File 'lib/github-pages-health-check/repository.rb', line 14

def initialize(name_with_owner, access_token: nil)
  unless name_with_owner.match(REPO_REGEX)
    raise Errors::InvalidRepositoryError
  end

  parts = name_with_owner.split("/")
  @owner = parts.first
  @name  = parts.last
  @access_token = access_token || ENV["OCTOKIT_ACCESS_TOKEN"]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/github-pages-health-check/repository.rb', line 6

def name
  @name
end

#ownerObject (readonly)

Returns the value of attribute owner.



6
7
8
# File 'lib/github-pages-health-check/repository.rb', line 6

def owner
  @owner
end

Instance Method Details

#build_durationObject



49
50
51
# File 'lib/github-pages-health-check/repository.rb', line 49

def build_duration
  last_build&.duration
end

#build_errorObject Also known as: reason



44
45
46
# File 'lib/github-pages-health-check/repository.rb', line 44

def build_error
  last_build.error["message"] unless built?
end

#built?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/github-pages-health-check/repository.rb', line 40

def built?
  last_build && last_build.status == "built"
end

#check!Object

Raises:



30
31
32
33
34
# File 'lib/github-pages-health-check/repository.rb', line 30

def check!
  raise Errors::BuildError.new(:repository => self), build_error unless built?

  true
end

#domainObject



57
58
59
60
61
# File 'lib/github-pages-health-check/repository.rb', line 57

def domain
  return if cname.nil?

  @domain ||= GitHubPages::HealthCheck::Domain.redundant(cname)
end

#last_buildObject



36
37
38
# File 'lib/github-pages-health-check/repository.rb', line 36

def last_build
  @last_build ||= client.latest_pages_build(name_with_owner)
end

#last_builtObject



53
54
55
# File 'lib/github-pages-health-check/repository.rb', line 53

def last_built
  last_build&.updated_at
end

#name_with_ownerObject Also known as: nwo



25
26
27
# File 'lib/github-pages-health-check/repository.rb', line 25

def name_with_owner
  @name_with_owner ||= [owner, name].join("/")
end