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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/branch/cleaner.rb +24 -4
- data/lib/branch/cleaner/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5acb9b7fe222c6cf31a8903f06b0cc56801ccf5f
|
4
|
+
data.tar.gz: fef5387f3c1676c2ae23da5effe3f08e38119ea8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14b439dec003e5d0fb377f89ca0f2e955539026e7270e96a20e6d87c8133ff2210eb05562816f8f4feffe379611b5ba201a88ebb4586d92df2bcbfed46cb706a
|
7
|
+
data.tar.gz: a8b18260ed431c49713e72ac34c6b9cc2a6f180fab7ffd081d648e987b98389cfafa92cf0f85eaa8e44b4b510f9e1b851239e3071108423729da056e53b95c8b
|
data/Gemfile.lock
CHANGED
data/lib/branch/cleaner.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2018-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|