lib/fourchette/fork.rb in fourchette-0.0.6 vs lib/fourchette/fork.rb in fourchette-0.0.7

- old
+ new

@@ -7,28 +7,32 @@ @github = Fourchette::GitHub.new end def update create_unless_exists - + tarball = Fourchette::Tarball.new + tarball_url = tarball.url(github_git_url, git_branch_name, ENV['FOURCHETTE_GITHUB_PROJECT']) options = { source_blob: { - url: "https://github.com/#{ENV['FOURCHETTE_GITHUB_PROJECT']}/archive/#{branch_name}.tar.gz?token=#{ENV['FOURCHETTE_GITHUB_PERSONAL_TOKEN']}" + url: tarball_url } } build = @heroku.client.build.create(fork_name, options) monitor_build(build) end def monitor_build build + logger.info "Start of the build process on Heroku..." build_info = @heroku.client.build.info(fork_name, build['id']) - while build_info['status'] == 'pending' - build_info = @heroku.client.build.info(fork_name, build['id']) - sleep 5 + # 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 Herok. See the activity tab on Heroku.") + fail Fourchette::DeployException end - fail Fourchette::DeployException if build_info['status'] == 'failed' end def create @github.comment_pr(pr_number, "Fourchette is initializing a new fork.") if Fourchette::DEBUG create_unless_exists @@ -59,7 +63,15 @@ 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 git_branch_name + "remotes/origin/#{branch_name}" + 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 end