This is an automated email from the ASF dual-hosted git repository.

sebb 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 f4222f6  Add epochs for emeritus request listings
f4222f6 is described below

commit f4222f6459c239748b8c8f4fd47502d3e86671cd
Author: Sebb <[email protected]>
AuthorDate: Wed Jul 15 15:28:45 2020 +0100

    Add epochs for emeritus request listings
---
 Rakefile                                    |  2 +-
 lib/spec/lib/svn_spec.rb                    | 18 ++++++++-
 lib/test/svn/emeritus-requests-received.txt |  4 +-
 lib/whimsy/asf/documents.rb                 | 14 ++++---
 lib/whimsy/asf/svn.rb                       | 59 ++++++++++++++++++++++++-----
 repository.yml                              |  3 +-
 www/roster/models/committer.rb              |  6 ++-
 www/roster/views/person/forms.js.rb         |  5 +++
 8 files changed, 90 insertions(+), 21 deletions(-)

diff --git a/Rakefile b/Rakefile
index 90dddd5..9363030 100644
--- a/Rakefile
+++ b/Rakefile
@@ -132,7 +132,7 @@ namespace :svn do
           puts File.join(Dir.pwd, name)
           if description['list']
             puts "#{PREFIX} Updating listing file"
-            old,new = ASF::SVN.updatelisting(name)
+            old,new = ASF::SVN.updatelisting(name,nil,nil,description['dates'])
             if old == new
               puts "List is at revision #{old}."
             elsif old == nil
diff --git a/lib/spec/lib/svn_spec.rb b/lib/spec/lib/svn_spec.rb
index 42c08db..85211a9 100644
--- a/lib/spec/lib/svn_spec.rb
+++ b/lib/spec/lib/svn_spec.rb
@@ -391,4 +391,20 @@ describe ASF::SVN do
     end
   end
 
-end
+  describe "ASF::SVN.getlisting" do
+    set_svnroot # need local test data here
+    it "getlisting('emeritus') returns array of 1" do
+      tag,list = ASF::SVN.getlisting('emeritus')
+      expect(list).to eq(['emeritus1.txt'])
+    end
+    it "getlisting('emeritus-requests-received') returns array of 1" do
+      tag,list = ASF::SVN.getlisting('emeritus-requests-received')
+      expect(list).to eq(['emeritus3.txt'])
+    end
+    it "getlisting('emeritus-requests-received,nil,true,true') returns array 
of [epoch,name]" do
+      tag,list = 
ASF::SVN.getlisting('emeritus-requests-received',nil,true,true)
+      expect(list).to eq([['1594814364','emeritus3.txt']])
+    end
+  end
+  
+  end
diff --git a/lib/test/svn/emeritus-requests-received.txt 
b/lib/test/svn/emeritus-requests-received.txt
index e9c6411..cd01b47 100644
--- a/lib/test/svn/emeritus-requests-received.txt
+++ b/lib/test/svn/emeritus-requests-received.txt
@@ -1,2 +1,2 @@
-0
-emeritus3.txt
+epoch:0
+1594814364:emeritus3.txt
diff --git a/lib/whimsy/asf/documents.rb b/lib/whimsy/asf/documents.rb
index b128fe6..a5e8ac2 100644
--- a/lib/whimsy/asf/documents.rb
+++ b/lib/whimsy/asf/documents.rb
@@ -104,21 +104,25 @@ module ASF
 
   class EmeritusFiles
     @base = 'emeritus'
-    def self.listnames
-      _, list = ASF::SVN.getlisting(@base)
+    def self.listnames(getDates=false)
+      _, list = ASF::SVN.getlisting(@base,nil,true,getDates)
       list
     end
 
     # Find the file name that matches a person
     # return nil if not exactly one match
     # TODO: should it raise an error on multiple matches?
-    def self.find(person)
+    def self.find(person, getDate=false)
       # TODO use common stem name method
       name = (person.attrs['cn'].first rescue 
person.member_name).force_encoding('utf-8').
         downcase.gsub(' ','-').gsub(/[^a-z0-9-]+/,'') rescue nil
       id = person.id
-      files = self.listnames.find_all do |file|
-        stem = file.split('.')[0] # directories don't have a trailing /
+      files = self.listnames(getDate).find_all do |file|
+        if getDate
+          stem = file[1].split('.')[0] # directories don't have a trailing /
+        else
+          stem = file.split('.')[0] # directories don't have a trailing /
+        end
         stem == id or stem == name
       end
       # Only valid if we match a single file or directory
diff --git a/lib/whimsy/asf/svn.rb b/lib/whimsy/asf/svn.rb
index ae2cc72..822c320 100644
--- a/lib/whimsy/asf/svn.rb
+++ b/lib/whimsy/asf/svn.rb
@@ -894,11 +894,14 @@ module ASF
       end
     end
     
+    EPOCH_SEP = ':' # separator
+    EPOCH_TAG = 'epoch'+EPOCH_SEP # marker in file to show epochs are present
+    EPOCH_LEN = EPOCH_TAG.size
     # update directory listing in /srv/svn/<name>.txt
     # N.B. The listing includes the trailing '/' so directory names can be 
distinguished
     # @return filerev, svnrev
     # on error return nil,message
-    def self.updatelisting(name, user=nil, password=nil)
+    def self.updatelisting(name, user=nil, password=nil, storedates=false)
       url = self.svnurl(name)
       unless url
         return nil,"Cannot find URL"
@@ -906,20 +909,42 @@ module ASF
       listfile, listfiletmp = self.listingNames(name)
       filerev = "0"
       svnrev = "?"
+      filedates = false
       begin
         open(listfile) do |l|
           filerev = l.gets.chomp
+          if filerev.start_with? EPOCH_TAG # drop the marker
+            filerev = filerev[EPOCH_LEN..] 
+            filedates = true
+          end
         end
       rescue
       end
       svnrev, err = self.getInfoItem(url,'last-changed-revision',user,password)
       if svnrev
         begin
-          unless filerev == svnrev
-            list = self.list(url, user, password)
-            open(listfiletmp,'w') do |w|
-              w.puts svnrev
-              w.puts list
+          unless filerev == svnrev && filedates == storedates
+            list = self.list(url, user, password, storedates)
+            if storedates
+              require 'nokogiri'
+              require 'date'
+              open(listfiletmp,'w') do |w|
+                w.puts "#{EPOCH_TAG}#{svnrev}" # show that this file has epochs
+                xml_doc  = Nokogiri::XML(list)
+                xml_doc.css('entry').each do |entry|
+                  kind = entry.css('@kind').text
+                  name = entry.at_css('name').text
+                  date = entry.at_css('date').text
+                  epoch = DateTime.parse(date).strftime('%s')
+                  # The separator is the last character of the epoch tag
+                  w.puts "%s#{EPOCH_SEP}%s%s" % [epoch,name,kind=='dir' ? '/' 
: '']
+                end
+              end
+            else
+              open(listfiletmp,'w') do |w|
+                w.puts svnrev
+                w.puts list
+              end
             end
             File.rename(listfiletmp,listfile)
           end
@@ -938,23 +963,37 @@ module ASF
     # - name: alias for SVN checkout
     # - tag: previous tag to check for changes, default nil
     # - trimSlash: whether to trim trailing '/', default true
+    # - getEpoch: whether to return the epoch if present, default false
     # @return tag, Array of names
     # or tag, nil if unchanged
     # or Exception if error
     # The tag should be regarded as opaque
-    def self.getlisting(name, tag=nil, trimSlash = true)
+    def self.getlisting(name, tag=nil, trimSlash = true, getEpoch = false)
       listfile, _ = self.listingNames(name)
-      curtag = "%s:%d" % [trimSlash, File.mtime(listfile)]
+      curtag = "%s:%s:%d" % [trimSlash, getEpoch, File.mtime(listfile)]
       if curtag == tag
         return curtag, nil
       else
         open(listfile) do |l|
           # fetch the file revision from the first line
           _filerev = l.gets.chomp # TODO should we be checking _filerev?
+          if _filerev.start_with?(EPOCH_TAG)
+            if getEpoch
+              trimEpoch = -> l { l.split(EPOCH_SEP,2) } # return as array
+            else
+              trimEpoch = -> l { l.split(EPOCH_SEP,2)[1] } # strip the epoch
+            end
+          else
+            trimEpoch = nil
+          end
           if trimSlash
-            return curtag, l.readlines.map {|x| x.chomp.chomp('/')}
+            list = l.readlines.map {|x| x.chomp.chomp('/')}
+            list = list.map(&trimEpoch) if trimEpoch
+            return curtag, list
           else
-            return curtag, l.readlines.map(&:chomp)
+            list = l.readlines.map(&:chomp)
+            list = list.map(&trimEpoch) if trimEpoch
+            return curtag, list
           end
         end
       end
diff --git a/repository.yml b/repository.yml
index 1e3516e..07f8024 100644
--- a/repository.yml
+++ b/repository.yml
@@ -99,10 +99,11 @@
     depth: delete
     list: true
 
-  emeritus-requests-received:
+  emeritus-requests-received: # listing has dates for age checks
     url: private/documents/emeritus-requests-received
     depth: delete
     list: true
+    dates: true
 
   emeritus-requests-rescinded:
     url: private/documents/emeritus-requests-rescinded
diff --git a/www/roster/models/committer.rb b/www/roster/models/committer.rb
index 9148165..0afb1fd 100644
--- a/www/roster/models/committer.rb
+++ b/www/roster/models/committer.rb
@@ -2,6 +2,8 @@ require 'whimsy/asf/memapps'
 
 class Committer
 
+  SECS_TO_DAYS = 60*60*24
+
   def self.serialize(id, env)
     response = {}
 
@@ -152,9 +154,11 @@ class Committer
           response[:forms][:emeritus] = ASF::SVN.svnpath!('emeritus', file)
         end
 
-        file = ASF::EmeritusRequestFiles.find(person)
+        epoch, file = ASF::EmeritusRequestFiles.find(person, true)
         if file
           response[:forms][:emeritus_request] = 
ASF::SVN.svnpath!('emeritus-requests-received', file)
+          # Calculate the age in days
+          response[:emeritus_request_age] = (((Time.now.to_i - 
epoch.to_i).to_f/SECS_TO_DAYS)).round(1).to_s
         end
 
         file = ASF::EmeritusRescindedFiles.find(person)
diff --git a/www/roster/views/person/forms.js.rb 
b/www/roster/views/person/forms.js.rb
index a95bc9c..b9f1f64 100644
--- a/www/roster/views/person/forms.js.rb
+++ b/www/roster/views/person/forms.js.rb
@@ -48,6 +48,11 @@ class PersonForms < Vue
                   _a 'Emeritus Request',
                     href: "#{link}"
                 end
+                emeritus_request_age = committer['emeritus_request_age']
+                if emeritus_request_age
+                  _ ' Days since submission: '
+                  _ emeritus_request_age
+                end
               end
             elsif form == 'emeritus_rescinded'
               _li do

Reply via email to