part of the two-phase gem build process now

This commit is contained in:
Tom Preston-Werner 2009-03-28 23:35:38 -07:00
Родитель 389700abc0
Коммит 66316a2281
4 изменённых файлов: 54 добавлений и 15 удалений

Просмотреть файл

@ -11,6 +11,8 @@ begin
s.homepage = "http://github.com/github/safegem"
s.description = "GitHub's safe gem eval web service"
s.authors = ["PJ Hyett", "Tom Preston-Werner"]
s.add_dependency('json', '>= 1.1.3')
s.add_dependency('json', '>= 0.9.9.1')
end
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"

Просмотреть файл

@ -7,19 +7,28 @@ require 'rubygems/specification'
require 'sinatra'
require 'timeout'
require 'yaml'
require 'net/http'
require 'safegem/exception'
require 'json'
require 'base64'
require 'zlib'
post '/' do
p params
r, w = IO.pipe
pid = nil
begin
repo = params[:repo]
data = params[:data]
tmpdir = "tmp/#{repo}"
spec = nil
repo = params[:repo]
data = params[:data]
callback = params[:callback]
token = params[:token]
tmpdir = "tmp/#{repo}"
spec = nil
Timeout::timeout(30) do
Timeout::timeout(300) do
`git clone --depth 1 git://github.com/#{repo} #{tmpdir}`
p "Cloned #{repo}"
pid = fork do
begin
@ -60,23 +69,41 @@ post '/' do
spec.validate
end
w.write YAML.dump(spec)
payload = Base64.encode64(Zlib::Deflate.deflate(YAML.dump(spec)))
p payload.size
w.write payload
w.close
rescue Object
puts $!,$@
puts $!, $@
w.write "ERROR: #$!"
w.close
end
end
w.close
p "Waiting for conversion"
Process.wait(pid)
r.read
end
rescue Exception
Process.kill(9, pid) if pid
puts $!,$@
yaml = r.read
r.close
"ERROR: #$!"
p "Request build from GitHub"
payload = {'token' => token, 'yaml' => yaml}
res = Net::HTTP.post_form(URI.parse(callback), payload)
data = res.body
p data
p "Success"
packet = {'result' => "Successfully converted #{repo} gemspec to YAML.", 'error' => nil}
p packet
packet.to_json
end
rescue Exception => e
Process.kill(9, pid) rescue nil
packet = {'error' => e.to_hash}
p packet
packet.to_json
ensure
`rm -rf #{tmpdir}` if tmpdir
end

Просмотреть файл

@ -1,2 +1,2 @@
require 'safegem/lazy_dir'
require 'safegem/security'
require 'safegem/security'

10
lib/safegem/exception.rb Normal file
Просмотреть файл

@ -0,0 +1,10 @@
RACK_ENV = 'development'
class Exception
def to_hash(extra = nil)
h = { 'message' => message }
h = h.merge('backtrace' => backtrace) if %w{development staging test}.include?(RACK_ENV)
h = h.merge(extra) if extra
h
end
end