yorobot 0.0.1 → 0.2.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: e4a01dffcd31d94c4d24d33805291506d63ff460
4
- data.tar.gz: f164e3bfc9bffb8d71aaf0712351cfc28bc9fc5b
3
+ metadata.gz: 847505c5153a9538c83b411771c985f37af24244
4
+ data.tar.gz: 65de3568ced94876da73ec17b76399604437efb6
5
5
  SHA512:
6
- metadata.gz: 118457eafb752db1011ee2b17af09433a1e7b40f2f92eb25af5f186889f104978a48a990b04df7f4352fac27da2e4269d842aa98bb5ee89fa983a8637992c8f8
7
- data.tar.gz: 4464d6db62229b4cfe77a32e4ed3f2b59cdedcadfd6fcd83574c1e957e4ccfe4edf218fa5af315cb843a389955d380b622a3b9810dc0d8be316a925ba9f11d57
6
+ metadata.gz: 4a9345178932c3ac2d4901a240f88b95d75992d7e024efcf608fa5e535a598df40f42b83ade976bc760b0a1c2ed6c19e7931c92c67474ef3c6f0d7cc40538249
7
+ data.tar.gz: f92929a759988a35020c5ae225c74186f9b29bc3f7c04a9f4c3e01a403bf76f4475375a58341fd3264c6b5f4271ad4f60bbdae9ec026fe039642ff43c8445967
@@ -2,5 +2,12 @@ CHANGELOG.md
2
2
  Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
+ bin/yo
6
+ bin/yorobot
5
7
  lib/yorobot.rb
8
+ lib/yorobot/base.rb
9
+ lib/yorobot/echo.rb
10
+ lib/yorobot/github/git.rb
11
+ lib/yorobot/github/github.rb
12
+ lib/yorobot/list.rb
6
13
  lib/yorobot/version.rb
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # yorobot
2
2
 
3
- yorobot gem - yorobot - automate, automate, automate - ready to use scripts
3
+ yorobot gem - yo, robot - automate, automate, automate - ready to use scripts and command line tool
4
4
 
5
5
 
6
6
  * home :: [github.com/rubycoco/git](https://github.com/rubycoco/git)
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ Hoe.spec 'yorobot' do
5
5
 
6
6
  self.version = YorobotCore::VERSION
7
7
 
8
- self.summary = "yorobot - automate, automate, automate - ready to use scripts"
8
+ self.summary = "yorbot gem - yo, robot - automate, automate, automate - ready to use scripts and command line tool"
9
9
  self.description = summary
10
10
 
11
11
  self.urls = { home: 'https://github.com/rubycoco/git' }
@@ -17,7 +17,10 @@ Hoe.spec 'yorobot' do
17
17
  self.readme_file = 'README.md'
18
18
  self.history_file = 'CHANGELOG.md'
19
19
 
20
- self.extra_deps = []
20
+ self.extra_deps = [
21
+ ['gitti', '>= 0.5.0' ],
22
+ ['hubba', '>= 1.0.0' ],
23
+ ]
21
24
 
22
25
  self.licenses = ['Public Domain']
23
26
 
data/bin/yo ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ###################
4
+ # DEV TIPS:
5
+ #
6
+ # For local testing run like:
7
+ #
8
+ # ruby -Ilib bin/yo
9
+ #
10
+ # Set the executable bit in Linux. Example:
11
+ #
12
+ # % chmod a+x bin/yo
13
+ #
14
+
15
+ require 'yorobot'
16
+
17
+ Yorobot::Tool.main
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ###################
4
+ # DEV TIPS:
5
+ #
6
+ # For local testing run like:
7
+ #
8
+ # ruby -Ilib bin/yorobot
9
+ #
10
+ # Set the executable bit in Linux. Example:
11
+ #
12
+ # % chmod a+x bin/yorobot
13
+ #
14
+
15
+ require 'yorobot'
16
+
17
+ Yorobot::Tool.main
@@ -1,7 +1,35 @@
1
+ ####
2
+ # 3rd party gems / libs
3
+ #
4
+ # require 'computer' # add shell run/call etc. machinery
5
+ # add via gitti & hubba
6
+ require 'gitti'
7
+ require 'hubba'
8
+
9
+
1
10
  # our own code
2
11
  require 'yorobot/version' # note: let version always go first
12
+ require 'yorobot/base'
13
+ require 'yorobot/echo'
14
+ require 'yorobot/list'
15
+
16
+ require 'yorobot/github/git'
17
+ require 'yorobot/github/github'
18
+
19
+
3
20
 
21
+ module Yorobot
22
+ class Tool
23
+ def self.main( args=ARGV )
24
+ if args.size > 0
25
+ Yorobot.run( args )
26
+ else
27
+ # list all known steps
28
+ List.run
29
+ end
30
+ end
31
+ end # class Tool
32
+ end # module Yorobot
4
33
 
5
34
 
6
- # say hello
7
- puts YorobotCore.banner
35
+ puts YorobotCore.banner # say hello
@@ -0,0 +1,124 @@
1
+ module Yorobot
2
+
3
+
4
+ class Step
5
+
6
+ def self.option_defs
7
+ @option_defs ||= {}
8
+ end
9
+
10
+ def self.option( key, *args )
11
+ option_defs[ key ] = args
12
+ end
13
+
14
+
15
+
16
+ def options
17
+ @options ||= {}
18
+ end
19
+
20
+ def parse!( args )
21
+ ### todo/check - cache option parser!!!! - why? why not?
22
+ OptionParser.new do |parser|
23
+ ## add default banner - overwrite if needed/to customize
24
+ parser.banner = <<TXT
25
+
26
+ Usage: #{name} [OPTIONS] ARGUMENTS
27
+
28
+ TXT
29
+
30
+ self.class.option_defs.each do | key, on_args|
31
+ parser.on( *on_args ) do |value|
32
+ options[ key ] = value
33
+ end
34
+ end
35
+ end.parse!( args )
36
+ end
37
+
38
+
39
+
40
+ def self.run( args=[] )
41
+ step = new
42
+
43
+ puts "--> (#{step.name}) #{args.join('·')}"
44
+
45
+ ## check for options
46
+ step.parse!( args )
47
+
48
+ puts " #{step.options.size} opt(s): #{step.options.pretty_inspect}"
49
+ puts " #{args.size} arg(s):"
50
+ args.each_with_index do |arg,i|
51
+ puts " #{[i]} >#{arg}<"
52
+ end
53
+
54
+
55
+ if args.size > 0
56
+ ## todo/check: check/verify arity of run - why? why not?
57
+ step.call( *args ) ## use run - why? why not?
58
+ else
59
+ step. call
60
+ end
61
+ end
62
+
63
+
64
+ def self.step_name
65
+ ## note: cut-off leading Yorobot:: for now in class name!!!
66
+ ## note: always remove _ for now too!!!
67
+ ## note: do NOT use @@name!!! - one instance variable per class needed!!
68
+ @name ||= self.name.downcase
69
+ .sub( /^yorobot::/, '' )
70
+ .gsub( /[_-]/, '' )
71
+ @name
72
+ end
73
+
74
+ def name() self.class.step_name; end
75
+
76
+
77
+
78
+
79
+
80
+ def self.inherited( klass )
81
+ # puts klass.class.name #=> Class
82
+ ## auto-register steps for now - why? why not?
83
+ Yorobot.register( klass )
84
+ end
85
+
86
+ end # class Step
87
+
88
+
89
+
90
+ def self.steps ## todo/check: change to registry or such - why? why not?
91
+ @@register ||= {}
92
+ end
93
+
94
+ def self.register( klass )
95
+ raise ArgumentError, "class MUST be a Yorobot::Step" unless klass.ancestors.include?( Step )
96
+
97
+ h = steps
98
+ h[ klass.step_name] = klass
99
+ h
100
+ end
101
+
102
+
103
+ def self.run( args=[] )
104
+ step_name = args.shift
105
+
106
+ ## 1) downcase e.g. GithubStats
107
+ ## 2) remove - to _ ## treat them the same e.g. github-stats => github_stats
108
+ step_name = step_name
109
+ .gsub( /[_-]/, '' )
110
+ .downcase
111
+
112
+ step = steps[ step_name ]
113
+ if step.nil?
114
+ puts "!! ERROR: no step definition found for >#{step_name}<; known steps include:"
115
+ List.run
116
+ exit 1
117
+ end
118
+
119
+ step.run( args )
120
+ end
121
+
122
+
123
+
124
+ end # module Yorobot
@@ -0,0 +1,13 @@
1
+ module Yorobot
2
+
3
+
4
+ class Echo < Step
5
+
6
+ def call( *args )
7
+ puts args.join( ' ' )
8
+ end
9
+
10
+ end # class Echo
11
+
12
+ end # module Yorobot
13
+
@@ -0,0 +1,109 @@
1
+ module Yorobot
2
+
3
+
4
+ class Setup < Step
5
+
6
+ =begin
7
+ # check ssh
8
+ if [ ! -d ~/.ssh ]; then mkdir ~/.ssh; fi
9
+ echo "$SSH_KEY" > ~/.ssh/id_rsa
10
+ chmod 600 ~/.ssh/id_rsa
11
+ echo "ssh directory - ~/.ssh:"
12
+ ls -la ~/.ssh
13
+ # ssh -vT git@github.com
14
+
15
+ # check git
16
+ git --version
17
+ git config --global user.name "Yo Robot"
18
+ git config --global user.email "gerald.bauer+yorobot@gmail.com"
19
+ git config -l --show-origin
20
+ =end
21
+
22
+ def call
23
+ ##############
24
+ ## setup ssh
25
+
26
+ ssh_key = ENV['SSH_KEY']
27
+
28
+ if ssh_key.nil?
29
+ STDERR.puts "!! ERROR - required SSH_KEY env(ironment) variable missing"
30
+ exit 1
31
+ end
32
+
33
+ ssh_path = File.expand_path( '~/.ssh' )
34
+
35
+ if File.exist?( "#{ssh_path}/id_rsa" )
36
+ STDERR.puts "!! ERROR - ssh key >#{ssh_path}/id_rsa< already exists"
37
+ exit 1
38
+ end
39
+
40
+ ## make sure path exists
41
+ FileUtils.mkdir_p( ssh_path ) unless Dir.exist?( ssh_path )
42
+ puts "--> writing ssh key to >#{ssh_path}/id_rsa<..."
43
+ File.open( "#{ssh_path}/id_rsa", 'w:utf-8' ) do |f|
44
+ f.write( ssh_key )
45
+ end
46
+ ## note: ssh key must be "private" only access by owner (otherwise) WILL NOT work
47
+ ## res = File.chmod( 0600, "#{ssh_path}/id_rsa" )
48
+ ## puts res ## returns number of files processed; should be 1 - assert - why? why not?
49
+ Computer::Shell.run( %Q{chmod 600 #{ssh_path}/id_rsa} )
50
+
51
+ Computer::Shell.run( %Q{ls -la #{ssh_path}} )
52
+ # ssh -vT git@github.com
53
+
54
+
55
+ #####
56
+ ## setup git
57
+ ## git --version
58
+ Git.version
59
+
60
+ user_name = ENV['YOROBOT_NAME'] || ENV['YO_NAME']
61
+ user_email = ENV['YOROBOT_EMAIL'] || ENV['YO_EMAIL']
62
+
63
+ Computer::Shell.run( %Q{git config --global user.name "#{user_name}"} )
64
+ Computer::Shell.run( %Q{git config --global user.email "#{user_email}"} )
65
+
66
+ Computer::Shell.run( %Q{git config -l --show-origin} )
67
+ end
68
+ end # class Setup
69
+
70
+
71
+
72
+ class Clone < Step ## change to SshClone(r) or such - why? why not?
73
+ option :depth, "--depth DEPTH", Integer, "shallow clone depth"
74
+
75
+ def call( *repos )
76
+ repos.each do |repo|
77
+ if options[:depth]
78
+ ### shallow "fast clone" - support libraries
79
+ ### use https:// instead of ssh - why? why not?
80
+ Git.clone( "git@github.com:#{repo}.git", depth: options[:depth] )
81
+ else
82
+ ### "deep" standard/ regular clone
83
+ Git.clone( "git@github.com:#{repo}.git" )
84
+ end
85
+ end
86
+ end
87
+ end # class Clone
88
+
89
+
90
+
91
+ class Push < Step ## change to SshPush(r) or such - why? why not?
92
+
93
+ def call( *paths ) ## e.g. "./cache.github" etc.
94
+ msg = "auto-update week #{Date.today.cweek}"
95
+
96
+ paths.each do |path|
97
+ GitProject.open( path ) do |proj|
98
+ if proj.changes?
99
+ proj.add( "." )
100
+ proj.commit( msg )
101
+ proj.push
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end # class Push
107
+
108
+
109
+ end # module Yorobot
@@ -0,0 +1,30 @@
1
+ module Yorobot
2
+
3
+ class Github < Step ## change to GithubStats or such - why? why not?
4
+
5
+ ## todo/check: use --data-dir/--datadir - why? why not?
6
+ option :data_dir, "-d DIR", "--dir DIR",
7
+ "data dir (defaults to #{Hubba.config.data_dir})"
8
+
9
+ ## todo/check: add switch --[no]-traffic - why? why not?
10
+
11
+
12
+ def call( username )
13
+ ## username e.g. geraldb
14
+
15
+ if options[:data_dir] ## e.g. "./cache.github"
16
+ puts " setting data_dir to >#{options[:data_dir]}<"
17
+ Hubba.config.data_dir = options[:data_dir]
18
+ end
19
+
20
+ h = Hubba.reposet( username ) ## note: do NOT include yorobot for now
21
+ pp h
22
+
23
+ Hubba.update_stats( h )
24
+ Hubba.update_traffic( h )
25
+ puts "Done."
26
+ end
27
+
28
+ end # class Github
29
+ end # module Yorobot
30
+
@@ -0,0 +1,25 @@
1
+ module Yorobot
2
+
3
+
4
+ class List < Step
5
+
6
+ def call
7
+ ## list all know steps
8
+ steps = Yorobot.steps
9
+ puts "#{steps.size} step(s):"
10
+ steps.each do |name, step|
11
+ puts " #{name} | #{step.class.name}"
12
+ end
13
+ end
14
+ end
15
+
16
+ end # module Yorobot
17
+
18
+
19
+ #####
20
+ #
21
+ #
22
+ # -- add "shortcut why? why not?"
23
+ # step [:list, :ls] do |args|
24
+ # ....
25
+ # end
@@ -5,8 +5,8 @@
5
5
 
6
6
  module YorobotCore ## todo/check: rename GittiBase or GittiMeta or such - why? why not?
7
7
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
8
- MINOR = 0
9
- PATCH = 1
8
+ MINOR = 2
9
+ PATCH = 2
10
10
  VERSION = [MAJOR,MINOR,PATCH].join('.')
11
11
 
12
12
  def self.version
@@ -18,7 +18,7 @@ module YorobotCore ## todo/check: rename GittiBase or GittiMeta or such - why
18
18
  end
19
19
 
20
20
  def self.root
21
- "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
21
+ File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
22
22
  end
23
23
  end # module YorobotCore
24
24
 
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yorobot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.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-19 00:00:00.000000000 Z
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gitti
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: hubba
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: rdoc
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -44,9 +72,12 @@ dependencies:
44
72
  - - "~>"
45
73
  - !ruby/object:Gem::Version
46
74
  version: '3.22'
47
- description: yorobot - automate, automate, automate - ready to use scripts
75
+ description: yorbot gem - yo, robot - automate, automate, automate - ready to use
76
+ scripts and command line tool
48
77
  email: ruby-talk@ruby-lang.org
49
- executables: []
78
+ executables:
79
+ - yo
80
+ - yorobot
50
81
  extensions: []
51
82
  extra_rdoc_files:
52
83
  - CHANGELOG.md
@@ -57,7 +88,14 @@ files:
57
88
  - Manifest.txt
58
89
  - README.md
59
90
  - Rakefile
91
+ - bin/yo
92
+ - bin/yorobot
60
93
  - lib/yorobot.rb
94
+ - lib/yorobot/base.rb
95
+ - lib/yorobot/echo.rb
96
+ - lib/yorobot/github/git.rb
97
+ - lib/yorobot/github/github.rb
98
+ - lib/yorobot/list.rb
61
99
  - lib/yorobot/version.rb
62
100
  homepage: https://github.com/rubycoco/git
63
101
  licenses:
@@ -84,5 +122,6 @@ rubyforge_project:
84
122
  rubygems_version: 2.5.2
85
123
  signing_key:
86
124
  specification_version: 4
87
- summary: yorobot - automate, automate, automate - ready to use scripts
125
+ summary: yorbot gem - yo, robot - automate, automate, automate - ready to use scripts
126
+ and command line tool
88
127
  test_files: []