public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Robin H. Johnson" <robbat2@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/rbot-gentoo:master commit in: /
Date: Mon, 11 Jan 2016 16:25:58 +0000 (UTC)	[thread overview]
Message-ID: <1452529518.eda77830a3201e013e95e747b81e5b0ea0b5ecc2.robbat2@gentoo> (raw)

commit:     eda77830a3201e013e95e747b81e5b0ea0b5ecc2
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 11 16:25:12 2016 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Mon Jan 11 16:25:18 2016 +0000
URL:        https://gitweb.gentoo.org/proj/rbot-gentoo.git/commit/?id=eda77830

Add !proj to obtain project members from projects.xml

Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>

 gentoo-data.rb | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

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,


             reply	other threads:[~2016-01-11 16:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-11 16:25 Robin H. Johnson [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-11-22  4:25 [gentoo-commits] proj/rbot-gentoo:master commit in: / Robin H. Johnson
2016-11-22  4:25 Robin H. Johnson
2016-11-22  4:17 Robin H. Johnson
2016-11-22  4:11 Robin H. Johnson
2016-08-13 18:24 Michał Górny
2016-06-15  3:13 Robin H. Johnson
2016-05-31 15:01 Robin H. Johnson
2016-01-27 18:21 Michał Górny
2016-01-27 18:21 Michał Górny
2016-01-27 18:21 Michał Górny
2016-01-27 18:21 Michał Górny
2016-01-27 18:21 Michał Górny
2016-01-27 18:21 Michał Górny
2016-01-12 19:09 Michał Górny
2016-01-12 19:09 Michał Górny
2016-01-12 19:09 Michał Górny
2012-04-01 15:59 Robin H. Johnson
2012-02-20  1:40 Robin H. Johnson
2011-11-17 19:55 Robin H. Johnson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1452529518.eda77830a3201e013e95e747b81e5b0ea0b5ecc2.robbat2@gentoo \
    --to=robbat2@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox