raykit 0.0.543 → 0.0.544

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -21
  3. data/README.md +25 -25
  4. data/bin/raykit +6 -6
  5. data/lib/raykit/auto_setup.rb +69 -69
  6. data/lib/raykit/command.rb +374 -374
  7. data/lib/raykit/conan/buildinfo.rb +69 -69
  8. data/lib/raykit/conanpackage.rb +49 -49
  9. data/lib/raykit/configuration.rb +53 -53
  10. data/lib/raykit/console.rb +310 -310
  11. data/lib/raykit/default_content.rb +8 -8
  12. data/lib/raykit/default_content.txt +219 -219
  13. data/lib/raykit/dir.rb +127 -127
  14. data/lib/raykit/dotnet.rb +174 -174
  15. data/lib/raykit/environment.rb +115 -115
  16. data/lib/raykit/filesystem.rb +34 -34
  17. data/lib/raykit/git/commit.rb +16 -16
  18. data/lib/raykit/git/directory.rb +279 -279
  19. data/lib/raykit/git/files.rb +46 -46
  20. data/lib/raykit/git/repositories.rb +89 -89
  21. data/lib/raykit/git/repository.rb +362 -362
  22. data/lib/raykit/installer.rb +17 -17
  23. data/lib/raykit/log.rb +80 -80
  24. data/lib/raykit/logevent.rb +29 -29
  25. data/lib/raykit/logger.rb +100 -100
  26. data/lib/raykit/logging.rb +57 -57
  27. data/lib/raykit/markdown.rb +21 -21
  28. data/lib/raykit/msbuild.rb +54 -54
  29. data/lib/raykit/nugetpackage.rb +54 -54
  30. data/lib/raykit/nunit.rb +13 -13
  31. data/lib/raykit/project.rb +343 -343
  32. data/lib/raykit/rake.rb +39 -39
  33. data/lib/raykit/runner.rb +42 -42
  34. data/lib/raykit/secrets.rb +38 -38
  35. data/lib/raykit/sourceImport.rb +76 -76
  36. data/lib/raykit/sourceImports.rb +43 -43
  37. data/lib/raykit/string.rb +18 -18
  38. data/lib/raykit/symbols.rb +115 -115
  39. data/lib/raykit/tasks.rb +91 -91
  40. data/lib/raykit/text.rb +32 -32
  41. data/lib/raykit/timer.rb +31 -31
  42. data/lib/raykit/version.rb +97 -95
  43. data/lib/raykit/vstest.rb +24 -24
  44. data/lib/raykit/wix.rb +61 -61
  45. data/lib/raykit/wt.rb +28 -28
  46. data/lib/raykit/zip.rb +73 -73
  47. data/lib/raykit.rb +143 -140
  48. metadata +3 -3
@@ -1,362 +1,362 @@
1
- # frozen_string_literal: true
2
- require "uri"
3
-
4
- module Raykit
5
- module Git
6
- # Functionality to manage a remote git repository
7
- class Repository
8
- # The url of the remote repository
9
- attr_accessor :url, :latest_commit_id, :latest_commit_exit_status
10
- attr_accessor :clone_directory, :work_directory
11
-
12
- def initialize(url)
13
- if (url.nil? || url.empty?)
14
- raise "Raykit::Git::Repository::initialize(url), url is nil or empty!"
15
- end
16
- @url = url
17
- @clone_directory = Raykit::Git::Directory.new(get_dev_dir("clone"))
18
- @work_directory = Raykit::Git::Directory.new(get_dev_dir("work"))
19
- load
20
- end
21
-
22
- def filename
23
- Environment.get_dev_dir("data") + File::SEPARATOR + "repository" + File::SEPARATOR + Raykit::FileSystem::replace_invalid_chars(relative_path.gsub("/", ".").gsub("\\", ".")) + ".json"
24
- end
25
-
26
- def save
27
- # Create the config directory if it doesn't exist.
28
- dir = File.dirname(filename)
29
- FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
30
-
31
- File.write(filename, {
32
- latest_commit_id: @latest_commit_id,
33
- latest_commit_exit_status: @latest_commit_exit_status,
34
- }.to_json)
35
- end
36
-
37
- def load
38
- if (File.exist?(filename))
39
- data = JSON.parse(File.read(filename))
40
- @latest_commit_id = data["latest_commit_id"]
41
- @latest_commit_exit_status = data["latest_commit_exit_status"]
42
- end
43
- end
44
-
45
- def update
46
- @latest_commit_id = latest_commit(default_branch)
47
- if (@latest_commit_id.nil? || @latest_commit_id.empty?)
48
- cmd = get_make_command(@latest_commit_id, "rake default")
49
- if (!cmd.nil?)
50
- @latest_commit_exit_status = cmd.exitstatus
51
- end
52
- end
53
- save
54
- end
55
-
56
- def short_name()
57
- @url.split("/").last.gsub(".git", "")
58
- end
59
-
60
- def to_json(*_args)
61
- JSON.generate({ "url" => @url })
62
- end
63
-
64
- def self.parse(json)
65
- hash = JSON.parse(json)
66
- Repository.new(hash["url"])
67
- end
68
-
69
- # The relative path is a valid local path name derived from the url
70
- def relative_path
71
- Repository::get_relative_path(@url)
72
- end
73
-
74
- def self.get_relative_path(url)
75
- uri = URI.parse(url)
76
-
77
- # Remove top-level domain (e.g., ".com")
78
- if (uri.host.nil?)
79
- puts "uri.host is nil for #{url}"
80
- end
81
- host = uri.host.split(".")[0]
82
- #host.pop # remove the last element which should be the top-level domain
83
- #host = host.join(".")
84
-
85
- # Remove scheme (e.g., "http" or "https")
86
- path = host + uri.path
87
-
88
- # Remove top-level domain (e.g., ".com")
89
- #path = path.split(".")
90
- #path.pop # remove the last element which should be the top-level domain
91
- #path = path.join(".")
92
-
93
- # Remove trailing ".git" if present
94
- path = path.chomp(".git")
95
-
96
- path
97
- end
98
-
99
- def get_dev_dir(dir)
100
- dev_dir = Environment.get_dev_dir(dir)
101
- Raykit::Environment::normalize_path("#{dev_dir}/#{relative_path}")
102
- end
103
-
104
- # Clone the repository to a specific directory
105
- def clone(directory, depth = 0)
106
- if depth.zero?
107
- PROJECT.run("git clone #{@url} #{directory}")
108
- else
109
- PROJECT.run("git clone #{@url} #{directory} --depth #{depth}")
110
- end
111
- end
112
-
113
- # default branch
114
- def default_branch
115
- update_local_clone_directory
116
- if Dir.exist?(local_clone_directory)
117
- Dir.chdir(local_clone_directory) do
118
- # refs/remotes/origin/master
119
- default_branch = `git symbolic-ref refs/remotes/origin/HEAD`.split("/").last.strip
120
- return default_branch
121
- end
122
- end
123
- "main"
124
- end
125
-
126
- # The branches for the git repository
127
- def branches
128
- results = []
129
- update_local_clone_directory
130
- if Dir.exist?(local_clone_directory)
131
- Dir.chdir(local_clone_directory) do
132
- `git branch`.split('\n').each do |line|
133
- branch = line.gsub("*", "").strip
134
- results.insert(-1, branch) if branch.length.positive?
135
- end
136
- end
137
- end
138
- results
139
- end
140
-
141
- # The latest commit id for a branch of the repostiory
142
- def latest_commit(branch)
143
- if checkout_local_clone_directory_branch(branch)
144
- update_local_clone_directory
145
- Dir.chdir(local_clone_directory) do
146
- text = `git log -n 1`
147
- scan = text.scan(/commit (\w+)\s/)
148
- return scan[0][0].to_s
149
- end
150
- end
151
- ""
152
- end
153
-
154
- def latest_commit_date(branch)
155
- if checkout_local_clone_directory_branch(branch)
156
- update_local_clone_directory
157
- Dir.chdir(local_clone_directory) do
158
- text = `git log -n 1`
159
- scan = text.scan(/Date:\s+(.*)/)
160
- return scan[0][0].to_s
161
- end # Dir.chdir
162
- end # if checkout_local_clone_directory_branch
163
- ""
164
- end
165
-
166
- # The latest tag for a branch of the repository
167
- def latest_tag(branch)
168
- return `git describe --abbrev=0`.strip if checkout_local_clone_directory_branch(branch)
169
-
170
- ""
171
- end
172
-
173
- private def local_clone_directory
174
- clone_dir = Environment::normalize_path("#{Environment.get_dev_dir("clone")}/#{relative_path}")
175
- end
176
-
177
- public def update_local_clone_directory
178
- if Dir.exist?(local_clone_directory)
179
- Dir.chdir(local_clone_directory) do
180
- pull = Raykit::Command.new("git pull")
181
- pull.run
182
- pull
183
- # t = `git pull`
184
- end
185
- else
186
- PROJECT.run("git clone #{@url} #{local_clone_directory}")
187
- end
188
- end
189
-
190
- private def checkout_local_clone_directory_branch(branch)
191
- update_local_clone_directory
192
- if Dir.exist?(local_clone_directory)
193
- Dir.chdir(local_clone_directory) do
194
- check = `git branch`
195
- t = `git checkout #{branch}` unless check.include?("* #{branch}")
196
- check = `git branch`
197
- return check.include?("* #{branch}")
198
- end
199
- end
200
- false
201
- end
202
-
203
- def clobber
204
- ["work", "clone", "make"].each { |d|
205
- dir = get_dev_dir(d)
206
- if (Dir.exist?(dir))
207
- begin
208
- puts " deleting #{dir}"
209
- FileUtils.rm_rf(dir)
210
- FileUtils.rm(dir) if (Dir.exist?(dir))
211
- rescue
212
- puts " problem while deleting #{dir}"
213
- end
214
- end
215
- }
216
- end
217
-
218
- def pull
219
- Raykit::Git::Repository::work_pull(url)
220
- update_local_clone_directory
221
- end
222
-
223
- def work(command, force = false)
224
- pull if (!Dir.exist?(get_dev_dir("work")))
225
- fcommand = Raykit::FileSystem::replace_invalid_chars(command)
226
- filename = "#{Raykit::Environment::log_dir}/work_#{fcommand}_#{relative_path.gsub("/", "-")}.json"
227
- if (Raykit::Git::Directory.new(get_dev_dir("work")).outstanding_commit? || force)
228
- puts " outstanding commit in #{get_dev_dir("work")}"
229
- work_cmd = Raykit::Git::Repository::work_url(url, command)
230
- work_cmd.save_as(filename)
231
- return work_cmd
232
- else
233
- if (File.exist?(filename))
234
- return Raykit::Command::parse(IO.read(filename))
235
- else
236
- work_cmd = Raykit::Git::Repository::work_url(url, command)
237
- work_cmd.save_as(filename)
238
- update
239
- end
240
- #
241
- end
242
- end
243
-
244
- def get_make_command(commit_id, command)
245
- make_id = "make_#{relative_path.gsub("/", "-")}_#{commit_id}"
246
- fcommand = Raykit::FileSystem::replace_invalid_chars(command)
247
- filename = "#{Raykit::Environment::log_dir}/#{make_id}_#{fcommand}.json"
248
- return Raykit::Command::parse(IO.read(filename)) if (File.exist?(filename))
249
- nil
250
- end
251
-
252
- def make(command, force = false)
253
- commit_id = "#{latest_commit(default_branch)}"
254
- make_id = "make_#{relative_path.gsub("/", "-")}_#{commit_id}"
255
- fcommand = Raykit::FileSystem::replace_invalid_chars(command)
256
- filename = "#{Raykit::Environment::log_dir}/#{make_id}_#{fcommand}.json"
257
- if (!force && File.exist?(filename))
258
- return Raykit::Command::parse(IO.read(filename))
259
- else
260
- make_cmd = Raykit::Git::Repository::make_url(url, commit_id, "rake default")
261
- make_cmd.save_as(filename)
262
- update
263
- return make_cmd
264
- end
265
- end
266
-
267
- def self.work_pull(url)
268
- repo = Raykit::Git::Repository.new(url)
269
- work_dir = repo.get_dev_dir("work")
270
- repo.clone(work_dir) if !Dir.exist?(work_dir)
271
- Dir.chdir(work_dir) do
272
- run("git pull")
273
- end
274
- end
275
-
276
- def self.work_integrate(url)
277
- repo = Raykit::Git::Repository.new(url)
278
- work_dir = repo.get_dev_dir("work")
279
- repo.clone(work_dir) if !Dir.exist?(work_dir)
280
- Dir.chdir(work_dir) do
281
- run("git pull")
282
- run("rake integrate")
283
- end
284
- end
285
-
286
- def self.work_url(url, cmd)
287
- repo = Raykit::Git::Repository.new(url)
288
- puts " work #{url} #{cmd}"
289
- work_dir = repo.get_dev_dir("work")
290
- repo.clone(work_dir) if !Dir.exist?(work_dir)
291
- Dir.chdir(work_dir) do
292
- #run("git pull")
293
- cmd = Raykit::Command.new(cmd)
294
- cmd = cmd.run().summary().details()
295
- cmd
296
- end
297
- end
298
-
299
- def self.make_url(url, commit_id, command)
300
- repo = Raykit::Git::Repository.new(url)
301
- puts " make #{url} #{commit_id} #{command}"
302
- make_dir = Raykit::Environment::normalize_path(repo.get_dev_dir("make") + "/" + commit_id)
303
- FileUtils.mkdir_p(repo.get_dev_dir("make")) if !Dir.exist?(repo.get_dev_dir("make"))
304
- if (Dir.exist?(make_dir))
305
- FileUtils.rm_rf(make_dir)
306
- end
307
- run("git clone #{url} #{make_dir}")
308
- cmd = 0
309
- Dir.chdir(make_dir) do
310
- run("git reset --hard #{commit_id}")
311
- FileUtils.rm_rf(".git")
312
- cmd = Raykit::Command.new(command)
313
- cmd = cmd.run().summary()
314
- end
315
- FileUtils.rm_rf(make_dir) if (cmd.exitstatus == 0)
316
- cmd
317
- end
318
-
319
- def self.backup(url, backup_dir)
320
- if (Dir.exist?(backup_dir))
321
- Dir.chdir(backup_dir) do
322
- run("git pull")
323
- end
324
- else
325
- run("git clone #{url} \"#{backup_dir}\"")
326
- end
327
- end # def self.backup
328
-
329
- def to_s
330
- #short_name
331
- latest_commit_id = @latest_commit_id.nil? ? "" : @latest_commit_id # latest_commit(default_branch)
332
- latest_commit_exit_status = @latest_commit_exit_status.nil? ? nil : @latest_commit_exit_status # latest_commit(default_branch)
333
- symbol = Raykit::Symbols::warning
334
- symbol = Raykit::Symbols::success if (!latest_commit_exit_status.nil? && latest_commit_exit_status == 0)
335
- symbol = Raykit::Symbols::success if (!latest_commit_exit_status.nil? && latest_commit_exit_status != 0)
336
- commit = latest_commit_id[0..8]
337
- "#{symbol} #{commit} #{short_name}"
338
- end # def to_s
339
-
340
- def to_table
341
- header = "==Repository=="
342
- table = header
343
- table += "\n" + to_table_row("Name", short_name)
344
- table += "\n" + to_table_row("Url", @url)
345
- table += "\n" + to_table_row("Default Branch", default_branch)
346
- table += "\n" + to_table_row("Latest Commit", latest_commit(default_branch))
347
- table += "\n" + to_table_row("Latest Commit Date", latest_commit_date(default_branch))
348
- table += "\n" + to_table_row("Latest Commit Make", make("rake default").summary(false))
349
- table += "\n" + to_table_row("Clone Directory", local_clone_directory)
350
- table += "\n" + to_table_row("Work Directory", get_dev_dir("work"))
351
- table += "\n" + to_table_row("Latest Tag", latest_tag(default_branch))
352
- table
353
- end # def to_table
354
-
355
- def to_table_row(name, value)
356
- max_name_width = 20
357
- max_value_width = 30
358
- Rainbow(name.rjust(max_name_width, " ")).cyan + " | " + Rainbow(value).white.bold
359
- end
360
- end # class Repository
361
- end # module Git
362
- end # module Raykit
1
+ # frozen_string_literal: true
2
+ require "uri"
3
+
4
+ module Raykit
5
+ module Git
6
+ # Functionality to manage a remote git repository
7
+ class Repository
8
+ # The url of the remote repository
9
+ attr_accessor :url, :latest_commit_id, :latest_commit_exit_status
10
+ attr_accessor :clone_directory, :work_directory
11
+
12
+ def initialize(url)
13
+ if (url.nil? || url.empty?)
14
+ raise "Raykit::Git::Repository::initialize(url), url is nil or empty!"
15
+ end
16
+ @url = url
17
+ @clone_directory = Raykit::Git::Directory.new(get_dev_dir("clone"))
18
+ @work_directory = Raykit::Git::Directory.new(get_dev_dir("work"))
19
+ load
20
+ end
21
+
22
+ def filename
23
+ Environment.get_dev_dir("data") + File::SEPARATOR + "repository" + File::SEPARATOR + Raykit::FileSystem::replace_invalid_chars(relative_path.gsub("/", ".").gsub("\\", ".")) + ".json"
24
+ end
25
+
26
+ def save
27
+ # Create the config directory if it doesn't exist.
28
+ dir = File.dirname(filename)
29
+ FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
30
+
31
+ File.write(filename, {
32
+ latest_commit_id: @latest_commit_id,
33
+ latest_commit_exit_status: @latest_commit_exit_status,
34
+ }.to_json)
35
+ end
36
+
37
+ def load
38
+ if (File.exist?(filename))
39
+ data = JSON.parse(File.read(filename))
40
+ @latest_commit_id = data["latest_commit_id"]
41
+ @latest_commit_exit_status = data["latest_commit_exit_status"]
42
+ end
43
+ end
44
+
45
+ def update
46
+ @latest_commit_id = latest_commit(default_branch)
47
+ if (@latest_commit_id.nil? || @latest_commit_id.empty?)
48
+ cmd = get_make_command(@latest_commit_id, "rake default")
49
+ if (!cmd.nil?)
50
+ @latest_commit_exit_status = cmd.exitstatus
51
+ end
52
+ end
53
+ save
54
+ end
55
+
56
+ def short_name()
57
+ @url.split("/").last.gsub(".git", "")
58
+ end
59
+
60
+ def to_json(*_args)
61
+ JSON.generate({ "url" => @url })
62
+ end
63
+
64
+ def self.parse(json)
65
+ hash = JSON.parse(json)
66
+ Repository.new(hash["url"])
67
+ end
68
+
69
+ # The relative path is a valid local path name derived from the url
70
+ def relative_path
71
+ Repository::get_relative_path(@url)
72
+ end
73
+
74
+ def self.get_relative_path(url)
75
+ uri = URI.parse(url)
76
+
77
+ # Remove top-level domain (e.g., ".com")
78
+ if (uri.host.nil?)
79
+ puts "uri.host is nil for #{url}"
80
+ end
81
+ host = uri.host.split(".")[0]
82
+ #host.pop # remove the last element which should be the top-level domain
83
+ #host = host.join(".")
84
+
85
+ # Remove scheme (e.g., "http" or "https")
86
+ path = host + uri.path
87
+
88
+ # Remove top-level domain (e.g., ".com")
89
+ #path = path.split(".")
90
+ #path.pop # remove the last element which should be the top-level domain
91
+ #path = path.join(".")
92
+
93
+ # Remove trailing ".git" if present
94
+ path = path.chomp(".git")
95
+
96
+ path
97
+ end
98
+
99
+ def get_dev_dir(dir)
100
+ dev_dir = Environment.get_dev_dir(dir)
101
+ Raykit::Environment::normalize_path("#{dev_dir}/#{relative_path}")
102
+ end
103
+
104
+ # Clone the repository to a specific directory
105
+ def clone(directory, depth = 0)
106
+ if depth.zero?
107
+ PROJECT.run("git clone #{@url} #{directory}")
108
+ else
109
+ PROJECT.run("git clone #{@url} #{directory} --depth #{depth}")
110
+ end
111
+ end
112
+
113
+ # default branch
114
+ def default_branch
115
+ update_local_clone_directory
116
+ if Dir.exist?(local_clone_directory)
117
+ Dir.chdir(local_clone_directory) do
118
+ # refs/remotes/origin/master
119
+ default_branch = `git symbolic-ref refs/remotes/origin/HEAD`.split("/").last.strip
120
+ return default_branch
121
+ end
122
+ end
123
+ "main"
124
+ end
125
+
126
+ # The branches for the git repository
127
+ def branches
128
+ results = []
129
+ update_local_clone_directory
130
+ if Dir.exist?(local_clone_directory)
131
+ Dir.chdir(local_clone_directory) do
132
+ `git branch`.split('\n').each do |line|
133
+ branch = line.gsub("*", "").strip
134
+ results.insert(-1, branch) if branch.length.positive?
135
+ end
136
+ end
137
+ end
138
+ results
139
+ end
140
+
141
+ # The latest commit id for a branch of the repostiory
142
+ def latest_commit(branch)
143
+ if checkout_local_clone_directory_branch(branch)
144
+ update_local_clone_directory
145
+ Dir.chdir(local_clone_directory) do
146
+ text = `git log -n 1`
147
+ scan = text.scan(/commit (\w+)\s/)
148
+ return scan[0][0].to_s
149
+ end
150
+ end
151
+ ""
152
+ end
153
+
154
+ def latest_commit_date(branch)
155
+ if checkout_local_clone_directory_branch(branch)
156
+ update_local_clone_directory
157
+ Dir.chdir(local_clone_directory) do
158
+ text = `git log -n 1`
159
+ scan = text.scan(/Date:\s+(.*)/)
160
+ return scan[0][0].to_s
161
+ end # Dir.chdir
162
+ end # if checkout_local_clone_directory_branch
163
+ ""
164
+ end
165
+
166
+ # The latest tag for a branch of the repository
167
+ def latest_tag(branch)
168
+ return `git describe --abbrev=0`.strip if checkout_local_clone_directory_branch(branch)
169
+
170
+ ""
171
+ end
172
+
173
+ private def local_clone_directory
174
+ clone_dir = Environment::normalize_path("#{Environment.get_dev_dir("clone")}/#{relative_path}")
175
+ end
176
+
177
+ public def update_local_clone_directory
178
+ if Dir.exist?(local_clone_directory)
179
+ Dir.chdir(local_clone_directory) do
180
+ pull = Raykit::Command.new("git pull")
181
+ pull.run
182
+ pull
183
+ # t = `git pull`
184
+ end
185
+ else
186
+ PROJECT.run("git clone #{@url} #{local_clone_directory}")
187
+ end
188
+ end
189
+
190
+ private def checkout_local_clone_directory_branch(branch)
191
+ update_local_clone_directory
192
+ if Dir.exist?(local_clone_directory)
193
+ Dir.chdir(local_clone_directory) do
194
+ check = `git branch`
195
+ t = `git checkout #{branch}` unless check.include?("* #{branch}")
196
+ check = `git branch`
197
+ return check.include?("* #{branch}")
198
+ end
199
+ end
200
+ false
201
+ end
202
+
203
+ def clobber
204
+ ["work", "clone", "make"].each { |d|
205
+ dir = get_dev_dir(d)
206
+ if (Dir.exist?(dir))
207
+ begin
208
+ puts " deleting #{dir}"
209
+ FileUtils.rm_rf(dir)
210
+ FileUtils.rm(dir) if (Dir.exist?(dir))
211
+ rescue
212
+ puts " problem while deleting #{dir}"
213
+ end
214
+ end
215
+ }
216
+ end
217
+
218
+ def pull
219
+ Raykit::Git::Repository::work_pull(url)
220
+ update_local_clone_directory
221
+ end
222
+
223
+ def work(command, force = false)
224
+ pull if (!Dir.exist?(get_dev_dir("work")))
225
+ fcommand = Raykit::FileSystem::replace_invalid_chars(command)
226
+ filename = "#{Raykit::Environment::log_dir}/work_#{fcommand}_#{relative_path.gsub("/", "-")}.json"
227
+ if (Raykit::Git::Directory.new(get_dev_dir("work")).outstanding_commit? || force)
228
+ puts " outstanding commit in #{get_dev_dir("work")}"
229
+ work_cmd = Raykit::Git::Repository::work_url(url, command)
230
+ work_cmd.save_as(filename)
231
+ return work_cmd
232
+ else
233
+ if (File.exist?(filename))
234
+ return Raykit::Command::parse(IO.read(filename))
235
+ else
236
+ work_cmd = Raykit::Git::Repository::work_url(url, command)
237
+ work_cmd.save_as(filename)
238
+ update
239
+ end
240
+ #
241
+ end
242
+ end
243
+
244
+ def get_make_command(commit_id, command)
245
+ make_id = "make_#{relative_path.gsub("/", "-")}_#{commit_id}"
246
+ fcommand = Raykit::FileSystem::replace_invalid_chars(command)
247
+ filename = "#{Raykit::Environment::log_dir}/#{make_id}_#{fcommand}.json"
248
+ return Raykit::Command::parse(IO.read(filename)) if (File.exist?(filename))
249
+ nil
250
+ end
251
+
252
+ def make(command, force = false)
253
+ commit_id = "#{latest_commit(default_branch)}"
254
+ make_id = "make_#{relative_path.gsub("/", "-")}_#{commit_id}"
255
+ fcommand = Raykit::FileSystem::replace_invalid_chars(command)
256
+ filename = "#{Raykit::Environment::log_dir}/#{make_id}_#{fcommand}.json"
257
+ if (!force && File.exist?(filename))
258
+ return Raykit::Command::parse(IO.read(filename))
259
+ else
260
+ make_cmd = Raykit::Git::Repository::make_url(url, commit_id, "rake default")
261
+ make_cmd.save_as(filename)
262
+ update
263
+ return make_cmd
264
+ end
265
+ end
266
+
267
+ def self.work_pull(url)
268
+ repo = Raykit::Git::Repository.new(url)
269
+ work_dir = repo.get_dev_dir("work")
270
+ repo.clone(work_dir) if !Dir.exist?(work_dir)
271
+ Dir.chdir(work_dir) do
272
+ run("git pull")
273
+ end
274
+ end
275
+
276
+ def self.work_integrate(url)
277
+ repo = Raykit::Git::Repository.new(url)
278
+ work_dir = repo.get_dev_dir("work")
279
+ repo.clone(work_dir) if !Dir.exist?(work_dir)
280
+ Dir.chdir(work_dir) do
281
+ run("git pull")
282
+ run("rake integrate")
283
+ end
284
+ end
285
+
286
+ def self.work_url(url, cmd)
287
+ repo = Raykit::Git::Repository.new(url)
288
+ puts " work #{url} #{cmd}"
289
+ work_dir = repo.get_dev_dir("work")
290
+ repo.clone(work_dir) if !Dir.exist?(work_dir)
291
+ Dir.chdir(work_dir) do
292
+ #run("git pull")
293
+ cmd = Raykit::Command.new(cmd)
294
+ cmd = cmd.run().summary().details()
295
+ cmd
296
+ end
297
+ end
298
+
299
+ def self.make_url(url, commit_id, command)
300
+ repo = Raykit::Git::Repository.new(url)
301
+ puts " make #{url} #{commit_id} #{command}"
302
+ make_dir = Raykit::Environment::normalize_path(repo.get_dev_dir("make") + "/" + commit_id)
303
+ FileUtils.mkdir_p(repo.get_dev_dir("make")) if !Dir.exist?(repo.get_dev_dir("make"))
304
+ if (Dir.exist?(make_dir))
305
+ FileUtils.rm_rf(make_dir)
306
+ end
307
+ run("git clone #{url} #{make_dir}")
308
+ cmd = 0
309
+ Dir.chdir(make_dir) do
310
+ run("git reset --hard #{commit_id}")
311
+ FileUtils.rm_rf(".git")
312
+ cmd = Raykit::Command.new(command)
313
+ cmd = cmd.run().summary()
314
+ end
315
+ FileUtils.rm_rf(make_dir) if (cmd.exitstatus == 0)
316
+ cmd
317
+ end
318
+
319
+ def self.backup(url, backup_dir)
320
+ if (Dir.exist?(backup_dir))
321
+ Dir.chdir(backup_dir) do
322
+ run("git pull")
323
+ end
324
+ else
325
+ run("git clone #{url} \"#{backup_dir}\"")
326
+ end
327
+ end # def self.backup
328
+
329
+ def to_s
330
+ #short_name
331
+ latest_commit_id = @latest_commit_id.nil? ? "" : @latest_commit_id # latest_commit(default_branch)
332
+ latest_commit_exit_status = @latest_commit_exit_status.nil? ? nil : @latest_commit_exit_status # latest_commit(default_branch)
333
+ symbol = Raykit::Symbols::warning
334
+ symbol = Raykit::Symbols::success if (!latest_commit_exit_status.nil? && latest_commit_exit_status == 0)
335
+ symbol = Raykit::Symbols::success if (!latest_commit_exit_status.nil? && latest_commit_exit_status != 0)
336
+ commit = latest_commit_id[0..8]
337
+ "#{symbol} #{commit} #{short_name}"
338
+ end # def to_s
339
+
340
+ def to_table
341
+ header = "==Repository=="
342
+ table = header
343
+ table += "\n" + to_table_row("Name", short_name)
344
+ table += "\n" + to_table_row("Url", @url)
345
+ table += "\n" + to_table_row("Default Branch", default_branch)
346
+ table += "\n" + to_table_row("Latest Commit", latest_commit(default_branch))
347
+ table += "\n" + to_table_row("Latest Commit Date", latest_commit_date(default_branch))
348
+ table += "\n" + to_table_row("Latest Commit Make", make("rake default").summary(false))
349
+ table += "\n" + to_table_row("Clone Directory", local_clone_directory)
350
+ table += "\n" + to_table_row("Work Directory", get_dev_dir("work"))
351
+ table += "\n" + to_table_row("Latest Tag", latest_tag(default_branch))
352
+ table
353
+ end # def to_table
354
+
355
+ def to_table_row(name, value)
356
+ max_name_width = 20
357
+ max_value_width = 30
358
+ Rainbow(name.rjust(max_name_width, " ")).cyan + " | " + Rainbow(value).white.bold
359
+ end
360
+ end # class Repository
361
+ end # module Git
362
+ end # module Raykit