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 2020/10/17 12:19:52 UTC

[whimsy] branch master updated: Simplify by using new YamlFile method

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 2ae8285  Simplify by using new YamlFile method
2ae8285 is described below

commit 2ae8285abb595f41fd4e85cbfc9c5f84319814cc
Author: Sebb <se...@apache.org>
AuthorDate: Sat Oct 17 13:19:43 2020 +0100

    Simplify by using new YamlFile method
---
 lib/whimsy/asf/committee.rb | 41 ++++++++++++++---------------------------
 1 file changed, 14 insertions(+), 27 deletions(-)

diff --git a/lib/whimsy/asf/committee.rb b/lib/whimsy/asf/committee.rb
index b5415cc..7334a00 100644
--- a/lib/whimsy/asf/committee.rb
+++ b/lib/whimsy/asf/committee.rb
@@ -1,4 +1,5 @@
 require 'time'
+require 'whimsy/asf/yaml'
 
 module ASF
 
@@ -632,38 +633,24 @@ module ASF
       meta[:description] if meta
     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.appendtlpmetadata(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,
-            }
+    def self.appendtlpmetadata(input, committee, description)
+      YamlFile.replace_section(input, :tlps) do |section, yaml|
+        output = section # default no change
+        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
+          section[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
+          output = section.sort.to_h
         end
+        output
       end
-      output
     end
 
   end