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 3c8d10e Add method to append a tlp entry
3c8d10e is described below
commit 3c8d10e0834b2a422a93d30022ed2800cddb8264
Author: Sebb <[email protected]>
AuthorDate: Tue Oct 22 15:22:31 2019 +0100
Add method to append a tlp entry
---
lib/whimsy/asf/site.rb | 69 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 68 insertions(+), 1 deletion(-)
diff --git a/lib/whimsy/asf/site.rb b/lib/whimsy/asf/site.rb
index 5fa92df..6e1f582 100644
--- a/lib/whimsy/asf/site.rb
+++ b/lib/whimsy/asf/site.rb
@@ -1,3 +1,8 @@
+if __FILE__ == $0 # testing only
+ require 'wunderbar'
+ require_relative 'config'
+ require_relative 'svn'
+end
require 'yaml'
module ASF
@@ -23,11 +28,45 @@ module ASF
@@list = yaml[:cttees].merge yaml[:tlps]
end
- # find the site for a given committee.
+ # find the data for a given committee.
def self.find(committee)
committee = committee.name if ASF::Committee == committee
list[committee]
end
+
+ # append the description for a new tlp committee.
+ # this is intended to be called from todos.json.rb in the block for
ASF::SVN.update
+ def self.appendtlp(input,committee,description)
+ output = input # default no change
+ yaml = YAML.load input
+ if yaml[:cttees][committee]
+ Wunderbar.warn "Entry for '#{committee}' already exists under :cttees"
+ elsif yaml[:tlps][committee]
+ Wunderbar.warn "Entry for '#{committee}' already exists under :tlps"
+ else
+ data = { # create single entry in :tlps hierarchy
+ tlps: {
+ committee => {
+ site: "http://#{committee}.apache.org",
+ description: description,
+ }
+ }
+ }
+ # Use YAML dump to ensure correct syntax
+ # drop the YAML header
+ newtlp = YAML.dump(data).sub(%r{^---\n:tlps:\n}m,'')
+ # add the new section just before the ... terminator
+ output = input.sub(%r{^\.\.\.},newtlp+"...")
+ # Check it worked
+ check = YAML.load(output)
+ unless data[:tlps][committee] == check[:tlps][committee]
+ Wunderbar.warn "Failed to add section for #{committee}"
+ output = input # don't change anything
+ end
+ end
+ output
+ end
+
end
class Committee
@@ -44,3 +83,31 @@ module ASF
end
end
end
+
+if __FILE__ == $0
+ require 'tempfile'
+ board = ASF::SVN.find('board')
+ file = File.join(board, 'committee-info.yaml')
+ if not File.exist?(file)
+ Wunderbar.error "Unable to find 'committee-info.yaml'"
+ return
+ end
+ input = File.read(file)
+ output = ASF::Site.appendtlp(input,'ant','ABCD.')
+ puts (output == input)
+ output = ASF::Site.appendtlp(input,'comdev','ABCD.')
+ puts (output == input)
+ output = ASF::Site.appendtlp(input,'antic1','ABCD.')
+ puts (output == input)
+ output = ASF::Site.appendtlp(output,'antic2','ABCD.')
+ puts (output == input)
+ Tempfile.create('site-ciy1') do |f|
+ Tempfile.create('site-ciy2') do |g|
+ f.write(input)
+ g.write(output)
+ f.close()
+ g.close()
+ system("diff #{f.path} #{g.path}")
+ end
+ end
+end