gta 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a402ae4132a2d3ab9159de4812b34a26e5d0fbe
4
- data.tar.gz: 85a81e0cdef130f23ba49c537fc584c86c6390e9
3
+ metadata.gz: b7c83543f7db348de676f317ef0e8370cfd608ff
4
+ data.tar.gz: af6b5c0dcf5e84ebd32146d9f5fe2bddd9bc40c1
5
5
  SHA512:
6
- metadata.gz: fb6112662bae1c01c45610fb22b7f9ebac9ee3604f274a99cce2b0290841d848cf1ee13a48b2bdecd5a20bb145208dca02cb8456c9c69bcbd0388c37a30be8bf
7
- data.tar.gz: e8ca1779c9613c309009227ac9d7f03ea2762aaefa4c7786a3d39a586ceb2fff96f2e7976bbc1c0ec4c2fa1b6d5933d2b41fb32ccee0022878bfcf212f15d827
6
+ metadata.gz: aaad9aea700001ba735cafb6a02694a02dd40e7f01ef18190d9001bffe93fb9ae093e3bf7c59ba3044542179acae609fdbb639d4242e1ae6fa97acba275cf62e
7
+ data.tar.gz: 174d4ee8738fd9ed3abbd31a353a2fd5f03e09944acc47d40d52a45f517deeb4a9b35bc2eaa09c98cadf3a850ac00a8348fbaab973c1a912e552e971a1845bc3
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Code Climate](https://codeclimate.com/github/socialchorus/gta.png)](https://codeclimate.com/github/socialchorus/gta)
2
+
1
3
  # GTA - the Git Transit Authority
2
4
 
3
5
  GTA is a git-based deploy tool for moving code from stage to stage.
data/lib/gta/deploy.rb ADDED
@@ -0,0 +1,31 @@
1
+ module GTA
2
+ class Deploy
3
+ attr_reader :gta_config_path, :stage_name
4
+
5
+ def initialize(stage_name, gta_config_path=nil)
6
+ @stage_name = stage_name
7
+ @gta_config_path = gta_config_path
8
+ end
9
+
10
+ def manager
11
+ @manager ||= Manager.new(gta_config_path)
12
+ end
13
+
14
+ def destination
15
+ @destination ||= manager.stage!(stage_name)
16
+ end
17
+
18
+ def source
19
+ @source ||= destination.source
20
+ end
21
+
22
+ def deploy(forced=nil)
23
+ destination.fetch!
24
+ source.fetch!
25
+
26
+ source.checkout! # so the tracking branch exists
27
+
28
+ forced == :force ? destination.force_push : destination.push
29
+ end
30
+ end
31
+ end
data/lib/gta/stage.rb CHANGED
@@ -33,10 +33,12 @@ module GTA
33
33
  end
34
34
 
35
35
  def checkout
36
+ delete_existing_branch if existing_branch?
36
37
  sh(checkout_command)
37
38
  end
38
39
 
39
40
  def checkout!
41
+ delete_existing_branch if existing_branch?
40
42
  sh!(checkout_command)
41
43
  end
42
44
 
@@ -64,6 +66,15 @@ module GTA
64
66
  "git fetch #{name}"
65
67
  end
66
68
 
69
+ def delete_existing_branch
70
+ sh("git checkout master") # in case already on branch
71
+ sh("git branch -D #{name}")
72
+ end
73
+
74
+ def existing_branch?
75
+ sh('git branch').include?(name)
76
+ end
77
+
67
78
  def ==(other)
68
79
  other.is_a?(self.class) &&
69
80
  name == other.name &&
@@ -6,22 +6,19 @@ namespace :gta do
6
6
  desc 'task that will be run after a deploy'
7
7
  task :after, :stage_name
8
8
 
9
- def gta_manager(args={})
10
- return @manager if @manager
11
- raise GTA::Manager.stage_name_error unless stage_name = args[:stage_name]
12
- @manager = GTA::Manager.new(GTA::Manager.env_config)
9
+ def deployer(args)
10
+ stage_name = args[:stage_name]
11
+ GTA::Deploy.new(stage_name, GTA::Manager.env_config)
13
12
  end
14
13
 
15
14
  # the meat of a deploy, a git push from source to destination
16
15
  task :gta_push, :stage_name do |t, args|
17
- stage_name = args[:stage_name]
18
- gta_manager(args).push_to(stage_name)
16
+ deployer(args).deploy
19
17
  end
20
18
 
21
19
  # a forced version of the meat of the matter
22
20
  task :gta_force_push, :stage_name do |t, args|
23
- stage_name = args[:stage_name]
24
- gta_manager(args).push_to(stage_name, :force)
21
+ deployer(args).deploy(:force)
25
22
  end
26
23
 
27
24
  task :deploy, :stage_name do |t, args|
data/lib/gta/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module GTA
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
data/lib/gta.rb CHANGED
@@ -14,3 +14,4 @@ require "gta/tag_finder"
14
14
  require "gta/commander"
15
15
  require "gta/file_logger"
16
16
  require "gta/diff"
17
+ require "gta/deploy"
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe GTA::Deploy do
4
+ let(:config_path) { File.dirname(__FILE__) + "/fixtures/config/gta.yml" }
5
+ let(:deployer) { GTA::Deploy.new('qa', config_path) }
6
+ let(:destination) { deployer.destination }
7
+ let(:source) { deployer.source }
8
+
9
+ it "has the right source and destination" do
10
+ destination.name.should == 'qa'
11
+ source.name.should == 'staging'
12
+ end
13
+
14
+ describe '#deploy' do
15
+ before do
16
+ destination.stub(:fetch!)
17
+ destination.stub(:push)
18
+ destination.stub(:force_push)
19
+
20
+ source.stub(:checkout!)
21
+ source.stub(:fetch!)
22
+
23
+ deployer.stub(:sh)
24
+ end
25
+
26
+ it "fetches the destination" do
27
+ destination.should_receive(:fetch!)
28
+ deployer.deploy
29
+ end
30
+
31
+ it "fetches the source" do
32
+ source.should_receive(:fetch!)
33
+ deployer.deploy
34
+ end
35
+
36
+ it "checks out the source" do
37
+ source.should_receive(:checkout!)
38
+ deployer.deploy
39
+ end
40
+
41
+ context "non-forced push" do
42
+ it "pushes the destination" do
43
+ destination.should_receive(:push)
44
+ deployer.deploy
45
+ end
46
+ end
47
+
48
+ context "forced push" do
49
+ it "forces a push" do
50
+ destination.should_receive(:force_push)
51
+ deployer.deploy(:force)
52
+ end
53
+ end
54
+ end
55
+ end
data/spec/stage_spec.rb CHANGED
@@ -40,9 +40,50 @@ describe GTA::Stage do
40
40
  end
41
41
 
42
42
  describe '#checkout' do
43
- it "send the command to checkout a tracking branch from the remote" do
44
- stage.should_receive(:sh).with("git checkout -b staging -t staging/master")
45
- stage.checkout
43
+ let(:commands) { [] }
44
+
45
+ context "branch exists" do
46
+ before do
47
+ stage.stub(:sh) do |command|
48
+ commands << command
49
+
50
+ if command == "git branch"
51
+ " master\n* staging\n qa"
52
+ end
53
+ end
54
+ end
55
+
56
+ it "removes the existing branch" do
57
+ stage.checkout
58
+ commands.should include("git branch -D staging")
59
+ end
60
+
61
+ it "checks out a new tracking branch" do
62
+ stage.checkout
63
+ commands.should include("git checkout -b staging -t staging/master")
64
+ end
65
+ end
66
+
67
+ context "branch does not exist yet" do
68
+ before do
69
+ stage.stub(:sh) do |command|
70
+ commands << command
71
+
72
+ if command == "git branch"
73
+ "* master\n"
74
+ end
75
+ end
76
+ end
77
+
78
+ it "does not try to delete the branch" do
79
+ stage.checkout
80
+ commands.should_not include("git branch -D staging")
81
+ end
82
+
83
+ it "checks out a new tracking branch" do
84
+ stage.checkout
85
+ commands.should include("git checkout -b staging -t staging/master")
86
+ end
46
87
  end
47
88
  end
48
89
 
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.0
4
+ version: 0.4.1
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-08-01 00:00:00.000000000 Z
13
+ date: 2013-08-02 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/deploy.rb
89
90
  - lib/gta/diff.rb
90
91
  - lib/gta/file_logger.rb
91
92
  - lib/gta/heroku_db.rb
@@ -107,6 +108,7 @@ files:
107
108
  - lib/gta/version.rb
108
109
  - spec/commander_spec.rb
109
110
  - spec/db_spec.rb
111
+ - spec/deploy_spec.rb
110
112
  - spec/diff_spec.rb
111
113
  - spec/fixtures/config/database.json
112
114
  - spec/fixtures/config/database.yml
@@ -147,6 +149,7 @@ summary: 'GTA: the Git Transit Authority - A git based deploy tool for moving co
147
149
  test_files:
148
150
  - spec/commander_spec.rb
149
151
  - spec/db_spec.rb
152
+ - spec/deploy_spec.rb
150
153
  - spec/diff_spec.rb
151
154
  - spec/fixtures/config/database.json
152
155
  - spec/fixtures/config/database.yml