diff options
-rw-r--r-- | gentoo-data.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/gentoo-data.rb b/gentoo-data.rb index bcd245a..79c3b34 100644 --- a/gentoo-data.rb +++ b/gentoo-data.rb @@ -32,6 +32,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' class GentooPlugin < Plugin Config.register Config::StringValue.new('gentoo.scriptdir', @@ -118,6 +119,7 @@ class GentooPlugin < Plugin super @@cached = {} @@cached['herds'] = [0, nil] + @@cached['projects'] = [0, nil] @@cached['pkgindex'] = [0, nil] @@cached['alias'] = [0, nil] @@cached['notherds'] = [0, nil] @@ -179,6 +181,55 @@ class GentooPlugin < Plugin end end + def project(m, params) + now = Time.now.tv_sec + unless @@cached['projects'] and @@cached['projects'][0] > now-600 + #m.reply "Fetch #{@@cached['projects'][0]} > #{now-600}" + res = @bot.httputil.get(PROJECTS_SRC) + projects = REXML::Document.new(res) + @@cached['projects'] = [now, projects] + else + #m.reply "Cache #{@@cached['projects'][0]} > #{now-600}" + projects = @@cached['projects'][1] + end + + req_project = params[:project] + unless req_project.include?('@') + req_project += '@gentoo.org' + end + + # Parse data + # xpath queries with REXML appear to be extremely slow, which is why we took the approach below + def expand_project_recursively(projects, proj_email) + project = nil + projects.elements[1].each_element { |elem| + if elem.get_elements('email')[0].text == proj_email + project = elem + break + end } + + emails = [] + if project + for maintainer in project.get_elements("member") + emails << maintainer.get_elements('email')[0].text.chomp('@gentoo.org') + end + for subproject in project.get_elements("subproject") + if subproject.attributes["inherit-members"] == "1" + emails += expand_project_recursively(projects, + subproject.attributes["ref"]) + end + end + end + return emails + end + emails = expand_project_recursively(projects, req_project) + unless emails.empty? + m.reply "(#{req_project}) #{emails.sort.uniq.join(', ')}" + else + m.reply "No such project: #{req_project}" + end + end + def expand_alias(m, params) now = Time.now.tv_sec unless @@cached['alias'] and @@cached['alias'][0] > now-600 @@ -340,6 +391,7 @@ class GentooPlugin < Plugin "changelog" => "changelog #{Bold}[cat/]package#{Bold} : Produce changelog statistics for a given package", "devaway" => "devaway #{Bold}devname|list#{Bold} : Print the .away for a developer (if any). Using 'list' shows the developers who are away.", "herd" => "herd #{Bold}herdname#{Bold} : Print the members of a herd.", + "proj" => "proj #{Bold}project-email#{Bold} : Print the members of a project.", "expn" => "expn #{Bold}alias#{Bold} : Print the addresses on a Gentoo mail alias.", "glsa" => [ "glsa #{Bold}GLSA-ID#{Bold} : Prints the title and reference IDs for a given GLSA.", @@ -371,6 +423,7 @@ plugin.default_auth( 'view', true ) REGEX_CP = /^(?:[-[:alnum:]]+\/)?[-+_[:alnum:]]+$/ REGEX_DEV = /^[-_[:alnum:]]+$/ REGEX_HERD = /^[-_[:alnum:]]+$/ +REGEX_PROJECT = /^[-_@.[:alnum:]]+$/ REGEX_GLSA = /^[-1234567890]+$/ plugin.map 'meta -v :pkg', @@ -428,6 +481,14 @@ plugin.map 'herd :herd', :thread => 'yes', :auth_path => 'view' +plugin.map 'proj :project', + :requirements => { + :project => REGEX_PROJECT, + }, + :action => 'project', + :thread => 'yes', + :auth_path => 'view' + plugin.map 'expn :alias', :requirements => { :alias => REGEX_DEV, |