monos 0.4.0 → 1.0.2

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: 17e75b31f208961c34bd615af15547d1ebe2f0ba
4
- data.tar.gz: 150a65ae3b0296acd3659732193377f4552ad1f9
3
+ metadata.gz: 9c0413c2258822899cb73e090438d21f3ea82fc5
4
+ data.tar.gz: a9cd0ddc80ea90a8c7cdbafc7a917eeabadb5b8f
5
5
  SHA512:
6
- metadata.gz: 17b55bd1201b91de073dd1e06fc35834231f0a0092fae88c9a6fbcf9f321127e77fb459786e5ba517508fbe66d8ee04f0d4a14ff6c9099be21fdc1124a16cbbc
7
- data.tar.gz: ac18e206c095d17a2586a7c7d6da30017010fa9aba2ff73be58b265be548bbb5712676ff482560d45d9a3a261b450e1cd86f3f15ae2a337dbb11836c8850819f
6
+ metadata.gz: bc5c4b2083a234faded31cc4bdad78068709c8d7f6aa0e4a21fa1eb0c276f9ba6d6b34fe77b3fcafac9f6024701536337563b5b9d1b7d7b1fa026f045592c3ac
7
+ data.tar.gz: db404f05b726c7d233996dca624e6e3bc9cfb204d721ca9ee43be701ea2f658d4a0f03233524aa1d4e7b70c218052ea05cf67f347185063cdb5d53b9e106ddb9
@@ -12,9 +12,10 @@ lib/mono/commands/fetch.rb
12
12
  lib/mono/commands/run.rb
13
13
  lib/mono/commands/status.rb
14
14
  lib/mono/commands/sync.rb
15
+ lib/mono/experimental.rb
15
16
  lib/mono/tool.rb
16
17
  lib/mono/version.rb
17
18
  lib/monos.rb
18
- lib/sportdb/setup.rb
19
19
  test/helper.rb
20
20
  test/test_base.rb
21
+ test/test_path.rb
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # monos - monorepo / mono source tree tools and (startup) scripts
2
2
 
3
3
 
4
- * home :: [github.com/rubycoco/monos](https://github.com/rubycoco/monos)
5
- * bugs :: [github.com/rubycoco/monos/issues](https://github.com/rubycoco/monos/issues)
4
+ * home :: [github.com/rubycoco/git](https://github.com/rubycoco/git)
5
+ * bugs :: [github.com/rubycoco/git/issues](https://github.com/rubycoco/git/issues)
6
6
  * gem :: [rubygems.org/gems/monos](https://rubygems.org/gems/monos)
7
7
  * rdoc :: [rubydoc.info/gems/monos](http://rubydoc.info/gems/monos)
8
8
  * forum :: [opensport](http://groups.google.com/group/opensport)
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ Hoe.spec 'monos' do
8
8
  self.summary = "monos - monorepo / mono source tree tools and (startup) scripts"
9
9
  self.description = summary
10
10
 
11
- self.urls = { home: 'https://github.com/rubycoco/monos' }
11
+ self.urls = { home: 'https://github.com/rubycoco/git' }
12
12
 
13
13
  self.author = 'Gerald Bauer'
14
14
  self.email = 'opensport@googlegroups.com'
@@ -20,7 +20,7 @@ Hoe.spec 'monos' do
20
20
  self.licenses = ['Public Domain']
21
21
 
22
22
  self.extra_deps = [
23
- ['gitti', '>= 0.4.0' ],
23
+ ['gitti', '>= 0.6.1' ],
24
24
  ['gitti-backup', '>= 0.4.1' ],
25
25
  ]
26
26
 
@@ -18,8 +18,9 @@ end
18
18
 
19
19
  ###
20
20
  # our own code
21
- require 'mono/version' # let version always go first
21
+ require 'mono/version' # let version always go first
22
22
  require 'mono/base'
23
+ require 'mono/experimental'
23
24
 
24
25
  require 'mono/commands/status'
25
26
  require 'mono/commands/fetch'
@@ -30,5 +31,4 @@ require 'mono/commands/run'
30
31
  require 'mono/tool'
31
32
 
32
33
 
33
-
34
34
  puts MonoCore.banner # say hello
@@ -1,40 +1,160 @@
1
-
2
- module Mono
3
-
4
- def self.root ## root of single (monorepo) source tree
5
- @@root ||= begin
6
- ## todo/fix:
7
- ## check if windows - otherwise use /sites
8
- ## check if root directory exists?
9
- if ENV['MOPATH']
10
- ENV['MOPATH']
11
- elsif Dir.exist?( 'C:/Sites' )
12
- 'C:/Sites'
13
- else
14
- '/sites'
15
- end
16
- end
17
- end
18
-
19
- def self.monofile
20
- path = if File.exist?( './monorepo.yml' )
21
- './monorepo.yml'
22
- elsif File.exist?( './monotree.yml' )
23
- './monotree.yml'
24
- elsif File.exist?( './repos.yml' )
25
- './repos.yml'
26
- else
27
- puts "!! WARN: no mono configuration file (that is, {monorepo,monotree,repos}.yml) found in >#{Dir.getwd}<"
28
- nil
29
- end
30
-
31
- if path
32
- GitRepoSet.read( path )
33
- else
34
- GitRepoSet.new( {} ) ## return empty set -todo/check: return nil - why? why not?
35
- end
36
- end
37
-
38
- end ## module Mono
39
-
40
-
1
+
2
+ module Mono
3
+
4
+ def self.root ## root of single (monorepo) source tree
5
+ @@root ||= begin
6
+ ## todo/fix:
7
+ ## check if windows - otherwise use /sites
8
+ ## check if root directory exists?
9
+ if ENV['MOPATH']
10
+ ## use expand path to make (assure) absolute path - why? why not?
11
+ File.expand_path( ENV['MOPATH'] )
12
+ elsif Dir.exist?( 'C:/Sites' )
13
+ 'C:/Sites'
14
+ else
15
+ '/sites'
16
+ end
17
+ end
18
+ end
19
+
20
+ def self.root=( path )
21
+ ## use expand path to make (assure) absolute path - why? why not?
22
+ @@root = File.expand_path( path )
23
+ end
24
+
25
+
26
+
27
+
28
+ MONOFILES = ['monorepo.yml', 'monotree.yml', 'repos.yml']
29
+
30
+ def self.find_monofile
31
+ MONOFILES.each do |name|
32
+ return "./#{name}" if File.exist?( "./#{name}")
33
+ end
34
+
35
+ nil ## no monofile found; return nil
36
+ end
37
+
38
+ def self.monofile
39
+ path = find_monofile
40
+
41
+ if path
42
+ GitRepoSet.read( path )
43
+ else
44
+ puts "!! WARN: no mono configuration file found; looking for #{MONOFILES.join(', ')} in (#{Dir.getwd})"
45
+ GitRepoSet.new( {} ) ## return empty set -todo/check: return nil - why? why not?
46
+ end
47
+ end
48
+ end ## module Mono
49
+
50
+
51
+
52
+
53
+ #####################
54
+ # add file and repo helper
55
+
56
+ ##
57
+ ## todo/fix: ALWAYS assert name format
58
+ ## (rename to mononame and monopath) - why? why not?
59
+
60
+ class MonoGitHub
61
+ def self.clone( name, depth: nil )
62
+ ## lets you use:
63
+ ## @rubycoco/gitti or
64
+ ## gitti@rubycoco
65
+ ## => rubycoco/gitti
66
+ norm_name = MonoFile.norm_name( name )
67
+ path = "#{Mono.root}/#{norm_name}"
68
+
69
+ org_path = File.dirname( path )
70
+ FileUtils.mkdir_p( org_path ) unless Dir.exist?( org_path ) ## make sure path exists
71
+
72
+ ### note: use a github clone url (using ssh) like:
73
+ ## git@github.com:rubycoco/gitti.git
74
+ ssh_clone_url = "git@github.com:#{norm_name}.git"
75
+
76
+ Dir.chdir( org_path ) do
77
+ Gitti::Git.clone( ssh_clone_url, depth: depth )
78
+ end
79
+ end
80
+ end
81
+ MonoGithub = MonoGitHub ## add convenience (typo?) alias
82
+
83
+
84
+
85
+ class MonoGitProject
86
+ def self.open( name, &block )
87
+ path = MonoFile.real_path( name )
88
+ Gitti::GitProject.open( path, &block )
89
+ end
90
+ end
91
+
92
+
93
+
94
+ class MonoFile
95
+ ## e.g. openfootball/austria etc.
96
+ ## expand to to "real" absolute path
97
+ ##
98
+ ## todo/check: assert name must be {orgname,username}/reponame
99
+ def self.real_path( path )
100
+ "#{Mono.root}/#{norm_name( path )}"
101
+ end
102
+
103
+ def self.norm_name( path )
104
+ # turn
105
+ # - @yorobot/stage/one
106
+ # - one@yorobot/stage
107
+ # - stage/one@yorobot
108
+ # => into
109
+ # - yorobot/stage/one
110
+
111
+
112
+ parts = path.split( '@' )
113
+ raise ArgumentError, "no (required) @ found in name; got >#{path}<" if parts.size == 1
114
+ raise ArgumentError, "too many @ found (#{parts.size-1}) in name; got >#{path}<" if parts.size > 2
115
+
116
+ norm_name = String.new('')
117
+ norm_name << parts[1] ## add orgs path first
118
+ if parts[0].length > 0 ## has leading repo name (w/ optional path)
119
+ norm_name << '/'
120
+ norm_name << parts[0]
121
+ end
122
+ norm_name
123
+ end
124
+
125
+ def self.exist?( path )
126
+ File.exist?( real_path( path ))
127
+ end
128
+
129
+
130
+ ## path always relative to Mono.root
131
+ ## todo/fix: use File.expand_path( path, Mono.root ) - why? why not?
132
+ ## or always enfore "absolut" path e.g. do NOT allow ../ or ./ or such
133
+ def self.open( path, mode='r:utf-8', &block )
134
+ full_path = real_path( path )
135
+ ## make sure path exists if we open for writing/appending - why? why not?
136
+ if mode[0] == 'w' || mode[0] == 'a'
137
+ FileUtils.mkdir_p( File.dirname( full_path ) ) ## make sure path exists
138
+ end
139
+
140
+ File.open( full_path, mode ) do |file|
141
+ block.call( file )
142
+ end
143
+ end
144
+
145
+ def self.read_utf8( path )
146
+ open( path, 'r:utf-8') { |file| file.read }
147
+ end
148
+ end ## class MonoFile
149
+
150
+
151
+
152
+ module Mono
153
+ #################
154
+ ## add some short cuts
155
+ def self.open( name, &block ) MonoGitProject.open( name, &block ); end
156
+ def self.clone( name, depth: nil ) MonoGitHub.clone( name, depth: depth ); end
157
+ def self.real_path( name ) MonoFile.real_path( name ); end
158
+ end ## module Mono
159
+
160
+
@@ -1,15 +1,15 @@
1
- module Mono
2
-
3
- ## pass along hash of repos (e.g. monorepo.yml or repos.yml )
4
- def self.backup
5
- repos = Mono.monofile
6
-
7
- backup = GitBackup.new
8
-
9
- ## step 2: pass in all repos to backup by using
10
- ## 1) git clone --mirror or
11
- ## 2) git remote update (if local backup already exists)
12
- backup.backup( repos )
13
- end # method backup
14
-
15
- end # module Mono
1
+ module Mono
2
+
3
+ ## pass along hash of repos (e.g. monorepo.yml or repos.yml )
4
+ def self.backup
5
+ repos = Mono.monofile
6
+
7
+ backup = GitBackup.new
8
+
9
+ ## step 2: pass in all repos to backup by using
10
+ ## 1) git clone --mirror or
11
+ ## 2) git remote update (if local backup already exists)
12
+ backup.backup( repos )
13
+ end # method backup
14
+
15
+ end # module Mono
@@ -1,26 +1,26 @@
1
- module Mono
2
-
3
- def self.env ## check environment setup
4
- puts "Mono.root (MOPATH): >#{Mono.root}<"
5
- puts "MonoCore.root: >#{MonoCore.root}<"
6
- puts
7
-
8
- ## add ruby version and path - why? why not? e.g.
9
- ## ruby:
10
- ## bin: C:/ri330/Ruby2.0.0/bin/ruby.exe
11
- ## version: ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
12
-
13
- puts "git version:"
14
- Git.version
15
- ## Git.config( 'user.name' )
16
- ## Git.config( 'user.email', show_origin: true )
17
-
18
- ## dump/print all user.* settings e.g. user.name, user.email
19
- Git.config( /user/, show_origin: true )
20
-
21
- puts
22
- puts "monorepo.yml:"
23
- pp Mono.monofile
24
- end
25
-
26
- end # module Mono
1
+ module Mono
2
+
3
+ def self.env ## check environment setup
4
+ puts "Mono.root (MOPATH): >#{Mono.root}<"
5
+ puts "MonoCore.root: >#{MonoCore.root}<"
6
+ puts
7
+
8
+ ## add ruby version and path - why? why not? e.g.
9
+ ## ruby:
10
+ ## bin: C:/ri330/Ruby2.0.0/bin/ruby.exe
11
+ ## version: ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
12
+
13
+ puts "git version:"
14
+ Git.version
15
+ ## Git.config( 'user.name' )
16
+ ## Git.config( 'user.email', show_origin: true )
17
+
18
+ ## dump/print all user.* settings e.g. user.name, user.email
19
+ Git.config( /user/, show_origin: true )
20
+
21
+ puts
22
+ puts "monorepo.yml:"
23
+ pp Mono.monofile
24
+ end
25
+
26
+ end # module Mono
@@ -1,44 +1,43 @@
1
- module Mono
2
-
3
- ## pass along hash of repos (e.g. monorepo.yml or repos.yml )
4
- def self.fetch
5
- repos = Mono.monofile
6
-
7
- count_orgs = 0
8
- count_repos = 0
9
-
10
- total_repos = repos.size
11
-
12
-
13
- repos.each do |org,names|
14
-
15
- org_path = "#{Mono.root}/#{org}"
16
-
17
- names.each do |name|
18
- puts "[#{count_repos+1}/#{total_repos}] #{org}@#{name}..."
19
-
20
- repo = GitHubRepo.new( org, name ) ## owner, name e.g. rubylibs/webservice
21
-
22
- Dir.chdir( org_path ) do
23
- if Dir.exist?( repo.name )
24
- GitProject.open( repo.name ) do |proj|
25
- proj.fetch
26
- end
27
- else
28
- puts "!! repo not found / missing"
29
- end
30
- end
31
-
32
- count_repos += 1
33
- end
34
- count_orgs += 1
35
- end
36
-
37
-
38
- ## print stats & changes summary
39
- puts
40
- print "#{count_repos} repo(s) @ #{count_orgs} org(s)"
41
- print "\n"
42
- end # method fetch
43
-
44
- end # module Mono
1
+ module Mono
2
+ ## pass along hash of repos (e.g. monorepo.yml or repos.yml )
3
+ def self.fetch
4
+ repos = Mono.monofile
5
+
6
+ count_orgs = 0
7
+ count_repos = 0
8
+
9
+ total_repos = repos.size
10
+
11
+
12
+ repos.each do |org,names|
13
+
14
+ org_path = "#{Mono.root}/#{org}"
15
+
16
+ names.each do |name|
17
+ puts "[#{count_repos+1}/#{total_repos}] #{org}@#{name}..."
18
+
19
+ repo = GitHubRepo.new( org, name ) ## owner, name e.g. rubylibs/webservice
20
+
21
+ Dir.chdir( org_path ) do
22
+ if Dir.exist?( repo.name )
23
+ GitProject.open( repo.name ) do |proj|
24
+ proj.fetch
25
+ end
26
+ else
27
+ puts "!! repo not found / missing"
28
+ end
29
+ end
30
+
31
+ count_repos += 1
32
+ end
33
+ count_orgs += 1
34
+ end
35
+
36
+
37
+ ## print stats & changes summary
38
+ puts
39
+ print "#{count_repos} repo(s) @ #{count_orgs} org(s)"
40
+ print "\n"
41
+ end # method fetch
42
+
43
+ end # module Mono
@@ -1,47 +1,47 @@
1
- module Mono
2
-
3
- def self.run( *args )
4
- ## todo/fix: use a "standard" argument to pass along hash of repos
5
- ## (e.g. monorepo.yml or repos.yml ) how? - why? why not?
6
- repos = Mono.monofile
7
-
8
-
9
- cmd = args.join( ' ' )
10
-
11
- count_orgs = 0
12
- count_repos = 0
13
-
14
- total_repos = repos.size
15
-
16
- repos.each do |org,names|
17
-
18
- org_path = "#{Mono.root}/#{org}"
19
-
20
- names.each do |name|
21
- puts "[#{count_repos+1}/#{total_repos}] #{org}@#{name}..."
22
-
23
- repo = GitHubRepo.new( org, name ) ## owner, name e.g. rubylibs/webservice
24
-
25
- Dir.chdir( org_path ) do
26
- if Dir.exist?( repo.name )
27
- GitProject.open( repo.name ) do |proj|
28
- proj.run( cmd )
29
- end
30
- else
31
- puts "!! repo not found / missing"
32
- end
33
- end
34
-
35
- count_repos += 1
36
- end
37
- count_orgs += 1
38
- end
39
-
40
-
41
- ## print stats & changes summary
42
- puts
43
- print "#{count_repos} repo(s) @ #{count_orgs} org(s)"
44
- print "\n"
45
- end # method run
46
-
47
- end # module Mono
1
+ module Mono
2
+
3
+ def self.run( *args )
4
+ ## todo/fix: use a "standard" argument to pass along hash of repos
5
+ ## (e.g. monorepo.yml or repos.yml ) how? - why? why not?
6
+ repos = Mono.monofile
7
+
8
+
9
+ cmd = args.join( ' ' )
10
+
11
+ count_orgs = 0
12
+ count_repos = 0
13
+
14
+ total_repos = repos.size
15
+
16
+ repos.each do |org,names|
17
+
18
+ org_path = "#{Mono.root}/#{org}"
19
+
20
+ names.each do |name|
21
+ puts "[#{count_repos+1}/#{total_repos}] #{org}@#{name}..."
22
+
23
+ repo = GitHubRepo.new( org, name ) ## owner, name e.g. rubylibs/webservice
24
+
25
+ Dir.chdir( org_path ) do
26
+ if Dir.exist?( repo.name )
27
+ GitProject.open( repo.name ) do |proj|
28
+ proj.run( cmd )
29
+ end
30
+ else
31
+ puts "!! repo not found / missing"
32
+ end
33
+ end
34
+
35
+ count_repos += 1
36
+ end
37
+ count_orgs += 1
38
+ end
39
+
40
+
41
+ ## print stats & changes summary
42
+ puts
43
+ print "#{count_repos} repo(s) @ #{count_orgs} org(s)"
44
+ print "\n"
45
+ end # method run
46
+
47
+ end # module Mono
@@ -1,65 +1,65 @@
1
- module Mono
2
-
3
- ## pass along hash of repos (e.g. monorepo.yml or repos.yml )
4
- def self.status
5
- repos = Mono.monofile
6
-
7
- changes = [] ## track changes
8
-
9
- count_orgs = 0
10
- count_repos = 0
11
-
12
- total_repos = repos.size
13
-
14
- repos.each do |org,names|
15
-
16
- org_path = "#{Mono.root}/#{org}"
17
-
18
- names.each do |name|
19
- puts "[#{count_repos+1}/#{total_repos}] #{org}@#{name}..."
20
-
21
- repo = GitHubRepo.new( org, name ) ## owner, name e.g. rubylibs/webservice
22
-
23
- Dir.chdir( org_path ) do
24
- if Dir.exist?( repo.name )
25
- GitProject.open( repo.name ) do |proj|
26
- output = proj.changes
27
- if output.empty?
28
- puts " - no changes -"
29
- else
30
- changes << ["#{org}@#{name}", :CHANGES, output]
31
- end
32
- end
33
- else
34
- puts "!! repo not found / missing"
35
- changes << ["#{org}@#{name}", :NOT_FOUND]
36
- end
37
- end
38
-
39
- count_repos += 1
40
- end
41
- count_orgs += 1
42
- end
43
-
44
-
45
- ## print stats & changes summary
46
- puts
47
- print "#{changes.size} change(s) in "
48
- print "#{count_repos} repo(s) @ #{count_orgs} org(s)"
49
- print "\n"
50
-
51
- changes.each do |item|
52
- puts
53
- print "== #{item[0]} - #{item[1]}"
54
- case item[1]
55
- when :CHANGES
56
- print ":\n"
57
- print item[2]
58
- when :NOT_FOUND
59
- print "\n"
60
- end
61
- end
62
-
63
- end # method status
64
-
65
- end # module Mono
1
+ module Mono
2
+
3
+ ## pass along hash of repos (e.g. monorepo.yml or repos.yml )
4
+ def self.status
5
+ repos = Mono.monofile
6
+
7
+ changes = [] ## track changes
8
+
9
+ count_orgs = 0
10
+ count_repos = 0
11
+
12
+ total_repos = repos.size
13
+
14
+ repos.each do |org,names|
15
+
16
+ org_path = "#{Mono.root}/#{org}"
17
+
18
+ names.each do |name|
19
+ puts "[#{count_repos+1}/#{total_repos}] #{org}@#{name}..."
20
+
21
+ repo = GitHubRepo.new( org, name ) ## owner, name e.g. rubylibs/webservice
22
+
23
+ Dir.chdir( org_path ) do
24
+ if Dir.exist?( repo.name )
25
+ GitProject.open( repo.name ) do |proj|
26
+ output = proj.changes
27
+ if output.empty?
28
+ puts " - no changes -"
29
+ else
30
+ changes << ["#{org}@#{name}", :CHANGES, output]
31
+ end
32
+ end
33
+ else
34
+ puts "!! repo not found / missing"
35
+ changes << ["#{org}@#{name}", :NOT_FOUND]
36
+ end
37
+ end
38
+
39
+ count_repos += 1
40
+ end
41
+ count_orgs += 1
42
+ end
43
+
44
+
45
+ ## print stats & changes summary
46
+ puts
47
+ print "#{changes.size} change(s) in "
48
+ print "#{count_repos} repo(s) @ #{count_orgs} org(s)"
49
+ print "\n"
50
+
51
+ changes.each do |item|
52
+ puts
53
+ print "== #{item[0]} - #{item[1]}"
54
+ case item[1]
55
+ when :CHANGES
56
+ print ":\n"
57
+ print item[2]
58
+ when :NOT_FOUND
59
+ print "\n"
60
+ end
61
+ end
62
+
63
+ end # method status
64
+
65
+ end # module Mono
@@ -1,53 +1,53 @@
1
- module Mono
2
-
3
- ## pass along hash of repos (e.g. monorepo.yml or repos.yml )
4
- def self.sync
5
- repos = Mono.monofile
6
-
7
- count_orgs = 0
8
- count_repos = 0
9
-
10
- total_repos = repos.size
11
-
12
- repos.each do |org,names|
13
- org_path = "#{Mono.root}/#{org}"
14
- FileUtils.mkdir_p( org_path ) unless Dir.exist?( org_path ) ## make sure path exists
15
-
16
- names.each do |name|
17
- puts "[#{count_repos+1}/#{total_repos}] #{org}@#{name}..."
18
-
19
- repo = GitHubRepo.new( org, name ) ## owner, name e.g. rubylibs/webservice
20
-
21
- Dir.chdir( org_path ) do
22
- if Dir.exist?( repo.name )
23
- GitProject.open( repo.name ) do |proj|
24
- if proj.changes?
25
- puts "!! WARN - local changes in workdir; skipping fast forward (remote) sync / merge"
26
- else
27
- proj.fast_forward ## note: use git pull --ff-only (fast forward only - do NOT merge)
28
- end
29
- end
30
- else
31
- Git.clone( repo.ssh_clone_url )
32
- end
33
- end
34
-
35
- #
36
- # todo/fix: add (back) error log !!!!!!!!!!!!
37
- # rescue GitError => ex
38
- # puts "!! ERROR: #{ex.message}"
39
- #
40
- # File.open( './errors.log', 'a' ) do |f|
41
- # f.write "#{Time.now} -- repo #{org}/#{name} - #{ex.message}\n"
42
- # end
43
-
44
- count_repos += 1
45
- end
46
- count_orgs += 1
47
- end
48
-
49
- ## print stats
50
- puts "#{count_repos} repo(s) @ #{count_orgs} org(s)"
51
- end # method sync
52
-
53
- end # module Mono
1
+ module Mono
2
+
3
+ ## pass along hash of repos (e.g. monorepo.yml or repos.yml )
4
+ def self.sync
5
+ repos = Mono.monofile
6
+
7
+ count_orgs = 0
8
+ count_repos = 0
9
+
10
+ total_repos = repos.size
11
+
12
+ repos.each do |org,names|
13
+ org_path = "#{Mono.root}/#{org}"
14
+ FileUtils.mkdir_p( org_path ) unless Dir.exist?( org_path ) ## make sure path exists
15
+
16
+ names.each do |name|
17
+ puts "[#{count_repos+1}/#{total_repos}] #{org}@#{name}..."
18
+
19
+ repo = GitHubRepo.new( org, name ) ## owner, name e.g. rubylibs/webservice
20
+
21
+ Dir.chdir( org_path ) do
22
+ if Dir.exist?( repo.name )
23
+ GitProject.open( repo.name ) do |proj|
24
+ if proj.changes?
25
+ puts "!! WARN - local changes in workdir; skipping fast forward (remote) sync / merge"
26
+ else
27
+ proj.fast_forward ## note: use git pull --ff-only (fast forward only - do NOT merge)
28
+ end
29
+ end
30
+ else
31
+ Git.clone( repo.ssh_clone_url )
32
+ end
33
+ end
34
+
35
+ #
36
+ # todo/fix: add (back) error log !!!!!!!!!!!!
37
+ # rescue GitError => ex
38
+ # puts "!! ERROR: #{ex.message}"
39
+ #
40
+ # File.open( './errors.log', 'a' ) do |f|
41
+ # f.write "#{Time.now} -- repo #{org}/#{name} - #{ex.message}\n"
42
+ # end
43
+
44
+ count_repos += 1
45
+ end
46
+ count_orgs += 1
47
+ end
48
+
49
+ ## print stats
50
+ puts "#{count_repos} repo(s) @ #{count_orgs} org(s)"
51
+ end # method sync
52
+
53
+ end # module Mono
@@ -0,0 +1,104 @@
1
+ ##############
2
+ # experimental stuff
3
+ #
4
+
5
+ module Mono
6
+
7
+ ######################
8
+ ### lint/print mono (source) tree
9
+ ### - check for git repos (via .git/ dir)
10
+ #
11
+ # turn into
12
+ # - tree or
13
+ # - lint or
14
+ # - doctor or
15
+ # - check or such command - why? why not?
16
+ def self.walk( path=root)
17
+ repos = walk_dir( path )
18
+ repos
19
+ end
20
+
21
+
22
+ ###############
23
+ # private helpers
24
+ private
25
+
26
+ ## todo/check - use max_depth or max_level or such - why? why not?
27
+ def self.walk_dir( path, repos=[], level=1, depth: nil )
28
+ entries = Dir.entries(path)
29
+
30
+ ## filter dirs
31
+ dirs = entries.select do |entry|
32
+ if ['..', '.'].include?( entry ) ## first check for excludes
33
+ false
34
+ else
35
+ full_path = File.join( path, entry )
36
+ File.directory?( full_path )
37
+ end
38
+ end
39
+
40
+ if dirs.size == 0 ## shortcircuit - no dirs in dir
41
+ return repos
42
+ end
43
+
44
+ repos_count = 0 ## note: local (only) repos count
45
+ warns_count = 0
46
+ sub_dirs = []
47
+
48
+
49
+
50
+ buf = String.new('') ## use an output buffer (allows optional print)
51
+
52
+
53
+ buf << ">#{path}< - level #{level}:\n"
54
+ dirs.each do |entry|
55
+ next if ['..', '.', '.git'].include?( entry )
56
+ full_path = File.join( path, entry )
57
+
58
+ if Dir.exist?( File.join( full_path, '.git' ))
59
+ repos_count += 1
60
+
61
+ if level == 1
62
+ warns_count += 1
63
+ buf << "!! WARN - top-level repo (w/o user/org) >#{entry}< @ #{path}\n"
64
+ end
65
+
66
+ if level > 2
67
+ warns_count += 1
68
+ buf << "!! WARN - hidden (?) sub-level #{level} repo (nested too deep?) >#{entry}< @ #{path}\n"
69
+ end
70
+
71
+ buf << " repo ##{'%-2d' % repos_count} | "
72
+ buf << "#{'%-20s' % entry} @ #{File.basename(path)} (#{path})"
73
+ buf << "\n"
74
+ repos << full_path
75
+
76
+ ## check for bare bone git repos - todo/fix: add .gitconfig or such and more - why? why not?
77
+ elsif Dir.exist?( File.join( full_path, 'hooks' )) &&
78
+ Dir.exist?( File.join( full_path, 'info' )) &&
79
+ Dir.exist?( File.join( full_path, 'objects' )) &&
80
+ Dir.exist?( File.join( full_path, 'refs' ))
81
+ warns_count += 1
82
+ buf << "!! WARN - skip bare git repo >#{entry}< @ #{path}\n"
83
+ else
84
+ buf << " x >#{entry}<\n"
85
+ sub_dirs << entry
86
+ end
87
+ end
88
+ buf << " #{repos_count} repos(s), #{dirs.size} dir(s), #{warns_count} warn(s)\n"
89
+ buf << "\n"
90
+
91
+ ## note: skip output of "plain" diretory listings (no repos, no warnings)
92
+ puts buf if repos_count > 0 || warns_count > 0
93
+
94
+
95
+ sub_dirs.each do |entry|
96
+ ## continue walking
97
+ full_path = File.join( path, entry )
98
+ walk_dir( full_path, repos, level+1, depth: depth )
99
+ end
100
+
101
+ repos
102
+ end
103
+
104
+ end # module Mono
@@ -1,41 +1,46 @@
1
- module Mono
2
-
3
-
4
- class Tool
5
- def self.main( args=ARGV )
6
-
7
- ## note: for now assume first argument is command
8
- ## add options later
9
-
10
- cmd = if args.size == 0
11
- 'status' ## make status "default" command
12
- else
13
- args.shift ## remove first (head) element
14
- end
15
-
16
- ## note: allow shortcut for commands
17
- case cmd.downcase
18
- when 'status', 'stati', 'stat', 'st', 's'
19
- Mono.status
20
- when 'sync', 'syn', 'sy', ## note: allow aliases such as install, get & up too
21
- 'get', 'g',
22
- 'install', 'insta', 'inst', 'ins', 'i',
23
- 'up', 'u'
24
- Mono.sync
25
- when 'fetch', 'f'
26
- Mono.fetch
27
- when 'env', 'e'
28
- Mono.env
29
- when 'backup', 'back', 'b'
30
- Mono.backup
31
- when 'run', 'r', 'exec'
32
- Mono.run( args )
33
- else
34
- puts "!! ERROR: unknown command >#{cmd}<"
35
- exit 1
36
- end
37
-
38
- end # method self.main
39
- end # class Tool
40
-
1
+ module Mono
2
+
3
+
4
+ class Tool
5
+ def self.main( args=ARGV )
6
+
7
+ ## note: for now assume first argument is command
8
+ ## add options later
9
+
10
+ cmd = if args.size == 0
11
+ 'status' ## make status "default" command
12
+ else
13
+ args.shift ## remove first (head) element
14
+ end
15
+
16
+ ## note: allow shortcut for commands
17
+ case cmd.downcase
18
+ when 'status', 'stati', 'stat', 'st', 's'
19
+ Mono.status
20
+ when 'sync', 'syn', 'sy', ## note: allow aliases such as install, get & up too
21
+ 'get', 'g',
22
+ 'install', 'insta', 'inst', 'ins', 'i',
23
+ 'up', 'u'
24
+ Mono.sync
25
+ when 'fetch', 'f'
26
+ Mono.fetch
27
+ when 'env', 'e'
28
+ Mono.env
29
+ when 'backup', 'back', 'b'
30
+ Mono.backup
31
+ when 'run', 'r', 'exec'
32
+ Mono.run( args )
33
+
34
+ ##################
35
+ ## for debugging / linting
36
+ when 'walk'
37
+ Mono.walk
38
+ else
39
+ puts "!! ERROR: unknown command >#{cmd}<"
40
+ exit 1
41
+ end
42
+
43
+ end # method self.main
44
+ end # class Tool
45
+
41
46
  end # module Mono
@@ -5,9 +5,9 @@ module MonoCore ## todo/check: rename to MonoMeta, MonoModule or such - why? w
5
5
 
6
6
  ## note: move root to its own namespace to avoid
7
7
  ## conflict with Mono.root!!!!
8
- MAJOR = 0 ## todo: namespace inside version or something - why? why not??
9
- MINOR = 4
10
- PATCH = 0
8
+ MAJOR = 1 ## todo: namespace inside version or something - why? why not??
9
+ MINOR = 0
10
+ PATCH = 2
11
11
  VERSION = [MAJOR,MINOR,PATCH].join('.')
12
12
 
13
13
  def self.version
@@ -0,0 +1,23 @@
1
+ ###
2
+ # to run use
3
+ # ruby -I ./lib -I ./test test/test_path.rb
4
+
5
+ require 'helper'
6
+
7
+ class TestPath < MiniTest::Test
8
+
9
+
10
+ def test_real_path
11
+ [
12
+ '@yorobot/stage/one',
13
+ 'one@yorobot/stage',
14
+ 'stage/one@yorobot',
15
+ ].each do |name|
16
+ puts "#{name} => >#{MonoFile.norm_name( name )}<"
17
+
18
+ assert_equal "#{Mono.root}/yorobot/stage/one", Mono.real_path( name )
19
+ end
20
+ end
21
+
22
+ end # class TestPath
23
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-06 00:00:00.000000000 Z
11
+ date: 2020-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitti
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.4.0
19
+ version: 0.6.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.4.0
26
+ version: 0.6.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: gitti-backup
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,30 +42,36 @@ dependencies:
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '4.0'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '7'
48
51
  type: :development
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
- - - "~>"
55
+ - - ">="
53
56
  - !ruby/object:Gem::Version
54
57
  version: '4.0'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '7'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: hoe
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '3.16'
67
+ version: '3.22'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '3.16'
74
+ version: '3.22'
69
75
  description: monos - monorepo / mono source tree tools and (startup) scripts
70
76
  email: opensport@googlegroups.com
71
77
  executables:
@@ -91,13 +97,14 @@ files:
91
97
  - lib/mono/commands/run.rb
92
98
  - lib/mono/commands/status.rb
93
99
  - lib/mono/commands/sync.rb
100
+ - lib/mono/experimental.rb
94
101
  - lib/mono/tool.rb
95
102
  - lib/mono/version.rb
96
103
  - lib/monos.rb
97
- - lib/sportdb/setup.rb
98
104
  - test/helper.rb
99
105
  - test/test_base.rb
100
- homepage: https://github.com/rubycoco/monos
106
+ - test/test_path.rb
107
+ homepage: https://github.com/rubycoco/git
101
108
  licenses:
102
109
  - Public Domain
103
110
  metadata: {}
@@ -1,106 +0,0 @@
1
- ########
2
- ##
3
- # fix:
4
- # move to sportdb/setup or sportdb/boot ?
5
- # use module SportDb::Boot
6
-
7
-
8
-
9
- ##########
10
- # setup load path
11
- # lets you use environments
12
- # e.g. dev/development or production
13
-
14
-
15
- ## todo/fix: move later app/gem-family/-specific configs
16
- ## to its own gem e.g. mono-sportdb or sportdb-boot/starter/startup or such - why? why not?
17
-
18
-
19
-
20
-
21
-
22
- $RUBYLIBS_DEBUG = true
23
- $RUBYCOCO_DEBUG = true ## always include (NOT just in sportdb?)
24
-
25
-
26
- ### include / check for ruby debug flag too - why? why not?
27
- def debug? ## always include (NOT just insportdb?)
28
- value = ENV['DEBUG']
29
- if value && ['true', 't',
30
- 'yes', 'y',
31
- 'on'].include?( value.downcase )
32
- true
33
- else
34
- false
35
- end
36
- end
37
-
38
-
39
- require_relative '../mono'
40
-
41
-
42
-
43
- ## convenience pre-configured/pre-built shortcut - lets you use
44
- ## require 'sportdb/setup'
45
- ## SportDb::Boot.setup
46
-
47
-
48
- module SportDb
49
- module Boot
50
- def self.root() Mono.root; end
51
-
52
- def self.setup ## setup load path
53
- ### note: for now always assume dev/development
54
- ### add ENV check later or pass in as args or such
55
-
56
- puts "SportDb::Boot.root: >#{root}<"
57
-
58
- ### todo/fix: use an inline Gemfile and bundler's setup? why? why not?
59
- $LOAD_PATH.unshift( "#{root}/yorobot/sport.db.more/sportdb-exporters/lib" )
60
- $LOAD_PATH.unshift( "#{root}/yorobot/sport.db.more/sportdb-writers/lib" )
61
- $LOAD_PATH.unshift( "#{root}/yorobot/sport.db.more/sportdb-linters/lib" )
62
-
63
- $LOAD_PATH.unshift( "#{root}/sportdb/sport.db/sports/lib" )
64
-
65
- $LOAD_PATH.unshift( "#{root}/sportdb/sport.db/sportdb-importers/lib" )
66
- $LOAD_PATH.unshift( "#{root}/sportdb/sport.db/sportdb-readers/lib" )
67
- $LOAD_PATH.unshift( "#{root}/sportdb/sport.db/sportdb-sync/lib" )
68
- $LOAD_PATH.unshift( "#{root}/sportdb/sport.db/sportdb-models/lib" )
69
- $LOAD_PATH.unshift( "#{root}/sportdb/sport.db/sportdb-catalogs/lib" )
70
-
71
- ## todo/check:
72
- ## add fifa, footballdb-leagues, footballdb-clubs too ???
73
- $LOAD_PATH.unshift( "#{root}/sportdb/football.db/footballdb-clubs/lib" ))
74
- $LOAD_PATH.unshift( "#{root}/sportdb/football.db/footballdb-leagues/lib" ))
75
- $LOAD_PATH.unshift( "#{root}/sportdb/football.db/fifa/lib" ))
76
-
77
- $LOAD_PATH.unshift( "#{root}/sportdb/sport.db/sportdb-formats/lib" )
78
- $LOAD_PATH.unshift( "#{root}/sportdb/sport.db/sportdb-structs/lib" )
79
- $LOAD_PATH.unshift( "#{root}/sportdb/sport.db/sportdb-langs/lib" )
80
- $LOAD_PATH.unshift( "#{root}/sportdb/sport.db/score-formats/lib" )
81
- $LOAD_PATH.unshift( "#{root}/sportdb/sport.db/date-formats/lib" )
82
- $LOAD_PATH.unshift( "#{root}/sportdb/sport.db/alphabets/lib" )
83
-
84
- pp $: # print load path
85
- end # method setup
86
- end # module Boot
87
- end # module Sportdb
88
-
89
-
90
- ### use something like SportDb::Path[:sportdb]
91
- ## SportDb.path( :sportdb )
92
- ## SportDb::Boot.sportdb_path or sportdb_dir or such???
93
- ## SportDb::Env.path( 'sportdb' ) ???
94
- ## SportDb::Env::SPORTDB_DIR ???
95
- ## or such - why? why not?
96
- ##
97
- ## check rails path setup / style ???
98
-
99
- SPORTDB_DIR = "#{SportDb::Boot.root}/sportdb" # path to libs
100
- OPENFOOTBALL_DIR = "#{SportDb::Boot.root}/openfootball"
101
- ## add more "standard" dirs - why? why not? - why? why not?
102
- ## use
103
- ## module SportDb::Source / Code / Boot or such????
104
- ##
105
- ## use module SportDb::Boot - yes, yes, yes - why? why not?
106
-