getv 1.7.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -7
- data/exe/getv +25 -23
- data/lib/getv/package/docker.rb +48 -0
- data/lib/getv/package/gem.rb +23 -0
- data/lib/getv/package/github/commit.rb +29 -0
- data/lib/getv/package/github/release.rb +22 -0
- data/lib/getv/package/github/tag.rb +22 -0
- data/lib/getv/package/github.rb +37 -0
- data/lib/getv/package/helm.rb +23 -0
- data/lib/getv/package/npm.rb +21 -0
- data/lib/getv/package/pypi.rb +21 -0
- data/lib/getv/package/text.rb +20 -0
- data/lib/getv/package/xml.rb +21 -0
- data/lib/getv/package.rb +23 -136
- data/lib/getv/version.rb +1 -1
- data/lib/getv.rb +11 -0
- metadata +17 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 519a4f5ae5d2129555292f828f3f60ec48f600b738ff2841477d3366502851c7
|
4
|
+
data.tar.gz: 23a08397b4fe40ca7512b1939ba43dd5262c404d09f8e08f4332e114ab184a0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c076cf15bee2101cfa3c1c53657c39a75e9d5accec6dc0c1949c82e459f925b7c51156c8ee1f8ee49d2c46a1d5811ddeba7dc83ad4a194285769db51ee629dd
|
7
|
+
data.tar.gz: d4624767daa67dd937992b6da9ce2c909fc26d5eb67267dc2c6b70cf40f29291edf37fc991f9c29e21fa034c65e0524a0fa22575141297453e42acfa461b8a17
|
data/README.md
CHANGED
@@ -39,7 +39,7 @@ SYNOPSIS
|
|
39
39
|
|
40
40
|
|
41
41
|
VERSION
|
42
|
-
|
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
|
-
|
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$'
|
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,7 +133,7 @@ Example:
|
|
133
133
|
```ruby
|
134
134
|
require 'getv'
|
135
135
|
|
136
|
-
superset = Getv::Package.new 'superset',
|
136
|
+
superset = Getv::Package::Docker.new 'apache/superset', reject: '-'
|
137
137
|
puts superset.versions
|
138
138
|
puts superset.latest_version
|
139
139
|
```
|
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'
|
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],
|
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'
|
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],
|
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 :
|
97
|
-
defaults = (Getv::Package.new 'name'
|
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],
|
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'
|
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],
|
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'
|
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],
|
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'
|
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],
|
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'
|
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],
|
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
|
228
|
+
desc 'Get package versions from XML file URL'
|
228
229
|
arg_name 'package_name'
|
229
|
-
command :
|
230
|
-
defaults = (Getv::Package.new 'name'
|
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],
|
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'
|
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],
|
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'
|
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],
|
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,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Getv
|
4
|
-
#
|
5
|
-
class Package
|
4
|
+
# Getv::Package class
|
5
|
+
class Package
|
6
6
|
attr_accessor :name, :opts
|
7
7
|
|
8
|
-
def
|
9
|
-
@name = name
|
8
|
+
def self.create(name, opts = {})
|
10
9
|
case name
|
11
|
-
when /
|
12
|
-
|
13
|
-
when /
|
14
|
-
|
10
|
+
when /ruby(gem)?-.*/
|
11
|
+
Getv::Package::Gem.new name, opts
|
12
|
+
when /node(js)?-.*/
|
13
|
+
Getv::Package::Npm.new name, opts
|
15
14
|
when /python.*-.*/
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
opts = {
|
20
|
-
branch: 'master',
|
21
|
-
select_search: '^((\d{8})(\d{6}),(([a-z\d]{7})(.*)))$',
|
22
|
-
semantic_only: false
|
23
|
-
}.merge(opts)
|
15
|
+
Getv::Package::Pypi.new name, opts
|
16
|
+
else
|
17
|
+
Getv::Package::GitHub::Release.new name, opts
|
24
18
|
end
|
25
|
-
|
26
|
-
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(name, opts = {})
|
22
|
+
@name = name
|
23
|
+
@opts = opts
|
24
|
+
end
|
25
|
+
|
26
|
+
def defaults
|
27
|
+
{
|
27
28
|
select_search: '^\s*v?(.*)\s*$',
|
28
29
|
select_replace: '\1',
|
29
30
|
reject: nil,
|
@@ -32,40 +33,7 @@ module Getv
|
|
32
33
|
proxy: nil,
|
33
34
|
versions: nil,
|
34
35
|
latest_version: nil
|
35
|
-
}
|
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
|
36
|
+
}
|
69
37
|
end
|
70
38
|
|
71
39
|
def latest_version
|
@@ -79,11 +47,8 @@ module Getv
|
|
79
47
|
end
|
80
48
|
|
81
49
|
def update_versions # rubocop:disable Metrics/PerceivedComplexity,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/AbcSize
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
versions = send(*method)
|
86
|
-
versions.sort! if opts[:type] == 'github_commit'
|
50
|
+
versions = retrieve_versions
|
51
|
+
versions.sort! if instance_of?(Getv::Package::GitHub::Commit)
|
87
52
|
select_pattern = Regexp.new(opts[:select_search])
|
88
53
|
versions.select! { |v| v =~ select_pattern }
|
89
54
|
versions.map! { |v| v.sub(select_pattern, opts[:select_replace]) }
|
@@ -97,7 +62,7 @@ module Getv
|
|
97
62
|
end
|
98
63
|
versions.sort_by! { |v| Semantic::Version.new(v) }
|
99
64
|
else
|
100
|
-
versions.sort! unless
|
65
|
+
versions.sort! unless instance_of?(Getv::Package::GitHub::Commit)
|
101
66
|
end
|
102
67
|
opts[:versions] = versions.uniq
|
103
68
|
opts[:latest_version] = opts[:versions][-1] unless opts[:versions].empty?
|
@@ -114,83 +79,5 @@ module Getv
|
|
114
79
|
RestClient::Request.execute(method: :get, url: url, proxy: opts[:proxy]).body
|
115
80
|
end
|
116
81
|
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(opts[:chart], []).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
82
|
end
|
196
83
|
end
|
data/lib/getv/version.rb
CHANGED
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:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- harbottle
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02
|
11
|
+
date: 2022-03-02 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:
|
@@ -151,7 +162,7 @@ metadata:
|
|
151
162
|
homepage_uri: https://github.com/liger1978/getv
|
152
163
|
source_code_uri: https://github.com/liger1978/getv
|
153
164
|
changelog_uri: https://github.com/liger1978/getv
|
154
|
-
post_install_message:
|
165
|
+
post_install_message:
|
155
166
|
rdoc_options: []
|
156
167
|
require_paths:
|
157
168
|
- lib
|
@@ -166,8 +177,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
177
|
- !ruby/object:Gem::Version
|
167
178
|
version: '0'
|
168
179
|
requirements: []
|
169
|
-
rubygems_version: 3.
|
170
|
-
signing_key:
|
180
|
+
rubygems_version: 3.2.22
|
181
|
+
signing_key:
|
171
182
|
specification_version: 4
|
172
183
|
summary: Pull package version numbers from the web in various ways.
|
173
184
|
test_files: []
|