From 1ea09584ed8b61b56fe807b197ed5966730e4c6b Mon Sep 17 00:00:00 2001 From: Sebb Date: Sun, 30 Apr 2023 13:45:32 +0100 Subject: [PATCH] Allow for different field offsets --- lib/whimsy/asf/committee.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/whimsy/asf/committee.rb b/lib/whimsy/asf/committee.rb index e627184934..f2e89ae435 100644 --- a/lib/whimsy/asf/committee.rb +++ b/lib/whimsy/asf/committee.rb @@ -252,15 +252,24 @@ def self.update_roster(contents, cttee, people, action) # split block into lines lines = block.strip.split("\n") - + # get the first line and use that to calculate the offsets to use + # Note: this only affects new entries + sample = lines[1] + namelen = 26 # original + nameaddrlen = 59 # original + # N.B. 4 spaces are assumed at the start + if sample =~ %r{^ (\S.+) (<\S+?>\s+)\[} + namelen = $1.size + nameaddrlen = namelen + $2.size + end # add or remove people people.each do |person| id = person.id if action == 'add' unless lines.any? {|line| line.include? "<#{id}@apache.org>"} - name = "#{person.public_name.ljust(26)} <#{id}@apache.org>" + name = "#{person.public_name.ljust(namelen)} <#{id}@apache.org>" time = Time.new.gmtime.strftime('%Y-%m-%d') - lines << " #{name.ljust(59)} [#{time}]" + lines << " #{name.ljust(nameaddrlen)} [#{time}]" end elsif action == 'remove' lines.reject! {|line| line.include? "<#{id}@apache.org>"}