raykit 0.0.471 → 0.0.472
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -21
- data/README.md +20 -20
- data/bin/raykit +6 -6
- data/lib/raykit/command.rb +341 -343
- data/lib/raykit/conan/buildinfo.rb +69 -69
- data/lib/raykit/conanpackage.rb +49 -49
- data/lib/raykit/console.rb +272 -274
- data/lib/raykit/dir.rb +49 -49
- data/lib/raykit/dotnet.rb +115 -115
- data/lib/raykit/environment.rb +109 -109
- data/lib/raykit/filesystem.rb +34 -34
- data/lib/raykit/git/commit.rb +16 -16
- data/lib/raykit/git/directory.rb +216 -186
- data/lib/raykit/git/files.rb +46 -46
- data/lib/raykit/git/repositories.rb +89 -89
- data/lib/raykit/git/repository.rb +244 -244
- data/lib/raykit/installer.rb +17 -17
- data/lib/raykit/log.rb +80 -80
- data/lib/raykit/logevent.rb +49 -49
- data/lib/raykit/logging.rb +57 -59
- data/lib/raykit/markdown.rb +21 -23
- data/lib/raykit/msbuild.rb +54 -54
- data/lib/raykit/nugetpackage.rb +54 -54
- data/lib/raykit/nunit.rb +13 -13
- data/lib/raykit/project.rb +339 -340
- data/lib/raykit/rake.rb +39 -39
- data/lib/raykit/runner.rb +42 -42
- data/lib/raykit/secrets.rb +38 -38
- data/lib/raykit/sourceImport.rb +74 -74
- data/lib/raykit/sourceImports.rb +43 -43
- data/lib/raykit/string.rb +18 -18
- data/lib/raykit/tasks.rb +105 -99
- data/lib/raykit/text.rb +32 -32
- data/lib/raykit/timer.rb +31 -31
- data/lib/raykit/version.rb +103 -103
- data/lib/raykit/vstest.rb +24 -24
- data/lib/raykit/wt.rb +28 -28
- data/lib/raykit/zip.rb +73 -73
- data/lib/raykit.rb +117 -103
- metadata +2 -2
data/lib/raykit/git/directory.rb
CHANGED
@@ -1,186 +1,216 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Raykit
|
4
|
-
module Git
|
5
|
-
# Functionality to manage a local clone of a git repository
|
6
|
-
class Directory
|
7
|
-
# The directory name of the local repository clone
|
8
|
-
attr_accessor :directory
|
9
|
-
|
10
|
-
@repository
|
11
|
-
|
12
|
-
def initialize(directory)
|
13
|
-
@directory = directory
|
14
|
-
end
|
15
|
-
|
16
|
-
def outstanding_commit?
|
17
|
-
Dir.chdir(directory) do
|
18
|
-
return false if !File.exist?(".git")
|
19
|
-
if user_can_commit
|
20
|
-
return !`git status`.include?("nothing to commit,")
|
21
|
-
else
|
22
|
-
return false
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def detached?
|
28
|
-
Dir.chdir(directory) do
|
29
|
-
status = `git status`.strip
|
30
|
-
if status.include?("detached")
|
31
|
-
true
|
32
|
-
else
|
33
|
-
false
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def pull
|
39
|
-
Dir.chdir(directory) do
|
40
|
-
diff = `git diff`.strip
|
41
|
-
status = `git status`.strip
|
42
|
-
PROJECT.run("git pull", false) if diff.length.zero? && status.include?("nothing to commit")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def rake(task)
|
47
|
-
unless Dir.exist?(@directory)
|
48
|
-
puts "directory not found."
|
49
|
-
return 1
|
50
|
-
end
|
51
|
-
debug = false
|
52
|
-
sub_dir = "work"
|
53
|
-
sub_dir = "make" if @directory.include?("/make/")
|
54
|
-
rake_log = repository.get_dev_dir("log") + "/#{sub_dir}.rake.#{task}.json"
|
55
|
-
|
56
|
-
puts "log filename #{rake_log}" if debug
|
57
|
-
if File.exist?(rake_log) && (File.mtime(rake_log) > last_modified_time)
|
58
|
-
puts "using logged data" if debug
|
59
|
-
cmd = Raykit::Command.parse(File.read(rake_log))
|
60
|
-
cmd.summary
|
61
|
-
return
|
62
|
-
end
|
63
|
-
|
64
|
-
Dir.chdir(@directory) do
|
65
|
-
if File.exist?("rakefile.rb")
|
66
|
-
cmd = Raykit::Command.new("rake #{task}")
|
67
|
-
cmd.summary
|
68
|
-
FileUtils.mkdir_p(File.dirname(rake_log))
|
69
|
-
File.open(rake_log, "w") { |f| f.write(JSON.generate(cmd.to_hash)) }
|
70
|
-
else
|
71
|
-
puts "rakefile.rb not found"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def last_modified_time
|
77
|
-
Dir.chdir(@directory) do
|
78
|
-
File.mtime(Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
# git ls-tree -r master --name-only
|
83
|
-
def src_files
|
84
|
-
files = Array.new
|
85
|
-
Dir.chdir(@directory) do
|
86
|
-
`git ls-tree -r #{branch} --name-only`.each_line { |line|
|
87
|
-
file = line.strip
|
88
|
-
files << file if file.length > 0
|
89
|
-
}
|
90
|
-
end
|
91
|
-
files
|
92
|
-
end
|
93
|
-
|
94
|
-
def last_modified_src_time
|
95
|
-
Dir.chdir(@directory) do
|
96
|
-
File.mtime(src_files.select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
# The latest tag for a branch of the repository
|
101
|
-
def latest_tag(_branch)
|
102
|
-
Dir.chdir(directory) do
|
103
|
-
return `git describe --abbrev=0`.strip
|
104
|
-
end
|
105
|
-
""
|
106
|
-
end
|
107
|
-
|
108
|
-
def get_tag_commit_id(name)
|
109
|
-
cmd = Raykit::Command.new("git rev-parse \"#{name}\"").run
|
110
|
-
if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
|
111
|
-
cmd.output.strip
|
112
|
-
else
|
113
|
-
""
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def has_tag(name)
|
118
|
-
cmd = Raykit::Command.new("git rev-parse \"#{name}\"").run
|
119
|
-
if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
|
120
|
-
true
|
121
|
-
else
|
122
|
-
false
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def get_sha(filename)
|
127
|
-
if File.exist?(filename)
|
128
|
-
Digest::SHA256.file(filename).hexdigest.to_s
|
129
|
-
else
|
130
|
-
"#{filename} not found"
|
131
|
-
end
|
132
|
-
# ''
|
133
|
-
end
|
134
|
-
|
135
|
-
def user_name
|
136
|
-
`git config --get user.name`.strip
|
137
|
-
end
|
138
|
-
|
139
|
-
def user_email
|
140
|
-
`git config --get user.email`.strip
|
141
|
-
end
|
142
|
-
|
143
|
-
def user_can_commit
|
144
|
-
return false if user_name.length.zero?
|
145
|
-
return false if user_email.length.zero?
|
146
|
-
|
147
|
-
true
|
148
|
-
end
|
149
|
-
|
150
|
-
def branch
|
151
|
-
Dir.chdir(directory) do
|
152
|
-
scan = `git branch`.scan(/\*\s([\w.-]+)/)
|
153
|
-
return scan[0][0].to_s if !scan.nil? && scan.length.positive? && scan[0].length.positive?
|
154
|
-
end
|
155
|
-
"master"
|
156
|
-
end
|
157
|
-
|
158
|
-
def repository
|
159
|
-
@repository = Raykit::Git::Repository.new(remote) if @repository.nil?
|
160
|
-
@repository
|
161
|
-
end
|
162
|
-
|
163
|
-
def remote
|
164
|
-
if Dir.exist?(directory)
|
165
|
-
Dir.chdir(directory) do
|
166
|
-
return Command.new("git config --get remote.origin.url").run.output.strip if Dir.exist?(".git")
|
167
|
-
end
|
168
|
-
end
|
169
|
-
""
|
170
|
-
end
|
171
|
-
|
172
|
-
def tag_version(version)
|
173
|
-
if has_tag "v#{version}"
|
174
|
-
puts " git tag v#{version} already exists"
|
175
|
-
else
|
176
|
-
if outstanding_commit?
|
177
|
-
raise "outstanding commit, will not tag"
|
178
|
-
else
|
179
|
-
puts " git tag v#{version} does not exist"
|
180
|
-
run("git tag -a v#{version} -m\"version #{version}\"")
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
|
186
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Raykit
|
4
|
+
module Git
|
5
|
+
# Functionality to manage a local clone of a git repository
|
6
|
+
class Directory
|
7
|
+
# The directory name of the local repository clone
|
8
|
+
attr_accessor :directory
|
9
|
+
|
10
|
+
@repository
|
11
|
+
|
12
|
+
def initialize(directory)
|
13
|
+
@directory = directory
|
14
|
+
end
|
15
|
+
|
16
|
+
def outstanding_commit?
|
17
|
+
Dir.chdir(directory) do
|
18
|
+
return false if !File.exist?(".git")
|
19
|
+
if user_can_commit
|
20
|
+
return !`git status`.include?("nothing to commit,")
|
21
|
+
else
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def detached?
|
28
|
+
Dir.chdir(directory) do
|
29
|
+
status = `git status`.strip
|
30
|
+
if status.include?("detached")
|
31
|
+
true
|
32
|
+
else
|
33
|
+
false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def pull
|
39
|
+
Dir.chdir(directory) do
|
40
|
+
diff = `git diff`.strip
|
41
|
+
status = `git status`.strip
|
42
|
+
PROJECT.run("git pull", false) if diff.length.zero? && status.include?("nothing to commit")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def rake(task)
|
47
|
+
unless Dir.exist?(@directory)
|
48
|
+
puts "directory not found."
|
49
|
+
return 1
|
50
|
+
end
|
51
|
+
debug = false
|
52
|
+
sub_dir = "work"
|
53
|
+
sub_dir = "make" if @directory.include?("/make/")
|
54
|
+
rake_log = repository.get_dev_dir("log") + "/#{sub_dir}.rake.#{task}.json"
|
55
|
+
|
56
|
+
puts "log filename #{rake_log}" if debug
|
57
|
+
if File.exist?(rake_log) && (File.mtime(rake_log) > last_modified_time)
|
58
|
+
puts "using logged data" if debug
|
59
|
+
cmd = Raykit::Command.parse(File.read(rake_log))
|
60
|
+
cmd.summary
|
61
|
+
return
|
62
|
+
end
|
63
|
+
|
64
|
+
Dir.chdir(@directory) do
|
65
|
+
if File.exist?("rakefile.rb")
|
66
|
+
cmd = Raykit::Command.new("rake #{task}")
|
67
|
+
cmd.summary
|
68
|
+
FileUtils.mkdir_p(File.dirname(rake_log))
|
69
|
+
File.open(rake_log, "w") { |f| f.write(JSON.generate(cmd.to_hash)) }
|
70
|
+
else
|
71
|
+
puts "rakefile.rb not found"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def last_modified_time
|
77
|
+
Dir.chdir(@directory) do
|
78
|
+
File.mtime(Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# git ls-tree -r master --name-only
|
83
|
+
def src_files
|
84
|
+
files = Array.new
|
85
|
+
Dir.chdir(@directory) do
|
86
|
+
`git ls-tree -r #{branch} --name-only`.each_line { |line|
|
87
|
+
file = line.strip
|
88
|
+
files << file if file.length > 0
|
89
|
+
}
|
90
|
+
end
|
91
|
+
files
|
92
|
+
end
|
93
|
+
|
94
|
+
def last_modified_src_time
|
95
|
+
Dir.chdir(@directory) do
|
96
|
+
File.mtime(src_files.select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# The latest tag for a branch of the repository
|
101
|
+
def latest_tag(_branch)
|
102
|
+
Dir.chdir(directory) do
|
103
|
+
return `git describe --abbrev=0`.strip
|
104
|
+
end
|
105
|
+
""
|
106
|
+
end
|
107
|
+
|
108
|
+
def get_tag_commit_id(name)
|
109
|
+
cmd = Raykit::Command.new("git rev-parse \"#{name}\"").run
|
110
|
+
if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
|
111
|
+
cmd.output.strip
|
112
|
+
else
|
113
|
+
""
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def has_tag(name)
|
118
|
+
cmd = Raykit::Command.new("git rev-parse \"#{name}\"").run
|
119
|
+
if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
|
120
|
+
true
|
121
|
+
else
|
122
|
+
false
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def get_sha(filename)
|
127
|
+
if File.exist?(filename)
|
128
|
+
Digest::SHA256.file(filename).hexdigest.to_s
|
129
|
+
else
|
130
|
+
"#{filename} not found"
|
131
|
+
end
|
132
|
+
# ''
|
133
|
+
end
|
134
|
+
|
135
|
+
def user_name
|
136
|
+
`git config --get user.name`.strip
|
137
|
+
end
|
138
|
+
|
139
|
+
def user_email
|
140
|
+
`git config --get user.email`.strip
|
141
|
+
end
|
142
|
+
|
143
|
+
def user_can_commit
|
144
|
+
return false if user_name.length.zero?
|
145
|
+
return false if user_email.length.zero?
|
146
|
+
|
147
|
+
true
|
148
|
+
end
|
149
|
+
|
150
|
+
def branch
|
151
|
+
Dir.chdir(directory) do
|
152
|
+
scan = `git branch`.scan(/\*\s([\w.-]+)/)
|
153
|
+
return scan[0][0].to_s if !scan.nil? && scan.length.positive? && scan[0].length.positive?
|
154
|
+
end
|
155
|
+
"master"
|
156
|
+
end
|
157
|
+
|
158
|
+
def repository
|
159
|
+
@repository = Raykit::Git::Repository.new(remote) if @repository.nil?
|
160
|
+
@repository
|
161
|
+
end
|
162
|
+
|
163
|
+
def remote
|
164
|
+
if Dir.exist?(directory)
|
165
|
+
Dir.chdir(directory) do
|
166
|
+
return Command.new("git config --get remote.origin.url").run.output.strip if Dir.exist?(".git")
|
167
|
+
end
|
168
|
+
end
|
169
|
+
""
|
170
|
+
end
|
171
|
+
|
172
|
+
def tag_version(version)
|
173
|
+
if has_tag "v#{version}"
|
174
|
+
puts " git tag v#{version} already exists"
|
175
|
+
else
|
176
|
+
if outstanding_commit?
|
177
|
+
raise "outstanding commit, will not tag"
|
178
|
+
else
|
179
|
+
puts " git tag v#{version} does not exist"
|
180
|
+
run("git tag -a v#{version} -m\"version #{version}\"")
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def get_unique_ruby_constants
|
186
|
+
# Define the regular expression pattern
|
187
|
+
pattern = /\b([A-Z][A-Z0-9_]*)\b\s*=/
|
188
|
+
|
189
|
+
constants = []
|
190
|
+
|
191
|
+
# Loop through each .rb file in the specified directory
|
192
|
+
Dir.glob("#{directory}/**/*.rb").each do |file|
|
193
|
+
# Read the contents of the file
|
194
|
+
content = File.read(file)
|
195
|
+
|
196
|
+
# Scan the content for constants and add the matches to the array.
|
197
|
+
content.scan(pattern) do |match|
|
198
|
+
# Add matched constant name to the constants array.
|
199
|
+
constants << match[0]
|
200
|
+
end
|
201
|
+
# Scan the content for constants and add the matches to the array
|
202
|
+
#constants.concat(content.scan(pattern))
|
203
|
+
end
|
204
|
+
|
205
|
+
# Return unique constants
|
206
|
+
constants.uniq
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def setup
|
211
|
+
DEFAULT_SUBDIRECTORIES.each do |subdirectory|
|
212
|
+
FileUtils.mkdir_p(subdirectory)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
data/lib/raykit/git/files.rb
CHANGED
@@ -1,46 +1,46 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Raykit
|
4
|
-
module Git
|
5
|
-
# Functionality to manage a local clone of a git repository
|
6
|
-
class Files
|
7
|
-
@url
|
8
|
-
@commit_id
|
9
|
-
|
10
|
-
def initialize(url, commit_id)
|
11
|
-
@url = url
|
12
|
-
@commit_id = commit_id
|
13
|
-
end
|
14
|
-
|
15
|
-
def clean
|
16
|
-
FileUtils.rm_rf(commit_path) if Dir.exist?(commit_path)
|
17
|
-
end
|
18
|
-
|
19
|
-
def get(name)
|
20
|
-
puts "commit_path(): #{commit_path}"
|
21
|
-
unless Dir.exist?(commit_path)
|
22
|
-
puts "cloning commit path..."
|
23
|
-
clone = Raykit::Command.new("git clone #{@url} #{commit_path}")
|
24
|
-
puts clone.output
|
25
|
-
puts clone.error
|
26
|
-
Dir.chdir(commit_path) do
|
27
|
-
checkout = Raykit::Command.new("git checkout #{@commit_id}")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
return filename(name) if File.exist?(filename(name))
|
32
|
-
|
33
|
-
""
|
34
|
-
end
|
35
|
-
|
36
|
-
def commit_path
|
37
|
-
Dir.tmpdir + File::SEPARATOR + "Raykit.Git.Files" + File::SEPARATOR + @url.gsub("://",
|
38
|
-
".") + File::SEPARATOR + @commit_id
|
39
|
-
end
|
40
|
-
|
41
|
-
def filename(name)
|
42
|
-
commit_path + File::SEPARATOR + name
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Raykit
|
4
|
+
module Git
|
5
|
+
# Functionality to manage a local clone of a git repository
|
6
|
+
class Files
|
7
|
+
@url
|
8
|
+
@commit_id
|
9
|
+
|
10
|
+
def initialize(url, commit_id)
|
11
|
+
@url = url
|
12
|
+
@commit_id = commit_id
|
13
|
+
end
|
14
|
+
|
15
|
+
def clean
|
16
|
+
FileUtils.rm_rf(commit_path) if Dir.exist?(commit_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(name)
|
20
|
+
puts "commit_path(): #{commit_path}"
|
21
|
+
unless Dir.exist?(commit_path)
|
22
|
+
puts "cloning commit path..."
|
23
|
+
clone = Raykit::Command.new("git clone #{@url} #{commit_path}")
|
24
|
+
puts clone.output
|
25
|
+
puts clone.error
|
26
|
+
Dir.chdir(commit_path) do
|
27
|
+
checkout = Raykit::Command.new("git checkout #{@commit_id}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
return filename(name) if File.exist?(filename(name))
|
32
|
+
|
33
|
+
""
|
34
|
+
end
|
35
|
+
|
36
|
+
def commit_path
|
37
|
+
Dir.tmpdir + File::SEPARATOR + "Raykit.Git.Files" + File::SEPARATOR + @url.gsub("://",
|
38
|
+
".") + File::SEPARATOR + @commit_id
|
39
|
+
end
|
40
|
+
|
41
|
+
def filename(name)
|
42
|
+
commit_path + File::SEPARATOR + name
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,89 +1,89 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative("./directory")
|
4
|
-
|
5
|
-
module Raykit
|
6
|
-
module Git
|
7
|
-
# Functionality to manage a remote git repository
|
8
|
-
class Repositories < Array
|
9
|
-
attr_accessor :filename
|
10
|
-
|
11
|
-
def initialize(filename)
|
12
|
-
@filename = filename
|
13
|
-
open(@filename)
|
14
|
-
end
|
15
|
-
|
16
|
-
def open(filename)
|
17
|
-
if File.exist?(filename)
|
18
|
-
JSON.parse(File.read(filename)).each do |url|
|
19
|
-
insert(-1, url)
|
20
|
-
end
|
21
|
-
else
|
22
|
-
# puts "filename #{filename} does not exist"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def save(_filename)
|
27
|
-
File.open(@filename, "w") do |f|
|
28
|
-
f.write(JSON.pretty_generate(self))
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def work_dir
|
33
|
-
Environment.get_dev_dir("work")
|
34
|
-
end
|
35
|
-
|
36
|
-
def is_remote_url(pattern)
|
37
|
-
return true if pattern.include?("http://")
|
38
|
-
return true if pattern.include?("https://")
|
39
|
-
|
40
|
-
false
|
41
|
-
end
|
42
|
-
|
43
|
-
def remove(url)
|
44
|
-
if include?(url)
|
45
|
-
delete(url)
|
46
|
-
save(@filename)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def import(pattern)
|
51
|
-
imported = []
|
52
|
-
if is_remote_url(pattern)
|
53
|
-
remote = pattern
|
54
|
-
unless include?(remote)
|
55
|
-
insert(-1, remote)
|
56
|
-
imported.insert(-1, remote)
|
57
|
-
end
|
58
|
-
else
|
59
|
-
git_dirs = []
|
60
|
-
Dir.chdir(work_dir) do
|
61
|
-
Dir.glob("**/.git") do |git_dir|
|
62
|
-
dir = File.expand_path("..", git_dir)
|
63
|
-
git_dirs.insert(0, dir) if dir.length.positive?
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
git_dirs.each do |git_dir|
|
68
|
-
dir = Raykit::Git::Directory.new(git_dir)
|
69
|
-
remote = dir.remote
|
70
|
-
if remote.include?(pattern) && !include?(remote)
|
71
|
-
insert(-1, remote)
|
72
|
-
imported.insert(-1, remote)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
save(@filename)
|
77
|
-
imported
|
78
|
-
end
|
79
|
-
|
80
|
-
def matches(pattern)
|
81
|
-
matches = []
|
82
|
-
REPOSITORIES.each do |url|
|
83
|
-
matches << url if url.include?(pattern)
|
84
|
-
end
|
85
|
-
matches
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative("./directory")
|
4
|
+
|
5
|
+
module Raykit
|
6
|
+
module Git
|
7
|
+
# Functionality to manage a remote git repository
|
8
|
+
class Repositories < Array
|
9
|
+
attr_accessor :filename
|
10
|
+
|
11
|
+
def initialize(filename)
|
12
|
+
@filename = filename
|
13
|
+
open(@filename)
|
14
|
+
end
|
15
|
+
|
16
|
+
def open(filename)
|
17
|
+
if File.exist?(filename)
|
18
|
+
JSON.parse(File.read(filename)).each do |url|
|
19
|
+
insert(-1, url)
|
20
|
+
end
|
21
|
+
else
|
22
|
+
# puts "filename #{filename} does not exist"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def save(_filename)
|
27
|
+
File.open(@filename, "w") do |f|
|
28
|
+
f.write(JSON.pretty_generate(self))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def work_dir
|
33
|
+
Environment.get_dev_dir("work")
|
34
|
+
end
|
35
|
+
|
36
|
+
def is_remote_url(pattern)
|
37
|
+
return true if pattern.include?("http://")
|
38
|
+
return true if pattern.include?("https://")
|
39
|
+
|
40
|
+
false
|
41
|
+
end
|
42
|
+
|
43
|
+
def remove(url)
|
44
|
+
if include?(url)
|
45
|
+
delete(url)
|
46
|
+
save(@filename)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def import(pattern)
|
51
|
+
imported = []
|
52
|
+
if is_remote_url(pattern)
|
53
|
+
remote = pattern
|
54
|
+
unless include?(remote)
|
55
|
+
insert(-1, remote)
|
56
|
+
imported.insert(-1, remote)
|
57
|
+
end
|
58
|
+
else
|
59
|
+
git_dirs = []
|
60
|
+
Dir.chdir(work_dir) do
|
61
|
+
Dir.glob("**/.git") do |git_dir|
|
62
|
+
dir = File.expand_path("..", git_dir)
|
63
|
+
git_dirs.insert(0, dir) if dir.length.positive?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
git_dirs.each do |git_dir|
|
68
|
+
dir = Raykit::Git::Directory.new(git_dir)
|
69
|
+
remote = dir.remote
|
70
|
+
if remote.include?(pattern) && !include?(remote)
|
71
|
+
insert(-1, remote)
|
72
|
+
imported.insert(-1, remote)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
save(@filename)
|
77
|
+
imported
|
78
|
+
end
|
79
|
+
|
80
|
+
def matches(pattern)
|
81
|
+
matches = []
|
82
|
+
REPOSITORIES.each do |url|
|
83
|
+
matches << url if url.include?(pattern)
|
84
|
+
end
|
85
|
+
matches
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|