You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2021/02/27 23:37:23 UTC

[whimsy] branch master updated: Simplify using shared nominee matcher

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 c5fef89  Simplify using shared nominee matcher
c5fef89 is described below

commit c5fef89548f655fb4693b92b7150a5d10efc372d
Author: Sebb <se...@apache.org>
AuthorDate: Sat Feb 27 23:35:20 2021 +0000

    Simplify using shared nominee matcher
---
 www/members/board-nominations.cgi | 33 +++++++++++++++++++++------------
 www/members/nominations.cgi       | 32 ++++++++++++++++++++------------
 2 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/www/members/board-nominations.cgi b/www/members/board-nominations.cgi
index 0c2e982..f9b7529 100755
--- a/www/members/board-nominations.cgi
+++ b/www/members/board-nominations.cgi
@@ -46,12 +46,27 @@ def setup_data
   end
 
   # preload names
-  people = ASF::Person.preload('cn',
+  ASF::Person.preload('cn',
     nominations.map {|nominee| ASF::Person.find(nominee[:id])})
 
-  return nominations, people, emails
+  return nominations, emails
 end
 
+# create the match RE from a nominee
+def create_match(nominee)
+  names = []
+  pname = nominee[:name]
+  names << pname
+  names << pname.sub(%r{ [A-Z]\. }, ' ') # drop initial
+  personname = ASF::Person.find(nominee[:id]).public_name
+  names << personname if personname
+  list = names.uniq.map{|name| Regexp.escape(name)}.join('|')
+  # N.B. \b does not match if it follows ')', so won't match John (Fred)
+  # TODO: Work-round is to also look for EOS, but this needs to be improved
+  %r{\b(#{list})(\b|$)}i
+end
+
+
 # produce HTML output of reports, highlighting ones that have not (yet)
 # been posted
 _html do
@@ -78,7 +93,7 @@ _html do
       }
     ) do
       cur_mtg_dir = File.basename(MeetingUtil.get_latest(MEETINGS))
-      nominations, people, emails = setup_data
+      nominations, emails = setup_data
       _div.flexbox do
         _div.flexitem do
           _h1_! do
@@ -91,9 +106,8 @@ _html do
           _ul nominations.sort_by {|nominee| nominee[:name]} do |nominee|
             _li! do
               person = ASF::Person.find(nominee[:id])
-              # N.B. \b does not match if it follows ')', so won't match John (Fred)
-              # TODO: Work-round is to also look for EOS, but this needs to be improved
-              match = /\b(#{Regexp.escape(nominee[:name]||'')}|#{Regexp.escape(person.public_name||'')})(\b|$)/i
+
+              match = create_match(nominee)
 
               if emails.any? {|mail| mail.subject.downcase =~ match}
                 _a.present person.public_name, href: "#{ROSTER}/#{nominee[:id]}"
@@ -110,9 +124,6 @@ _html do
           end
         end
 
-        nominees = nominations.map! {|person| person[:name]}
-        nominees += people.map {|person| person.public_name}
-
         _div.flexitem do
           _h1_.posted! do
             _a "Posted", href:
@@ -134,9 +145,7 @@ _html do
               href = MBOX + mail.date.strftime('%Y%m') + '.mbox/' +
               ERB::Util.url_encode('<' + mail.message_id + '>')
 
-              # N.B. \b does not match if it follows ')', so won't match John (Fred)
-              # TODO: Work-round is to also look for EOS, but this needs to be improved
-              if nominees.any? {|name| mail.subject =~ /\b#{Regexp.escape(name)}(\b|$)/i}
+              if nominations.any? {|nominee| mail.subject =~ create_match(nominee)}
                 _a.present mail.subject, href: href
               else
                 _a.missing mail.subject, href: href
diff --git a/www/members/nominations.cgi b/www/members/nominations.cgi
index 1ab8f69..796e1c2 100755
--- a/www/members/nominations.cgi
+++ b/www/members/nominations.cgi
@@ -46,10 +46,24 @@ def setup_data
   end
 
   # preload names
-  people = ASF::Person.preload('cn',
+  ASF::Person.preload('cn',
     nominations.map {|nominee| ASF::Person.find(nominee[:id])})
 
-  return nominations, people, emails
+  return nominations, emails
+end
+
+# create the match RE from a nominee
+def create_match(nominee)
+  names = []
+  pname = nominee[:name]
+  names << pname
+  names << pname.sub(%r{ [A-Z]\. }, ' ') # drop initial
+  personname = ASF::Person.find(nominee[:id]).public_name
+  names << personname if personname
+  list = names.uniq.map{|name| Regexp.escape(name)}.join('|')
+  # N.B. \b does not match if it follows ')', so won't match John (Fred)
+  # TODO: Work-round is to also look for EOS, but this needs to be improved
+  %r{\b(#{list})(\b|$)}i
 end
 
 # produce HTML output of reports, highlighting ones that have not (yet)
@@ -80,7 +94,7 @@ _html do
       }
     ) do
       cur_mtg_dir = File.basename(MeetingUtil.get_latest(MEETINGS))
-      nominations, people, emails = setup_data
+      nominations, emails = setup_data
       _div.flexbox do
         _div.flexitem do
           _h1_! do
@@ -94,9 +108,8 @@ _html do
           _ul nominations.sort_by {|nominee| nominee[:name]} do |nominee|
             _li! do
               person = ASF::Person.find(nominee[:id])
-              # N.B. \b does not match if it follows ')', so won't match John (Fred)
-              # TODO: Work-round is to also look for EOS, but this needs to be improved
-              match = /\b(#{Regexp.escape(nominee[:name]||'')}|#{Regexp.escape(person.public_name||'')})(\b|$)/i
+
+              match = create_match(nominee)
 
               if emails.any? {|mail| mail.subject.downcase =~ match}
                 _a.present person.public_name, href: "#{ROSTER}/#{nominee[:id]}"
@@ -113,9 +126,6 @@ _html do
           end
         end
 
-        nominees = nominations.map! {|person| person[:name]}
-        nominees += people.map {|person| person.public_name}
-
         _div.flexitem do
           _h1_.posted! do
             _a "Posted", href:
@@ -137,9 +147,7 @@ _html do
               href = MBOX + mail.date.strftime('%Y%m') + '.mbox/' +
               ERB::Util.url_encode('<' + mail.message_id + '>')
 
-              # N.B. \b does not match if it follows ')', so won't match John (Fred)
-              # TODO: Work-round is to also look for EOS, but this needs to be improved
-              if nominees.any? {|name| mail.subject =~ /\b#{Regexp.escape(name)}(\b|$)/i}
+              if nominations.any? {|nominee| mail.subject =~ create_match(nominee)}
                 _a.present mail.subject, href: href
               else
                 _a.missing mail.subject, href: href