Module: Deployinator::Helpers::GitHelpers

Defined in:
helpers/git.rb

Instance Method Summary collapse

Instance Method Details

#git_bump_version(stack, version_dir, extra_cmd = "sh -c") ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
# File 'helpers/git.rb', line 4

def git_bump_version(stack, version_dir, extra_cmd="sh -c")
  ts = Time.now.strftime("%Y%m%d-%H%M%S-%Z")
  # hack for now - need to talk to Matthew for a better way to do this
  #sha1 = %x{#{extra_cmd} cd #{checkout_root}/#{stack} && git fetch origin && git rev-parse --short refs/remotes/origin/master}
  sha1 = log_and_stream(%Q{#{extra_cmd} 'cd #{checkout_root}/#{stack} && git rev-parse --short HEAD'})
  sha1 = %x{#{extra_cmd} 'cd #{checkout_root}/#{stack} && git rev-parse --short HEAD'}
  version = "#{sha1.chomp}-#{ts}"

  log_and_stream "Setting #{version_dir}version.txt to #{version}"

  run_cmd %Q{#{extra_cmd} 'cd #{checkout_root}/#{stack} && echo #{version} > #{version_dir}version.txt'}
end

#git_clone(stack, repo_url, extra_cmd = "sh -c") ⇒ Object


26
27
28
# File 'helpers/git.rb', line 26

def git_clone(stack, repo_url, extra_cmd="sh -c")
  run_cmd %Q{#{extra_cmd} 'cd #{checkout_root} && git clone #{repo_url} #{stack}'}
end

#git_freshen_clone(stack, extra_cmd = "sh -c") {|"#{checkout_root}/#{stack}"| ... } ⇒ Object

Yields:

  • ("#{checkout_root}/#{stack}")

17
18
19
20
# File 'helpers/git.rb', line 17

def git_freshen_clone(stack, extra_cmd="sh -c")
  run_cmd %Q{#{extra_cmd} 'cd #{checkout_root}/#{stack} && git fetch && git reset --hard origin/master'}
  yield "#{checkout_root}/#{stack}" if block_given?
end

#git_url(stack, protocol = "git") ⇒ Object


30
31
32
33
34
35
36
37
38
# File 'helpers/git.rb', line 30

def git_url(stack, protocol="git")
  stack = stack.to_sym
  stack_git_meth = stack.to_s + "_git_repo_url"
  return self.send(stack_git_meth) if self.respond_to?(stack_git_meth)

  repo = github_info_for_stack[stack][:repository]
  repo += ".git" if protocol == "http"
  "#{protocol}://#{github_host}/#{github_info_for_stack[stack][:user]}/#{repo}"
end

#github_clone(stack, extra_cmd = "sh -c") ⇒ Object


22
23
24
# File 'helpers/git.rb', line 22

def github_clone(stack, extra_cmd="sh -c")
  git_clone(stack, git_url(stack), extra_cmd)
end

#github_hostObject


40
41
42
# File 'helpers/git.rb', line 40

def github_host
  Deployinator.github_host || "github.com"
end

#github_info_for_stackObject


48
49
50
51
52
53
54
55
56
57
58
# File 'helpers/git.rb', line 48

def github_info_for_stack
  {
    :photos     => {:user => "Engineering", :repository => "Photos"},
    :blog       => {:user => "Engineering", :repository => "Blog"},
    :b2         => {:user => "Engineering", :repository => "Blog"},
    :web        => {:user => "Engineering", :repository => "Web"},
    :config     => {:user => "Engineering", :repository => "Web"},
    :dashboards => {:user => "Engineering", :repository => "Dashboards"},
    :search     => {:user => "Engineering", :repository => "Search"}
  }
end

#github_urlObject


44
45
46
# File 'helpers/git.rb', line 44

def github_url
  "http://#{github_host}/"
end