Class: Roger::Release::Finalizers::GitBranch

Inherits:
Base show all
Defined in:
lib/roger/release/finalizers/git_branch.rb

Overview

Finalizes the release into a specific branch of a repository and pushes it

Instance Attribute Summary

Attributes inherited from Processors::Base

#options, #release

Instance Method Summary collapse

Methods inherited from Processors::Base

#call, #name

Instance Method Details

#default_optionsObject

Parameters:

  • Hash

    options The options

  • options (Hash)

    a customizable set of options



16
17
18
19
20
21
22
23
# File 'lib/roger/release/finalizers/git_branch.rb', line 16

def default_options
  {
    remote: nil,
    branch: "gh-pages",
    cleanup: true,
    push: true
  }
end

#performObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/roger/release/finalizers/git_branch.rb', line 25

def perform
  remote = find_git_remote(release.project.path)
  branch = @options[:branch]

  tmp_dir = Pathname.new(::Dir.mktmpdir)
  clone_dir = tmp_dir + "clone"

  # Check if remote already has branch
  if remote_has_branch?(remote, branch)
    release.log(self, "Cloning existing repo")
    clone_branch(clone_dir, remote, branch)
  else
    release.log(self, "Creating empty branch")
    create_empty_branch(clone_dir, remote, branch)
  end

  @release.log(self, "Working git magic in #{clone_dir}")

  commit_and_push_release(clone_dir, branch)

  if @options[:cleanup]
    FileUtils.rm_rf(tmp_dir)
  else
    tmp_dir
  end
end