redmine_stagecoach 0.6.13 → 0.6.14

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.13
1
+ 0.6.14
data/bin/stagecoach CHANGED
@@ -55,43 +55,44 @@ module Stagecoach
55
55
  exit
56
56
  end
57
57
  end
58
-
59
- # Checks for uncommitted/unstashed changes and aborts if present.
60
- if Git.changes != ''
61
- puts "You have uncommitted changes:".red
62
- puts Git.changes
63
- puts "Please commit or stash these changes before running Stagecoach. -h for help."
64
- puts "Exiting..."
65
- exit
66
- end
67
-
68
58
 
69
59
  # ------------------------------------------------------------------
70
- # Git branch operations: list, cleanup
60
+ # Git branch operations: list, tidy
71
61
  # ------------------------------------------------------------------
72
62
 
73
- if opts[:list]
63
+ if opts[:list] || opts[:tidy]
74
64
  CommandLine.line_break
75
- puts "Local Git Branches created with Stagecoach:"
76
- puts "%s = already merged into master" % "Green".green
77
- puts "%s = not merged into master" % "Red".red
78
- CommandLine.line_break
79
- local_stagecoach_branches = {}
80
- config.each { |k,v| local_stagecoach_branches[k] = v unless k =~ /redmine_site|redmine_api_key|redmine_user_id/}
81
- local_stagecoach_branches.keys.sort.each do |branch_name|
82
- branch_attributes = local_stagecoach_branches[branch_name]
83
-
84
- if Git.branches.select { |a| a.match(/\W+#{branch_name}/) }
85
- puts Git.branch_merged_to_master?(branch_name) ? branch_name.green : branch_name.red
86
- end
65
+ puts "-------------------------------------------"
66
+ puts "Local Git Branches created with Stagecoach "
67
+ puts "-------------------------------------------"
68
+
69
+ local_stagecoach_branches = Git.local_stagecoach_branches(config)
70
+
71
+ all_branches_list = Git.branches
72
+ all_branches_list << Git.current_branch
73
+
74
+ deletable_branches = Git.list(local_stagecoach_branches, all_branches_list)
75
+
76
+ if opts[:tidy]
77
+ Git.tidy(deletable_branches)
87
78
  end
79
+ puts "Complete! Exiting..."
88
80
  exit
89
81
  end
90
82
 
91
- # ------------------------------------------------------------------
83
+ # ------------------------------------------------------------------
92
84
  # Initial stage - set up branch and git issue.
93
85
  # ------------------------------------------------------------------
94
86
 
87
+ # Checks for uncommitted/unstashed changes and aborts if present.
88
+ if Git.changes != ''
89
+ puts "You have uncommitted changes:".red
90
+ puts Git.changes
91
+ puts "Please commit or stash these changes before running Stagecoach. -h for help."
92
+ puts "Exiting..."
93
+ exit
94
+ end
95
+
95
96
  # Set up redmine client config.
96
97
  RedmineApi::Client.instance_eval do
97
98
  self.site = config["redmine_site"]
@@ -331,7 +332,7 @@ module Stagecoach
331
332
  puts "Status set to 'Erledigt'"
332
333
  else
333
334
  end
334
- puts 'Completed deploy.'
335
+ puts 'Completed deploy.'
335
336
  end
336
337
  end
337
338
  end
@@ -27,13 +27,14 @@ For more info see the readme at https://github.com/omnikron/stagecoach#readme
27
27
  #{"Flags".red}
28
28
  EOS
29
29
  opt :branch, "Enter your new branch name here, eg. stagecoach -b new_branch (optional)", :type => :string
30
- opt :deploy, "Use this option to deploy from your current branch to any branch you choose, eg. stagecoach -d staging", :type => :string
30
+ opt :deploy, "Use this option to deploy from your current branch to any branch you choose, eg. stagecoach -d staging", :type => :string, :default => "staging"
31
31
  opt :from, "Use this option to set the branch you want to branch off from. Default is master", :type => :string, :default => "master"
32
32
  opt :github, "Enter your github issue number here, eg. stagecoach -g 1234 (optional)", :type => :string
33
33
  opt :list, "Use this to list local branches which you have created with Stagecoach"
34
34
  opt :push, "Use this option to push your changes to your remote branch (will be created if necessary)"
35
35
  opt :redmine, "Enter your redmine/planio issue number here, eg. stagecoach -r 1234 (optional)", :type => :string
36
36
  opt :setup, "Use this the first time you run stagecoach to save your redmine repository and api key"
37
+ opt :tidy, "This will remove all branches that are already merged to master, both remotely and locally."
37
38
  opt :version, "Prints the current version"
38
39
  end
39
40
  end
@@ -2,9 +2,67 @@ module Stagecoach
2
2
  class Git
3
3
  class << self
4
4
  def branches
5
- `git branch`.split("\n").each {|a| a.lstrip! }
5
+ `git branch`.split("\n").collect(&:strip)
6
6
  end
7
7
 
8
+ def list(local_stagecoach_branches, all_branches_list)
9
+ deletable_branches = []
10
+ local_stagecoach_branches.keys.sort.each do |branch_name|
11
+ # branch_attributes = local_stagecoach_branches[branch_name]
12
+ if all_branches_list.include?(branch_name.strip)
13
+ if Git.branch_merged_to_master?(branch_name)
14
+ puts branch_name
15
+ deletable_branches << branch_name
16
+ else
17
+ puts branch_name + " *".green
18
+ end
19
+ end
20
+ end
21
+ CommandLine.line_break
22
+ puts "*".green + " = not merged to master, will not be deleted by stagecoach -t"
23
+ CommandLine.line_break
24
+ deletable_branches
25
+ end
26
+
27
+ def local_stagecoach_branches(config)
28
+ local_stagecoach_branches = {}
29
+ config.each { |k,v| local_stagecoach_branches[k] = v unless k =~ /redmine_site|redmine_api_key|redmine_user_id|master|staging/i}
30
+ end
31
+
32
+ def tidy(deletable_branches)
33
+ CommandLine.line_break
34
+ if deletable_branches.length > 0
35
+ puts "All branches that have been merged into master will be deleted locally and remotely.".red
36
+ print "Continue? [Y]es or anything else to cancel: "
37
+ case STDIN.gets.chomp
38
+ when 'Y'
39
+ erase(deletable_branches)
40
+ else
41
+ puts 'No branches deleted. Exiting...'
42
+ exit
43
+ end
44
+ else
45
+ puts 'No branches to delete. Exiting...'
46
+ end
47
+ end
48
+
49
+ def remote_branches
50
+ (`git ls-remote`.split(" ").each.select { |e| e =~ /refs\/heads/}).collect {|a| a.gsub("refs/heads/", "")}
51
+ end
52
+
53
+ def erase(list)
54
+ change_to_branch('master')
55
+ branches_on_remote = Git.remote_branches
56
+ list.each {|b| delete_branch(b, branches_on_remote ) }
57
+ end
58
+
59
+ def delete_branch(branch, list)
60
+ puts "Local: " + `git branch -D #{branch}`
61
+ if list.include?(branch)
62
+ puts "Remote: " + `git push origin :#{branch}`
63
+ end
64
+ end
65
+
8
66
  def global_config(header, config)
9
67
  `git config --global #{header}.#{config}`
10
68
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "redmine_stagecoach"
8
- s.version = "0.6.13"
8
+ s.version = "0.6.14"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oli Barnett"]
12
- s.date = "2012-05-18"
12
+ s.date = "2012-05-21"
13
13
  s.description = "Git/capistrano workflow automation script with Redmine & Github issue integration"
14
14
  s.email = "o.barnett@digitaleseiten.de"
15
15
  s.executables = ["stagecoach"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_stagecoach
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.13
4
+ version: 0.6.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-18 00:00:00.000000000 Z
12
+ date: 2012-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activeresource
@@ -168,7 +168,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
168
  version: '0'
169
169
  segments:
170
170
  - 0
171
- hash: 2934984471721959034
171
+ hash: -3389804808014498820
172
172
  required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  none: false
174
174
  requirements: