optimis-workflow-scripts 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/finish-feature +2 -25
- data/bin/finish-hotfix +5 -0
- data/bin/start-feature +2 -32
- data/bin/start-hotfix +2 -9
- data/lib/optimis-workflow.rb +16 -0
- data/lib/optimis-workflow/commands/base.rb +24 -0
- data/lib/optimis-workflow/commands/finish_command.rb +48 -0
- data/lib/optimis-workflow/commands/finish_feature.rb +24 -0
- data/lib/optimis-workflow/commands/finish_hotfix.rb +50 -0
- data/lib/optimis-workflow/commands/start_command.rb +15 -0
- data/lib/optimis-workflow/commands/start_feature.rb +19 -0
- data/lib/optimis-workflow/commands/start_hotfix.rb +27 -0
- data/lib/optimis-workflow/common.rb +47 -0
- data/spec/finish_hotfix_spec.rb +31 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +2 -0
- metadata +19 -7
data/bin/finish-feature
CHANGED
@@ -1,28 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
# * Determine current local feature branch
|
5
|
-
# * Extract story id from branch name (should be feature-STORYID)
|
6
|
-
# * git checkout master
|
7
|
-
# * git merge --squash feature-branch
|
8
|
-
# * git commit 'Finish feature STORY TITLE [Story #STORYID]
|
9
|
-
# * git push origin master
|
3
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../lib/optimis-workflow'
|
10
4
|
|
11
|
-
|
12
|
-
|
13
|
-
current_branch = `git branch | grep '\*' | awk '{print $2}'`
|
14
|
-
story_id = current_branch.split("-").last.chomp!
|
15
|
-
modified_files = `git ls-files --modified && git ls-files --deleted && git ls-files --unmerged`
|
16
|
-
|
17
|
-
fail "Error! You must specify a commit message." unless ARGV[0]
|
18
|
-
fail "Whoops! You have uncommitted changes! Please commit or stash everything and then run again." unless modified_files.empty?
|
19
|
-
|
20
|
-
if ARGV[0] == "-h" || ARGV[0] == "--help" || ARGV[0] == "help"
|
21
|
-
puts "Syntax: finish-feature commit-msg"
|
22
|
-
else
|
23
|
-
commit_message = ARGV[0].chomp
|
24
|
-
system 'git checkout master'
|
25
|
-
system "git merge --squash #{current_branch}"
|
26
|
-
system "git commit -m '#{commit_message} [finishes ##{story_id}\]'"
|
27
|
-
system "git push origin master"
|
28
|
-
end
|
5
|
+
OptimisWorkflow::Commands::FinishFeature.new(ARGV.dup).execute!
|
data/bin/finish-hotfix
ADDED
data/bin/start-feature
CHANGED
@@ -1,35 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'uri'
|
5
|
-
require 'net/http'
|
6
|
-
|
7
|
-
fail "Please pass in a story id" if ARGV.empty?
|
8
|
-
|
9
|
-
if ARGV[0] == "-h" || ARGV[0] == "--help" || ARGV[0] == "help"
|
10
|
-
puts "Syntax: start-feature STORYID"
|
11
|
-
else
|
12
|
-
story_id = ARGV[0].chomp
|
13
|
-
current_dir = `pwd`.chomp
|
14
|
-
settings_file = current_dir + '/.tracker_settings.yml'
|
15
|
-
|
16
|
-
@tracker_settings = YAML.load_file(settings_file) if File.exists?(settings_file)
|
17
|
-
|
18
|
-
unless @tracker_settings.nil?
|
19
|
-
url = URI.parse("http://www.pivotaltracker.com/services/v3/projects/#{@tracker_settings['project_id']}/stories/#{story_id}")
|
20
|
-
|
21
|
-
net = Net::HTTP.new url.host, url.port
|
22
|
-
|
23
|
-
net.start do |http|
|
24
|
-
payload = '<story><current_state>started</current_state></story>'
|
25
|
-
req = Net::HTTP::Put.new(url.request_uri, {'Content-type' => 'application/xml', 'X-TrackerToken' => @tracker_settings['token']})
|
26
|
-
http.request(req, payload)
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
system "git checkout -b feature-#{story_id}"
|
32
|
-
end
|
33
|
-
|
34
|
-
|
3
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../lib/optimis-workflow'
|
35
4
|
|
5
|
+
OptimisWorkflow::Commands::StartFeature.new(ARGV.dup).execute!
|
data/bin/start-hotfix
CHANGED
@@ -1,12 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
if ARGV[0] == "-h" || ARGV[0] == "--help" || ARGV[0] == "help"
|
6
|
-
puts "Syntax: start-hotfix STORYID [stable]"
|
7
|
-
else
|
8
|
-
stable_branch = ARGV[1] || 'stable'
|
9
|
-
system "git checkout -b hotfix-#{ARGV[0]} #{stable_branch}"
|
10
|
-
end
|
11
|
-
|
3
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../lib/optimis-workflow'
|
12
4
|
|
5
|
+
OptimisWorkflow::Commands::StartHotfix.new(ARGV.dup).execute!
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
require File.expand_path(File.dirname(__FILE__)) + "/optimis-workflow/common"
|
6
|
+
|
7
|
+
require File.expand_path(File.dirname(__FILE__)) + "/optimis-workflow/commands/base"
|
8
|
+
require File.expand_path(File.dirname(__FILE__)) + "/optimis-workflow/commands/start_command"
|
9
|
+
require File.expand_path(File.dirname(__FILE__)) + "/optimis-workflow/commands/finish_command"
|
10
|
+
|
11
|
+
require File.expand_path(File.dirname(__FILE__)) + "/optimis-workflow/commands/start_feature"
|
12
|
+
require File.expand_path(File.dirname(__FILE__)) + "/optimis-workflow/commands/finish_feature"
|
13
|
+
|
14
|
+
require File.expand_path(File.dirname(__FILE__)) + "/optimis-workflow/commands/start_hotfix"
|
15
|
+
require File.expand_path(File.dirname(__FILE__)) + "/optimis-workflow/commands/finish_hotfix"
|
16
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
module OptimisWorkflow
|
3
|
+
module Commands
|
4
|
+
class Base
|
5
|
+
include OptimisWorkflow::Common
|
6
|
+
|
7
|
+
attr_reader :args
|
8
|
+
|
9
|
+
def initialize(args)
|
10
|
+
if args[0] == "-h" || args[0] == "--help" || args[0] == "help"
|
11
|
+
puts help_msg
|
12
|
+
exit 0
|
13
|
+
else
|
14
|
+
@args = args
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute!
|
19
|
+
local_stuff
|
20
|
+
remote_stuff
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
module OptimisWorkflow
|
3
|
+
module Commands
|
4
|
+
class FinishCommand < OptimisWorkflow::Commands::Base
|
5
|
+
attr_reader :feature_branch
|
6
|
+
def initialize(args)
|
7
|
+
super(args)
|
8
|
+
fail "\n\nError! You must specify a commit message.\n\n" if args[0].nil?
|
9
|
+
fail "\n\nWhoops! You have uncommitted changes! Please commit or stash everything and then run again.\n\n" unless self.class.modified_files.empty?
|
10
|
+
|
11
|
+
@feature_branch = `git branch | grep '\*' | awk '{print $2}'`
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.modified_files
|
15
|
+
@modified_files ||= `git ls-files --modified && git ls-files --deleted && git ls-files --unmerged`
|
16
|
+
end
|
17
|
+
|
18
|
+
def story_id
|
19
|
+
@story_id ||= feature_branch.split("-").last.chomp!
|
20
|
+
end
|
21
|
+
|
22
|
+
def commit_msg
|
23
|
+
@commit_msg ||= args[0].chomp
|
24
|
+
end
|
25
|
+
|
26
|
+
def update_parent_branch
|
27
|
+
system "git checkout #{parent_branch}"
|
28
|
+
system "git pull origin #{parent_branch}"
|
29
|
+
system "git checkout #{feature_branch}"
|
30
|
+
system "git rebase #{parent_branch}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def local_stuff
|
34
|
+
update_parent_branch
|
35
|
+
system "git checkout #{parent_branch}"
|
36
|
+
system "git merge --squash #{feature_branch}"
|
37
|
+
system "git commit -m '#{commit_msg} #{commit_msg_suffix}'"
|
38
|
+
system "git push origin #{parent_branch}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def remote_stuff
|
42
|
+
# currently nothing needs to be done here b/c we're inserting a hook
|
43
|
+
# into the commit msg that will get sent to pivotal via a github
|
44
|
+
# post-receive callback.
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
module OptimisWorkflow
|
3
|
+
module Commands
|
4
|
+
# * Determine current local feature branch
|
5
|
+
# * Extract story id from branch name (should be feature-STORYID)
|
6
|
+
# * git checkout master
|
7
|
+
# * git merge --squash feature-branch
|
8
|
+
# * git commit 'COMMITMSG [finishes #STORYID]
|
9
|
+
# * git push origin master
|
10
|
+
class FinishFeature < OptimisWorkflow::Commands::FinishCommand
|
11
|
+
def parent_branch
|
12
|
+
'master'
|
13
|
+
end
|
14
|
+
|
15
|
+
def commit_msg_suffix
|
16
|
+
"[finishes ##{story_id}]"
|
17
|
+
end
|
18
|
+
|
19
|
+
def help_msg
|
20
|
+
"Syntax: finish-feature commit-msg"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
module OptimisWorkflow
|
3
|
+
module Commands
|
4
|
+
|
5
|
+
# git checkout parent-branch
|
6
|
+
# git merge --squash hotfix-branch
|
7
|
+
# git commit COMMITMSG [fixes #STORYID]
|
8
|
+
# git push origin stable
|
9
|
+
# git checkout hotfix-branch
|
10
|
+
# git push -f origin feature-branch:staging
|
11
|
+
# git checkout master
|
12
|
+
# git merge stable
|
13
|
+
# merge squashed commits into stable and master
|
14
|
+
#
|
15
|
+
# mark as finished on pivotal
|
16
|
+
class FinishHotfix < OptimisWorkflow::Commands::FinishCommand
|
17
|
+
# need --no-deploy option
|
18
|
+
|
19
|
+
def local_stuff
|
20
|
+
super
|
21
|
+
do_deploy unless no_deploy?
|
22
|
+
update_master
|
23
|
+
end
|
24
|
+
|
25
|
+
def no_deploy?
|
26
|
+
args[1] && args[1].chomp == "--no-deploy"
|
27
|
+
end
|
28
|
+
|
29
|
+
def do_deploy
|
30
|
+
system "git checkout #{feature_branch}"
|
31
|
+
system "git push -f origin staging:#{feature_branch}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_master
|
35
|
+
system "git checkout master"
|
36
|
+
system "git pull origin master"
|
37
|
+
system "git merge stable"
|
38
|
+
end
|
39
|
+
|
40
|
+
def commit_msg_suffix
|
41
|
+
"[fixes ##{story_id}]"
|
42
|
+
end
|
43
|
+
|
44
|
+
def parent_branch
|
45
|
+
'stable'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
module OptimisWorkflow
|
3
|
+
module Commands
|
4
|
+
class StartFeature < OptimisWorkflow::Commands::StartCommand
|
5
|
+
def initialize(args)
|
6
|
+
super(args)
|
7
|
+
fail "Please pass in a story id" if args.empty?
|
8
|
+
end
|
9
|
+
|
10
|
+
def local_stuff
|
11
|
+
system "git checkout -b feature-#{story_id}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def help_msg
|
15
|
+
"Syntax: start-feature STORYID"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
module OptimisWorkflow
|
3
|
+
module Commands
|
4
|
+
class StartHotfix < OptimisWorkflow::Commands::StartCommand
|
5
|
+
attr_reader :stable_branch
|
6
|
+
|
7
|
+
def initialize(args)
|
8
|
+
super(args)
|
9
|
+
if args.empty?
|
10
|
+
puts "\nError! Please pass in a hotfix story id"
|
11
|
+
exit 1
|
12
|
+
end
|
13
|
+
@stable_branch = args[1] || 'stable'
|
14
|
+
end
|
15
|
+
|
16
|
+
def help_msg
|
17
|
+
"Syntax: start-hotfix STORYID [stable]"
|
18
|
+
end
|
19
|
+
|
20
|
+
def local_stuff
|
21
|
+
system "git checkout -b hotfix-#{args[0]} #{stable_branch}"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
module OptimisWorkflow
|
3
|
+
|
4
|
+
# This module gets included into OptimisWorkflow::Commands::Base
|
5
|
+
module Common
|
6
|
+
def settings_file
|
7
|
+
@settings_file ||= current_dir + '/.tracker_settings.yml'
|
8
|
+
end
|
9
|
+
|
10
|
+
def current_dir
|
11
|
+
@current_dir ||= `pwd`.chomp
|
12
|
+
end
|
13
|
+
|
14
|
+
def payload
|
15
|
+
'<story><current_state>started</current_state></story>'
|
16
|
+
end
|
17
|
+
|
18
|
+
def start_feature
|
19
|
+
story_id = args[0].chomp
|
20
|
+
current_dir = `pwd`.chomp
|
21
|
+
|
22
|
+
mark_as_started
|
23
|
+
end
|
24
|
+
|
25
|
+
def mark_as_started_on_pivotal
|
26
|
+
unless settings.nil?
|
27
|
+
url = URI.parse("http://www.pivotaltracker.com/services/v3/projects/#{settings['project_id']}/stories/#{story_id}")
|
28
|
+
|
29
|
+
net = Net::HTTP.new url.host, url.port
|
30
|
+
|
31
|
+
net.start do |http|
|
32
|
+
req = Net::HTTP::Put.new(url.request_uri, {'Content-type' => 'application/xml', 'X-TrackerToken' => settings['token']})
|
33
|
+
http.request(req, payload)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def settings
|
39
|
+
@tracker_settings ||= YAML.load_file(settings_file) if File.exists?(settings_file)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def sys(cmd)
|
44
|
+
system cmd
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
def cmd_klass
|
4
|
+
OptimisWorkflow::Commands::FinishHotfix
|
5
|
+
end
|
6
|
+
|
7
|
+
describe OptimisWorkflow::Commands::FinishHotfix, 'when called with default opts' do
|
8
|
+
before :each do
|
9
|
+
Kernel.stub!(:system).and_return(true)
|
10
|
+
cmd_klass.stub!(:modified_files).and_return([])
|
11
|
+
@cmd = cmd_klass.new(['12345'])
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should attempt to perform a deploy' do
|
15
|
+
@cmd.should_receive(:do_deploy)
|
16
|
+
@cmd.execute!
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe OptimisWorkflow::Commands::FinishHotfix, 'when passed --no-deploy' do
|
21
|
+
before :each do
|
22
|
+
Kernel.stub!(:system).and_return(true)
|
23
|
+
cmd_klass.stub!(:modified_files).and_return([])
|
24
|
+
@cmd = cmd_klass.new(['12345', '--no-deploy'])
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should not attempt to deploy the app' do
|
28
|
+
@cmd.should_not_receive(:do_deploy)
|
29
|
+
@cmd.execute!
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Alex Sharp
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-14 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -27,12 +27,22 @@ executables:
|
|
27
27
|
- start-hotfix
|
28
28
|
extensions: []
|
29
29
|
|
30
|
-
extra_rdoc_files:
|
31
|
-
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README.md
|
32
32
|
files:
|
33
33
|
- bin/finish-feature
|
34
|
+
- bin/finish-hotfix
|
34
35
|
- bin/start-feature
|
35
36
|
- bin/start-hotfix
|
37
|
+
- lib/optimis-workflow/commands/base.rb
|
38
|
+
- lib/optimis-workflow/commands/finish_command.rb
|
39
|
+
- lib/optimis-workflow/commands/finish_feature.rb
|
40
|
+
- lib/optimis-workflow/commands/finish_hotfix.rb
|
41
|
+
- lib/optimis-workflow/commands/start_command.rb
|
42
|
+
- lib/optimis-workflow/commands/start_feature.rb
|
43
|
+
- lib/optimis-workflow/commands/start_hotfix.rb
|
44
|
+
- lib/optimis-workflow/common.rb
|
45
|
+
- lib/optimis-workflow.rb
|
36
46
|
- LICENSE
|
37
47
|
- README.md
|
38
48
|
has_rdoc: true
|
@@ -65,5 +75,7 @@ rubygems_version: 1.3.6
|
|
65
75
|
signing_key:
|
66
76
|
specification_version: 3
|
67
77
|
summary: A collection of scripts we use to manage our workflow at OptimisDev.
|
68
|
-
test_files:
|
69
|
-
|
78
|
+
test_files:
|
79
|
+
- spec/finish_hotfix_spec.rb
|
80
|
+
- spec/spec.opts
|
81
|
+
- spec/spec_helper.rb
|