getv 1.7.0 → 2.1.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
  SHA256:
3
- metadata.gz: d49b33dd0cac92da670d6e87cd932f4fbd60b6cb5d1db7f9ea2448a295f1f9b5
4
- data.tar.gz: c8d460259782dbd03a353f79e7be1cee0d1e1f65124f06e04084931bcd880fad
3
+ metadata.gz: db69c25dd1811c324c47e3cce6a8d3ce4622ad2fcad25ae4a3703924ac332419
4
+ data.tar.gz: ba83a11669af015add4a7b35269d5c16e187fc81020adac07c0fb8de116ab431
5
5
  SHA512:
6
- metadata.gz: ef3b8cdbf5e974ff3c1663f3ec46eabc8b894aaea5e5f082ac5aa4c6d82d4c7e2ff3134cbc4e56f0da4fafe7eafb483eb0241d611b8d6b65370e50e8a66a86c8
7
- data.tar.gz: b641600ab4ba600a5b337b06036c7779c9d89520cd11a5c4a38c1665073d082b7cd056120e417c8acf597ba2bb773798f8cd53c230635191208e89133f0d674d
6
+ metadata.gz: 966f194d7fdaa930a8f60ca9500b46d756b3d67d735c1cc5a64c8fc6ec802cde7a3bf8ce6b1c8d0707acd59f7d6d2c9120b7a1c167089514cc72589dd6837120
7
+ data.tar.gz: ae5a6bee53a79a2902522126c83c30664195793c47f6148a32c663dc87a577527e0c9fbaf8b7ba6a99a64c8e1b0752213d47f73bf418c8512e7e2f20ef973f4d
data/README.md CHANGED
@@ -39,7 +39,7 @@ SYNOPSIS
39
39
 
40
40
 
41
41
  VERSION
42
- 1.7.0
42
+ 2.0.0
43
43
 
44
44
 
45
45
 
@@ -55,15 +55,15 @@ GLOBAL OPTIONS
55
55
  COMMANDS
56
56
  docker - Get package versions from a Docker or OCI container image registry
57
57
  gem - Get package versions from RubyGems.org
58
- get - Get package versions from text file URL
59
58
  github_commit - Get package versions from GitHub commits
60
59
  github_release - Get package versions from GitHub releases
61
60
  github_tag - Get package versions from GitHub tags
62
61
  helm - Get package versions from a Helm chart repository
63
62
  help - Shows a list of commands or help for one command
64
- index - Get package versions from web page of links
65
63
  npm - Get package versions from npm at registry.npmjs.org
66
64
  pypi - Get package versions from the Python Package Index at pypi.org
65
+ text - Get package versions from text file URL
66
+ xml - Get package versions from XML file URL
67
67
  ```
68
68
 
69
69
  ### CLI examples
@@ -72,7 +72,7 @@ Show the latest available version of the `getv` gem:
72
72
 
73
73
  ```console
74
74
  $ getv --latest gem getv
75
- 1.7.0
75
+ 2.0.0
76
76
  ```
77
77
 
78
78
  Show all `dep` GitHub release versions in JSON:
@@ -108,10 +108,10 @@ $ getv --json docker --reject '-' --semantic_select '~>1.3.0,!=1.3.1' apache/sup
108
108
  {"name":"apache/superset","versions":["1.3.0","1.3.2"]}
109
109
  ```
110
110
 
111
- Show all versions of `libnetfilter_acct` using selected link values on an indexed web page:
111
+ Show all versions of `libnetfilter_acct` using selected link values (`<a>` HTML elements) on an indexed web page:
112
112
 
113
113
  ```console
114
- $ getv --select_search='^.*libnetfilter_acct-([\d\.]*)\.tar\.bz2$' index --url=https://netfilter.org/projects/libnetfilter_acct/files --link_value libnetfilter_acct
114
+ $ getv xml --url=https://netfilter.org/projects/libnetfilter_acct/files --xpath '//a' --select_search='^.*libnetfilter_acct-([\d\.]*)\.tar\.bz2$' libnetfilter_acct
115
115
  1.0.0
116
116
  1.0.1
117
117
  1.0.2
@@ -133,9 +133,16 @@ Example:
133
133
  ```ruby
134
134
  require 'getv'
135
135
 
136
- superset = Getv::Package.new 'superset', type: 'docker', owner: 'apache', reject: '-'
136
+ superset = Getv::Package::Docker.new 'apache/superset', reject: '-'
137
137
  puts superset.versions
138
138
  puts superset.latest_version
139
+
140
+ # You can also use the flexible "create" factory method
141
+ Getv::Package.create 'apache/superset', type: 'docker', reject: '-'
142
+ Getv::Package.create 'golang/dep', type: 'github release'
143
+ Getv::Package.create 'golang/dep', type: 'github_release'
144
+ Getv::Package.create 'golang/dep', type: 'GitHub::Release'
145
+ Getv::Package.create 'rubygem-getv'
139
146
  ```
140
147
 
141
148
  ## Development
data/exe/getv CHANGED
@@ -39,7 +39,7 @@ class App # rubocop:disable Metrics/ClassLength
39
39
  desc 'Get package versions from a Docker or OCI container image registry'
40
40
  arg_name 'package_name'
41
41
  command :docker do |c| # rubocop:disable Metrics/BlockLength
42
- defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
42
+ defaults = (Getv::Package::Docker.new 'name').opts
43
43
  c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
44
44
  c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
45
45
  c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
@@ -63,7 +63,7 @@ class App # rubocop:disable Metrics/ClassLength
63
63
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
64
64
  opts[:semantic_only] = !options[:invalid_versions]
65
65
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
66
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
66
+ package = Getv::Package::Docker.new args[0], opts
67
67
  Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
68
68
  end
69
69
  end
@@ -71,7 +71,7 @@ class App # rubocop:disable Metrics/ClassLength
71
71
  desc 'Get package versions from RubyGems.org'
72
72
  arg_name 'package_name'
73
73
  command :gem do |c|
74
- defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
74
+ defaults = (Getv::Package::Gem.new 'name').opts
75
75
  c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
76
76
  c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
77
77
  c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
@@ -86,15 +86,15 @@ class App # rubocop:disable Metrics/ClassLength
86
86
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
87
87
  opts[:semantic_only] = !options[:invalid_versions]
88
88
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
89
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
89
+ package = Getv::Package::Gem.new args[0], opts
90
90
  Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
91
91
  end
92
92
  end
93
93
 
94
94
  desc 'Get package versions from text file URL'
95
95
  arg_name 'package_name'
96
- command :get do |c|
97
- defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
96
+ command :text do |c|
97
+ defaults = (Getv::Package::Text.new 'name').opts
98
98
  c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
99
99
  c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
100
100
  c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
@@ -105,11 +105,12 @@ class App # rubocop:disable Metrics/ClassLength
105
105
  c.action do |global_options, options, args|
106
106
  help_now! unless args.size == 1
107
107
 
108
+ opts = global_options.merge(options)
108
109
  opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :url, :proxy
109
110
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
110
111
  opts[:semantic_only] = !options[:invalid_versions]
111
112
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
112
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
113
+ package = Getv::Package::Text.new args[0], opts
113
114
  Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
114
115
  end
115
116
  end
@@ -117,7 +118,7 @@ class App # rubocop:disable Metrics/ClassLength
117
118
  desc 'Get package versions from GitHub commits'
118
119
  arg_name 'package_name'
119
120
  command :github_commit do |c|
120
- defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
121
+ defaults = (Getv::Package::GitHub::Commit.new 'name').opts
121
122
  c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
122
123
  c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
123
124
  c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
@@ -133,7 +134,7 @@ class App # rubocop:disable Metrics/ClassLength
133
134
  opts = global_options.merge(options)
134
135
  opts = opts.slice :select_search, :select_replace, :reject, :owner, :repo, :branch, :token, :proxy
135
136
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
136
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
137
+ package = Getv::Package::GitHub::Commit.new args[0], opts
137
138
  Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
138
139
  end
139
140
  end
@@ -141,7 +142,7 @@ class App # rubocop:disable Metrics/ClassLength
141
142
  desc 'Get package versions from GitHub releases'
142
143
  arg_name 'package_name'
143
144
  command :github_release do |c|
144
- defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
145
+ defaults = (Getv::Package::GitHub::Release.new 'name').opts
145
146
  c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
146
147
  c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
147
148
  c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
@@ -162,7 +163,7 @@ class App # rubocop:disable Metrics/ClassLength
162
163
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
163
164
  opts[:semantic_only] = !options[:invalid_versions]
164
165
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
165
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
166
+ package = Getv::Package::GitHub::Release.new args[0], opts
166
167
  Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
167
168
  end
168
169
  end
@@ -170,7 +171,7 @@ class App # rubocop:disable Metrics/ClassLength
170
171
  desc 'Get package versions from GitHub tags'
171
172
  arg_name 'package_name'
172
173
  command :github_tag do |c|
173
- defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
174
+ defaults = (Getv::Package::GitHub::Tag.new 'name').opts
174
175
  c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
175
176
  c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
176
177
  c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
@@ -191,7 +192,7 @@ class App # rubocop:disable Metrics/ClassLength
191
192
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
192
193
  opts[:semantic_only] = !options[:invalid_versions]
193
194
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
194
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
195
+ package = Getv::Package::GitHub::Tag.new args[0], opts
195
196
  Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
196
197
  end
197
198
  end
@@ -199,7 +200,7 @@ class App # rubocop:disable Metrics/ClassLength
199
200
  desc 'Get package versions from a Helm chart repository'
200
201
  arg_name 'package_name'
201
202
  command :helm do |c|
202
- defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
203
+ defaults = (Getv::Package::Helm.new 'name').opts
203
204
  c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
204
205
  c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
205
206
  c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
@@ -219,15 +220,15 @@ class App # rubocop:disable Metrics/ClassLength
219
220
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
220
221
  opts[:semantic_only] = !options[:invalid_versions]
221
222
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
222
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
223
+ package = Getv::Package::Helm.new args[0], opts
223
224
  Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
224
225
  end
225
226
  end
226
227
 
227
- desc 'Get package versions from web page of links'
228
+ desc 'Get package versions from XML file URL'
228
229
  arg_name 'package_name'
229
- command :index do |c|
230
- defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
230
+ command :xml do |c|
231
+ defaults = (Getv::Package::Xml.new 'name').opts
231
232
  c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
232
233
  c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
233
234
  c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
@@ -235,6 +236,7 @@ class App # rubocop:disable Metrics/ClassLength
235
236
  c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)',
236
237
  default_value: defaults[:semantic_select]
237
238
  c.flag %i[url], desc: 'URL', default_value: defaults[:url]
239
+ c.flag %i[xpath], desc: 'XPath', default_value: defaults[:xpath]
238
240
  c.switch %i[link_value], desc: 'Use the value (target) of links rather than the content (display text)',
239
241
  negatable: false, default_value: false
240
242
  c.action do |global_options, options, args|
@@ -246,7 +248,7 @@ class App # rubocop:disable Metrics/ClassLength
246
248
  opts[:link] == 'value' if options[:link_value]
247
249
  opts[:semantic_only] = !options[:invalid_versions]
248
250
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
249
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
251
+ package = Getv::Package::Xml.new args[0], opts
250
252
  Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
251
253
  end
252
254
  end
@@ -254,7 +256,7 @@ class App # rubocop:disable Metrics/ClassLength
254
256
  desc 'Get package versions from npm at registry.npmjs.org'
255
257
  arg_name 'package_name'
256
258
  command :npm do |c|
257
- defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
259
+ defaults = (Getv::Package::Npm.new 'name').opts
258
260
  c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
259
261
  c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
260
262
  c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
@@ -269,7 +271,7 @@ class App # rubocop:disable Metrics/ClassLength
269
271
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
270
272
  opts[:semantic_only] = !options[:invalid_versions]
271
273
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
272
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
274
+ package = Getv::Package::Npm.new args[0], opts
273
275
  Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
274
276
  end
275
277
  end
@@ -277,7 +279,7 @@ class App # rubocop:disable Metrics/ClassLength
277
279
  desc 'Get package versions from the Python Package Index at pypi.org'
278
280
  arg_name 'package_name'
279
281
  command :pypi do |c|
280
- defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
282
+ defaults = (Getv::Package::Pypi.new 'name').opts
281
283
  c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
282
284
  c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
283
285
  c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
@@ -292,7 +294,7 @@ class App # rubocop:disable Metrics/ClassLength
292
294
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
293
295
  opts[:semantic_only] = !options[:invalid_versions]
294
296
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
295
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
297
+ package = Getv::Package::Pypi.new args[0], opts
296
298
  Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
297
299
  end
298
300
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getv
4
+ class Package
5
+ # Getv::Package::Docker class
6
+ class Docker < Package
7
+ def initialize(name, opts = {})
8
+ opts = defaults.merge(opts)
9
+ opts = { user: nil, password: nil }.merge(opts)
10
+ opts = docker_defaults(name).merge(opts)
11
+ super name, opts
12
+ end
13
+
14
+ private
15
+
16
+ def docker_defaults(name)
17
+ case name.count('/')
18
+ when 0
19
+ { owner: 'library', repo: name, url: 'https://registry.hub.docker.com' }
20
+ when 1
21
+ { owner: name.split('/')[0], repo: name.split('/')[1],
22
+ url: 'https://registry.hub.docker.com' }
23
+ else
24
+ { owner: name.split('/')[1], repo: name.split('/')[2..-1].join('/'),
25
+ url: "https://#{name.split('/')[0]}" }
26
+ end
27
+ end
28
+
29
+ def docker_opts
30
+ d_opts = {}
31
+ d_opts[:http_options] = { proxy: opts[:proxy] } unless opts[:proxy].nil?
32
+ if opts[:user] && opts[:password]
33
+ d_opts[:user] = opts[:user]
34
+ d_opts[:password] = opts[:password]
35
+ end
36
+ d_opts
37
+ end
38
+
39
+ def retrieve_versions
40
+ require 'docker_registry2'
41
+ docker = DockerRegistry2.connect(opts[:url], docker_opts)
42
+ docker.tags("#{opts[:owner]}/#{opts[:repo]}")['tags']
43
+ rescue DockerRegistry2::NotFound
44
+ []
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getv
4
+ class Package
5
+ # Getv::Package::Gem class
6
+ class Gem < Package
7
+ def initialize(name, opts = {})
8
+ opts = defaults.merge(opts)
9
+ opts = { gem: name[/ruby(gem)?-(.*)/, 2] || name }.merge(opts)
10
+ super name, opts
11
+ end
12
+
13
+ private
14
+
15
+ def retrieve_versions
16
+ require 'json'
17
+ JSON.parse(get("https://rubygems.org/api/v1/versions/#{opts[:gem]}.json")).map do |v|
18
+ v['number']
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getv
4
+ class Package
5
+ class GitHub
6
+ # Getv::Package::GitHub::Commit class
7
+ class Commit < Package::GitHub
8
+ def initialize(name, opts = {})
9
+ opts = {
10
+ branch: 'master',
11
+ select_search: '^((\d{8})(\d{6}),(([a-z\d]{7})(.*)))$',
12
+ semantic_only: false
13
+ }.merge(opts)
14
+ opts = defaults.merge(opts)
15
+ opts = github_defaults(name).merge(opts)
16
+ super name, opts
17
+ end
18
+
19
+ private
20
+
21
+ def retrieve_versions
22
+ github.commits("#{opts[:owner]}/#{opts[:repo]}", opts[:branch]).map do |c|
23
+ "#{DateTime.parse(c[:commit][:author][:date].to_s).strftime('%Y%m%d%H%M%S')},#{c[:sha]}"
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getv
4
+ class Package
5
+ class GitHub
6
+ # Getv::Package::GitHub::Release class
7
+ class Release < Package::GitHub
8
+ def initialize(name, opts = {})
9
+ opts = defaults.merge(opts)
10
+ opts = github_defaults(name).merge(opts)
11
+ super name, opts
12
+ end
13
+
14
+ private
15
+
16
+ def retrieve_versions
17
+ github.releases("#{opts[:owner]}/#{opts[:repo]}").map(&:tag_name)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getv
4
+ class Package
5
+ class GitHub
6
+ # Getv::Package::GitHub::Tag class
7
+ class Tag < Package::GitHub
8
+ def initialize(name, opts = {})
9
+ opts = defaults.merge(opts)
10
+ opts = github_defaults(name).merge(opts)
11
+ super name, opts
12
+ end
13
+
14
+ private
15
+
16
+ def retrieve_versions
17
+ github.tags("#{opts[:owner]}/#{opts[:repo]}").map { |t| t[:name] }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getv
4
+ class Package
5
+ # Getv::Package::GitHub class
6
+ class GitHub < Package
7
+ def initialize(name, opts = {})
8
+ super name, opts
9
+ end
10
+
11
+ private
12
+
13
+ def github_defaults(name)
14
+ case name.count('/')
15
+ when 1
16
+ { owner: name.split('/')[0], repo: name.split('/')[1], token: nil }
17
+ else
18
+ { owner: name, repo: name, token: nil }
19
+ end
20
+ end
21
+
22
+ def github # rubocop:disable Metrics/MethodLength
23
+ require 'octokit'
24
+ if opts[:token]
25
+ github = Octokit::Client.new(access_token: opts[:token])
26
+ user = github.user
27
+ user.login
28
+ else
29
+ github = Octokit::Client.new
30
+ end
31
+ github.auto_paginate = true
32
+ github.proxy = opts[:proxy]
33
+ github
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getv
4
+ class Package
5
+ # Getv::Package::Helm class
6
+ class Helm < Package
7
+ def initialize(name, opts = {})
8
+ opts = defaults.merge(opts)
9
+ opts = { chart: name, url: nil, user: nil, password: nil }.merge(opts)
10
+ super name, opts
11
+ end
12
+
13
+ private
14
+
15
+ def retrieve_versions
16
+ require 'yaml'
17
+ YAML.safe_load(get("#{opts[:url]}/index.yaml")).fetch('entries', {}).fetch(opts[:chart], []).map do |e|
18
+ e['version']
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getv
4
+ class Package
5
+ # Getv::Package::Npm class
6
+ class Npm < Package
7
+ def initialize(name, opts = {})
8
+ opts = defaults.merge(opts)
9
+ opts = { npm: name[/node(js)?-(.*)/, 2] || name }.merge(opts)
10
+ super name, opts
11
+ end
12
+
13
+ private
14
+
15
+ def retrieve_versions
16
+ require 'json'
17
+ JSON.parse(get("https://registry.npmjs.org/#{opts[:npm]}"))['versions'].keys
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getv
4
+ class Package
5
+ # Getv::Package::Pypi class
6
+ class Pypi < Package
7
+ def initialize(name, opts = {})
8
+ opts = defaults.merge(opts)
9
+ opts = { pypi: name[/python.*-(.*)/, 1] || name }.merge(opts)
10
+ super name, opts
11
+ end
12
+
13
+ private
14
+
15
+ def retrieve_versions
16
+ require 'json'
17
+ JSON.parse(get("https://pypi.org/pypi/#{opts[:pypi]}/json"))['releases'].keys
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getv
4
+ class Package
5
+ # Getv::Package::Text class
6
+ class Text < Package
7
+ def initialize(name, opts = {})
8
+ opts = defaults.merge(opts)
9
+ opts = { url: nil, user: nil, password: nil }.merge(opts)
10
+ super name, opts
11
+ end
12
+
13
+ private
14
+
15
+ def retrieve_versions
16
+ get(opts[:url]).split("\n")
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getv
4
+ class Package
5
+ # Getv::Package::Xml class
6
+ class Xml < Package
7
+ def initialize(name, opts = {})
8
+ opts = defaults.merge(opts)
9
+ opts = { url: nil, user: nil, password: nil, xpath: '//a/@href' }.merge(opts)
10
+ super name, opts
11
+ end
12
+
13
+ private
14
+
15
+ def retrieve_versions
16
+ require 'nokogiri'
17
+ Nokogiri::XML(get(opts[:url])).xpath(opts[:xpath]).map(&:text)
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/getv/package.rb CHANGED
@@ -1,29 +1,49 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Getv
4
- # package class
5
- class Package # rubocop:disable Metrics/ClassLength
4
+ # Getv::Package class
5
+ class Package
6
6
  attr_accessor :name, :opts
7
7
 
8
- def initialize(name, opts = {}) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/PerceivedComplexity
9
- @name = name
8
+ def self.create(name, opts = {})
9
+ if opts.fetch(:type, nil).nil?
10
+ opts.delete(:type)
11
+ create_using_name(name, opts)
12
+ else
13
+ type = opts[:type]
14
+ opts.delete(:type)
15
+ type_to_class(type).new name, opts
16
+ end
17
+ end
18
+
19
+ private_class_method def self.create_using_name(name, opts)
10
20
  case name
11
- when /rubygem-.*/
12
- opts = { type: 'gem' }.merge(opts)
13
- when /nodejs-.*/
14
- opts = { type: 'npm' }.merge(opts)
21
+ when /ruby(gem)?-.*/
22
+ Getv::Package::Gem.new name, opts
23
+ when /node(js)?-.*/
24
+ Getv::Package::Npm.new name, opts
15
25
  when /python.*-.*/
16
- opts = { type: 'pypi' }.merge(opts)
17
- end
18
- if opts[:type] == 'github_commit'
19
- opts = {
20
- branch: 'master',
21
- select_search: '^((\d{8})(\d{6}),(([a-z\d]{7})(.*)))$',
22
- semantic_only: false
23
- }.merge(opts)
26
+ Getv::Package::Pypi.new name, opts
27
+ else
28
+ Getv::Package::GitHub::Release.new name, opts
24
29
  end
25
- opts = {
26
- type: 'github_release',
30
+ end
31
+
32
+ private_class_method def self.type_to_class(type)
33
+ sections = type.split(/_|::| |-|:/)
34
+ sections.each(&:capitalize!)
35
+ sections.each { |section| section.sub! 'Github', 'GitHub' }
36
+ type = sections.join '::'
37
+ Object.const_get("Getv::Package::#{type}")
38
+ end
39
+
40
+ def initialize(name, opts = {})
41
+ @name = name
42
+ @opts = opts
43
+ end
44
+
45
+ def defaults
46
+ {
27
47
  select_search: '^\s*v?(.*)\s*$',
28
48
  select_replace: '\1',
29
49
  reject: nil,
@@ -32,40 +52,7 @@ module Getv
32
52
  proxy: nil,
33
53
  versions: nil,
34
54
  latest_version: nil
35
- }.merge(opts)
36
- case opts[:type]
37
- when 'docker'
38
- opts = { user: nil, password: nil }.merge(opts)
39
- opts = case name.count('/')
40
- when 0
41
- { owner: 'library', repo: name, url: 'https://registry.hub.docker.com' }.merge(opts)
42
- when 1
43
- { owner: name.split('/')[0], repo: name.split('/')[1],
44
- url: 'https://registry.hub.docker.com' }.merge(opts)
45
- else
46
- { owner: name.split('/')[1], repo: name.split('/')[2..-1].join('/'),
47
- url: "https://#{name.split('/')[0]}" }.merge(opts)
48
- end
49
- when 'gem'
50
- opts = { gem: name[/rubygem-(.*)/, 1] || name }.merge(opts)
51
- when /github.*/
52
- opts = { token: nil }.merge(opts)
53
- opts = case name.count('/')
54
- when 1
55
- { owner: name.split('/')[0], repo: name.split('/')[1] }.merge(opts)
56
- else
57
- { owner: name, repo: name }.merge(opts)
58
- end
59
- when 'helm'
60
- opts = { chart: name, url: nil, user: nil, password: nil }.merge(opts)
61
- when 'index'
62
- opts = { link: 'content' }.merge(opts)
63
- when 'npm'
64
- opts = { npm: name[/nodejs-(.*)/, 1] || name }.merge(opts)
65
- when 'pypi'
66
- opts = { pypi: name[/python.*-(.*)/, 1] || name }.merge(opts)
67
- end
68
- @opts = opts
55
+ }
69
56
  end
70
57
 
71
58
  def latest_version
@@ -79,11 +66,8 @@ module Getv
79
66
  end
80
67
 
81
68
  def update_versions # rubocop:disable Metrics/PerceivedComplexity,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/AbcSize
82
- method = opts[:type].split('_')
83
- method[0] = "versions_using_#{method[0]}"
84
-
85
- versions = send(*method)
86
- versions.sort! if opts[:type] == 'github_commit'
69
+ versions = retrieve_versions
70
+ versions.sort! if instance_of?(Getv::Package::GitHub::Commit)
87
71
  select_pattern = Regexp.new(opts[:select_search])
88
72
  versions.select! { |v| v =~ select_pattern }
89
73
  versions.map! { |v| v.sub(select_pattern, opts[:select_replace]) }
@@ -97,7 +81,7 @@ module Getv
97
81
  end
98
82
  versions.sort_by! { |v| Semantic::Version.new(v) }
99
83
  else
100
- versions.sort! unless opts[:type] == 'github_commit'
84
+ versions.sort! unless instance_of?(Getv::Package::GitHub::Commit)
101
85
  end
102
86
  opts[:versions] = versions.uniq
103
87
  opts[:latest_version] = opts[:versions][-1] unless opts[:versions].empty?
@@ -114,83 +98,5 @@ module Getv
114
98
  RestClient::Request.execute(method: :get, url: url, proxy: opts[:proxy]).body
115
99
  end
116
100
  end
117
-
118
- def versions_using_docker # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
119
- require 'docker_registry2'
120
- docker_opts = {}
121
- docker_opts[:http_options] = { proxy: opts[:proxy] } unless opts[:proxy].nil?
122
- if opts[:user] && opts[:password]
123
- docker_opts[:user] = opts[:user]
124
- docker_opts[:password] = opts[:password]
125
- end
126
- docker = DockerRegistry2.connect(opts[:url], docker_opts)
127
- docker.tags("#{opts[:owner]}/#{opts[:repo]}")['tags']
128
- rescue DockerRegistry2::NotFound
129
- []
130
- end
131
-
132
- def versions_using_gem
133
- require 'json'
134
- JSON.parse(get("https://rubygems.org/api/v1/versions/#{opts[:gem]}.json")).map do |v|
135
- v['number']
136
- end
137
- end
138
-
139
- def versions_using_get
140
- get(opts[:url]).split("\n")
141
- end
142
-
143
- def github # rubocop:disable Metrics/MethodLength
144
- require 'octokit'
145
- if opts[:token]
146
- github = Octokit::Client.new(access_token: opts[:token])
147
- user = github.user
148
- user.login
149
- else
150
- github = Octokit::Client.new
151
- end
152
- github.auto_paginate = true
153
- github.proxy = opts[:proxy]
154
- github
155
- end
156
-
157
- def versions_using_github(method) # rubocop:disable Metrics/AbcSize
158
- case method
159
- when 'release'
160
- github.releases("#{opts[:owner]}/#{opts[:repo]}").map(&:tag_name)
161
- when 'commit'
162
- github.commits("#{opts[:owner]}/#{opts[:repo]}", opts[:branch]).map do |c|
163
- "#{DateTime.parse(c[:commit][:author][:date].to_s).strftime('%Y%m%d%H%M%S')},#{c[:sha]}"
164
- end
165
- else
166
- github.tags("#{opts[:owner]}/#{opts[:repo]}").map { |t| t[:name] }
167
- end
168
- end
169
-
170
- def versions_using_helm
171
- require 'yaml'
172
- YAML.safe_load(get("#{opts[:url]}/index.yaml")).fetch('entries', {}).fetch(name, []).map { |e| e['version'] }
173
- end
174
-
175
- def versions_using_index
176
- require 'nokogiri'
177
- Nokogiri::HTML(get(opts[:url])).css('a').map do |a|
178
- if opts[:link] == 'value'
179
- a.values[0]
180
- else
181
- a.public_send(opts[:link])
182
- end
183
- end
184
- end
185
-
186
- def versions_using_npm
187
- require 'json'
188
- JSON.parse(get("https://registry.npmjs.org/#{opts[:npm]}"))['versions'].keys
189
- end
190
-
191
- def versions_using_pypi
192
- require 'json'
193
- JSON.parse(get("https://pypi.org/pypi/#{opts[:pypi]}/json"))['releases'].keys
194
- end
195
101
  end
196
102
  end
data/lib/getv/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Getv
4
- VERSION = '1.7.0'
4
+ VERSION = '2.1.0'
5
5
  end
data/lib/getv.rb CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  require 'getv/version'
4
4
  require 'getv/package'
5
+ require 'getv/package/docker'
6
+ require 'getv/package/gem'
7
+ require 'getv/package/github'
8
+ require 'getv/package/github/commit'
9
+ require 'getv/package/github/release'
10
+ require 'getv/package/github/tag'
11
+ require 'getv/package/helm'
12
+ require 'getv/package/npm'
13
+ require 'getv/package/pypi'
14
+ require 'getv/package/text'
15
+ require 'getv/package/xml'
5
16
 
6
17
  module Getv
7
18
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - harbottle
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-03 00:00:00.000000000 Z
11
+ date: 2022-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -143,6 +143,17 @@ files:
143
143
  - exe/getv
144
144
  - lib/getv.rb
145
145
  - lib/getv/package.rb
146
+ - lib/getv/package/docker.rb
147
+ - lib/getv/package/gem.rb
148
+ - lib/getv/package/github.rb
149
+ - lib/getv/package/github/commit.rb
150
+ - lib/getv/package/github/release.rb
151
+ - lib/getv/package/github/tag.rb
152
+ - lib/getv/package/helm.rb
153
+ - lib/getv/package/npm.rb
154
+ - lib/getv/package/pypi.rb
155
+ - lib/getv/package/text.rb
156
+ - lib/getv/package/xml.rb
146
157
  - lib/getv/version.rb
147
158
  homepage: https://github.com/liger1978/getv
148
159
  licenses: