whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] branch master updated: implement adding/removing mentors
Date Sat, 27 May 2017 18:10:27 GMT
This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git

The following commit(s) were added to refs/heads/master by this push:
       new  013f3c3   implement adding/removing mentors
013f3c3 is described below

commit 013f3c3babf1b02fb81aa2682d79765445545327
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Sat May 27 14:10:09 2017 -0400

    implement adding/removing mentors
---
 lib/whimsy/asf/config.rb                   |  1 +
 lib/whimsy/asf/podlings.rb                 |  8 +++
 www/roster/views/actions/committee.json.rb |  2 +-
 www/roster/views/actions/ppmc.json.rb      | 84 ++++++++++++++++++++++++------
 4 files changed, 79 insertions(+), 16 deletions(-)

diff --git a/lib/whimsy/asf/config.rb b/lib/whimsy/asf/config.rb
index 6ecbcde..6980442 100644
--- a/lib/whimsy/asf/config.rb
+++ b/lib/whimsy/asf/config.rb
@@ -12,6 +12,7 @@ module ASF
     # default :svn and :git
     @config[:svn] ||= '/srv/svn/*'
     @config[:git] ||= '/srv/git/*'
+    @config[:cache] ||= '/srv/cache'
 
     @config[:lib] ||= []
 
diff --git a/lib/whimsy/asf/podlings.rb b/lib/whimsy/asf/podlings.rb
index b44c219..1cda7e6 100644
--- a/lib/whimsy/asf/podlings.rb
+++ b/lib/whimsy/asf/podlings.rb
@@ -99,6 +99,14 @@ module ASF
       incubator_content = ASF::SVN['asf/incubator/public/trunk/content']
       podlings_xml = "#{incubator_content}/podlings.xml"
 
+      # see if there is a later version
+      cache = ASF::Config.get(:cache)
+      if File.exist? "#{cache}/podlings.xml"
+        if File.mtime("#{cache}/podlings.xml") > File.mtime(podlings_xml)
+          podlings_xml = "#{cache}/podlings.xml"
+        end
+      end
+
       if @mtime != File.mtime(podlings_xml)
         @list = []
         podlings = Nokogiri::XML(File.read(podlings_xml))
diff --git a/www/roster/views/actions/committee.json.rb b/www/roster/views/actions/committee.json.rb
index 9e08c7c..5fabd35 100644
--- a/www/roster/views/actions/committee.json.rb
+++ b/www/roster/views/actions/committee.json.rb
@@ -70,7 +70,7 @@ if env.password
         ASF::Committee.parse_committee_info(info)
       else
         # die
-        raise Error.new('Update committee-info.txt failed')
+        raise Exception.new('Update committee-info.txt failed')
       end
     end
   end
diff --git a/www/roster/views/actions/ppmc.json.rb b/www/roster/views/actions/ppmc.json.rb
index 1afbe78..04a6940 100644
--- a/www/roster/views/actions/ppmc.json.rb
+++ b/www/roster/views/actions/ppmc.json.rb
@@ -1,7 +1,3 @@
-if @targets.include? 'mentor'
-  raise Exception.new('mentor updates not yet implemented') 
-end
-
 if env.password
   people = @ids.split(',').map {|id| ASF::Person.find(id)}
   project = ASF::Project.find(@project)
@@ -19,11 +15,14 @@ if env.password
     end
   end
 
-  # compose E-mail
-  action = (@action == 'add' ? 'added to' : 'removed from')
-  details = people.map {|person| person.dn} + [project.dn]
-  from = ASF::Person.find(env.user)
-  ppmc = ASF::Podling.find(@project)
+  # identify what has changed
+  if @targets.include? 'mentor'
+    target = 'mentors'
+  elsif @targets.include? 'ppmc'
+    target = 'PMC'
+  else
+    target = 'committers'
+  end
 
   # extract people's names (for short lists) or ids (for longer lists)
   if people.length <= 2
@@ -33,15 +32,70 @@ if env.password
       ', and ' + people.last.id
   end
 
-  # identify what has changed
+  # update podlings.xml
   if @targets.include? 'mentor'
-    target = 'mentors'
-  elsif @targets.include? 'ppmc'
-    target = 'PMC'
-  else
-    target = 'committers'
+    Dir.mktmpdir do |tmpdir|
+      # checkout committers/board
+      Kernel.system 'svn', 'checkout', '--quiet', '--depth=empty',
+        '--no-auth-cache', '--non-interactive',
+        '--username', env.user.untaint, '--password', env.password.untaint,
+        'https://svn.apache.org/repos/asf/incubator/public/trunk/content',
+         tmpdir.untaint
+
+      # read in podlings.xml
+      file = File.join(tmpdir, 'podlings.xml')
+      Kernel.system 'svn', 'update', '--quiet', file
+      podlings = File.read(file)
+
+      pre = /<podling[^>]* resource="#{@project}".*?<\/podling>/m
+      people.each do |person|
+        id = person.id
+        if @action == 'add'
+	  podlings.sub! pre do |element|
+	    element.sub! /<mentors>.*<\/mentors>/m do |mentors|
+	      spaces = mentors[/(\s+)<mentor /, 1] || 
+		mentors[/(\s+)<\/mentors>/, 1] + '    '
+	      mentors[/()\s+<\/mentors>/, 1] = spaces +
+		"<mentor username=#{id.inspect}>#{person.public_name}</mentor>"
+	      mentors
+	    end
+	    element
+	  end
+        else
+	  podlings.sub! pre do |element|
+	    element.sub! /\s+<mentor username=#{id.inspect}>.*<\/mentor>/, ''
+	    element
+	  end
+        end
+      end
+
+      # write file out to disk
+      File.write(file, podlings)
+
+      # commit changes
+      rc = Kernel.system 'svn', 'commit', '--quiet',
+        '--no-auth-cache', '--non-interactive',
+        '--username', env.user.untaint, '--password', env.password.untaint,
+        tmpdir.untaint, '--message',
+        "#{@project} #{target} #{@action == 'add' ? '+' : '-'}= #{who}"
+
+      if rc
+        # update cache
+        cache = ASF::Config.get(:cache)
+        File.write("#{cache}/podlings.xml", podlings) if Dir.exist? cache
+      else
+        # die
+        raise Exception.new('Update podlings.xml failed')
+      end
+    end
   end
 
+  # compose E-mail
+  action = (@action == 'add' ? 'added to' : 'removed from')
+  details = people.map {|person| person.dn} + [project.dn]
+  from = ASF::Person.find(env.user)
+  ppmc = ASF::Podling.find(@project)
+
   # draft email
   mail = Mail.new do
     from "#{from.public_name} <#{from.id}@apache.org>".untaint

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <commits@whimsical.apache.org>'].

Mime
View raw message