diff options
Diffstat (limited to 'gentoo-data.rb')
-rw-r--r-- | gentoo-data.rb | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/gentoo-data.rb b/gentoo-data.rb index 37b606f..b1d9827 100644 --- a/gentoo-data.rb +++ b/gentoo-data.rb @@ -33,6 +33,7 @@ VALID_PACKAGE_SRC = "/dev/shm/qsearch.txt" GLSA_SRC = "#{ENV['PORTDIR']}/metadata/glsa/glsa-@GLSA_ID@.xml" HERDS_SRC = 'https://api.gentoo.org/packages/herds.xml' PROJECTS_SRC = 'https://api.gentoo.org/metastructure/projects.xml' +PGO_RESOLVE_URI = 'https://packages.gentoo.org/packages/resolve.json?atom=%s' class GentooPlugin < Plugin Config.register Config::StringValue.new('gentoo.scriptdir', @@ -54,7 +55,24 @@ class GentooPlugin < Plugin py = '/usr/bin/python' unless py return py end - + + def pgo_resolve(atom) + uri = PGO_RESOLVE_URI % [URI.escape(atom, '\W+')] + res = @bot.httputil.get(uri) + return JSON.parse(res) + end + + def pgo_resolve_one(m, atom) + pkgs = pgo_resolve(atom)['packages'] + if pkgs.empty? + m.reply "No matching packages for '#{atom}'" + elsif pkgs.length > 1 + m.reply "Ambiguous name '#{atom}'. Possible options: #{pkgs.map{ |x| x['atom'] }.sort.join(' ')}" + else + return pkgs[0] + end + end + def meta(m, params) cp = params[:pkg] cp = validate_package(m, cp) @@ -68,12 +86,12 @@ class GentooPlugin < Plugin m.reply "Cannot find metadata for '#{cp}'" end end - + def validpkg(m, params) - icp = params[:pkg] - cp = validate_package(m, icp) - return if cp.nil? - m.reply "#{icp} => #{cp} is valid" + atom = params[:pkg] + pkg = pgo_resolve_one(m, atom) + return if pkg.nil? + m.reply "#{atom} => #{pkg['atom']} is valid" end def meta_verbose(m, params) |