getv 1.6.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 +13 -11
- data/exe/getv +51 -21
- 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 +27 -128
- 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,29 +39,31 @@ SYNOPSIS
|
|
39
39
|
|
40
40
|
|
41
41
|
VERSION
|
42
|
-
|
42
|
+
2.0.0
|
43
43
|
|
44
44
|
|
45
45
|
|
46
46
|
GLOBAL OPTIONS
|
47
|
-
--help
|
48
|
-
-j, --json
|
49
|
-
-l, --latest
|
50
|
-
--
|
47
|
+
--help - Show this message
|
48
|
+
-j, --json - Output in json
|
49
|
+
-l, --latest - Latest version
|
50
|
+
-p, --proxy=arg - Web proxy (default: none)
|
51
|
+
--version - Display the program version
|
51
52
|
|
52
53
|
|
53
54
|
|
54
55
|
COMMANDS
|
55
56
|
docker - Get package versions from a Docker or OCI container image registry
|
56
57
|
gem - Get package versions from RubyGems.org
|
57
|
-
get - Get package versions from text file URL
|
58
58
|
github_commit - Get package versions from GitHub commits
|
59
59
|
github_release - Get package versions from GitHub releases
|
60
60
|
github_tag - Get package versions from GitHub tags
|
61
|
+
helm - Get package versions from a Helm chart repository
|
61
62
|
help - Shows a list of commands or help for one command
|
62
|
-
index - Get package versions from web page of links
|
63
63
|
npm - Get package versions from npm at registry.npmjs.org
|
64
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
|
65
67
|
```
|
66
68
|
|
67
69
|
### CLI examples
|
@@ -70,7 +72,7 @@ Show the latest available version of the `getv` gem:
|
|
70
72
|
|
71
73
|
```console
|
72
74
|
$ getv --latest gem getv
|
73
|
-
|
75
|
+
2.0.0
|
74
76
|
```
|
75
77
|
|
76
78
|
Show all `dep` GitHub release versions in JSON:
|
@@ -106,10 +108,10 @@ $ getv --json docker --reject '-' --semantic_select '~>1.3.0,!=1.3.1' apache/sup
|
|
106
108
|
{"name":"apache/superset","versions":["1.3.0","1.3.2"]}
|
107
109
|
```
|
108
110
|
|
109
|
-
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:
|
110
112
|
|
111
113
|
```console
|
112
|
-
$ 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
|
113
115
|
1.0.0
|
114
116
|
1.0.1
|
115
117
|
1.0.2
|
@@ -131,7 +133,7 @@ Example:
|
|
131
133
|
```ruby
|
132
134
|
require 'getv'
|
133
135
|
|
134
|
-
superset = Getv::Package.new 'superset',
|
136
|
+
superset = Getv::Package::Docker.new 'apache/superset', reject: '-'
|
135
137
|
puts superset.versions
|
136
138
|
puts superset.latest_version
|
137
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,15 +192,43 @@ 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
|
196
|
+
Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
desc 'Get package versions from a Helm chart repository'
|
201
|
+
arg_name 'package_name'
|
202
|
+
command :helm do |c|
|
203
|
+
defaults = (Getv::Package::Helm.new 'name').opts
|
204
|
+
c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
|
205
|
+
c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
|
206
|
+
c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
|
207
|
+
c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
|
208
|
+
c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)',
|
209
|
+
default_value: defaults[:semantic_select]
|
210
|
+
c.flag %i[chart], desc: 'Chart name', default_value: 'package_name'
|
211
|
+
c.flag %i[url], desc: 'URL', default_value: defaults[:url]
|
212
|
+
c.flag %i[user], desc: 'Username', default_value: defaults[:user]
|
213
|
+
c.flag %i[password], desc: 'Password', default_value: defaults[:password]
|
214
|
+
c.action do |global_options, options, args|
|
215
|
+
help_now! unless args.size == 1
|
216
|
+
|
217
|
+
opts = global_options.merge(options)
|
218
|
+
opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :chart, :url,
|
219
|
+
:user, :password, :proxy
|
220
|
+
opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
|
221
|
+
opts[:semantic_only] = !options[:invalid_versions]
|
222
|
+
opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
|
223
|
+
package = Getv::Package::Helm.new args[0], opts
|
195
224
|
Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
|
196
225
|
end
|
197
226
|
end
|
198
227
|
|
199
|
-
desc 'Get package versions from
|
228
|
+
desc 'Get package versions from XML file URL'
|
200
229
|
arg_name 'package_name'
|
201
|
-
command :
|
202
|
-
defaults = (Getv::Package.new 'name'
|
230
|
+
command :xml do |c|
|
231
|
+
defaults = (Getv::Package::Xml.new 'name').opts
|
203
232
|
c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
|
204
233
|
c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
|
205
234
|
c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
|
@@ -207,6 +236,7 @@ class App # rubocop:disable Metrics/ClassLength
|
|
207
236
|
c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)',
|
208
237
|
default_value: defaults[:semantic_select]
|
209
238
|
c.flag %i[url], desc: 'URL', default_value: defaults[:url]
|
239
|
+
c.flag %i[xpath], desc: 'XPath', default_value: defaults[:xpath]
|
210
240
|
c.switch %i[link_value], desc: 'Use the value (target) of links rather than the content (display text)',
|
211
241
|
negatable: false, default_value: false
|
212
242
|
c.action do |global_options, options, args|
|
@@ -218,7 +248,7 @@ class App # rubocop:disable Metrics/ClassLength
|
|
218
248
|
opts[:link] == 'value' if options[:link_value]
|
219
249
|
opts[:semantic_only] = !options[:invalid_versions]
|
220
250
|
opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
|
221
|
-
package = Getv::Package.new args[0],
|
251
|
+
package = Getv::Package::Xml.new args[0], opts
|
222
252
|
Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
|
223
253
|
end
|
224
254
|
end
|
@@ -226,7 +256,7 @@ class App # rubocop:disable Metrics/ClassLength
|
|
226
256
|
desc 'Get package versions from npm at registry.npmjs.org'
|
227
257
|
arg_name 'package_name'
|
228
258
|
command :npm do |c|
|
229
|
-
defaults = (Getv::Package.new 'name'
|
259
|
+
defaults = (Getv::Package::Npm.new 'name').opts
|
230
260
|
c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
|
231
261
|
c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
|
232
262
|
c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
|
@@ -241,7 +271,7 @@ class App # rubocop:disable Metrics/ClassLength
|
|
241
271
|
opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
|
242
272
|
opts[:semantic_only] = !options[:invalid_versions]
|
243
273
|
opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
|
244
|
-
package = Getv::Package.new args[0],
|
274
|
+
package = Getv::Package::Npm.new args[0], opts
|
245
275
|
Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
|
246
276
|
end
|
247
277
|
end
|
@@ -249,7 +279,7 @@ class App # rubocop:disable Metrics/ClassLength
|
|
249
279
|
desc 'Get package versions from the Python Package Index at pypi.org'
|
250
280
|
arg_name 'package_name'
|
251
281
|
command :pypi do |c|
|
252
|
-
defaults = (Getv::Package.new 'name'
|
282
|
+
defaults = (Getv::Package::Pypi.new 'name').opts
|
253
283
|
c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
|
254
284
|
c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
|
255
285
|
c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
|
@@ -264,7 +294,7 @@ class App # rubocop:disable Metrics/ClassLength
|
|
264
294
|
opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
|
265
295
|
opts[:semantic_only] = !options[:invalid_versions]
|
266
296
|
opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
|
267
|
-
package = Getv::Package.new args[0],
|
297
|
+
package = Getv::Package::Pypi.new args[0], opts
|
268
298
|
Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
|
269
299
|
end
|
270
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,38 +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 'index'
|
60
|
-
opts = { link: 'content' }.merge(opts)
|
61
|
-
when 'npm'
|
62
|
-
opts = { npm: name[/nodejs-(.*)/, 1] || name }.merge(opts)
|
63
|
-
when 'pypi'
|
64
|
-
opts = { pypi: name[/python.*-(.*)/, 1] || name }.merge(opts)
|
65
|
-
end
|
66
|
-
@opts = opts
|
36
|
+
}
|
67
37
|
end
|
68
38
|
|
69
39
|
def latest_version
|
@@ -77,11 +47,8 @@ module Getv
|
|
77
47
|
end
|
78
48
|
|
79
49
|
def update_versions # rubocop:disable Metrics/PerceivedComplexity,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/AbcSize
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
versions = send(*method)
|
84
|
-
versions.sort! if opts[:type] == 'github_commit'
|
50
|
+
versions = retrieve_versions
|
51
|
+
versions.sort! if instance_of?(Getv::Package::GitHub::Commit)
|
85
52
|
select_pattern = Regexp.new(opts[:select_search])
|
86
53
|
versions.select! { |v| v =~ select_pattern }
|
87
54
|
versions.map! { |v| v.sub(select_pattern, opts[:select_replace]) }
|
@@ -95,7 +62,7 @@ module Getv
|
|
95
62
|
end
|
96
63
|
versions.sort_by! { |v| Semantic::Version.new(v) }
|
97
64
|
else
|
98
|
-
versions.sort! unless
|
65
|
+
versions.sort! unless instance_of?(Getv::Package::GitHub::Commit)
|
99
66
|
end
|
100
67
|
opts[:versions] = versions.uniq
|
101
68
|
opts[:latest_version] = opts[:versions][-1] unless opts[:versions].empty?
|
@@ -103,82 +70,14 @@ module Getv
|
|
103
70
|
|
104
71
|
private
|
105
72
|
|
106
|
-
def get(url)
|
73
|
+
def get(url) # rubocop:disable Metrics/AbcSize
|
107
74
|
require 'rest-client'
|
108
|
-
RestClient::Request.execute(method: :get, url: url, proxy: opts[:proxy]).body
|
109
|
-
end
|
110
|
-
|
111
|
-
def versions_using_docker # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
112
|
-
require 'docker_registry2'
|
113
|
-
docker_opts = {}
|
114
|
-
docker_opts[:http_options] = { proxy: opts[:proxy] } unless opts[:proxy].nil?
|
115
75
|
if opts[:user] && opts[:password]
|
116
|
-
|
117
|
-
|
118
|
-
end
|
119
|
-
docker = DockerRegistry2.connect(opts[:url], docker_opts)
|
120
|
-
docker.tags("#{opts[:owner]}/#{opts[:repo]}")['tags']
|
121
|
-
rescue DockerRegistry2::NotFound
|
122
|
-
[]
|
123
|
-
end
|
124
|
-
|
125
|
-
def versions_using_gem
|
126
|
-
require 'json'
|
127
|
-
JSON.parse(get("https://rubygems.org/api/v1/versions/#{opts[:gem]}.json")).map do |v|
|
128
|
-
v['number']
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def versions_using_get
|
133
|
-
get(opts[:url]).split("\n")
|
134
|
-
end
|
135
|
-
|
136
|
-
def github # rubocop:disable Metrics/MethodLength
|
137
|
-
require 'octokit'
|
138
|
-
if opts[:token]
|
139
|
-
github = Octokit::Client.new(access_token: opts[:token])
|
140
|
-
user = github.user
|
141
|
-
user.login
|
142
|
-
else
|
143
|
-
github = Octokit::Client.new
|
144
|
-
end
|
145
|
-
github.auto_paginate = true
|
146
|
-
github.proxy = opts[:proxy]
|
147
|
-
github
|
148
|
-
end
|
149
|
-
|
150
|
-
def versions_using_github(method) # rubocop:disable Metrics/AbcSize
|
151
|
-
case method
|
152
|
-
when 'release'
|
153
|
-
github.releases("#{opts[:owner]}/#{opts[:repo]}").map(&:tag_name)
|
154
|
-
when 'commit'
|
155
|
-
github.commits("#{opts[:owner]}/#{opts[:repo]}", opts[:branch]).map do |c|
|
156
|
-
"#{DateTime.parse(c[:commit][:author][:date].to_s).strftime('%Y%m%d%H%M%S')},#{c[:sha]}"
|
157
|
-
end
|
76
|
+
RestClient::Request.execute(method: :get, url: url, proxy: opts[:proxy], user: opts[:user],
|
77
|
+
password: opts[:password]).body
|
158
78
|
else
|
159
|
-
|
79
|
+
RestClient::Request.execute(method: :get, url: url, proxy: opts[:proxy]).body
|
160
80
|
end
|
161
81
|
end
|
162
|
-
|
163
|
-
def versions_using_index
|
164
|
-
require 'nokogiri'
|
165
|
-
Nokogiri::HTML(get(opts[:url])).css('a').map do |a|
|
166
|
-
if opts[:link] == 'value'
|
167
|
-
a.values[0]
|
168
|
-
else
|
169
|
-
a.public_send(opts[:link])
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def versions_using_npm
|
175
|
-
require 'json'
|
176
|
-
JSON.parse(get("https://registry.npmjs.org/#{opts[:npm]}"))['versions'].keys
|
177
|
-
end
|
178
|
-
|
179
|
-
def versions_using_pypi
|
180
|
-
require 'json'
|
181
|
-
JSON.parse(get("https://pypi.org/pypi/#{opts[:pypi]}/json"))['releases'].keys
|
182
|
-
end
|
183
82
|
end
|
184
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-
|
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: []
|