Class: Deliv::Deploy::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/deliv/deploy/git.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ Git

Returns a new instance of Git.



6
7
8
9
10
11
12
13
# File 'lib/deliv/deploy/git.rb', line 6

def initialize(environment)
  @environment = environment
  @source_remote = 'origin'
  @source_branch = current_branch
  @release_remote = 'upstream'
  @release_branch = "release-#{@environment}"
  @release_tag = "#{@release_branch}-#{Time.current.to_i}"
end

Instance Attribute Details

#release_branchObject

Returns the value of attribute release_branch.



4
5
6
# File 'lib/deliv/deploy/git.rb', line 4

def release_branch
  @release_branch
end

#release_remoteObject

Returns the value of attribute release_remote.



4
5
6
# File 'lib/deliv/deploy/git.rb', line 4

def release_remote
  @release_remote
end

#release_tagObject

Returns the value of attribute release_tag.



4
5
6
# File 'lib/deliv/deploy/git.rb', line 4

def release_tag
  @release_tag
end

#source_branchObject

Returns the value of attribute source_branch.



4
5
6
# File 'lib/deliv/deploy/git.rb', line 4

def source_branch
  @source_branch
end

#source_remoteObject

Returns the value of attribute source_remote.



4
5
6
# File 'lib/deliv/deploy/git.rb', line 4

def source_remote
  @source_remote
end

Instance Method Details

#current_branchObject



28
29
30
# File 'lib/deliv/deploy/git.rb', line 28

def current_branch
  `git rev-parse --abbrev-ref HEAD`&.squish
end

#deployObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/deliv/deploy/git.rb', line 15

def deploy
  print_debug
  old_branch = current_branch

  `git commit --all --message='Saving before #{release_tag}'`
  `git push #{source_remote} #{source_branch}`
  `git fetch #{source_remote} #{source_branch}`
  `git checkout --quiet #{source_remote}/#{source_branch}`
  `git tag --message='#{user_name} pointed #{release_branch} at #{current_branch}' #{release_tag}`
  `git push --force --follow-tags #{release_remote} HEAD:#{release_branch}`
  `git checkout #{old_branch}`
end


36
37
38
39
40
41
42
43
# File 'lib/deliv/deploy/git.rb', line 36

def print_debug
  puts "User Name: #{user_name}".blue
  puts "Current Branc: #{current_branch}".blue
  puts  "Source Remote: #{source_remote}".blue
  puts  "Source Branch: #{source_branch}".blue
  puts  "Release Remote: #{release_remote}".blue
  puts  "Release Branch: #{release_branch}".blue
end

#user_nameObject



32
33
34
# File 'lib/deliv/deploy/git.rb', line 32

def user_name
  `git config --get user.name`&.squish
end