raykit 0.0.49 → 0.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b317f633ca2cb66a7f82a200081804a133d96b5aa3a22a8a50857b69468954e2
4
- data.tar.gz: 3af4b61349f2d5fbce324db2116c214dc83b56fd08a7bfff3f514b2898ac9ff3
3
+ metadata.gz: cc13a57b744ff422351ff702e896ea0674597e990d38d037e859e4229d57d4ca
4
+ data.tar.gz: b18b4d532221b9d9479f17e686de57005e1682dd1347348d8ea280921875971b
5
5
  SHA512:
6
- metadata.gz: 311ab8cf559de63e1fc696c72d31de74b7a534b12a16ab8e6ec9d3c14acd270f224a0844a0f1751d5f0909e30f5e753922bc9f193956a3d2d03389671043cbaf
7
- data.tar.gz: cf2d8fa22bf9071247693857a436a01be66204ccae06cf89a56df7c4a7f09290d1eed663b06d7530935a2444ae6d5486f33af0c809b3190dc4061bb30efa334a
6
+ metadata.gz: e48927331652260d8c221c933761c94e1a544f01fa6e5b8811ed530c45277abab89e368926a29dbb84a09a966191e8faf1fde62703bd4ed7c0833731ca710ff4
7
+ data.tar.gz: 0edb350db610b2fd54472290950f9e8f987936c260377dc5ed9abd697bfbb2fbdf40fe23c6fd73663b1350e90187f2ed9e86ed34a2e784bca2679c1fba2757c1
data/bin/raykit CHANGED
@@ -1,9 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require_relative '../lib/raykit.rb'
4
- #NAME='raykit'
5
- #VERSION=Raykit::Version.detect
6
-
7
- #puts "#{NAME} #{VERSION}"
8
-
9
3
  Raykit::Console::run
@@ -1,12 +1,17 @@
1
- require_relative './raykit/timer.rb'
2
- require_relative './raykit/git.rb'
3
- require_relative './raykit/dotnet.rb'
4
- require_relative './raykit/version.rb'
5
- require_relative './raykit/environment.rb'
6
- require_relative './raykit/logging.rb'
7
- require_relative './raykit/command.rb'
8
- require_relative './raykit/rake.rb'
9
- require_relative './raykit/console.rb'
1
+ #require_relative './raykit/timer.rb'
2
+ #require_relative './raykit/gitlegacy.rb'
3
+ #require_relative './raykit/git/commit.rb'
4
+ #require_relative './raykit/dotnet.rb'
5
+ #require_relative './raykit/version.rb'
6
+ #require_relative './raykit/environment.rb'
7
+ #require_relative './raykit/logging.rb'
8
+ #require_relative './raykit/command.rb'
9
+ #require_relative './raykit/rake.rb'
10
+ #require_relative './raykit/console.rb'
11
+ lib_root = File.dirname(File.absolute_path(__FILE__))
12
+ puts "lib_root #{lib_root}"
13
+ Dir.glob(lib_root + '/raykit/**/*.rb') {|file| require file}
14
+
10
15
  require 'rainbow'
11
16
  require 'rake/clean'
12
17
  require 'open3'
@@ -14,7 +19,11 @@ require 'rake/testtask'
14
19
 
15
20
  TIMER= Raykit::Timer.new
16
21
  LOG = Raykit::Logging.new
22
+ REPOSITORIES = Raykit::Git::Repositories.new(Raykit::Environment::get_dev_dir('log') + "/Raykit.Git.Repositories.json")
17
23
 
24
+ if(Dir.exist?('.git'))
25
+ GIT_DIRECTORY=Raykit::Git::Directory.new(File.dirname(__FILE__))
26
+ end
18
27
 
19
28
  module Raykit
20
29
  def Raykit.run(command)
@@ -1,7 +1,6 @@
1
1
  require 'optparse'
2
2
 
3
3
  module Raykit
4
-
5
4
  # Parses the command line arguments for the Raykit console application
6
5
  class Parser
7
6
  def self.parse(options)
@@ -63,37 +62,32 @@ module Raykit
63
62
  end
64
63
 
65
64
  def self.list(hash)
66
- pattern=nil
65
+ pattern=''
67
66
  if(hash.include?(:pattern))
68
- pattern=hash[:pattern]
67
+ pattern=hash["pattern"]
69
68
  end
70
- Raykit::Git::remote_urls.each{|url|
71
- if(pattern.nil? || url.include?(pattern))
69
+ pattern='' if(pattern.nil?)
70
+
71
+ REPOSITORIES.each{|url|
72
+ if(url.include?(pattern))
72
73
  puts Rainbow(url).yellow.bright
73
74
  end
74
75
  }
75
76
  end
76
77
 
77
78
  def self.import(hash)
79
+ pattern=''
80
+ pattern=hash["pattern"] if(hash.include?("pattern"))
78
81
  puts 'scanning...'
79
- scanned_remotes = Raykit::Git::scan_remote_urls
80
- remotes = Raykit::Git::remote_urls
81
- count = 0
82
- scanned_remotes.each{|remote|
83
- if(!remotes.include?(remote))
84
- puts "imported " + Rainbow(remote).yellow.bright
85
- remotes.insert(0,remote)
86
- count = count + 1
87
- end
88
- }
89
- if(count > 0)
90
- puts 'updating Raykit::Git::remote_urls'
91
- Raykit::Git::remote_urls = remotes
92
- end
82
+ count=REPOSITORIES.length
83
+ REPOSITORIES.import(pattern)
84
+ new_count=REPOSITORIES.length-count
85
+ puts "imported #{new_count} git repositories"
93
86
  end
94
87
 
95
88
  def self.rake(hash)
96
- Raykit::Git::remote_urls.each{|remote|
89
+ REPOSITORIES.each{|remote|
90
+ #Raykit::Git::remote_urls.each{|remote|
97
91
  if(remote.include?(hash[:pattern]))
98
92
  begin
99
93
  puts "remote: #{remote}"
@@ -0,0 +1,17 @@
1
+
2
+ module Raykit
3
+ module Git
4
+ # Functionality to manage a git commit
5
+ class Commit
6
+ attr_accessor :url
7
+ attr_accessor :branch
8
+ attr_accessor :commit_id
9
+
10
+ def initialize(url,branch,commit_id)
11
+ @url=url
12
+ @branch=branch
13
+ @commit_id=commit_id
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,53 @@
1
+ module Raykit
2
+ module Git
3
+ # Functionality to manage a local clone of a git repository
4
+ class Directory
5
+ # The directory name of the local repository clone
6
+ attr_accessor :directory
7
+
8
+ def initialize(directory)
9
+ @directory=directory
10
+ end
11
+
12
+ def outstanding_commit?
13
+ Dir.chdir(directory) do
14
+ if(user_can_commit)
15
+ #puts `git status`
16
+ return !`git status`.include?('nothing to commit,')
17
+ else
18
+ return false
19
+ end
20
+ end
21
+ end
22
+
23
+ def user_name
24
+ `git config --get user.name`.strip
25
+ end
26
+
27
+ def user_email
28
+ `git config --get user.email`.strip
29
+ end
30
+
31
+ def user_can_commit
32
+ return false if(user_name.length == 0)
33
+ return false if(user_email.length == 0)
34
+ return true
35
+ end
36
+
37
+ def branch
38
+ Dir.chdir(directory) do
39
+ scan=`git branch`.scan(/\*\s([\w\.-]+)/)
40
+ return scan[0][0].to_s if(!scan.nil? && scan.length > 0 && scan[0].length > 0)
41
+ end
42
+ 'master'
43
+ end
44
+
45
+ def remote
46
+ Dir.chdir(directory) do
47
+ return Command.new('git config --get remote.origin.url').output.strip if(Dir.exist?('.git'))
48
+ end
49
+ ``
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,55 @@
1
+ require_relative('./directory.rb')
2
+
3
+ module Raykit
4
+ module Git
5
+ # Functionality to manage a remote git repository
6
+ class Repositories < Array
7
+ attr_accessor :filename
8
+
9
+ def initialize(filename)
10
+ @filename=filename
11
+ open(@filename)
12
+ end
13
+
14
+ def open(filename)
15
+ if(File.exist?(filename))
16
+ JSON.parse(File.read(filename)).each{|url|
17
+ insert(-1,url)
18
+ }
19
+ puts "filename #{filename} imported #{self.length} entries"
20
+ else
21
+ puts "filename #{filename} does not exist"
22
+ end
23
+ end
24
+
25
+ def save(filename)
26
+ File.open(@filename,'w'){|f|
27
+ f.write(self.to_json)
28
+ }
29
+ end
30
+
31
+ def import(pattern)
32
+ git_dirs = Array.new
33
+ Dir.chdir(Environment::get_dev_dir('work')) do
34
+ Dir.glob('**/.git'){|git_dir|
35
+ dir = File.expand_path('..',git_dir)
36
+ if(dir.length > 0)
37
+ git_dirs.insert(0,dir)
38
+ end
39
+ }
40
+ end
41
+
42
+ git_dirs.each{|git_dir|
43
+ dir=Raykit::Git::Directory.new(git_dir)
44
+ remote=dir.remote
45
+ if(remote.include?(pattern) && !include?(remote))
46
+ insert(-1,remote)
47
+ end
48
+ }
49
+ save(@filename)
50
+ self
51
+ end
52
+ end
53
+ end
54
+ end
55
+
@@ -0,0 +1,105 @@
1
+ module Raykit
2
+ module Git
3
+ # Functionality to manage a remote git repository
4
+ class Repository
5
+ # The url of the remote repository
6
+ attr_accessor :url
7
+
8
+ def initialize(url)
9
+ @url=url
10
+ end
11
+
12
+ def to_json
13
+ JSON.generate({"url" => @url})
14
+ end
15
+
16
+ def self.parse(json)
17
+ hash=JSON.parse(json)
18
+ repo=Repository.new(hash["url"])
19
+ repo
20
+ end
21
+
22
+ # The relative path is a valid local path name derived from the url
23
+ def relative_path
24
+ @url.gsub('https://','').gsub('.git','')
25
+ end
26
+
27
+ def get_dev_dir(dir)
28
+ dev_dir=Environment::get_dev_dir(dir)
29
+ return "#{dev_dir}/#{relative_path}"
30
+ end
31
+
32
+ # Clone the repository to a specific directory
33
+ def clone(directory,depth=0)
34
+ if(depth == 0)
35
+ Raykit::run("git clone #{@url} #{directory}")
36
+ else
37
+ Raykit::run("git clone #{@url} #{directory} --depth #{depth}")
38
+ end
39
+ end
40
+
41
+ # The branches for the git repository
42
+ def branches
43
+ results = Array.new
44
+ update_local_clone_directory
45
+ if(Dir.exist?(local_clone_directory))
46
+ Dir.chdir(local_clone_directory) do
47
+ `git branch`.split('\n').each{|line|
48
+ branch = line.gsub('*','').strip
49
+ results.insert(-1,branch) if(branch.length > 0)
50
+ }
51
+ end
52
+ end
53
+ results
54
+ end
55
+
56
+ # The latest commit id for a branch of the repostiory
57
+ def latest_commit(branch)
58
+ if(checkout_local_clone_directory_branch(branch))
59
+ text=`git log -n 1`
60
+ scan=text.scan(/commit ([\w]+)\s/)
61
+ return scan[0][0].to_s
62
+ end
63
+ ''
64
+ end
65
+
66
+ # The latest tag for a branch of the repository
67
+ def latest_tag(branch)
68
+ # git describe --abbrev=0
69
+ if(checkout_local_clone_directory_branch(branch))
70
+ return `git describe --abbrev=0`.strip
71
+ end
72
+ ''
73
+ end
74
+
75
+ private def local_clone_directory
76
+ clone_dir="#{Environment::get_dev_dir('clone')}/#{relative_path}"
77
+ end
78
+
79
+ private def update_local_clone_directory
80
+ if(Dir.exist?(local_clone_directory))
81
+ Dir.chdir(local_clone_directory) do
82
+ `git pull`
83
+ end
84
+ else
85
+ Raykit::run("git clone #{@url} #{local_clone_directory}")
86
+ end
87
+ end
88
+
89
+ private def checkout_local_clone_directory_branch(branch)
90
+ update_local_clone_directory
91
+ if(Dir.exist?(local_clone_directory))
92
+ Dir.chdir(local_clone_directory) do
93
+ check=`git branch`
94
+ if(!check.include?("* #{branch}"))
95
+ `git checkout #{branch}`
96
+ end
97
+ check=`git branch`
98
+ return check.include?("* #{branch}")
99
+ end
100
+ end
101
+ false
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,68 @@
1
+ module Raykit
2
+ class GitLegacy
3
+ def self.get_remote
4
+ if(Dir.exist?('.git'))
5
+ cmd = Command.new('git config --get remote.origin.url')
6
+ #cmd.run
7
+ return cmd.output.strip
8
+ else
9
+ ``
10
+ end
11
+ end
12
+
13
+ def self.add_remote
14
+ remote = get_remote
15
+ if(remote.length > 0)
16
+ remote_urls_copy = remote_urls
17
+ if(!remote_urls_copy.include?(remote))
18
+ remote_urls_copy.insert(0,remote)
19
+ Git::remote_urls = remote_urls_copy
20
+ end
21
+ end
22
+ end
23
+
24
+ def self.remote_urls
25
+ filename="#{Environment::get_dev_dir('log')}/Raykit.Git.RemoteUrls.json";
26
+ if(File.exist?(filename))
27
+ JSON.parse(File.read(filename))
28
+ else
29
+ Array.new
30
+ end
31
+ end
32
+
33
+ def self.remote_urls=(urls)
34
+ filename="#{Environment::get_dev_dir('log')}/Raykit.Git.RemoteUrls.json"
35
+ File.open(filename,'w'){|f|
36
+ f.write(JSON.generate(urls))
37
+ }
38
+ end
39
+
40
+ def self.list_remotes
41
+ remote_urls.each{|url| puts url}
42
+ end
43
+
44
+ def self.scan_remote_urls
45
+ remotes = Array.new
46
+ git_dirs = Array.new
47
+ Dir.chdir(Environment::work_dir) do
48
+ Dir.glob('**/.git'){|git_dir|
49
+ dir = File.expand_path('..',git_dir)
50
+ if(dir.length > 0)
51
+ git_dirs.insert(0,dir)
52
+ end
53
+
54
+ }
55
+ end
56
+
57
+ git_dirs.each{|git_dir|
58
+ Dir.chdir(git_dir) do
59
+ remote = get_remote
60
+ if(remote.length > 0)
61
+ remotes.insert(0,remote)
62
+ end
63
+ end
64
+ }
65
+ remotes
66
+ end
67
+ end
68
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raykit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.49
4
+ version: 0.0.50
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lou Parslow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-22 00:00:00.000000000 Z
11
+ date: 2019-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,7 +67,11 @@ files:
67
67
  - lib/raykit/console.rb
68
68
  - lib/raykit/dotnet.rb
69
69
  - lib/raykit/environment.rb
70
- - lib/raykit/git.rb
70
+ - lib/raykit/git/commit.rb
71
+ - lib/raykit/git/directory.rb
72
+ - lib/raykit/git/repositories.rb
73
+ - lib/raykit/git/repository.rb
74
+ - lib/raykit/gitlegacy.rb
71
75
  - lib/raykit/logging.rb
72
76
  - lib/raykit/rake.rb
73
77
  - lib/raykit/timer.rb
@@ -1,143 +0,0 @@
1
- module Raykit
2
- class Git
3
- attr_accessor :start_time
4
-
5
- def self.branch
6
- branches = `git branch`
7
- branches.match(/ ([\w.]+)/).captures[0]
8
- end
9
-
10
- def self.last_tag
11
- `git describe --abbrev=0 --tags`.strip
12
- end
13
-
14
- def self.user_name
15
- return `git config --get user.name`.strip
16
- end
17
-
18
- def self.user_email
19
- return `git config --get user.email`.strip
20
- end
21
-
22
- def self.user_can_commit
23
- return false if(user_name.length == 0)
24
- return false if(user_email.length == 0)
25
- return true
26
- end
27
-
28
- def self.outstanding_commit
29
- if(Git::user_can_commit)
30
- return !`git status`.include?('nothing to commit,')
31
- else
32
- return false
33
- end
34
- end
35
-
36
- # get the latest tag for the current directory
37
- def self.get_latest_tag
38
- `git describe --abbrev=0 --tags`.strip
39
- end
40
-
41
- def self.get_current_branch
42
- text=`git branch`
43
- if(text.include?('HEAD detached'))
44
- return 'master'
45
- end
46
- #puts "get_current_branch text=#{text}"
47
- scan=text.scan(/\*\s([\w\.-]+)/)
48
- #puts "scan=#{scan}"
49
- scan[0][0].to_s
50
- end
51
-
52
- def self.get_latest_commit(remote,branch)
53
- clone_dir="#{Environment::get_dev_dir('clone')}/#{get_relative_path(remote)}"
54
- if(!Dir.exist?(clone_dir))
55
- parent_dir = File.expand_path('..',clone_dir)
56
- if(!Dir.exist?(parent_dir))
57
- FileUtils.mkdir_p(parent_dir)
58
- end
59
- Command.new("git clone #{remote} #{clone_dir}")
60
- end
61
- Dir.chdir(clone_dir) do
62
- Command.new('git pull')
63
- if(get_current_branch != branch)
64
- Command.new("git checkout #{branch}")
65
- end
66
- text=`git log --name-status HEAD^..HEAD`
67
- #puts "get_latest_commit text: #{text}"
68
- scan=text.scan(/commit ([\w]+)\s/)
69
- #puts "scan: #{scan}"
70
- return scan[0][0].to_s
71
- end
72
- end
73
-
74
- def self.get_relative_path(remote)
75
- remote.gsub('https://','').gsub('.git','')
76
- end
77
-
78
- def self.get_remote
79
- if(Dir.exist?('.git'))
80
- cmd = Command.new('git config --get remote.origin.url')
81
- #cmd.run
82
- return cmd.output.strip
83
- else
84
- ``
85
- end
86
- end
87
-
88
- def self.add_remote
89
- remote = get_remote
90
- if(remote.length > 0)
91
- remote_urls_copy = remote_urls
92
- if(!remote_urls_copy.include?(remote))
93
- remote_urls_copy.insert(0,remote)
94
- Git::remote_urls = remote_urls_copy
95
- end
96
- end
97
- end
98
-
99
- def self.remote_urls
100
- filename="#{Environment::get_dev_dir('log')}/Raykit.Git.RemoteUrls.json";
101
- if(File.exist?(filename))
102
- JSON.parse(File.read(filename))
103
- else
104
- Array.new
105
- end
106
- end
107
-
108
- def self.remote_urls=(urls)
109
- filename="#{Environment::get_dev_dir('log')}/Raykit.Git.RemoteUrls.json"
110
- File.open(filename,'w'){|f|
111
- f.write(JSON.generate(urls))
112
- }
113
- end
114
-
115
- def self.list_remotes
116
- remote_urls.each{|url| puts url}
117
- end
118
-
119
- def self.scan_remote_urls
120
- remotes = Array.new
121
- git_dirs = Array.new
122
- Dir.chdir(Environment::work_dir) do
123
- Dir.glob('**/.git'){|git_dir|
124
- dir = File.expand_path('..',git_dir)
125
- if(dir.length > 0)
126
- git_dirs.insert(0,dir)
127
- end
128
-
129
- }
130
- end
131
-
132
- git_dirs.each{|git_dir|
133
- Dir.chdir(git_dir) do
134
- remote = get_remote
135
- if(remote.length > 0)
136
- remotes.insert(0,remote)
137
- end
138
- end
139
- }
140
- remotes
141
- end
142
- end
143
- end