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/06/29 20:32:54 UTC

[whimsy] branch master updated: Add svnpath! method to generate SVN URLs

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 26638a1  Add svnpath! method to generate SVN URLs
26638a1 is described below

commit 26638a1be4ef48289136243d5054e2e10c5facbc
Author: Sebb <se...@apache.org>
AuthorDate: Mon Jun 29 21:32:45 2020 +0100

    Add svnpath! method to generate SVN URLs
---
 lib/spec/lib/svn_spec.rb | 13 +++++++++++++
 lib/whimsy/asf/svn.rb    | 12 ++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/lib/spec/lib/svn_spec.rb b/lib/spec/lib/svn_spec.rb
index 29475dd..de4b5df 100644
--- a/lib/spec/lib/svn_spec.rb
+++ b/lib/spec/lib/svn_spec.rb
@@ -342,4 +342,17 @@ describe ASF::SVN do
       expect { ASF::SVN._svn_build_cmd('help', 'path', {_error: true}) }.to raise_error(ArgumentError, "Following options not recognised: [:_error]")
     end
   end
+
+  describe "ASF::SVN.svnpath!" do
+    it "svnpath!('board', 'committee-info.txt') should be https://svn.apache.org/repos/private/committers/board/committee-info.txt" do
+      exp = 'https://svn.apache.org/repos/private/committers/board/committee-info.txt'
+      act = ASF::SVN.svnpath!('board', 'committee-info.txt')
+      expect(act).to eq(exp)
+      act = ASF::SVN.svnpath!('board', '/committee-info.txt')
+      expect(act).to eq(exp)
+      act = ASF::SVN.svnpath!('board', '//committee-info.txt')
+      expect(act).to eq(exp)
+    end
+  end
+
 end
diff --git a/lib/whimsy/asf/svn.rb b/lib/whimsy/asf/svn.rb
index 13a63f8..2f32e70 100644
--- a/lib/whimsy/asf/svn.rb
+++ b/lib/whimsy/asf/svn.rb
@@ -136,6 +136,18 @@ module ASF
       entry
     end
 
+    # Construct a repository URL by name and relative path - abort if name is not found
+    # Includes aliases
+    # assumes that the relative paths are cumulative, unlike URI.merge
+    # name - the nickname for the URL
+    # relpath - the relative path(s) to the file
+    def self.svnpath!(name,*relpath)
+      base = self.svnurl!(name)
+      base = base + '/' unless base.end_with? '/'
+      endpart = [relpath].join('/').sub(%r{^/+},'').gsub(%r{/+},'/')
+      return base + endpart
+    end
+
     # find a local directory corresponding to a path in Subversion.  Returns
     # <tt>nil</tt> if not found.
 		# Excludes aliases