Skip to content

Commit

Permalink
Allow for different field offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbASF committed Apr 30, 2023
1 parent a5cff38 commit 1ea0958
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/whimsy/asf/committee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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>"}
Expand Down

0 comments on commit 1ea0958

Please sign in to comment.