lib/fourchette/fork.rb in fourchette-0.0.2 vs lib/fourchette/fork.rb in fourchette-0.0.3
- old
+ new
@@ -8,63 +8,27 @@
end
def update
create_unless_exists
- heroku_git_url = @heroku.git_url(fork_name)
+ options = {
+ source_blob: {
+ url: "https://github.com/#{ENV['FOURCHETTE_GITHUB_PROJECT']}/archive/#{branch_name}.tar.gz?token=#{ENV['FOURCHETTE_GITHUB_PERSONAL_TOKEN']}"
+ }
+ }
- FileUtils.rm_rf('tmp/')
+ build = @heroku.client.build.create(fork_name, options)
+ monitor_build(build)
+ end
- # Add key to current
- logger.info "Creating an SSH key"
- key_path = "~/.ssh/id_rsa-fourchette"
- public_key_path = "#{key_path}.pub"
- `ssh-keygen -t rsa -C "temporary@fourchetteapp" -N "" -f #{key_path} -q`
- public_key_content = `cat #{public_key_path}`
-
- # Create SSH config file, so that it uses the right SSH key
- ssh_config_path = "~/.ssh/config"
- if `cat #{ssh_config_path}`.length == 0
- # Set the SSH key used, and disable strict host key checking
- `echo "Host heroku.com\n IdentityFile #{key_path}\n StrictHostKeyChecking no" >> ~/.ssh/config`
+ def monitor_build build
+ 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
end
-
- # Add SSH key to the Heroku account
- logger.info "Adding the SSH key to your Heroku account"
- heroku_public_key = @heroku.client.key.create(public_key: public_key_content)
-
- # Clone & push
- logger.info "Cloning repository..."
- repo = Git.clone(github_git_url, 'tmp')
- repo.checkout(branch_name)
-
- # TODO - HACK ALERT - Next couple lines are really hacky, and used
- # instead of calling `git push heroku my_branch_name:master`
- begin
- repo.branch('master').delete
- rescue Git::GitExecuteError
- # There is no master branch? Hmmm
- end
-
- begin
- repo.branch('master').merge(branch_name)
- rescue Git::GitExecuteError
- # TODO - HACK ALERT! There is certainly a cleaner way to do this...
- end
- repo.add_remote('heroku', heroku_git_url)
-
- logger.info "Pushing to Heroku..."
- repo.push(repo.remote('heroku'))
- logger.info "Done pushing to Heroku, apparently!"
-
- # REMOVE key to the Heroku account
- logger.info "Removing SSH key from your Heroku account"
- @heroku.client.key.delete(heroku_public_key['id'])
-
- # Remove ssh key
- logger.info "Removing SSH key for file system"
- FileUtils.rm_rf("~./ssh/id_rsa-fourchette*")
+ 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
@@ -80,15 +44,11 @@
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
- "remotes/origin/#{@params['pull_request']['head']['ref']}"
+ @params['pull_request']['head']['ref']
end
def pr_number
@params['pull_request']['number']
end