lib/fourchette/fork.rb in fourchette-0.0.1 vs lib/fourchette/fork.rb in fourchette-0.0.2

- old
+ new

@@ -2,10 +2,11 @@ include Fourchette::Logger def initialize params @params = params @heroku = Fourchette::Heroku.new + @github = Fourchette::GitHub.new end def update create_unless_exists @@ -63,46 +64,42 @@ logger.info "Removing SSH key for file system" FileUtils.rm_rf("~./ssh/id_rsa-fourchette*") end def create - github.comment_pr(pr_number, "Fourchette is initializing a new fork.") + @github.comment_pr(pr_number, "Fourchette is initializing a new fork.") if Fourchette::DEBUG create_unless_exists update end def delete @heroku.delete(fork_name) # Update PR with URL - github.comment_pr(pr_number, "Test app deleted!") + @github.comment_pr(pr_number, "Test app deleted!") end - - private - def github - @github ||= Fourchette::GitHub.new - end - - def create_unless_exists - unless @heroku.app_exists?(fork_name) - @heroku.fork(ENV['FOURCHETTE_HEROKU_APP_TO_FORK'] ,fork_name) - # Update PR with URL - github.comment_pr(pr_number, "Test URL: #{@heroku.client.app.info(fork_name)['web_url']}") - end - end - + def fork_name "#{ENV['FOURCHETTE_HEROKU_APP_PREFIX']}-PR-#{pr_number}".downcase # It needs to be lowercase only. end def github_git_url @params['pull_request']['head']['repo']['clone_url'].gsub("//github.com", "//#{ENV['FOURCHETTE_GITHUB_USERNAME']}:#{ENV['FOURCHETTE_GITHUB_PERSONAL_TOKEN']}@github.com") end def branch_name - @branch_name ||= "remotes/origin/#{@params['pull_request']['head']['ref']}" + "remotes/origin/#{@params['pull_request']['head']['ref']}" end def pr_number - @pr_number ||= @params['pull_request']['number'] + @params['pull_request']['number'] + end + + private + def create_unless_exists + unless @heroku.app_exists?(fork_name) + @heroku.fork(ENV['FOURCHETTE_HEROKU_APP_TO_FORK'] ,fork_name) + # Update PR with URL + @github.comment_pr(pr_number, "Test URL: #{@heroku.client.app.info(fork_name)['web_url']}") + end end end