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 3d31f78b Extra validation of parsing
3d31f78b is described below

commit 3d31f78bfb50fd6f3b999a4dd5693b295d08c35b
Author: Sebb <s...@apache.org>
AuthorDate: Sat Feb 17 16:07:25 2024 +0000

    Extra validation of parsing
    
    Ensure required keys are generated
---
 lib/whimsy/asf/member-files.rb | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/lib/whimsy/asf/member-files.rb b/lib/whimsy/asf/member-files.rb
index b529fcc7..f7165ab0 100644
--- a/lib/whimsy/asf/member-files.rb
+++ b/lib/whimsy/asf/member-files.rb
@@ -1,3 +1,5 @@
+$LOAD_PATH.unshift '/srv/whimsy/lib' if __FILE__ == $PROGRAM_NAME
+
 require 'whimsy/asf/string-utils'
 
 require_relative 'config'
@@ -10,6 +12,8 @@ module ASF
 
     NOMINATED_MEMBERS = 'nominated-members.txt'
     NOMINATED_BOARD = 'board_nominations.txt'
+    # N.B. Board does not include email
+    VALID_KEYS = ['Nominated by','Nomination statement', 'Nominee email', 
'Seconded by']
   
     # get the latest meeting directory or nomination file
     def self.latest_meeting(name=nil)
@@ -56,12 +60,15 @@ module ASF
         nominee = {}
         header = nil
         block
-            .slice_before(/^ +(\S+ \S+):\s*/) # split on the header names
+            .slice_before(/^ +(\w+ \w+):\s*/) # split on the header names
             .each_with_index do |para, idx|
           if idx == 0 # id and name (or just name for board)
             header = para.first.strip
           else
-            key, value = para.shift.strip.split(': ', 2)
+            key, value = para.shift.strip.split(':', 2)
+            unless VALID_KEYS.include? key
+              raise ArgumentError.new "Invalid key name '#{key}' at 
'#{header}' in #{nomfile}"
+            end
             if para.size == 0 # no more data to follow
               nominee[key] = value
             else
@@ -71,7 +78,17 @@ module ASF
             end
           end
         end
-        yield header, nominee unless header.nil? || header.empty?
+
+        unless header.nil? || header.empty?
+          keys = nominee.keys
+          case name
+          when NOMINATED_BOARD
+            raise ArgumentError.new "Expected 3 keys, found #{keys} at 
'#{header}' in #{name}" unless keys.size == 3
+          when NOMINATED_MEMBERS
+            raise ArgumentError.new "Expected 4 keys, found #{keys} at 
'#{header}' in #{name}" unless keys.size == 4
+          end
+          yield header, nominee 
+        end
       end
     end
 

Reply via email to