Class: Janky::Branch
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Janky::Branch
- Defined in:
- lib/janky/branch.rb
Instance Method Summary collapse
-
#build_for(commit, user, room_id = nil, compare = nil) ⇒ Object
Create a build for the given commit.
-
#building? ⇒ Boolean
Is this branch building?.
-
#completed? ⇒ Boolean
Is this branch completed?.
-
#completed_builds ⇒ Object
Find all completed builds, sorted by completion date, most recent first.
-
#current_build ⇒ Object
The current build, e.g.
-
#green? ⇒ Boolean
Is this branch green?.
-
#head_build_for(room_id, user) ⇒ Object
Fetch the HEAD commit of this branch using the GitHub API and create a build and commit record.
-
#queued_builds ⇒ Object
See Build.queued.
-
#red? ⇒ Boolean
Is this branch red?.
-
#status ⇒ Object
Human readable status of this branch.
-
#to_hash ⇒ Object
Hash representation of this branch status.
Instance Method Details
#build_for(commit, user, room_id = nil, compare = nil) ⇒ Object
Create a build for the given commit.
commit - the Janky::Commit instance to build. user - The login of the GitHub user who pushed. compare - optional String GitHub Compare View URL. Defaults to the
commit last build, if any.
room_id - optional String room ID. Defaults to the room set on
the repository.
Returns the newly created Janky::Build.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/janky/branch.rb', line 64 def build_for(commit, user, room_id = nil, compare = nil) if compare.nil? && build = commit.last_build compare = build.compare end room_id = room_id.to_s if room_id.empty? || room_id == "0" room_id = repository.room_id end builds.create!( :compare => compare, :user => user, :commit => commit, :room_id => room_id ) end |
#building? ⇒ Boolean
Is this branch building?
Returns a Boolean.
27 28 29 30 31 |
# File 'lib/janky/branch.rb', line 27 def building? if current_build current_build.building? end end |
#completed? ⇒ Boolean
Is this branch completed?
Returns a Boolean.
36 37 38 39 40 |
# File 'lib/janky/branch.rb', line 36 def completed? if current_build current_build.completed? end end |
#completed_builds ⇒ Object
Find all completed builds, sorted by completion date, most recent first.
Returns an Array of Builds.
45 46 47 |
# File 'lib/janky/branch.rb', line 45 def completed_builds builds.completed end |
#current_build ⇒ Object
The current build, e.g. the most recent one.
Returns a Build.
104 105 106 |
# File 'lib/janky/branch.rb', line 104 def current_build builds.last end |
#green? ⇒ Boolean
Is this branch green?
Returns a Boolean.
9 10 11 12 13 |
# File 'lib/janky/branch.rb', line 9 def green? if current_build current_build.green? end end |
#head_build_for(room_id, user) ⇒ Object
Fetch the HEAD commit of this branch using the GitHub API and create a build and commit record.
room_id - See build_for documentation. This is passed as is to the
build_for method.
user - Ditto.
Returns the newly created Janky::Build.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/janky/branch.rb', line 90 def head_build_for(room_id, user) sha_to_build = GitHub.branch_head_sha(repository.nwo, name) return if !sha_to_build commit = repository.commit_for_sha(sha_to_build) current_sha = current_build ? current_build.sha1 : "#{sha_to_build}^" compare_url = repository.github_url("compare/#{current_sha}...#{commit.sha1}") build_for(commit, user, room_id, compare_url) end |
#queued_builds ⇒ Object
See Build.queued.
50 51 52 |
# File 'lib/janky/branch.rb', line 50 def queued_builds builds.queued end |
#red? ⇒ Boolean
Is this branch red?
Returns a Boolean.
18 19 20 21 22 |
# File 'lib/janky/branch.rb', line 18 def red? if current_build current_build.red? end end |
#status ⇒ Object
Human readable status of this branch
Returns a String.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/janky/branch.rb', line 111 def status if current_build && current_build.building? "building" elsif build = completed_builds.first if build.green? "green" elsif build.red? "red" end elsif completed_builds.empty? || builds.empty? "no build" else raise Error, "unexpected branch status: #{id.inspect}" end end |
#to_hash ⇒ Object
Hash representation of this branch status.
Returns a Hash with the name, status, sha1 and compare url.
130 131 132 133 134 135 136 137 |
# File 'lib/janky/branch.rb', line 130 def to_hash { :name => repository.name, :status => status, :sha1 => (current_build && current_build.sha1), :compare => (current_build && current_build.compare) } end |