ding 0.6.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f255fe679b89e3e89e2d7011c3a82dbecd95434
4
- data.tar.gz: b4e0e524d57bf280ca89dff0bde53a33e754657f
3
+ metadata.gz: 1448685cc5d407fbdd9924ac31a25a64d2faf4ac
4
+ data.tar.gz: de0955b503538011870dcfaf5e7b95318428c079
5
5
  SHA512:
6
- metadata.gz: a6de47b962be00866f7d74bdc028261b5e117a43c9eb2a38fb1669aec82b4412e025f1dffa7bb0f135a9a29847b58d7ce331e9412dee98482585aac447ea83ac
7
- data.tar.gz: 1eb7ff246c2a3996ab7615647d6a9bfb462658d5faf8274df68e994feede913497c5edd4b2c63ee0b5c8ee9f42394cff207a3fe413cafed0fd80fa5e74d6c385
6
+ metadata.gz: e9c454b3caf74446e05117033986edf0576af89e7c82bfe7ecd19113bd6014e64b8ba450e42af92b1b5ea0969e250d6dd6bdaade9d0521f48616213396e857c6
7
+ data.tar.gz: 3474202fb0762eaa9fb0264635f923c265d6d002c4622bab12c05a61e3121912e8bc4064c27db9bcec4b8f846a23e79773a01a79aaf912da697c0456dd523280
data/README.md CHANGED
@@ -15,12 +15,13 @@ The usual method works:
15
15
 
16
16
  By default, `ding` will create a branch called `testing` from the
17
17
  selected feature branch. It also assumes that the master branch is
18
- called `master`. Branches named `master` and `develop` cannot be deleted
19
- by calling `Ding::Git.delete_branch` in code.
18
+ called `master` and the main development branch is called `develop`.
19
+ These main branches cannot be deleted using `Ding::Git.delete_branch`.
20
20
 
21
21
  These defaults can be over-ridden by providing ENV vars to the shell:
22
22
 
23
23
  DING_MASTER_BRANCH - main branch to switch to for synchronising
24
+ DING_DEVELOP_BRANCH - used to compare merge against feature
24
25
  DING_TESTING_BRANCH - branch to over-ride from feature branch
25
26
  DING_SACROSANCT_BRANCHES - space separated list of protected branches
26
27
 
@@ -43,7 +44,9 @@ There are several commands available with global options for verbosity and forci
43
44
  This is the default action so running `ding` is the equivalent of `ding test`.
44
45
 
45
46
  There is an option to specify the feature branch pattern to display for
46
- selection of the code to be pushed to `testing`.
47
+ selection of the code to be pushed to `testing`. By default, only
48
+ remote branches that haven't already been merged to `develop` will be
49
+ listed, this can be over-ridden by using the `-m` flag.
47
50
 
48
51
  $ ding help test
49
52
 
@@ -51,6 +54,7 @@ selection of the code to be pushed to `testing`.
51
54
  ding test
52
55
 
53
56
  Options:
57
+ -m, [--merged], [--no-merged] # display branches that have been merged
54
58
  -p, [--pattern=PATTERN] # specify a pattern for listing branches
55
59
  # Default: origin/XAP*
56
60
 
data/lib/ding/cli.rb CHANGED
@@ -8,15 +8,16 @@ module Ding
8
8
 
9
9
  default_task :test
10
10
 
11
- desc "test", "Push a feature branch to the testing branch (this is the default action)"
12
- option :pattern, type: 'string', aliases: '-p', default: 'origin/XAP*', desc: 'specify a pattern for listing branches'
11
+ desc "test", "Push a feature branch(es) to the testing branch (this is the default action)"
12
+ option :merged, type: 'boolean', aliases: '-m', default: false, desc: 'display branches that have been merged'
13
+ option :pattern, type: 'string', aliases: '-p', default: 'origin/XAP*', desc: 'specify a pattern for listing branches'
13
14
  def test
14
- master_branch, testing_branch = Ding::MASTER_BRANCH.dup, Ding::TESTING_BRANCH.dup
15
- say "\nDing ding ding: let's push a feature branch to #{testing_branch}...\n\n", :green
15
+ develop_branch, testing_branch = Ding::DEVELOP_BRANCH.dup, Ding::TESTING_BRANCH.dup
16
+ say "\nDing ding ding: let's merge one or more feature branches to #{testing_branch}...\n\n", :green
16
17
 
17
18
  repo = Ding::Git.new(options).tap do |r|
18
19
  say "> Synchronising with the remote...", :green
19
- r.checkout master_branch
20
+ r.checkout develop_branch
20
21
  r.update
21
22
  end
22
23
 
@@ -26,17 +27,39 @@ module Ding
26
27
  exit 1
27
28
  end
28
29
 
29
- feature_branch = ask_which_item(branches, 'Which feature branch should I use?')
30
+ feature_branches = ask_which_item(branches, 'Which feature branch should I use?', :multiple)
30
31
 
31
32
  repo.tap do |r|
32
33
  say "\n> Deleting #{testing_branch}...", :green
33
34
  r.delete_branch(testing_branch)
34
- say "> Checking out #{feature_branch}...", :green
35
- r.checkout(feature_branch)
35
+
36
+ say "> Checking out #{develop_branch}...", :green
37
+ r.checkout(develop_branch)
38
+
36
39
  say "> Creating #{testing_branch}...", :green
37
40
  r.create_branch(testing_branch)
38
- say "> Pushing #{testing_branch} to the remote...", :green
39
- r.push(testing_branch)
41
+
42
+ say "> Checking out #{testing_branch}...", :green
43
+ r.checkout(testing_branch)
44
+
45
+ say "> Merging in selected feature #{feature_branches.count == 1 ? 'branch' : 'branches'}...", :green
46
+ merge_errors = false
47
+ feature_branches.each do |branch|
48
+ if r.merge_branch(branch)
49
+ say ">>> #{branch} succeeded", :green
50
+ else
51
+ say ">>> #{branch} failed", :red
52
+ merge_errors = true
53
+ end
54
+ end
55
+
56
+ unless merge_errors
57
+ say "> Pushing #{testing_branch} to the remote...", :green
58
+ r.push(testing_branch)
59
+ else
60
+ say "\n --> There were merge errors, ding dang it!\n\n", :red
61
+ exit 1
62
+ end
40
63
  end
41
64
 
42
65
  rescue => e
@@ -100,14 +123,17 @@ module Ding
100
123
  private
101
124
 
102
125
  def show_error(e)
103
- say "\n --> Error: #{e.message}\n\n", :red
126
+ say "\n --> ERROR: #{e.message}\n\n", :red
104
127
  raise if options[:verbose]
105
128
  exit 1
106
129
  end
107
130
 
108
- def ask_which_item(items, prompt)
109
- return items.first if items.size == 1
131
+ # presents a list of choices and allows either a single or multiple selection
132
+ # returns the selected choices in an array or exist if selection is invalid
133
+ def ask_which_item(items, prompt, mode=:single)
134
+ return Array(items.first) if items.size == 1
110
135
  str_format = "\n %#{items.count.to_s.size}s: %s"
136
+ prompt = prompt << "\n > Enter multiple selections separated by ',' or 'A' for all" if mode == :multiple
111
137
  question = set_color prompt, :yellow
112
138
  answers = {}
113
139
 
@@ -118,10 +144,20 @@ module Ding
118
144
  end
119
145
 
120
146
  say question
121
- reply = ask("> ").to_s
122
- if answers[reply]
123
- answers[reply]
124
- else
147
+ reply = ask(" >", :yellow).to_s
148
+ begin
149
+ replies = reply.split(',')
150
+ if answers[reply]
151
+ answers.values_at(reply)
152
+ elsif mode == :multiple && reply == 'A'
153
+ answers.values
154
+ elsif mode == :multiple && !replies.empty?
155
+ selected_items = answers.values_at(*replies)
156
+ raise "Invalid selection" if selected_items.include?(nil)
157
+ selected_items
158
+ end
159
+ rescue
160
+ raise if options[:verbose]
125
161
  say "\n --> That's not a valid selection, I'm out of here!\n\n", :red
126
162
  exit 1
127
163
  end
@@ -7,7 +7,8 @@ module Ding
7
7
  end
8
8
 
9
9
  def branches(pattern)
10
- %x(git branch --remote --list #{remote_version(pattern)}).split.map {|b| b.split('/').last}
10
+ merged = options[:merged] ? '--merged' : '--no-merged'
11
+ %x(git branch --remote --list #{remote_version(pattern)} #{merged}).split
11
12
  end
12
13
 
13
14
  def branch_exists?(branch)
@@ -19,7 +20,11 @@ module Ding
19
20
  end
20
21
 
21
22
  def create_branch(branch)
22
- raise "Unable to create #{branch}" unless run_cmd "git branch --track #{branch}"
23
+ raise "Unable to create #{branch}" unless run_cmd "git branch --no-track #{branch}"
24
+ end
25
+
26
+ def current_branch
27
+ %x(git rev-parse --abbrev-ref HEAD)
23
28
  end
24
29
 
25
30
  def delete_branch(branch)
@@ -36,6 +41,15 @@ module Ding
36
41
  end
37
42
  end
38
43
 
44
+ def merge_branch(branch)
45
+ raise "Can't merge into protected branch #{current_branch}" if Ding::SACROSANCT_BRANCHES.include?(current_branch)
46
+ success = !!(run_cmd "git merge -m 'Merge branch #{branch} into #{current_branch}' #{branch}")
47
+ unless success
48
+ run_cmd 'git merge --abort'
49
+ end
50
+ success
51
+ end
52
+
39
53
  def push(branch)
40
54
  checkout branch
41
55
  push_cmd = "git push #{remote_name} #{branch}"
data/lib/ding/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ding
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.2"
3
3
  end
data/lib/ding.rb CHANGED
@@ -5,8 +5,9 @@ require 'ding/models/ssh'
5
5
 
6
6
  module Ding
7
7
  MASTER_BRANCH = ENV['DING_MASTER_BRANCH'] || 'master'
8
+ DEVELOP_BRANCH = ENV['DING_DEVELOP_BRANCH'] || 'develop'
8
9
  TESTING_BRANCH = ENV['DING_TESTING_BRANCH'] || 'testing'
9
- SACROSANCT_BRANCHES = (ENV['DING_SACROSANCT_BRANCHES'] || 'master develop').split
10
+ SACROSANCT_BRANCHES = (ENV['DING_SACROSANCT_BRANCHES'] || "#{MASTER_BRANCH} #{DEVELOP_BRANCH}").split
10
11
 
11
12
  # because we lurve the command line... ding!
12
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Warren Bain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-18 00:00:00.000000000 Z
11
+ date: 2015-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler