forked from timcharper/git_osx_installer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload-to-github.rb
executable file
·53 lines (43 loc) · 1.35 KB
/
upload-to-github.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/env ruby
#
# ruby upload-to-github.rb user user/repo file '(description)'
#
require 'rubygems'
require 'json'
if ARGV.size < 3
puts "\nUSAGE: upload-to-github.rb [user] [user/repo] [filepath] ('description')"
exit
end
user = ARGV[0]
repo = ARGV[1]
file = ARGV[2]
desc = ARGV[3] rescue ''
def url(path)
"https://api.github.com#{path}"
end
size = File.size(file)
fname = File.basename(file)
pass=`git gui--askpass "Password for #{user}"`.chomp
# create entry
args =
data = `curl -s -XPOST -d '{"name":"#{fname}","size":#{size},"description":"#{desc}"}' -u "#{user}:#{pass}" #{url("/repos/#{repo}/downloads")}`
data = JSON.parse(data)
# upload file to bucket
cmd = "curl -s "
cmd += "-F \"key=#{data['path']}\" "
cmd += "-F \"acl=#{data['acl']}\" "
cmd += "-F \"success_action_status=201\" "
cmd += "-F \"Filename=#{data['name']}\" "
cmd += "-F \"AWSAccessKeyId=#{data['accesskeyid']}\" "
cmd += "-F \"Policy=#{data['policy']}\" "
cmd += "-F \"Signature=#{data['signature']}\" "
cmd += "-F \"Content-Type=#{data['mime_type']}\" "
cmd += "-F \"file=@#{file}\" "
cmd += "https://github.s3.amazonaws.com/"
xml = `#{cmd}`
if m = /\<Location\>(.*)\<\/Location\>/.match(xml)
puts "Your file is uploaded to:"
puts m[1].gsub('%2F', '/') # not sure i want to fully URL decode this, but these will not do
else
puts "Upload failed. Response is:\n\n #{xml}"
end