kookeeper 3.0.2 → 3.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.idea/.gitignore +8 -0
  3. data/.idea/bigkeeper.iml +68 -0
  4. data/.idea/modules.xml +8 -0
  5. data/.idea/vcs.xml +6 -0
  6. data/CODE_OF_CONDUCT.md +46 -0
  7. data/CONTRIBUTING.md +70 -0
  8. data/Gemfile +10 -0
  9. data/Gemfile.lock +145 -0
  10. data/LICENSE +21 -0
  11. data/README.md +113 -0
  12. data/big_keeper.gemspec +50 -0
  13. data/docs/en-US/FEATURE.md +0 -0
  14. data/docs/en-US/README.md +54 -0
  15. data/docs/zh-CN/BIGKEEPER_FILE.md +84 -0
  16. data/docs/zh-CN/FEATURE&HOTFIX.md +88 -0
  17. data/docs/zh-CN/IMAGE.md +0 -0
  18. data/docs/zh-CN/PODFILE.md +43 -0
  19. data/docs/zh-CN/README.md +113 -0
  20. data/docs/zh-CN/RECOMMEND.md +22 -0
  21. data/docs/zh-CN/RELEASE.md +60 -0
  22. data/docs/zh-CN/SPEC.md +39 -0
  23. data/lib/big_keeper/command/feature&hotfix/delete.rb +40 -0
  24. data/lib/big_keeper/command/feature&hotfix/finish.rb +54 -0
  25. data/lib/big_keeper/command/feature&hotfix/list.rb +63 -0
  26. data/lib/big_keeper/command/feature&hotfix/publish.rb +56 -0
  27. data/lib/big_keeper/command/feature&hotfix/pull.rb +26 -0
  28. data/lib/big_keeper/command/feature&hotfix/push.rb +27 -0
  29. data/lib/big_keeper/command/feature&hotfix/rebase.rb +32 -0
  30. data/lib/big_keeper/command/feature&hotfix/start.rb +89 -0
  31. data/lib/big_keeper/command/feature&hotfix/switch.rb +46 -0
  32. data/lib/big_keeper/command/feature&hotfix/update.rb +71 -0
  33. data/lib/big_keeper/command/feature&hotfix.rb +167 -0
  34. data/lib/big_keeper/command/image/image.rb +0 -0
  35. data/lib/big_keeper/command/image.rb +28 -0
  36. data/lib/big_keeper/command/pod/podfile.rb +69 -0
  37. data/lib/big_keeper/command/pod.rb +42 -0
  38. data/lib/big_keeper/command/release/home.rb +91 -0
  39. data/lib/big_keeper/command/release/module.rb +61 -0
  40. data/lib/big_keeper/command/release.rb +75 -0
  41. data/lib/big_keeper/command/spec/add.rb +9 -0
  42. data/lib/big_keeper/command/spec/analyze.rb +88 -0
  43. data/lib/big_keeper/command/spec/delete.rb +9 -0
  44. data/lib/big_keeper/command/spec/list.rb +19 -0
  45. data/lib/big_keeper/command/spec/search.rb +9 -0
  46. data/lib/big_keeper/command/spec/sync.rb +12 -0
  47. data/lib/big_keeper/command/spec.rb +78 -0
  48. data/lib/big_keeper/dependency/dep_gradle_operator.rb +56 -0
  49. data/lib/big_keeper/dependency/dep_operator.rb +32 -0
  50. data/lib/big_keeper/dependency/dep_pod_operator.rb +130 -0
  51. data/lib/big_keeper/dependency/dep_service.rb +14 -0
  52. data/lib/big_keeper/dependency/dep_type.rb +33 -0
  53. data/lib/big_keeper/model/gitflow_type.rb +43 -0
  54. data/lib/big_keeper/model/library_model.rb +116 -0
  55. data/lib/big_keeper/model/operate_type.rb +27 -0
  56. data/lib/big_keeper/model/podfile_model.rb +33 -0
  57. data/lib/big_keeper/service/git_service.rb +259 -0
  58. data/lib/big_keeper/service/module_service.rb +159 -0
  59. data/lib/big_keeper/service/stash_service.rb +58 -0
  60. data/lib/big_keeper/util/bigkeeper_parser.rb +244 -0
  61. data/lib/big_keeper/util/cache_operator.rb +117 -0
  62. data/lib/big_keeper/util/code_operator.rb +37 -0
  63. data/lib/big_keeper/util/file_operator.rb +33 -0
  64. data/lib/big_keeper/util/git_operator.rb +226 -0
  65. data/lib/big_keeper/util/gitflow_operator.rb +51 -0
  66. data/lib/big_keeper/util/gradle_operator.rb +209 -0
  67. data/lib/big_keeper/util/info_plist_operator.rb +46 -0
  68. data/lib/big_keeper/util/leancloud_logger.rb +72 -0
  69. data/lib/big_keeper/util/list_generator.rb +101 -0
  70. data/lib/big_keeper/util/logger.rb +46 -0
  71. data/lib/big_keeper/util/pod_operator.rb +71 -0
  72. data/lib/big_keeper/util/podfile_detector.rb +111 -0
  73. data/lib/big_keeper/util/podfile_module.rb +63 -0
  74. data/lib/big_keeper/util/podfile_operator.rb +117 -0
  75. data/lib/big_keeper/util/verify_operator.rb +17 -0
  76. data/lib/big_keeper/util/xcode_operator.rb +15 -0
  77. data/lib/big_keeper/version.rb +3 -0
  78. data/lib/big_keeper.rb +71 -0
  79. data/resources/banner.png +0 -0
  80. data/resources/command.png +0 -0
  81. data/resources/keynote/big-keeper-readme-analyze.key +0 -0
  82. data/resources/keynote/big-keeper-readme-example.key +0 -0
  83. data/resources/keynote/big-keeper-readme-feature.key +0 -0
  84. data/resources/keynote/big-keeper-readme-release.key +0 -0
  85. data/resources/readme/big-keeper-readme.001.png +0 -0
  86. metadata +86 -3
@@ -0,0 +1,14 @@
1
+ require 'big_keeper/util/git_operator'
2
+ require 'big_keeper/model/gitflow_type'
3
+ require 'big_keeper/model/operate_type'
4
+ require 'big_keeper/util/logger'
5
+ require 'big_keeper/dependency/dep_type'
6
+
7
+ module BigKeeper
8
+ # Operator for podfile
9
+ class DepService
10
+ def self.dep_operator(path, user)
11
+ DepType.operator(path, user)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,33 @@
1
+ require 'big_keeper/dependency/dep_operator'
2
+ require 'big_keeper/dependency/dep_pod_operator'
3
+ require 'big_keeper/dependency/dep_gradle_operator'
4
+ require 'big_keeper/util/file_operator'
5
+
6
+ module BigKeeper
7
+ module DepType
8
+ NONE = 0
9
+ COCOAPODS = 1
10
+ GRADLE = 2
11
+
12
+ def self.type(path)
13
+ if FileOperator.definitely_exists?("#{path}/Podfile")
14
+ COCOAPODS
15
+ elsif FileOperator.definitely_exists?("#{path}/build.gradle")
16
+ GRADLE
17
+ else
18
+ NONE
19
+ end
20
+ end
21
+
22
+ def self.operator(path, user)
23
+ operator_type = type(path)
24
+ if COCOAPODS == operator_type
25
+ DepPodOperator.new(path, user)
26
+ elsif GRADLE == operator_type
27
+ DepGradleOperator.new(path, user)
28
+ else
29
+ DepOperator.new(path, user)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,43 @@
1
+ module BigKeeper
2
+ module GitflowType
3
+ FEATURE = 1
4
+ HOTFIX = 2
5
+ RELEASE = 3
6
+
7
+ def self.name(type)
8
+ if FEATURE == type
9
+ "feature"
10
+ elsif HOTFIX == type
11
+ "hotfix"
12
+ elsif RELEASE == type
13
+ "release"
14
+ else
15
+ "feature"
16
+ end
17
+ end
18
+
19
+ def self.command(type)
20
+ if FEATURE == type
21
+ :feature
22
+ elsif HOTFIX == type
23
+ :hotfix
24
+ elsif RELEASE == type
25
+ :release
26
+ else
27
+ :feature
28
+ end
29
+ end
30
+
31
+ def self.base_branch(type)
32
+ if FEATURE == type
33
+ "develop"
34
+ elsif HOTFIX == type
35
+ "master"
36
+ elsif RELEASE == type
37
+ "develop"
38
+ else
39
+ "master"
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,116 @@
1
+ require 'big_keeper/util/file_operator'
2
+ require 'big_keeper/util/code_operator'
3
+
4
+
5
+ module BigKeeper
6
+ class LibraryModel
7
+ attr_accessor :name, :file_list, :header_file_list, :keyword_list, :spec_library
8
+ def initialize(name)
9
+ @name = name
10
+ @file_list = []
11
+ @header_file_list = []
12
+ @spec_library = []
13
+ @keyword_list = []
14
+ end
15
+
16
+ def get_all_public_file(path)
17
+ all_header = FileOperator.find_all_header_file("#{path}/Pods/#{@name}")
18
+ for file_path in all_header do
19
+ @header_file_list[@header_file_list.size] = file_path
20
+ file_name = File.basename(file_path)
21
+ @keyword_list[@keyword_list.size] = file_name
22
+ in_note = false
23
+ File.foreach(file_path) { |line|
24
+ hash = Hash.new
25
+ hash["in_note"]=in_note
26
+ hash["line"]=line
27
+ OCCodeOperator.in_note_code(hash)
28
+ in_note = hash["in_note"]
29
+ line = hash["line"]
30
+ if line.empty?
31
+ next
32
+ end
33
+ if line.include?("@interface ")
34
+ line[0,line.index("@interface ")+11]=""
35
+ column = line.split(/:/)
36
+ if column.size > 1
37
+ class_name = column[0]
38
+ if class_name.include?("<")
39
+ class_name = class_name[0, class_name.index("<")]
40
+ end
41
+ class_name = class_name.strip
42
+ if (@keyword_list.include?(class_name+".h"))
43
+ @keyword_list.delete(class_name+".h")
44
+ end
45
+ @keyword_list[@keyword_list.size] = class_name
46
+ end
47
+ end
48
+ }
49
+ end
50
+ # if @name == ""
51
+ # puts @keyword_list
52
+ # end
53
+ @file_list = FileOperator.find_all_code_file("#{path}/Pods/#{@name}")
54
+ end
55
+
56
+ def spec_dependece_library(library_keywords_hash)
57
+ if library_keywords_hash.include?(@name)
58
+ library_keywords_hash.delete(@name)
59
+ end
60
+
61
+ for file_path in @file_list do
62
+ # note for coding
63
+ in_note = false
64
+ File.foreach(file_path) { |line|
65
+ hash = Hash.new
66
+ hash["in_note"]=in_note
67
+ hash["line"]=line
68
+ OCCodeOperator.in_note_code(hash)
69
+ in_note = hash["in_note"]
70
+ line = hash["line"]
71
+ if line.empty?
72
+ next
73
+ end
74
+ library_keywords_hash.each {|library_name, keyword_list|
75
+ is_dependence = false
76
+ tip = ""
77
+ for keyword in keyword_list do
78
+ if line.include?(keyword)
79
+ last_char = '.'
80
+ last_index = line.index(keyword)-1
81
+ if last_index >= 0
82
+ last_char = line[last_index]
83
+ end
84
+ next_char = '.'
85
+ next_index = line.index(keyword)+keyword.size
86
+ if next_index < line.size
87
+ next_char = line[next_index]
88
+ end
89
+ if !(((next_char<='z'&&next_char>='a')||(next_char<='Z'&&next_char>='A')||(next_char<='9'&&next_char>='0')||next_char=='_')||((last_char<='z'&&last_char>='a')||(last_char<='Z'&&last_char>='A')||(last_char<='9'&&last_char>='0')||last_char=='_'))
90
+ if keyword.include?(".h") && line.include?("import") && line.include?("/"+keyword+">")
91
+ dependence_library_name = line[line.index("<")+1...line.index("/"+keyword+">")]
92
+ if dependence_library_name == library_name
93
+ tip = " [file]:"+File.basename(file_path)+" [line]: "+line.strip+" [keyword]: "+keyword
94
+ is_dependence = true
95
+ break
96
+ end
97
+ else
98
+ tip = " [file]:"+File.basename(file_path)+" [line]: "+line.strip+" [keyword]: "+keyword
99
+ is_dependence = true
100
+ break
101
+ end
102
+ end
103
+ end
104
+ end
105
+ if is_dependence
106
+ @spec_library[@spec_library.size] = library_name+tip
107
+ library_keywords_hash.delete(library_name)
108
+ end
109
+ }
110
+
111
+ }
112
+ end
113
+ end
114
+
115
+ end
116
+ end
@@ -0,0 +1,27 @@
1
+ module BigKeeper
2
+ module OperateType
3
+ START = 1
4
+ UPDATE = 2
5
+ SWITCH = 3
6
+
7
+ def self.name(type)
8
+ if START == type
9
+ "start"
10
+ elsif UPDATE == type
11
+ "update"
12
+ elsif SWITCH == type
13
+ "switch"
14
+ else
15
+ name
16
+ end
17
+ end
18
+ end
19
+
20
+ module ModuleOperateType
21
+ ADD = 1
22
+ DELETE = 2
23
+ FINISH = 3
24
+ PUBLISH = 4
25
+ RELEASE = 5
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+
2
+ module BigKeeper
3
+
4
+ class PodfileModel
5
+ attr_accessor :name, :git, :path, :configurations, :branch,:tag, :comment
6
+ def initialize(sentence)
7
+ if sentence.include?('#')
8
+ list = sentence.split('#')
9
+ @comment = list[1]
10
+ sentence = list[0]
11
+ end
12
+
13
+ sentence_slip_list = sentence.split(',')
14
+ return if sentence_slip_list.size.zero?
15
+ for piece in sentence_slip_list do
16
+ if /:git =>/ =~ piece
17
+ @git = $~.post_match.strip
18
+ elsif /:path =>/ =~ piece
19
+ @path = $~.post_match.strip
20
+ elsif /:configurations =>/ =~ piece
21
+ @configurations = $~.post_match.strip
22
+ elsif /:branch =>/ =~ piece
23
+ @branch = $~.post_match.strip
24
+ elsif /:tag =>/ =~ piece
25
+ @tag = $~.post_match.strip
26
+ elsif /pod /=~ piece
27
+ @name = $~.post_match.delete("'\n ")
28
+ end
29
+ # p %Q{model name:#{@name},git:#{@git},path:#{@path},config:#{@configurations},branch:#{@branch},tag:#{@tag},comment:#{@comment}}
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,259 @@
1
+ require 'big_keeper/util/git_operator'
2
+ require 'big_keeper/util/gitflow_operator'
3
+ require 'big_keeper/model/gitflow_type'
4
+ require 'big_keeper/model/operate_type'
5
+ require 'big_keeper/util/logger'
6
+
7
+ module BigKeeper
8
+ # Operator for got
9
+ class GitService
10
+
11
+ def startHome(path, name, type)
12
+ p "----------startHome"
13
+ git = GitOperator.new
14
+ branch_name = "#{GitflowType.name(type)}/#{name}"
15
+ p "----------branch_name:#{branch_name}"
16
+ if !git.has_remote_branch(path, branch_name) && !git.has_local_branch(path, branch_name)
17
+ p "----------如果远程和本地没有#{branch_name}分支"
18
+ verify_special_branch(path, 'master')
19
+
20
+
21
+ #verify_special_branch(path, 'develop')
22
+
23
+ #GitflowOperator.new.verify_git_flow(path)
24
+
25
+ #GitflowOperator.new.start(path, name, type)
26
+ #
27
+ Dir.chdir(path) do
28
+ p "git checkout -b #{branch_name}"
29
+ `git checkout -b #{branch_name}`
30
+ end
31
+ git.push_to_remote(path, branch_name)
32
+ else
33
+ verify_checkout(path, branch_name)
34
+
35
+ if !git.has_remote_branch(path, branch_name)
36
+ p "如果远程没有 #{branch_name}"
37
+ git.push_to_remote(path, branch_name)
38
+ end
39
+ end
40
+ end
41
+
42
+
43
+ def start(path, name, type)
44
+ git = GitOperator.new
45
+
46
+ branch_name = "#{GitflowType.name(type)}/#{name}"
47
+ if !git.has_remote_branch(path, branch_name) && !git.has_local_branch(path, branch_name)
48
+
49
+ verify_special_branch(path, 'master')
50
+ #verify_special_branch(path, 'develop')
51
+
52
+ GitflowOperator.new.verify_git_flow(path)
53
+
54
+ GitflowOperator.new.start(path, name, type)
55
+
56
+ verify_checkout(path, branch_name)
57
+ git.push_to_remote(path, branch_name)
58
+ else
59
+ verify_checkout(path, branch_name)
60
+
61
+ if !git.has_remote_branch(path, branch_name)
62
+ git.push_to_remote(path, branch_name)
63
+ end
64
+ end
65
+ end
66
+
67
+ def verify_checkout(path, branch_name)
68
+ Dir.chdir(path) do
69
+ p "----------cd:#{path}"
70
+ cmd = "git checkout -b #{branch_name}"
71
+ if GitOperator.new.has_branch(path, branch_name)
72
+ p "有#{branch_name}"
73
+ cmd = "git checkout #{branch_name}"
74
+ end
75
+ p "cmd:#{cmd}"
76
+ IO.popen(cmd) do |io|
77
+ io.each do |line|
78
+ Logger.error("Checkout #{branch_name} failed.") if line.include? 'error'
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ def verify_checkout_pull(path, branch_name)
85
+ GitService.new.verify_checkout(path, branch_name)
86
+ GitService.new.pull(path, branch_name)
87
+ end
88
+
89
+ def verify_special_branch(path, name)
90
+ git = GitOperator.new
91
+ p "----------检查#{name}分支"
92
+ if git.has_remote_branch(path, name)
93
+ p "--------------------有远程#{name}分支"
94
+ if git.has_local_branch(path, name)
95
+ p "------------------------------有本地#{name}分支"
96
+ if git.has_commits(path, name)
97
+ p "----------------------------------------有commits"
98
+ Logger.error(%Q('#{name}' has unpushed commits, you should fix it manually...))
99
+ end
100
+ p "------------------------------git pull"
101
+ pull(path, name)
102
+ else
103
+ p "------------------------------没有本地#{name}分支"
104
+ git.checkout(path, name)
105
+ end
106
+ else
107
+ p "--------------------没有远程#{name}分支"
108
+ verify_checkout(path, name)
109
+ git.push_to_remote(path, name)
110
+ end
111
+ end
112
+
113
+ def verify_home_branch(path, branch_name, type)
114
+
115
+ p "--------------------7.1.从远程同步本地分支"
116
+ Logger.highlight('Sync local branchs from remote, waiting...')
117
+ git = GitOperator.new
118
+ p "--------------------7.2.git fetch origin"
119
+ git.fetch(path)
120
+
121
+ if OperateType::START == type
122
+ if git.current_branch(path) == branch_name
123
+ Logger.error(%(Current branch is '#{branch_name}' already. Use 'update' please))
124
+ end
125
+ if git.has_branch(path, branch_name)
126
+ Logger.error(%(Branch '#{branch_name}' already exists. Use 'switch' please))
127
+ end
128
+ elsif OperateType::SWITCH == type
129
+ if !git.has_branch(path, branch_name)
130
+ Logger.error(%(Can't find a branch named '#{branch_name}'. Use 'start' please))
131
+ end
132
+ if git.current_branch(path) == branch_name
133
+ Logger.error(%(Current branch is '#{branch_name}' already. Use 'update' please))
134
+ end
135
+ elsif OperateType::UPDATE == type
136
+ if !git.has_branch(path, branch_name)
137
+ Logger.error(%(Can't find a branch named '#{branch_name}'. Use 'start' please))
138
+ end
139
+ if git.current_branch(path) != branch_name
140
+ Logger.error(%(Current branch is not '#{branch_name}'. Use 'switch' please))
141
+ end
142
+ else
143
+ Logger.error(%(Not a valid command for '#{branch_name}'.))
144
+ end
145
+ end
146
+
147
+ def current_branch_type(path)
148
+ branch_name = GitOperator.new.current_branch(path)
149
+ if branch_name =~ /^feature\/S*/
150
+ GitflowType::FEATURE
151
+ elsif branch_name =~ /^hotfix\/S*/
152
+ GitflowType::HOTFIX
153
+ elsif branch_name =~ /^release\/S*/
154
+ GitflowType::RELEASE
155
+ else
156
+ GitflowType::FEATURE
157
+ end
158
+ end
159
+
160
+ def branchs_with_type(path, type)
161
+ branchs = []
162
+ Dir.chdir(path) do
163
+ IO.popen('git branch -r') do | io |
164
+ io.each do | line |
165
+ branchs << line.gsub(/\s/, '') if line =~ /[\s\S]*#{GitflowType.name(type)}*/
166
+ end
167
+ end
168
+ end
169
+ branchs
170
+ end
171
+
172
+ def pull(path, branch_name)
173
+ git = GitOperator.new
174
+ current_branch_name = git.current_branch(path)
175
+
176
+ p "----------current_branch_name:#{current_branch_name}"
177
+ p "----------branch_name:#{branch_name}"
178
+ if current_branch_name == branch_name
179
+ git.pull(path)
180
+ else
181
+ git.checkout(path, branch_name)
182
+ git.pull(path)
183
+ git.checkout(path, current_branch_name)
184
+ end
185
+ end
186
+
187
+ def verify_del(path, branch_name, name, type)
188
+ git = GitOperator.new
189
+
190
+ if git.has_local_branch(path, branch_name)
191
+ Logger.highlight("Delete local branch '#{branch_name}' for '#{name}'...")
192
+
193
+ if git.current_branch(path) == branch_name
194
+ git.discard(path)
195
+ git.checkout(path, GitflowType.base_branch(type))
196
+ end
197
+ git.del_local(path, branch_name)
198
+ end
199
+
200
+ if git.has_remote_branch(path, branch_name)
201
+ Logger.highlight("Delete remote branch '#{branch_name}' for '#{name}'...")
202
+ git.del_remote(path, branch_name)
203
+ end
204
+ end
205
+
206
+ def verify_push(path, comment, branch_name, name)
207
+ git = GitOperator.new
208
+ if git.has_changes(path) || git.has_commits(path, branch_name)
209
+
210
+ git.commit(path, comment) if git.has_changes(path)
211
+
212
+ if git.has_remote_branch(path, branch_name)
213
+ Dir.chdir(path) do
214
+ `git push`
215
+ end
216
+ else
217
+ git.push_to_remote(path, branch_name)
218
+ end
219
+
220
+ GitOperator.new.check_push_success(path, branch_name, "origin/#{branch_name}")
221
+ else
222
+ Logger.default("Nothing to push for '#{name}'.")
223
+ end
224
+ end
225
+
226
+ def verify_rebase(path, branch_name, name)
227
+
228
+ # pull rebased branch
229
+ pull(path, branch_name)
230
+
231
+ Dir.chdir(path) do
232
+ IO.popen("git rebase #{branch_name} --ignore-whitespace") do |io|
233
+ unless io.gets
234
+ Logger.error("#{name} is already in a rebase-apply, Please:\n"\
235
+ " 1.Resolve it;\n"\
236
+ " 2.Commit the changes;\n"\
237
+ " 3.Push to remote;\n"\
238
+ " 4.Create a MR;\n"\
239
+ " 5.Run 'finish' again.")
240
+ end
241
+ io.each do |line|
242
+ next unless line.include? 'Merge conflict'
243
+ Logger.error("Merge conflict in #{name}, Please:\n"\
244
+ " 1.Resolve it;\n"\
245
+ " 2.Commit the changes;\n"\
246
+ " 3.Push to remote;\n"\
247
+ " 4.Create a MR;\n"\
248
+ " 5.Run 'finish' again.")
249
+ end
250
+ end
251
+ if GitOperator.new.current_branch(path) != 'develop' && GitOperator.new.current_branch(path) != 'master'
252
+ `git push -f`
253
+ else
254
+ Logger.error("You should not push 'master' or 'develop'")
255
+ end
256
+ end
257
+ end
258
+ end
259
+ end
@@ -0,0 +1,159 @@
1
+ require 'big_keeper/service/git_service'
2
+
3
+ require 'big_keeper/util/logger'
4
+ require 'big_keeper/util/cache_operator'
5
+
6
+ module BigKeeper
7
+ # Operator for got
8
+ class ModuleService
9
+
10
+ def verify_module(path, user, module_name, home_branch_name, type)
11
+ name = home_branch_name.gsub(/#{GitflowType.name(type)}\//, '')
12
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
13
+
14
+ git = GitOperator.new
15
+ if !File.exist? module_full_path
16
+ Logger.default("No local repository for module '#{module_name}', clone it...")
17
+ module_git = BigkeeperParser.module_git(module_name)
18
+ git.clone(File.expand_path("#{module_full_path}/../"), module_git)
19
+ end
20
+
21
+ current_branch_name = git.current_branch(module_full_path)
22
+ if current_branch_name != home_branch_name
23
+ # stash current branch
24
+ StashService.new.stash(module_full_path, current_branch_name, module_name)
25
+
26
+ GitService.new.start(module_full_path, name, type)
27
+
28
+ StashService.new.pop_stash(module_full_path, home_branch_name, module_name)
29
+ end
30
+ end
31
+
32
+ def push(path, user, module_name, home_branch_name, type, comment)
33
+ Logger.highlight("Push branch '#{home_branch_name}' for module '#{module_name}'...")
34
+
35
+ verify_module(path, user, module_name, home_branch_name, type)
36
+
37
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
38
+ GitService.new.verify_push(module_full_path, comment, home_branch_name, module_name)
39
+ end
40
+
41
+ def rebase(path, user, module_name, home_branch_name, type)
42
+ Logger.highlight("Rebase '#{GitflowType.base_branch(type)}' "\
43
+ "to branch '#{home_branch_name}' for module "\
44
+ "'#{module_name}'...")
45
+
46
+ verify_module(path, user, module_name, home_branch_name, type)
47
+
48
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
49
+
50
+ Logger.error("You have some changes in branch "\
51
+ "'#{home_branch_name}' for module '#{module_name}'. "\
52
+ "Use 'push' first please") if GitOperator.new.has_changes(module_full_path)
53
+
54
+ GitService.new.verify_rebase(module_full_path, GitflowType.base_branch(type), module_name)
55
+ end
56
+
57
+ def pull(path, user, module_name, home_branch_name, type)
58
+ Logger.highlight("Pull branch '#{home_branch_name}' for module '#{module_name}'...")
59
+
60
+ verify_module(path, user, module_name, home_branch_name, type)
61
+
62
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
63
+ GitOperator.new.pull(module_full_path)
64
+ end
65
+
66
+ def switch_to(path, user, module_name, home_branch_name, type)
67
+ Logger.highlight("Switch to branch '#{home_branch_name}' for module '#{module_name}'...")
68
+
69
+ verify_module(path, user, module_name, home_branch_name, type)
70
+ end
71
+
72
+ def pre_publish(path, user, module_name, home_branch_name, type)
73
+ Logger.highlight("Prepare to publish branch '#{home_branch_name}' for module '#{module_name}'...")
74
+
75
+ verify_module(path, user, module_name, home_branch_name, type)
76
+
77
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
78
+ GitService.new.verify_push(module_full_path, "prepare to rebase '#{GitflowType.base_branch(type)}'", home_branch_name, module_name)
79
+ GitService.new.verify_rebase(module_full_path, GitflowType.base_branch(type), module_name)
80
+ end
81
+
82
+ def publish(path, user, module_name, home_branch_name, type)
83
+ Logger.highlight("Publish branch '#{home_branch_name}' for module '#{module_name}'...")
84
+
85
+ DepService.dep_operator(path, user).update_module_config(module_name, ModuleOperateType::PUBLISH)
86
+
87
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
88
+ GitService.new.verify_push(module_full_path, "publish branch #{home_branch_name}", home_branch_name, module_name)
89
+
90
+ `open #{BigkeeperParser.module_pulls(module_name)}`
91
+
92
+ ModuleCacheOperator.new(path).del_git_module(module_name)
93
+ end
94
+
95
+ def finish(path, user, module_name, home_branch_name, type)
96
+ Logger.highlight("Finish branch '#{home_branch_name}' for module '#{module_name}'...")
97
+
98
+ verify_module(path, user, module_name, home_branch_name, type)
99
+
100
+ DepService.dep_operator(path, user).update_module_config(module_name, ModuleOperateType::FINISH)
101
+
102
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
103
+ GitService.new.verify_push(module_full_path, "finish branch #{home_branch_name}", home_branch_name, module_name)
104
+
105
+ ModuleCacheOperator.new(path).add_git_module(module_name)
106
+ ModuleCacheOperator.new(path).del_path_module(module_name)
107
+ end
108
+
109
+ def add(path, user, module_name, name, type)
110
+ home_branch_name = "#{GitflowType.name(type)}/#{name}"
111
+ Logger.highlight("Add branch '#{home_branch_name}' for module '#{module_name}'...")
112
+
113
+ verify_module(path, user, module_name, home_branch_name, type)
114
+
115
+ DepService.dep_operator(path, user).update_module_config(module_name, ModuleOperateType::ADD)
116
+
117
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
118
+ GitService.new.verify_push(module_full_path, "init #{GitflowType.name(type)} #{name}", home_branch_name, module_name)
119
+
120
+ ModuleCacheOperator.new(path).add_path_module(module_name)
121
+ end
122
+
123
+ def del(path, user, module_name, name, type)
124
+ home_branch_name = "#{GitflowType.name(type)}/#{name}"
125
+
126
+ Logger.highlight("Delete branch '#{home_branch_name}' for module '#{module_name}'...")
127
+
128
+ module_git = BigkeeperParser.module_git(module_name)
129
+ DepService.dep_operator(path, user).update_module_config(module_name, ModuleOperateType::DELETE)
130
+
131
+ # Stash module current branch
132
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
133
+ current_branch_name = GitOperator.new.current_branch(module_full_path)
134
+ StashService.new.stash(module_full_path, current_branch_name, module_name)
135
+ GitOperator.new.checkout(module_full_path, GitflowType.base_branch(type))
136
+
137
+ ModuleCacheOperator.new(path).del_path_module(module_name)
138
+ end
139
+
140
+ def module_info(module_path, home_branch_name, user, type, module_name, version)
141
+ result_dic = {}
142
+ matched_branches = []
143
+ branches = GitService.new.branchs_with_type(module_path, type)
144
+ if version == 'all versions'
145
+ matched_branches = branches
146
+ else
147
+ branches.each do | branch |
148
+ matched_branches << branch if branch.include?(version)
149
+ end
150
+ end
151
+ result_dic[:module_name] = module_name
152
+ result_dic[:current_branch] = GitOperator.new.current_branch(module_path)
153
+ result_dic[:branches] = matched_branches
154
+ result_dic
155
+ end
156
+
157
+ private :verify_module
158
+ end
159
+ end