branch-cleaner 0.1.1 → 0.2.0

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: 12716974eac388586df7653ab531b8a4d824a1cc
4
- data.tar.gz: d08b0e40e6cdc0abf5693a24a516a8fdb77596cb
3
+ metadata.gz: 5acb9b7fe222c6cf31a8903f06b0cc56801ccf5f
4
+ data.tar.gz: fef5387f3c1676c2ae23da5effe3f08e38119ea8
5
5
  SHA512:
6
- metadata.gz: fa7f430447fe65113ed13830ef3b14f23d3bd029a09d6873ccbc4762a71c71cc69d1d058f08096958d9c66192dc4dbddc18ba7f1fc4d1dc5d5d191b8d0f4afac
7
- data.tar.gz: c0f8e54087336d002e7c2e68c3a84f7b845348cd85e4b4f022304ce19841147dfba1665e583dcd41c9ae3bcff339646a0310435a21af06613ee77469ea0b726a
6
+ metadata.gz: 14b439dec003e5d0fb377f89ca0f2e955539026e7270e96a20e6d87c8133ff2210eb05562816f8f4feffe379611b5ba201a88ebb4586d92df2bcbfed46cb706a
7
+ data.tar.gz: a8b18260ed431c49713e72ac34c6b9cc2a6f180fab7ffd081d648e987b98389cfafa92cf0f85eaa8e44b4b510f9e1b851239e3071108423729da056e53b95c8b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- branch-cleaner (0.1.1)
4
+ branch-cleaner (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -6,18 +6,23 @@ module Branch
6
6
  module Cleaner
7
7
  NOBLE_BRANCHES_NAMES = ["master", "develop"]
8
8
  DEFAULT_WEEKS = 2
9
+ DEFAULT_PROFIXS = ['keep']
9
10
 
10
11
  options = {}
11
12
  OptionParser.new do |opts|
12
- opts.banner = "bcleaner is a tool to clean branch which is out of date."
13
+ opts.banner = "bcleaner is a tool to clean branch which is out of date. master and develop branch is being protected."
13
14
 
14
15
  opts.on('-p', '--push', 'push to remote repo.') do
15
16
  options[:push] = true
16
17
  end
17
18
 
18
- opts.on('-w=NUMBER', '--week=NUMBER', 'number of weeks. If last commit of branch if before the date, the branch will be deleted.') do |value|
19
+ opts.on('-w NUMBER', '--week NUMBER', 'number of weeks. If last commit of branch if before the date, the branch will be deleted.') do |value|
19
20
  options[:weeks] = Float(value) rescue DEFAULT_WEEKS
20
21
  end
22
+
23
+ opts.on('-b PROFIXA,PROFIXB', '--branch-profixs PROFIXA,PROFIXB', Array, 'profixs of branch that is protected from being deleting. For default value is [keep], a branch with name "keep/branch_subname" will be protected from being deleting, while a branch with name "keep_branch_subname" will not.') do |value|
24
+ options[:protected_profixs] = Array(value) rescue DEFAULT_PROFIXS
25
+ end
21
26
  end.parse!
22
27
 
23
28
  exec_command_result = `for branch in \`git branch -r | grep -v HEAD\`;do echo -e \`git show --format="%ci %cr" $branch | head -n 1\` $branch; done | sort -r`
@@ -28,11 +33,26 @@ module Branch
28
33
  end
29
34
 
30
35
  all_remote_branches = exec_command_result.split("\n")
31
- branches_to_delete = all_remote_branches.select do |branch|
36
+
37
+ protected_profixs = options[:protected_profixs] || DEFAULT_PROFIXS
38
+ protected_branches = all_remote_branches.select do |branch|
39
+ valid_branch_name = branch.split(' ').last.split('/', 2).last
40
+
41
+ protected_profixs.include?(valid_branch_name.split('/').first)
42
+ end
43
+
44
+ puts <<-FOO
45
+ these branches will be protected (branch profixs #{protected_profixs}) : \n#{protected_branches.join("\n")}\n\n
46
+ FOO
47
+
48
+ not_protected_branches = all_remote_branches - protected_branches
49
+ branches_to_delete = not_protected_branches.select do |branch|
32
50
  branch_time = Time.parse(branch)
33
51
  now_time = Time.new
34
52
  weeks = (now_time - branch_time) / 3600 / 24 / 7
35
- (weeks > (options[:weeks] || DEFAULT_WEEKS)) && !(NOBLE_BRANCHES_NAMES.include?(branch.split(' ').last.split('/', 2).last))
53
+ valid_branch_name = branch.split(' ').last.split('/', 2).last
54
+
55
+ (weeks > (options[:weeks] || DEFAULT_WEEKS)) && !(NOBLE_BRANCHES_NAMES.include?(valid_branch_name))
36
56
  end
37
57
 
38
58
  puts <<-FOO
@@ -1,5 +1,5 @@
1
1
  module Branch
2
2
  module Cleaner
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: branch-cleaner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tripleCC
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-28 00:00:00.000000000 Z
11
+ date: 2018-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler