gta 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gta.rb +2 -0
- data/lib/gta/db.rb +3 -4
- data/lib/gta/diff.rb +45 -0
- data/lib/gta/local_db.rb +14 -6
- data/lib/gta/manager.rb +15 -2
- data/lib/gta/tasks/diff.rb +16 -0
- data/lib/gta/tasks/heroku_db.rake +1 -1
- data/lib/gta/version.rb +1 -1
- data/spec/diff_spec.rb +68 -0
- data/spec/fixtures/config/database.json +22 -0
- data/spec/fixtures/config/gta.yml +4 -1
- data/spec/local_db_spec.rb +11 -0
- data/spec/manager_spec.rb +5 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a402ae4132a2d3ab9159de4812b34a26e5d0fbe
|
4
|
+
data.tar.gz: 85a81e0cdef130f23ba49c537fc584c86c6390e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb6112662bae1c01c45610fb22b7f9ebac9ee3604f274a99cce2b0290841d848cf1ee13a48b2bdecd5a20bb145208dca02cb8456c9c69bcbd0388c37a30be8bf
|
7
|
+
data.tar.gz: e8ca1779c9613c309009227ac9d7f03ea2762aaefa4c7786a3d39a586ceb2fff96f2e7976bbc1c0ec4c2fa1b6d5933d2b41fb32ccee0022878bfcf212f15d827
|
data/lib/gta.rb
CHANGED
data/lib/gta/db.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
module GTA
|
2
2
|
class DB
|
3
|
-
attr_reader :gta_config_path, :
|
3
|
+
attr_reader :gta_config_path, :local_env
|
4
4
|
|
5
|
-
def initialize(gta_config_path=nil,
|
5
|
+
def initialize(gta_config_path=nil, local_env=nil)
|
6
6
|
@gta_config_path = gta_config_path
|
7
|
-
@database_config_path = database_config_path
|
8
7
|
@local_env = local_env || 'development'
|
9
8
|
end
|
10
9
|
|
@@ -13,7 +12,7 @@ module GTA
|
|
13
12
|
end
|
14
13
|
|
15
14
|
def local_db
|
16
|
-
@local_db ||= LocalDB.new(local_env, database_config_path)
|
15
|
+
@local_db ||= LocalDB.new(local_env, manager.database_config_path)
|
17
16
|
end
|
18
17
|
|
19
18
|
def fetch(stage_name=nil)
|
data/lib/gta/diff.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module GTA
|
2
|
+
class Diff
|
3
|
+
include Sh
|
4
|
+
|
5
|
+
attr_reader :source_name, :destination_name, :gta_config_path
|
6
|
+
|
7
|
+
DEFAULT_FORMAT = 'short'
|
8
|
+
|
9
|
+
def initialize(source_name, destination_name, gta_config_path=nil)
|
10
|
+
@source_name = source_name
|
11
|
+
@destination_name = destination_name
|
12
|
+
@gta_config_path = gta_config_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def manager
|
16
|
+
@manager ||= Manager.new(gta_config_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def source
|
20
|
+
@source ||= manager.stage!(source_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def destination
|
24
|
+
@destination ||= manager.stage!(destination_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def report(format=DEFAULT_FORMAT)
|
28
|
+
source.fetch!
|
29
|
+
destination.fetch!
|
30
|
+
sh("git log #{source.name}/master..#{destination.name}/master --format=#{format}")
|
31
|
+
end
|
32
|
+
|
33
|
+
def shas
|
34
|
+
report('%h')
|
35
|
+
end
|
36
|
+
|
37
|
+
def cherry_pick
|
38
|
+
commits = shas.split("\n")
|
39
|
+
sh("git checkout #{destination.name}")
|
40
|
+
commits.each do |sha|
|
41
|
+
sh("git cherry-pick #{sha}")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/gta/local_db.rb
CHANGED
@@ -14,11 +14,23 @@ module GTA
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def config
|
17
|
-
@config ||=
|
17
|
+
@config ||= parsed_config[env]
|
18
|
+
end
|
19
|
+
|
20
|
+
def file_contents
|
21
|
+
File.read(database_config_path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def parsed_config
|
25
|
+
database_config_path.match(/yml$/) ? YAML.load(file_contents) : JSON.parse(file_contents)
|
26
|
+
end
|
27
|
+
|
28
|
+
def _username
|
29
|
+
config['username'] || config['user']
|
18
30
|
end
|
19
31
|
|
20
32
|
def username
|
21
|
-
|
33
|
+
_username ? " -U #{_username}" : ''
|
22
34
|
end
|
23
35
|
|
24
36
|
def database
|
@@ -29,10 +41,6 @@ module GTA
|
|
29
41
|
"#{Dir.pwd}/config/database.yml"
|
30
42
|
end
|
31
43
|
|
32
|
-
def self.env_config
|
33
|
-
ENV['GTA_DATABASE_CONFIG_PATH']
|
34
|
-
end
|
35
|
-
|
36
44
|
def self.local_database_env
|
37
45
|
ENV['RAILS_ENV'] || ENV['GTA_LOCAL_ENV']
|
38
46
|
end
|
data/lib/gta/manager.rb
CHANGED
@@ -20,6 +20,10 @@ module GTA
|
|
20
20
|
@app_name || config && @app_name
|
21
21
|
end
|
22
22
|
|
23
|
+
def database_config_path
|
24
|
+
@database_config_path || config && @database_config_path
|
25
|
+
end
|
26
|
+
|
23
27
|
def checkout(name)
|
24
28
|
stage!(name).checkout
|
25
29
|
end
|
@@ -41,8 +45,17 @@ module GTA
|
|
41
45
|
def config
|
42
46
|
return @config if @config
|
43
47
|
parsed = YAML.load(File.read(config_path))
|
44
|
-
@app_name = parsed
|
45
|
-
@
|
48
|
+
@app_name = parsed['name']
|
49
|
+
@database_config_path = find_database_config(parsed['database_config'])
|
50
|
+
@config = parsed['stages']
|
51
|
+
end
|
52
|
+
|
53
|
+
def find_database_config(path)
|
54
|
+
if path
|
55
|
+
File.dirname(config_path) + "/#{path}"
|
56
|
+
else
|
57
|
+
LocalDB.default_database_config_path
|
58
|
+
end
|
46
59
|
end
|
47
60
|
|
48
61
|
def stages
|
@@ -0,0 +1,16 @@
|
|
1
|
+
namespace :gta do
|
2
|
+
def gta_differ(args)
|
3
|
+
@differ ||= GTA::Diff.new(args[:source_stage], args[:destination_stage], GTA::Manager.env_config)
|
4
|
+
end
|
5
|
+
|
6
|
+
namespace :diff do
|
7
|
+
task :cherry_pick, :source_stage, :destination_stage do |t, args|
|
8
|
+
gta_differ(args).cherry_pick
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "report commit differences between stages"
|
13
|
+
task :report, :source_stage, :destination_stage do |t, args|
|
14
|
+
gta_differ(args).report
|
15
|
+
end
|
16
|
+
end
|
@@ -2,7 +2,7 @@ namespace :gta do
|
|
2
2
|
namespace :heroku do
|
3
3
|
namespace :db do
|
4
4
|
def gta_db
|
5
|
-
@gta_db ||= GTA::DB.new(GTA::Manager.env_config, GTA::LocalDB.
|
5
|
+
@gta_db ||= GTA::DB.new(GTA::Manager.env_config, GTA::LocalDB.local_database_env)
|
6
6
|
end
|
7
7
|
|
8
8
|
desc 'download the database from the specified stage or from the last stage'
|
data/lib/gta/version.rb
CHANGED
data/spec/diff_spec.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GTA::Diff do
|
4
|
+
let(:gta_config_path) { File.dirname(__FILE__) + "/fixtures/config/gta.yml" }
|
5
|
+
let(:diff) { GTA::Diff.new('staging', 'production', gta_config_path) }
|
6
|
+
|
7
|
+
before do
|
8
|
+
diff.stub(:sh)
|
9
|
+
diff.source.stub(:fetch!)
|
10
|
+
diff.destination.stub(:fetch!)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'stages' do
|
14
|
+
it "gets a source from the manager" do
|
15
|
+
diff.source.name.should == 'staging'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "gets a destination from the manager" do
|
19
|
+
diff.destination.name.should == 'production'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#report' do
|
24
|
+
it "should fetch the stages" do
|
25
|
+
diff.source.should_receive(:fetch!)
|
26
|
+
diff.destination.should_receive(:fetch!)
|
27
|
+
|
28
|
+
diff.report
|
29
|
+
end
|
30
|
+
|
31
|
+
it "sends the right command" do
|
32
|
+
diff.should_receive(:sh)
|
33
|
+
.with("git log staging/master..production/master --format=short")
|
34
|
+
diff.report
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#cherry_pick' do
|
39
|
+
let(:cherry_pick_commands) { [] }
|
40
|
+
let(:checkout_commands) { [] }
|
41
|
+
|
42
|
+
before do
|
43
|
+
diff.stub(:sh) do |command|
|
44
|
+
if command.match(/git log/)
|
45
|
+
"12345\n23456\n34567\n"
|
46
|
+
elsif command.match(/git checkout/)
|
47
|
+
checkout_commands << command
|
48
|
+
else
|
49
|
+
cherry_pick_commands << command
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "checks out the destination" do
|
55
|
+
diff.cherry_pick
|
56
|
+
checkout_commands.first.should == "git checkout production"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "sends a cherry pick command for each sha" do
|
60
|
+
diff.cherry_pick
|
61
|
+
cherry_pick_commands.should == [
|
62
|
+
"git cherry-pick 12345",
|
63
|
+
"git cherry-pick 23456",
|
64
|
+
"git cherry-pick 34567",
|
65
|
+
]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"development": {
|
3
|
+
"driver": "pg",
|
4
|
+
"host": "localhost",
|
5
|
+
"user": "socialchorus",
|
6
|
+
"database": "linktivator_development"
|
7
|
+
},
|
8
|
+
|
9
|
+
"test": {
|
10
|
+
"driver": "pg",
|
11
|
+
"host": "localhost",
|
12
|
+
"user": "socialchorus",
|
13
|
+
"database": "linktivator_test"
|
14
|
+
},
|
15
|
+
|
16
|
+
"nimbus": {
|
17
|
+
"driver": "pg",
|
18
|
+
"host": "localhost",
|
19
|
+
"user": "socialchorus",
|
20
|
+
"database": "linktivator_test"
|
21
|
+
}
|
22
|
+
}
|
data/spec/local_db_spec.rb
CHANGED
@@ -13,4 +13,15 @@ describe GTA::LocalDB do
|
|
13
13
|
local_db.load("~/Downloads/activator-staging.sql")
|
14
14
|
end
|
15
15
|
end
|
16
|
+
|
17
|
+
context 'when the database config is not yml' do
|
18
|
+
let(:database_config_path) { File.dirname(__FILE__) + "/fixtures/config/database.json" }
|
19
|
+
|
20
|
+
it "loads the config via json" do
|
21
|
+
local_db.should_receive(:sh).with(
|
22
|
+
"pg_restore --verbose --clean --no-acl --no-owner -h localhost -U socialchorus -d linktivator_development ~/Downloads/activator-staging.sql"
|
23
|
+
)
|
24
|
+
local_db.load("~/Downloads/activator-staging.sql")
|
25
|
+
end
|
26
|
+
end
|
16
27
|
end
|
data/spec/manager_spec.rb
CHANGED
@@ -13,6 +13,11 @@ describe GTA::Manager do
|
|
13
13
|
manager.app_name.should == 'activator'
|
14
14
|
end
|
15
15
|
|
16
|
+
it "has a reference to the database config file" do
|
17
|
+
File.expand_path(manager.database_config_path).should ==
|
18
|
+
File.expand_path(File.dirname(__FILE__) + "/fixtures/config/database.yml")
|
19
|
+
end
|
20
|
+
|
16
21
|
describe '#fetch' do
|
17
22
|
it "loops through each stage and calls fetch" do
|
18
23
|
manager.stages.each do |stage|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- socialchorus
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-08-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ansi
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/gta.rb
|
87
87
|
- lib/gta/commander.rb
|
88
88
|
- lib/gta/db.rb
|
89
|
+
- lib/gta/diff.rb
|
89
90
|
- lib/gta/file_logger.rb
|
90
91
|
- lib/gta/heroku_db.rb
|
91
92
|
- lib/gta/hotfix.rb
|
@@ -98,6 +99,7 @@ files:
|
|
98
99
|
- lib/gta/tasks.rb
|
99
100
|
- lib/gta/tasks/commander.rb
|
100
101
|
- lib/gta/tasks/deploy.rake
|
102
|
+
- lib/gta/tasks/diff.rb
|
101
103
|
- lib/gta/tasks/gta.rake
|
102
104
|
- lib/gta/tasks/heroku.rake
|
103
105
|
- lib/gta/tasks/heroku_db.rake
|
@@ -105,6 +107,8 @@ files:
|
|
105
107
|
- lib/gta/version.rb
|
106
108
|
- spec/commander_spec.rb
|
107
109
|
- spec/db_spec.rb
|
110
|
+
- spec/diff_spec.rb
|
111
|
+
- spec/fixtures/config/database.json
|
108
112
|
- spec/fixtures/config/database.yml
|
109
113
|
- spec/fixtures/config/gta.yml
|
110
114
|
- spec/heroku_db_spec.rb
|
@@ -143,6 +147,8 @@ summary: 'GTA: the Git Transit Authority - A git based deploy tool for moving co
|
|
143
147
|
test_files:
|
144
148
|
- spec/commander_spec.rb
|
145
149
|
- spec/db_spec.rb
|
150
|
+
- spec/diff_spec.rb
|
151
|
+
- spec/fixtures/config/database.json
|
146
152
|
- spec/fixtures/config/database.yml
|
147
153
|
- spec/fixtures/config/gta.yml
|
148
154
|
- spec/heroku_db_spec.rb
|