Class: GitHubPages::HealthCheck::Repository
- Inherits:
-
Checkable
- Object
- Checkable
- GitHubPages::HealthCheck::Repository
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
#name ⇒ Object
Returns the value of attribute name.
6
7
8
|
# File 'lib/github-pages-health-check/repository.rb', line 6
def name
@name
end
|
#owner ⇒ Object
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_duration ⇒ Object
49
50
51
|
# File 'lib/github-pages-health-check/repository.rb', line 49
def build_duration
last_build&.duration
end
|
#build_error ⇒ Object
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
40
41
42
|
# File 'lib/github-pages-health-check/repository.rb', line 40
def built?
last_build && last_build.status == "built"
end
|
#check! ⇒ Object
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
|
#last_build ⇒ Object
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_built ⇒ Object
53
54
55
|
# File 'lib/github-pages-health-check/repository.rb', line 53
def last_built
last_build&.updated_at
end
|
#name_with_owner ⇒ Object
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
|