forked from openshift/verification-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_image.rb
executable file
·59 lines (50 loc) · 1.82 KB
/
find_image.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env ruby
require 'commander'
require 'open-uri'
require 'nokogiri'
require 'thread'
"""
Utility to query release page for matching payload containing a fix/PR matching a description provider by the user
"""
class QueryPayload
include Commander::Methods
# include whatever modules you need
def run
program :name, 'find_image'
program :version, '0.0.1'
program :description, 'Query the release page to find a matching image based on user defined query parameter'
default_command :query
command :query do |c|
c.syntax = 'query_images pattern, [options]'
c.description = ''
c.example 'description', 'command example'
c.option('-q', "--query QUERY_STRING", "search string")
c.option('-b', "--build_type BUILD_TYPE", "build type to filter out (ci-|nightly-)")
c.option('-u', "--url RELEASE_PAGE_URL", "URL of the release page")
c.action do |args, options|
options.default \
:build_type => "nightly-",
:url => "https://amd64.ocp.releases.ci.openshift.org/"
raise "missing query string" if options.query.nil?
print("Querying #{options.url} against #{options.build_type}\n")
doc = Nokogiri::HTML(URI.open(options.url).read)
links = doc.xpath("//a[contains(text(), '#{options.build_type}')]")
target_links = links.map { |l| options.url + l.attributes['href'].value }
threads = []
target_links.each do |link|
threads << Thread.new(link) do |i|
doc = Nokogiri::HTML(URI.open(link).read)
if doc.to_s.include? options.query
puts "Pattern '#{options.query}' found in payload: #{link}"
end
end
end
threads.each { |thr| thr.join }
end
end
run!
end
end
if $0 == __FILE__
QueryPayload.new.run
end