Class: Fourchette::Fork
- Inherits:
-
Object
- Object
- Fourchette::Fork
- Includes:
- Logger
- Defined in:
- lib/fourchette/fork.rb
Instance Method Summary collapse
- #branch_name ⇒ Object
- #create ⇒ Object
- #create_unless_exists ⇒ Object
- #delete ⇒ Object
- #fork_name ⇒ Object
-
#initialize(params) ⇒ Fork
constructor
A new instance of Fork.
- #monitor_build(build) ⇒ Object
- #pr_number ⇒ Object
- #update ⇒ Object
Methods included from Logger
Constructor Details
#initialize(params) ⇒ Fork
Returns a new instance of Fork.
4 5 6 7 8 |
# File 'lib/fourchette/fork.rb', line 4 def initialize(params) @params = params @heroku = Fourchette::Heroku.new @github = Fourchette::GitHub.new end |
Instance Method Details
#branch_name ⇒ Object
48 49 50 |
# File 'lib/fourchette/fork.rb', line 48 def branch_name @params['pull_request']['head']['ref'] end |
#create ⇒ Object
31 32 33 34 35 36 |
# File 'lib/fourchette/fork.rb', line 31 def create @github.comment_pr( pr_number, 'Fourchette is initializing a new fork.') if Fourchette::DEBUG create_unless_exists update end |
#create_unless_exists ⇒ Object
56 57 58 59 60 61 |
# File 'lib/fourchette/fork.rb', line 56 def create_unless_exists unless app_exists? @heroku.fork(ENV['FOURCHETTE_HEROKU_APP_TO_FORK'], fork_name) post_fork_url end end |
#delete ⇒ Object
38 39 40 41 |
# File 'lib/fourchette/fork.rb', line 38 def delete @heroku.delete(fork_name) @github.comment_pr(pr_number, 'Test app deleted!') end |
#fork_name ⇒ Object
43 44 45 46 |
# File 'lib/fourchette/fork.rb', line 43 def fork_name # It needs to be lowercase only. "#{ENV['FOURCHETTE_HEROKU_APP_PREFIX']}-PR-#{pr_number}".downcase end |
#monitor_build(build) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fourchette/fork.rb', line 17 def monitor_build(build) logger.info 'Start of the build process on Heroku...' build_info = @heroku.client.build.info(fork_name, build['id']) # Let's just leave some time to Heroku to download the tarball and start # the process. This is some random timing that seems to make sense at first. sleep 30 if build_info['status'] == 'failed' @github.comment_pr( pr_number, 'The build failed on Heroku. See the activity tab on Heroku.' ) fail Fourchette::DeployException end end |
#pr_number ⇒ Object
52 53 54 |
# File 'lib/fourchette/fork.rb', line 52 def pr_number @params['pull_request']['number'] end |
#update ⇒ Object
10 11 12 13 14 15 |
# File 'lib/fourchette/fork.rb', line 10 def update create_unless_exists build = @heroku.client.build.create(fork_name, ) monitor_build(build) end |