Class: Octofart::Tasks::CreateBranch

Inherits:
Object
  • Object
show all
Defined in:
lib/octofart/tasks/create_branch.rb

Instance Method Summary collapse

Instance Method Details

#run(params) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/octofart/tasks/create_branch.rb', line 5

def run(params)
  params[:repositories].each_pair do |repo_name, |
    head_branch_name ||= params[:pull_request][:branch_name]
    head_branch_name ||= Octofart.unique_head_branch_name
    [:head_branch][:name] ||= "heads/#{head_branch_name}"

    head_branch =
      begin
        Octofart.client.ref(repo_name, [:head_branch][:name])
      rescue
        puts "Ref not found, so we'll create one."
        Octofart.client.create_ref(repo_name, [:head_branch][:name], [:base_branch][:sha])
      end

    [:head_branch][:sha] = head_branch.object.sha
    [:head_branch][:ref] = head_branch.ref
  end

  params
end