Class: Jumpup::Heroku::Integrate

Inherits:
Object
  • Object
show all
Defined in:
lib/jumpup/heroku/integrate.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Integrate

Returns a new instance of Integrate.



58
59
60
61
# File 'lib/jumpup/heroku/integrate.rb', line 58

def initialize(app)
  @app = app
  @envs = Env.all
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



6
7
8
# File 'lib/jumpup/heroku/integrate.rb', line 6

def app
  @app
end

Class Method Details

.add_remoteObject



24
25
26
27
28
29
# File 'lib/jumpup/heroku/integrate.rb', line 24

def self.add_remote
  message = "Adding Heroku git remotes for app #{integrate.app}"
  integrate.when_branch_send_to_heroku(message) do
    integrate.add_remote
  end
end

.checkObject



31
32
33
34
35
36
# File 'lib/jumpup/heroku/integrate.rb', line 31

def self.check
  message = "Checking if there's already someone integrating to #{integrate.app}"
  integrate.when_branch_send_to_heroku(message) do
    integrate.check
  end
end

.deployObject



8
9
10
11
12
13
# File 'lib/jumpup/heroku/integrate.rb', line 8

def self.deploy
  message = "Starting to deploy on Heroku app #{integrate.app}"
  integrate.when_branch_send_to_heroku(message) do
    integrate.deploy
  end
end

.deploy_to_productionObject



15
16
17
18
19
20
21
22
# File 'lib/jumpup/heroku/integrate.rb', line 15

def self.deploy_to_production
  app = Env.all[:production_app]
  integrate = new(app)
  message = "Starting to deploy to production on Heroku app #{integrate.app}"
  integrate.when_branch_send_to_heroku(message) do
    integrate.deploy_to_production
  end
end

.integrateObject



52
53
54
55
56
# File 'lib/jumpup/heroku/integrate.rb', line 52

def self.integrate
  envs = Env.all
  app = envs[:app] || envs[:staging_app]
  new(app)
end

.lockObject



38
39
40
41
42
43
# File 'lib/jumpup/heroku/integrate.rb', line 38

def self.lock
  message = "Locking Heroku integration on app #{integrate.app}"
  integrate.when_branch_send_to_heroku(message) do
    integrate.lock
  end
end

.unlockObject



45
46
47
48
49
50
# File 'lib/jumpup/heroku/integrate.rb', line 45

def self.unlock
  message = "Unlocking Heroku integration on app #{integrate.app}"
  integrate.when_branch_send_to_heroku(message) do
    integrate.unlock
  end
end

Instance Method Details

#add_remoteObject



108
109
110
111
# File 'lib/jumpup/heroku/integrate.rb', line 108

def add_remote
  remote = run_with_clean_env("git remote | grep heroku").strip
  exec_with_clean_env("git remote add heroku [email protected]:#{app}.git") if remote.blank?
end

#branches_that_send_to_herokuObject



72
73
74
# File 'lib/jumpup/heroku/integrate.rb', line 72

def branches_that_send_to_heroku
  [Env.all[:deploy_branch], Env.all[:deploy_to_production_branch]]
end

#checkObject



113
114
115
116
117
# File 'lib/jumpup/heroku/integrate.rb', line 113

def check
  return if can_start_integration?(user)
  puts "----> Project is already being integrated by '#{integrating_by}', halting"
  exit 1
end

#deployObject



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/jumpup/heroku/integrate.rb', line 76

def deploy
  if run_database_tasks?
    check_if_migration_is_needed
    check_if_seed_is_needed
  end

  backup
  push(Env.all[:deploy_branch])
  migrate
  seed
  restart
end

#deploy_to_productionObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/jumpup/heroku/integrate.rb', line 89

def deploy_to_production
  if run_database_tasks?
    check_if_migration_is_needed
    check_if_seed_is_needed
  end

  confirm_deploy
  spec
  confirm_maintenance
  maintenance
  backup
  tag
  push(Env.all[:deploy_to_production_branch])
  migrate
  seed
  close_maintenance
  restart
end

#lockObject



119
120
121
122
123
124
# File 'lib/jumpup/heroku/integrate.rb', line 119

def lock
  return if integrating_by?(user)

  puts "----> Locking Heroku integration for you (#{user})"
  exec_with_clean_env("heroku config:set INTEGRATING_BY='#{user}' --app #{app}")
end

#unlockObject



126
127
128
# File 'lib/jumpup/heroku/integrate.rb', line 126

def unlock
  exec_with_clean_env("heroku config:unset INTEGRATING_BY --app #{app}")
end

#when_branch_send_to_heroku(message, &block) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/jumpup/heroku/integrate.rb', line 63

def when_branch_send_to_heroku(message, &block)
  puts "--> #{message}"
  if branches_that_send_to_heroku.include?(actual_branch)
    block.call
  else
    puts "----> Skipping since you are in a feature branch [#{actual_branch}]"
  end
end