You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by Sam Ruby <ru...@apache.org> on 2016/03/30 22:18:21 UTC
[whimsy.git] [1/1] Commit a403860: add funding source to bill upload function
Commit a4038605e65c7ee0a5b81325e3677d390649a6ed:
add funding source to bill upload function
Branch: refs/heads/master
Author: Sam Ruby <ru...@intertwingly.net>
Committer: Sam Ruby <ru...@intertwingly.net>
Pusher: rubys <ru...@apache.org>
------------------------------------------------------------
www/treasurer/bill-upload.cgi | +++++ ----
------------------------------------------------------------
67 changes: 38 additions, 29 deletions.
------------------------------------------------------------
diff --git a/www/treasurer/bill-upload.cgi b/www/treasurer/bill-upload.cgi
index 035d88e..a4d6587 100755
--- a/www/treasurer/bill-upload.cgi
+++ b/www/treasurer/bill-upload.cgi
@@ -2,6 +2,7 @@
require 'whimsy/asf'
require 'wunderbar'
+require 'tmpdir'
user = ASF::Person.new($USER)
unless user.asf_member? or ASF.pmc_chairs.include? user or $USER=='ea'
@@ -34,6 +35,9 @@ _html do
_label 'Enter Commit Message:', for: 'message'
_textarea name: 'message', id: 'message', cols: 80, required: true
+ _label 'Funding source:', for: 'source'
+ _textarea name: 'source', id: 'source', cols: 80
+
_label 'Select a destination:'
_div do
_input 'Bills/received', type: 'radio', name: 'dest', value: 'received',
@@ -48,6 +52,15 @@ _html do
end
if @file
+ # extract remote user's svn credentials
+ auth = ['--no-auth-cache', '--non-interactive']
+ if $PASSWORD
+ auth += ['--username', $USER, '--password', $PASSWORD]
+ end
+
+ # destination directory
+ bills = 'https://svn.apache.org/repos/private/financials/Bills'
+
# validate @file, @dest form parameters
name = @file.original_filename.gsub(/[^-.\w]/, '_').sub(/^\.+/, '_').untaint
@dest.untaint if @dest =~ /^\w+$/
@@ -59,36 +72,32 @@ _html do
elsif not @dest or @dest.empty?
_pre 'Destination is required', class: '_stderr'
else
- Dir.chdir File.join(ASF::SVN['private/financials/Bills'], @dest) do
- _h2 'Commit log'
-
- # cleanup anything left over from previous runs
- `svn cleanup`
- status = `svn status`
- unless status.empty?
- status.scan(/^[?A]\s*\+?\s*(.*)/).flatten.each do |uncommitted|
- _.system ['rm', '-rf', uncommitted]
- end
- if status =~ /^\w/
- _.system ['svn', 'revert', '-R', file]
- end
- end
+ # append funding source to message, if present
+ @message += "\n\nFunding source: #{@source}" if @source
+
+ # perform all operations in a temporary directory
+ Dir.mktmpdir do |tmpdir|
+ tmpdir.untaint
+ Dir.chdir tmpdir do
+ _h2 'Commit log'
+
+ # checkout out empty destination directory
+ _.system ['svn', 'checkout', '--quiet', '--depth', 'empty', auth,
+ File.join(bills, @dest), '.']
+
+ # fetch single file to see if it already exists
+ _.system ['svn', 'update', '--quiet', auth, name]
- _.system 'svn up'
-
- if File.exist? name
- _pre "File #{name} already exists", class: '_stderr'
- else
- # write file out to disk
- File.open(name, 'wb') {|file| file.write @file.read}
- _.system ['svn', 'add', name]
-
- # commit
- _.system [
- 'svn', 'commit', '-m', @message, name,
- ['--no-auth-cache', '--non-interactive'],
- (['--username', $USER, '--password', $PASSWORD] if $PASSWORD)
- ]
+ if File.exist? name
+ _pre "File #{name} already exists", class: '_stderr'
+ else
+ # write file out to disk
+ File.write(name, @file.read)
+ _.system ['svn', 'add', name]
+
+ # commit
+ _.system ['svn', 'commit', auth, '-m', @message, name]
+ end
end
end
end