monos 1.0.1 → 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: 62adfa9ee77f46c0ff4a0c5c7946a4ccf5cac96e
4
- data.tar.gz: e0d7a90b32fb6b422e00667570d69a6dea33ab09
3
+ metadata.gz: 9c0413c2258822899cb73e090438d21f3ea82fc5
4
+ data.tar.gz: a9cd0ddc80ea90a8c7cdbafc7a917eeabadb5b8f
5
5
  SHA512:
6
- metadata.gz: 149cc0dc4355b4dbe4e4c1dfd715edec2b692d62b2de8487dff55ee51a00e82a5fa832bf1ae1c1ee480ca99afaf5f6a447003dc1ac6db961cbc9e5d9c928c4dc
7
- data.tar.gz: 7d7e020fff8866dd966835e5a260c70282b03a87314b204bc539fe8b77333e345bfb34d159b282bcf4be06710ec621765a77f5350200dd389baddc1cc1270b22
6
+ metadata.gz: bc5c4b2083a234faded31cc4bdad78068709c8d7f6aa0e4a21fa1eb0c276f9ba6d6b34fe77b3fcafac9f6024701536337563b5b9d1b7d7b1fa026f045592c3ac
7
+ data.tar.gz: db404f05b726c7d233996dca624e6e3bc9cfb204d721ca9ee43be701ea2f658d4a0f03233524aa1d4e7b70c218052ea05cf67f347185063cdb5d53b9e106ddb9
@@ -18,3 +18,4 @@ lib/mono/version.rb
18
18
  lib/monos.rb
19
19
  test/helper.rb
20
20
  test/test_base.rb
21
+ test/test_path.rb
@@ -8,8 +8,8 @@ module Mono
8
8
  ## check if root directory exists?
9
9
  if ENV['MOPATH']
10
10
  ## use expand path to make (assure) absolute path - why? why not?
11
- ::File.expand_path( ENV['MOPATH'] )
12
- elsif ::Dir.exist?( 'C:/Sites' )
11
+ File.expand_path( ENV['MOPATH'] )
12
+ elsif Dir.exist?( 'C:/Sites' )
13
13
  'C:/Sites'
14
14
  else
15
15
  '/sites'
@@ -19,27 +19,29 @@ module Mono
19
19
 
20
20
  def self.root=( path )
21
21
  ## use expand path to make (assure) absolute path - why? why not?
22
- @@root = ::File.expand_path( path )
22
+ @@root = File.expand_path( path )
23
23
  end
24
24
 
25
25
 
26
26
 
27
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
+
28
38
  def self.monofile
29
- path = if ::File.exist?( './monorepo.yml' )
30
- './monorepo.yml'
31
- elsif ::File.exist?( './monotree.yml' )
32
- './monotree.yml'
33
- elsif ::File.exist?( './repos.yml' )
34
- './repos.yml'
35
- else
36
- puts "!! WARN: no mono configuration file (that is, {monorepo,monotree,repos}.yml) found in >#{Dir.getwd}<"
37
- nil
38
- end
39
+ path = find_monofile
39
40
 
40
41
  if path
41
42
  GitRepoSet.read( path )
42
43
  else
44
+ puts "!! WARN: no mono configuration file found; looking for #{MONOFILES.join(', ')} in (#{Dir.getwd})"
43
45
  GitRepoSet.new( {} ) ## return empty set -todo/check: return nil - why? why not?
44
46
  end
45
47
  end
@@ -57,14 +59,19 @@ end ## module Mono
57
59
 
58
60
  class MonoGitHub
59
61
  def self.clone( name, depth: nil )
60
- path = MonoFile.real_path( name )
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}"
61
68
 
62
69
  org_path = File.dirname( path )
63
70
  FileUtils.mkdir_p( org_path ) unless Dir.exist?( org_path ) ## make sure path exists
64
71
 
65
72
  ### note: use a github clone url (using ssh) like:
66
73
  ## git@github.com:rubycoco/gitti.git
67
- ssh_clone_url = "git@github.com:#{name}.git"
74
+ ssh_clone_url = "git@github.com:#{norm_name}.git"
68
75
 
69
76
  Dir.chdir( org_path ) do
70
77
  Gitti::Git.clone( ssh_clone_url, depth: depth )
@@ -90,10 +97,33 @@ class MonoFile
90
97
  ##
91
98
  ## todo/check: assert name must be {orgname,username}/reponame
92
99
  def self.real_path( path )
93
- "#{Mono.root}/#{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
94
123
  end
124
+
95
125
  def self.exist?( path )
96
- ::File.exist?( real_path( path ))
126
+ File.exist?( real_path( path ))
97
127
  end
98
128
 
99
129
 
@@ -104,10 +134,10 @@ class MonoFile
104
134
  full_path = real_path( path )
105
135
  ## make sure path exists if we open for writing/appending - why? why not?
106
136
  if mode[0] == 'w' || mode[0] == 'a'
107
- ::FileUtils.mkdir_p( ::File.dirname( full_path ) ) ## make sure path exists
137
+ FileUtils.mkdir_p( File.dirname( full_path ) ) ## make sure path exists
108
138
  end
109
139
 
110
- ::File.open( full_path, mode ) do |file|
140
+ File.open( full_path, mode ) do |file|
111
141
  block.call( file )
112
142
  end
113
143
  end
@@ -124,7 +154,7 @@ module Mono
124
154
  ## add some short cuts
125
155
  def self.open( name, &block ) MonoGitProject.open( name, &block ); end
126
156
  def self.clone( name, depth: nil ) MonoGitHub.clone( name, depth: depth ); end
127
- def self.real_path( name) MonoFile.real_path( name ); end
157
+ def self.real_path( name ) MonoFile.real_path( name ); end
128
158
  end ## module Mono
129
159
 
130
160
 
@@ -18,8 +18,8 @@ module Mono
18
18
 
19
19
  repo = GitHubRepo.new( org, name ) ## owner, name e.g. rubylibs/webservice
20
20
 
21
- ::Dir.chdir( org_path ) do
22
- if ::Dir.exist?( repo.name )
21
+ Dir.chdir( org_path ) do
22
+ if Dir.exist?( repo.name )
23
23
  GitProject.open( repo.name ) do |proj|
24
24
  proj.fetch
25
25
  end
@@ -22,8 +22,8 @@ module Mono
22
22
 
23
23
  repo = GitHubRepo.new( org, name ) ## owner, name e.g. rubylibs/webservice
24
24
 
25
- ::Dir.chdir( org_path ) do
26
- if ::Dir.exist?( repo.name )
25
+ Dir.chdir( org_path ) do
26
+ if Dir.exist?( repo.name )
27
27
  GitProject.open( repo.name ) do |proj|
28
28
  proj.run( cmd )
29
29
  end
@@ -20,8 +20,8 @@ module Mono
20
20
 
21
21
  repo = GitHubRepo.new( org, name ) ## owner, name e.g. rubylibs/webservice
22
22
 
23
- ::Dir.chdir( org_path ) do
24
- if ::Dir.exist?( repo.name )
23
+ Dir.chdir( org_path ) do
24
+ if Dir.exist?( repo.name )
25
25
  GitProject.open( repo.name ) do |proj|
26
26
  output = proj.changes
27
27
  if output.empty?
@@ -11,15 +11,15 @@ module Mono
11
11
 
12
12
  repos.each do |org,names|
13
13
  org_path = "#{Mono.root}/#{org}"
14
- ::FileUtils.mkdir_p( org_path ) unless ::Dir.exist?( org_path ) ## make sure path exists
14
+ FileUtils.mkdir_p( org_path ) unless Dir.exist?( org_path ) ## make sure path exists
15
15
 
16
16
  names.each do |name|
17
17
  puts "[#{count_repos+1}/#{total_repos}] #{org}@#{name}..."
18
18
 
19
19
  repo = GitHubRepo.new( org, name ) ## owner, name e.g. rubylibs/webservice
20
20
 
21
- ::Dir.chdir( org_path ) do
22
- if ::Dir.exist?( repo.name )
21
+ Dir.chdir( org_path ) do
22
+ if Dir.exist?( repo.name )
23
23
  GitProject.open( repo.name ) do |proj|
24
24
  if proj.changes?
25
25
  puts "!! WARN - local changes in workdir; skipping fast forward (remote) sync / merge"
@@ -25,15 +25,15 @@ private
25
25
 
26
26
  ## todo/check - use max_depth or max_level or such - why? why not?
27
27
  def self.walk_dir( path, repos=[], level=1, depth: nil )
28
- entries = ::Dir.entries(path)
28
+ entries = Dir.entries(path)
29
29
 
30
30
  ## filter dirs
31
31
  dirs = entries.select do |entry|
32
32
  if ['..', '.'].include?( entry ) ## first check for excludes
33
33
  false
34
34
  else
35
- full_path = ::File.join( path, entry )
36
- ::File.directory?( full_path )
35
+ full_path = File.join( path, entry )
36
+ File.directory?( full_path )
37
37
  end
38
38
  end
39
39
 
@@ -53,9 +53,9 @@ def self.walk_dir( path, repos=[], level=1, depth: nil )
53
53
  buf << ">#{path}< - level #{level}:\n"
54
54
  dirs.each do |entry|
55
55
  next if ['..', '.', '.git'].include?( entry )
56
- full_path = ::File.join( path, entry )
56
+ full_path = File.join( path, entry )
57
57
 
58
- if ::Dir.exist?( ::File.join( full_path, '.git' ))
58
+ if Dir.exist?( File.join( full_path, '.git' ))
59
59
  repos_count += 1
60
60
 
61
61
  if level == 1
@@ -69,15 +69,15 @@ def self.walk_dir( path, repos=[], level=1, depth: nil )
69
69
  end
70
70
 
71
71
  buf << " repo ##{'%-2d' % repos_count} | "
72
- buf << "#{'%-20s' % entry} @ #{::File.basename(path)} (#{path})"
72
+ buf << "#{'%-20s' % entry} @ #{File.basename(path)} (#{path})"
73
73
  buf << "\n"
74
74
  repos << full_path
75
75
 
76
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' ))
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
81
  warns_count += 1
82
82
  buf << "!! WARN - skip bare git repo >#{entry}< @ #{path}\n"
83
83
  else
@@ -94,7 +94,7 @@ def self.walk_dir( path, repos=[], level=1, depth: nil )
94
94
 
95
95
  sub_dirs.each do |entry|
96
96
  ## continue walking
97
- full_path = ::File.join( path, entry )
97
+ full_path = File.join( path, entry )
98
98
  walk_dir( full_path, repos, level+1, depth: depth )
99
99
  end
100
100
 
@@ -7,7 +7,7 @@ module MonoCore ## todo/check: rename to MonoMeta, MonoModule or such - why? w
7
7
  ## conflict with Mono.root!!!!
8
8
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
9
9
  MINOR = 0
10
- PATCH = 1
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: 1.0.1
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-10-26 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
@@ -103,6 +103,7 @@ files:
103
103
  - lib/monos.rb
104
104
  - test/helper.rb
105
105
  - test/test_base.rb
106
+ - test/test_path.rb
106
107
  homepage: https://github.com/rubycoco/git
107
108
  licenses:
108
109
  - Public Domain