autowow 0.1.0 → 0.2.0

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: 10f7a14f0576ced3352895a30cc324a4bc230ab8
4
- data.tar.gz: 2965fb8eac0567e25d45ace1225deb8e4920f90b
3
+ metadata.gz: a8446539611012b7efebab8fd52da0b8ab1321be
4
+ data.tar.gz: 96f9443a411a6f7ed32f4127e62dbfeae82f8fc2
5
5
  SHA512:
6
- metadata.gz: 2f6f8ca60672d34f473877980e17f8b503462ef27a2ff1860a31703f1bff69cd12ef2fa6ede088b59b54c78687c4815eff43835c11c14e8c8b83dbd41de5c092
7
- data.tar.gz: 5b900454d685e75c10299da0836945ac5dd67a47a54db11e784df2c85808b16d41f752d1cee794ba25315043383c8239408dbf066d065a72ca108c96468c5c89
6
+ metadata.gz: 317588df63149979a28abb55f5d5938dc74d6d5f4d77b8d0e1a07b38aaf631a0faa63039c829df72008b0245b965952499e649f4e4e2bd3f01209013cd71aaa0
7
+ data.tar.gz: bb64255d9c3fcc79cc7596b6447b122f29010703f9e4dc1d59bb49b5fe41308aef67d10a4474eb68339ddf023cdb4888aebf925cbf0990a8ca151cfc4e84ea26
data/README.md CHANGED
@@ -65,6 +65,9 @@ Day starter routine
65
65
 
66
66
  * Updates projects (runs 'Update projects')
67
67
  * Shows latest and deprecated repos
68
+ * Shows deprecated Ruby versions
69
+
70
+ Prerequisites: in a directory that contains git repos, not in the repo itself
68
71
 
69
72
  #### Hi!
70
73
 
@@ -86,6 +89,17 @@ Day starter routine for a new start
86
89
 
87
90
  Prerequisites: on master
88
91
 
92
+ #### Gem clean
93
+
94
+ * Removes unused gems
95
+
96
+ ### Ruby
97
+
98
+ #### Ruby versions
99
+
100
+ * Shows Ruby versions in use
101
+ * Searches for repositories on paths: `.`, `./*/`
102
+
89
103
  ## Feedback
90
104
 
91
105
  Any feedback is much appreciated.
@@ -107,7 +121,7 @@ This gem is developed using the following conventions:
107
121
 
108
122
  ## Contributing
109
123
 
110
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/your_gem.
124
+ Bug reports and pull requests are welcome on GitHub at https://github.com/thisismydesign/autowow.
111
125
 
112
126
  ## License
113
127
 
data/lib/autowow/cli.rb CHANGED
@@ -11,6 +11,8 @@ module Autowow
11
11
  map %w[up] => :update_projects
12
12
  map %w[cb] => :clear_branches
13
13
  map %w[au] => :add_upstream
14
+ map %w[gc] => :gem_clean
15
+ map %w[rv] => :ruby_versions
14
16
 
15
17
  desc "branch_merged", "clean working branch and return to master"
16
18
  def branch_merged
@@ -51,5 +53,15 @@ module Autowow
51
53
  def open
52
54
  Autowow::Vcs.open
53
55
  end
56
+
57
+ desc "gem_clean", "cleans unused gems"
58
+ def gem_clean
59
+ Autowow::Gem.clean
60
+ end
61
+
62
+ desc "ruby_versions", "shows ruby versions in use"
63
+ def ruby_versions
64
+ logger.info(Autowow::Ruby.used_versions)
65
+ end
54
66
  end
55
67
  end
@@ -6,11 +6,11 @@ module Autowow
6
6
  include EasyLogging
7
7
 
8
8
  def self.run(*args)
9
- Command.new(*args).explain.chronic_execute
9
+ Command.new(*args).check.explain.chronic_execute
10
10
  end
11
11
 
12
12
  def self.run_dry(*args)
13
- Command.new(*args).execute
13
+ Command.new(*args).silent_check.execute
14
14
  end
15
15
 
16
16
  def self.popen3_reader(*args)
@@ -38,16 +38,31 @@ module Autowow
38
38
  end
39
39
 
40
40
  def execute
41
- @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(*@cmd)
41
+ @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(*@cmd) unless @cmd.empty?
42
42
  self
43
43
  end
44
44
 
45
45
  def chronic_execute
46
- @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(*@cmd)
46
+ @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(*@cmd) unless @cmd.empty?
47
47
  logger.error(stderr) unless stderr.empty?
48
48
  self
49
49
  end
50
50
 
51
+ def silent_check
52
+ @stdin, @stdout, @stderr, @wait_thr = Open3.popen3('which', @cmd[0])
53
+ unless output_matches?(not_empty_matcher)
54
+ yield if block_given?
55
+ @cmd = []
56
+ end
57
+ self
58
+ end
59
+
60
+ def check
61
+ silent_check do
62
+ logger.info("Skipping '#{@cmd.join(' ')}' because command '#{@cmd[0]}' is not found.")
63
+ end
64
+ end
65
+
51
66
  def output_matches?(matcher)
52
67
  stdout.match(matcher)
53
68
  end
@@ -56,5 +71,8 @@ module Autowow
56
71
  !output_matches?(matcher)
57
72
  end
58
73
 
74
+ def not_empty_matcher
75
+ %r{.*\S.*}
76
+ end
59
77
  end
60
78
  end
data/lib/autowow/fs.rb CHANGED
@@ -5,7 +5,7 @@ module Autowow
5
5
  using RefinedTimeDifference
6
6
 
7
7
  def self.ls_dirs
8
- Dir.glob(File.expand_path('./*/'))
8
+ Dir.glob(File.expand_path('./*/')).select {|f| File.directory? f}
9
9
  end
10
10
 
11
11
  def self.latest(files)
data/lib/autowow/gem.rb CHANGED
@@ -24,5 +24,9 @@ module Autowow
24
24
  def self.release
25
25
  Command.run('rake', 'release')
26
26
  end
27
+
28
+ def self.clean
29
+ Command.run('gem', 'clean')
30
+ end
27
31
  end
28
32
  end
@@ -0,0 +1,38 @@
1
+ module Autowow
2
+ class Ruby
3
+ include EasyLogging
4
+
5
+ def self.used_versions
6
+ rubies = []
7
+ Fs.in_place_or_subdirs(Vcs.is_git?(Vcs.status_dry)) do
8
+ rubies.push(version)
9
+ end
10
+ rubies.uniq
11
+ end
12
+
13
+ def self.version
14
+ Command.run_dry('rbenv', 'local').stdout
15
+ end
16
+
17
+ def self.installed_versions
18
+ Command.run_dry('rbenv', 'versions', '--bare', '--skip-aliases').stdout.each_line.map(&:strip)
19
+ end
20
+
21
+ def self.aliases
22
+ aliases = {}
23
+ Command.run_dry('rbenv', 'alias').stdout.each_line do |line|
24
+ aliases[line.strip.split(' => ')[0]] = line.strip.split(' => ')[1]
25
+ end
26
+ aliases
27
+ end
28
+
29
+ def self.obsolete_versions
30
+ alias_map = aliases
31
+ used_versions_and_aliases = used_versions
32
+ used_versions.each do |v|
33
+ used_versions_and_aliases.push(alias_map[v]) if alias_map.has_key?(v)
34
+ end
35
+ installed_versions - used_versions_and_aliases
36
+ end
37
+ end
38
+ end
data/lib/autowow/vcs.rb CHANGED
@@ -8,6 +8,8 @@ require_relative 'command'
8
8
  require_relative 'decorators/string_decorator'
9
9
  require_relative 'fs'
10
10
  require_relative 'time_difference'
11
+ require_relative 'gem'
12
+ require_relative 'ruby'
11
13
 
12
14
  module Autowow
13
15
  class Vcs
@@ -74,16 +76,24 @@ module Autowow
74
76
  request.verify_mode = OpenSSL::SSL::VERIFY_NONE
75
77
  request.use_ssl = url.scheme == 'https'
76
78
  response = request.get(path)
77
- logger.error("Github API (#{url.scheme}://#{host}#{path}) could not be reached: #{response.body}") and return unless response.kind_of?(Net::HTTPSuccess)
78
- parsed_response = JSON.parse(response.body)
79
- logger.warn('Not a fork.') and return unless parsed_response['fork']
80
- parent_url = parsed_response.dig('parent', 'html_url')
81
- add_remote('upstream', parent_url) unless parent_url.to_s.empty?
82
79
 
83
- logger.info(remotes.stdout)
80
+ if response.kind_of?(Net::HTTPRedirection)
81
+ logger.error('Repository moved / renamed. Update remote or implement redirect handling. :)')
82
+ elsif response.kind_of?(Net::HTTPNotFound)
83
+ logger.error('Repository not found. Maybe it is private.')
84
+ elsif response.kind_of?(Net::HTTPSuccess)
85
+ parsed_response = JSON.parse(response.body)
86
+ logger.warn('Not a fork.') and return unless parsed_response['fork']
87
+ parent_url = parsed_response.dig('parent', 'html_url')
88
+ add_remote('upstream', parent_url) unless parent_url.to_s.empty?
89
+ logger.info(remotes.stdout)
90
+ else
91
+ logger.error("Github API (#{url.scheme}://#{host}#{path}) could not be reached: #{response.body}")
92
+ end
84
93
  end
85
94
 
86
95
  def self.hi
96
+ logger.error("In a git repository. Try 1 level higher.") && return if is_git?(status_dry)
87
97
  latest_project_info = get_latest_project_info
88
98
  logger.info("\nHang on, updating your local projects and remote forks...\n\n")
89
99
  git_projects.each do |project|
@@ -96,14 +106,18 @@ module Autowow
96
106
  logger.info("\nGood morning!\n\n")
97
107
  logger.info(latest_project_info)
98
108
  check_projects_older_than(1, :months)
109
+ logger.info("\nThe following Ruby versions are not used by any projects, maybe consider removing them?\n #{Ruby.obsolete_versions.join("\n ")}")
99
110
  end
100
111
 
101
112
  def self.hi!
113
+ logger.error("In a git repository. Try 1 level higher.") && return if is_git?(status_dry)
102
114
  hi do
103
115
  logger.info('Removing unused branches...')
104
116
  clear_branches
105
117
  logger.info('Adding upstream...')
106
118
  add_upstream
119
+ logger.info('Removing unused gems...')
120
+ logger.info(Gem.clean.stdout)
107
121
  end
108
122
  end
109
123
 
@@ -1,3 +1,3 @@
1
1
  module Autowow
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autowow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thisismydesign
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-24 00:00:00.000000000 Z
11
+ date: 2017-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: easy_logging
@@ -207,6 +207,7 @@ files:
207
207
  - lib/autowow/fs.rb
208
208
  - lib/autowow/gem.rb
209
209
  - lib/autowow/log_formatter.rb
210
+ - lib/autowow/ruby.rb
210
211
  - lib/autowow/time_difference.rb
211
212
  - lib/autowow/vcs.rb
212
213
  - lib/autowow/version.rb
@@ -230,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
231
  version: '0'
231
232
  requirements: []
232
233
  rubyforge_project:
233
- rubygems_version: 2.6.11
234
+ rubygems_version: 2.5.1
234
235
  signing_key:
235
236
  specification_version: 4
236
237
  summary: Set of commands to AUTOmate Way Of Working