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 a15b10f WHIMSY-336 atomic SVN updates a15b10f is described below commit a15b10f68a87355708c0828dde9006ce99fe804c Author: Sebb <s...@apache.org> AuthorDate: Tue Jul 21 12:00:56 2020 +0100 WHIMSY-336 atomic SVN updates Extract common code --- www/secretary/workbench/tasks.rb | 40 ++++++++++++++++++++++ www/secretary/workbench/views/actions/ccla.json.rb | 26 +++----------- .../workbench/views/actions/grant.json.rb | 26 ++------------ 3 files changed, 48 insertions(+), 44 deletions(-) diff --git a/www/secretary/workbench/tasks.rb b/www/secretary/workbench/tasks.rb index ced5fb2..cba6bd1 100644 --- a/www/secretary/workbench/tasks.rb +++ b/www/secretary/workbench/tasks.rb @@ -77,6 +77,46 @@ class Wunderbar::JsonBuilder ] end + # Commit new file(s) and update associated index + # e.g. add ccla.pdf, ccla.pdf.asc to documents/cclas/xyz/ and update officers/cclas.txt + # Parameters: + # index_dir - SVN alias of directory containint the index (e.g. foundation or officers) + # index_name - name of index file to update (e.g. cclas.txt) + # docdir - SVN alias for document directory (e.g. cclas) + # docname - document name (as per email) + # docsig - document signature (may be null) + # outfilename - name of output file (without extension) + # outfileext - output file extension + # emessage - the email message + # svnmessage - the svn commit message + # block - the block which is passed the contents of the index file to be updated + def svn_multi(index_dir, index_name, docdir, docname, docsig, outfilename, outfileext, emessage, svnmessage, &block) + ASF::SVN.multiUpdate_(ASF::SVN.svnpath!(index_dir, index_name), svnmessage, env, _) do |text| + + extras = [] + # write the attachments as file(s) + dest = emessage.write_att(docname, docsig) + + if dest.size > 1 # write to a container directory + unless outfilename =~ /\A[a-zA-Z][-.\w]+\z/ # previously done by write_svn + raise IOError.new("invalid filename: #{outfilename}") + end + container = ASF::SVN.svnpath!(docdir, outfilename) + extras << ['mkdir', container] + dest.each do |name, path| + extras << ['put', path, File.join(container, name)] + end + else + name, path = dest.flatten + extras << ['put', path, ASF::SVN.svnpath!(docdir,"#{outfilename}#{outfileext}")] + end + + text = yield text # update the index + + [text, extras] + end + end + def template(name) path = File.expand_path("../templates/#{name}", __FILE__.untaint) ERB.new(File.read(path.untaint).untaint).result(binding) diff --git a/www/secretary/workbench/views/actions/ccla.json.rb b/www/secretary/workbench/views/actions/ccla.json.rb index 92e6b51..e9377d1 100644 --- a/www/secretary/workbench/views/actions/ccla.json.rb +++ b/www/secretary/workbench/views/actions/ccla.json.rb @@ -62,30 +62,14 @@ task "svn commit documents/cclas/#@filename#{fileext} and update cclas.txt" do end complete do |dir| - ASF::SVN.multiUpdate_(ASF::SVN.svnpath!('officers', 'cclas.txt'), @document, env, _) do |text| - - extras = [] - # write the file(s) - dest = message.write_att(@selected, @signature) - - if dest.size > 1 # write to a container directory - unless @filename =~ /\A[a-zA-Z][-.\w]+\z/ # previously done by write_svn - raise IOError.new("invalid filename: #{@filename}") - end - container = ASF::SVN.svnpath!('cclas', @filename) - extras << ['mkdir', container] - dest.each do |name, path| - extras << ['put', path, File.join(container, name)] - end - else - name, path = dest.flatten - extras << ['put', path, ASF::SVN.svnpath!('cclas',"#{@filename}#{fileext}")] - end - - [text + @cclalines + "\n", extras] + + svn_multi('officers', 'cclas.txt', 'cclas', @selected, @signature, @filename, fileext, message, @document) do |input| + # append entry to cclas.txt + text + @cclalines +"\n" end end + end ######################################################################## diff --git a/www/secretary/workbench/views/actions/grant.json.rb b/www/secretary/workbench/views/actions/grant.json.rb index 3338c9f..33aa99d 100644 --- a/www/secretary/workbench/views/actions/grant.json.rb +++ b/www/secretary/workbench/views/actions/grant.json.rb @@ -56,33 +56,13 @@ task "svn commit documents/grants/#@filename#{fileext} and update grants.txt" do end complete do |dir| - ASF::SVN.multiUpdate_(ASF::SVN.svnpath!('officers', 'grants.txt'), @document, env, _) do |input| - - extras = [] - - # write the file(s) - dest = message.write_att(@selected, @signature) - - if dest.size > 1 # write to a container directory - unless @filename =~ /\A[a-zA-Z][-.\w]+\z/ - raise IOError.new("invalid filename: #{@filename}") - end - container = ASF::SVN.svnpath!('grants', @filename) - extras << ['mkdir', container] - dest.each do |name, path| - extras << ['put', path, File.join(container, name)] - end - else - name, path = dest.flatten - extras << ['put', path, ASF::SVN.svnpath!('grants',"#{@filename}#{fileext}")] - end + svn_multi('officers', 'grants.txt', 'grants', @selected, @signature, @filename, fileext, message, @document) do |input| # update grants.txt marker = "\n# registering. documents on way to Secretary.\n" - out = input.split(marker).insert(1, "\n#{@grantlines}\n", marker).join - - [out, extras] + input.split(marker).insert(1, "\n#{@grantlines}\n", marker).join end + end end