class Pully::TestHelpers::Branch
Public Class Methods
new(user:, pass:, repo_selector:, clone_url:)
click to toggle source
repo_selector is like ‘my_user/repo’
# File lib/pully.rb, line 92 def initialize(user:, pass:, repo_selector:, clone_url:) @user = user @pass = pass @repo_selector = repo_selector @clone_url = clone_url #Setup the local git client ############################################################## Git.configure do |config| config.git_ssh = "./spec/assets/git_ssh" end ############################################################## clone_repo #Setup Octocat client ############################################################## @gh_client = Octokit::Client.new(:login => @user, :password => @pass) begin @gh_client.user #throw exception if auth is bad rescue Octokit::Unauthorized raise Error::BadLogin end begin @repo = @gh_client.repo(repo_selector) rescue ArgumentError raise Error::BadRepoSelector rescue Octokit::NotFound raise Error::NoSuchRepository end ############################################################## end
Public Instance Methods
clone_repo()
click to toggle source
Will clone down repo and set @gh_client to the new repo
# File lib/pully.rb, line 127 def clone_repo #Create a temp path temp_file = Tempfile.new('pully') @path = temp_file.path temp_file.close temp_file.unlink #Clone repo begin @git_client = Git.clone(@clone_url, 'pully', :path => @path) @git_client.config("user.name", "pully-test-account") @git_client.config("user.email", "pully-test-account@gmail.com") rescue Git::GitExecuteError => e raise Error::NoSuchCloneURL if e.message =~ /fatal: repository.*does not exist/ raise "Unknown git execute error: #{e}" end end
commit_new_random_file(branch_name)
click to toggle source
Create, commit, and push to github
# File lib/pully.rb, line 179 def commit_new_random_file(branch_name) #Create a new file Dir.chdir "#{@path}/pully" do File.write "#{branch_name}.#{SecureRandom.hex}", branch_name end #Commit @git_client.add(:all => true) @git_client.commit_all("New branch from Pully Test Suite #{SecureRandom.hex}") local_sha = @git_client.object("HEAD").sha @git_client.push("origin", branch_name) return local_sha end
create_branch(new_branch_name)
click to toggle source
# File lib/pully.rb, line 145 def create_branch(new_branch_name) #Checkout what ever real master is @git_client.branch(master_branch).checkout #Create a new branch @git_client.branch(new_branch_name) @git_client.branch(new_branch_name).checkout end
delete_branch(branch_name)
click to toggle source
# File lib/pully.rb, line 154 def delete_branch(branch_name) @git_client.push("origin", ":#{branch_name}") end
latest_message(branch_name)
click to toggle source
# File lib/pully.rb, line 169 def latest_message branch_name @git_client.checkout(branch_name) @git_client.object("HEAD").message end
latest_sha(branch_name)
click to toggle source
# File lib/pully.rb, line 164 def latest_sha branch_name @git_client.checkout(branch_name) @git_client.object("HEAD").sha end
list_branches()
click to toggle source
# File lib/pully.rb, line 158 def list_branches #Re-pull repo from github clone_repo @git_client.branches.remote.map{|e| e.name} end
master_branch()
click to toggle source
# File lib/pully.rb, line 174 def master_branch @repo.default_branch end