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
- HASH_METHODS =
[
: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.
13
14
15
16
17
18
19
20
21
|
# File 'lib/github-pages-health-check/repository.rb', line 13
def initialize(name_with_owner, access_token: nil)
unless name_with_owner =~ 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.
5
6
7
|
# File 'lib/github-pages-health-check/repository.rb', line 5
def name
@name
end
|
#owner ⇒ Object
Returns the value of attribute owner.
5
6
7
|
# File 'lib/github-pages-health-check/repository.rb', line 5
def owner
@owner
end
|
Instance Method Details
#build_duration ⇒ Object
46
47
48
|
# File 'lib/github-pages-health-check/repository.rb', line 46
def build_duration
last_build.duration unless last_build.nil?
end
|
#build_error ⇒ Object
Also known as:
reason
41
42
43
|
# File 'lib/github-pages-health-check/repository.rb', line 41
def build_error
last_build.error["message"] unless built?
end
|
#built? ⇒ Boolean
37
38
39
|
# File 'lib/github-pages-health-check/repository.rb', line 37
def built?
last_build && last_build.status == "built"
end
|
#check! ⇒ Object
28
29
30
31
|
# File 'lib/github-pages-health-check/repository.rb', line 28
def check!
raise Errors::BuildError.new(repository: self), build_error unless built?
true
end
|
#domain ⇒ Object
54
55
56
57
|
# File 'lib/github-pages-health-check/repository.rb', line 54
def domain
return if cname.nil?
@domain ||= GitHubPages::HealthCheck::Domain.new(cname)
end
|
#last_build ⇒ Object
33
34
35
|
# File 'lib/github-pages-health-check/repository.rb', line 33
def last_build
@last_build ||= client.latest_pages_build(name_with_owner)
end
|
#last_built ⇒ Object
50
51
52
|
# File 'lib/github-pages-health-check/repository.rb', line 50
def last_built
last_build.updated_at unless last_build.nil?
end
|
#name_with_owner ⇒ Object
Also known as:
nwo
23
24
25
|
# File 'lib/github-pages-health-check/repository.rb', line 23
def name_with_owner
@name_with_owner ||= [owner,name].join("/")
end
|