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
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
# 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



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

def build_duration
  last_build && last_build.duration
end

#build_errorObject Also known as: reason



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

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

#built?Boolean

Returns:

  • (Boolean)


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

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

#check!Object

Raises:



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

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

#domainObject



55
56
57
58
# File 'lib/github-pages-health-check/repository.rb', line 55

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

#last_buildObject



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

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

#last_builtObject



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

def last_built
  last_build && last_build.updated_at
end

#name_with_ownerObject Also known as: nwo



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

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