gitscape 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,8 +8,12 @@ rescue LoadError
8
8
  end
9
9
 
10
10
  if ARGV.size < 2
11
- puts "Usage: gitscape upstream head"
11
+ puts "Examples: "
12
+ puts "\tgitscape diff master staging"
13
+ puts "\tgitscape deploy_iteration i22"
12
14
  exit(1)
13
- else
14
- GitScape.branch_diff(ARGV[0], ARGV[1])
15
+ elsif ARGV[0] == "diff"
16
+ GitScape.compare(ARGV[1], ARGV[2])
17
+ elsif ARGV[0] == "deploy_iteration"
18
+ GitScape.deploy_iteration(ARGV[1])
15
19
  end
@@ -1,5 +1,20 @@
1
1
  class GitScape
2
- def self.branch_diff(upstream, head)
2
+ # Returns true if the supplied Git commit hash or reference exists
3
+ def self.commit_exists?(commit_id)
4
+ `git rev-parse #{commit_id}`
5
+ if $? == 0
6
+ true
7
+ else
8
+ raise "Invalid commit/ref ID: #{commit_id}"
9
+ end
10
+ end
11
+
12
+
13
+ def self.abort!
14
+
15
+ end
16
+
17
+ def self.compare(upstream, head)
3
18
  puts "#" * 80
4
19
  puts "# Commits on #{head} not on #{upstream}"
5
20
  puts "#" * 80
@@ -11,5 +26,88 @@ class GitScape
11
26
  puts
12
27
  end
13
28
  end
29
+
30
+ def self.run_script(script, quiet=true)
31
+ IO.popen(script.split("\n").join(" && ")) do |io|
32
+ while (line = io.gets) do
33
+ unless quiet
34
+ puts line
35
+ end
36
+ end
37
+ end
38
+ $?.exitstatus
39
+ end
40
+
41
+ def promote_commit(commit_id, upstream)
42
+ commit_exists? commit_id
43
+ run_script <<-EOH
44
+ git stash
45
+ git checkout master
46
+ git pull
47
+ git checkout staging
48
+ git reset --hard origin/staging
49
+ git cherry-pick #{commit_id}
50
+ git push origin staging
51
+ EOH
52
+ end
53
+
54
+ def promote_branch(head, upstream)
55
+ run_script <<-EOH
56
+ git fetch
57
+ git stash
58
+ git checkout #{head}
59
+ git reset --hard origin/#{head}
60
+ git push -f origin #{head}:#{upstream}
61
+ EOH
62
+ end
63
+
64
+
65
+ def self.result_ok?(result)
66
+ if result.nil? or result == 0
67
+ puts "done"
68
+ return true
69
+ else
70
+ puts "failed"
71
+ puts "Aborting"
72
+ run_script "git checkout master"
73
+ return false
74
+ end
75
+ end
76
+
77
+ def self.deploy_iteration(iteration, projects=%w{android-client builder ios-client rails3 web-client})
78
+
79
+ date = `date +%Y%m%d-%H%M`.strip
80
+ tag = "#{iteration}-#{date}"
81
+ puts "Starting deploy of #{iteration}"
82
+ puts "Will tag with '#{tag}'"
83
+ puts
84
+
85
+ projects.each do |proj|
86
+ print "Tagging #{proj}..."
87
+ result = run_script <<-EOH
88
+ cd /code/#{proj}/
89
+ git stash
90
+ git checkout qa
91
+ git fetch
92
+ git reset --hard origin/qa
93
+ git tag -a #{tag} -m 'Release to live'
94
+ EOH
95
+ return unless result_ok?(result)
96
+ end
97
+
98
+ projects.each do |proj|
99
+ print "Pushing #{proj}..."
100
+ result = run_script <<-EOH
101
+ cd /code/#{proj}/
102
+ git push -f origin qa:live
103
+ git push --tags
104
+ git checkout master
105
+ EOH
106
+ #return unless result_ok?(result)
107
+ end
108
+
109
+ puts
110
+ puts "Deploy of #{iteration} completed successfully."
111
+ end
14
112
  end
15
113
 
@@ -1,3 +1,3 @@
1
1
  module GitScape
2
- VERSION = "0.1"
2
+ VERSION = "0.2"
3
3
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitscape
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- version: "0.1"
8
+ - 2
9
+ version: "0.2"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jon Botelho
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-06-14 00:00:00 Z
17
+ date: 2012-07-12 00:00:00 Z
18
18
  dependencies: []
19
19
 
20
20
  description: Various Git utilities for cherry-pick/rebase workflows.