forked from integrity/integrity
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use POST /:project for github post-receive [integrity#15 state:resolved]
- Loading branch information
Showing
2 changed files
with
37 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,34 @@ | ||
require 'rubygems' | ||
require 'json' | ||
|
||
require File.dirname(__FILE__) + '/../integrity' | ||
require 'sinatra' | ||
require 'json' | ||
|
||
configure do | ||
Integrity.new | ||
end | ||
|
||
include Integrity | ||
|
||
post '/' do | ||
post '/:project' do | ||
content_type 'text/plain' | ||
|
||
project = Project.first(:permalink => params[:project]) | ||
unknown_project! if project.nil? | ||
|
||
begin | ||
payload = JSON.parse(params[:payload] || '') | ||
unless project = Project.first(:name => payload['repository']['name']) | ||
throw :halt, [400, "Unknown project `#{payload['repository']['name']}'"] | ||
else | ||
payload['commits'].each_key { |commit| project.build(commit) } | ||
end | ||
payload = JSON.parse(params[:payload] || "") | ||
payload['commits'].each_key { |commit| project.build(commit) } | ||
'Thanks, build started.' | ||
rescue JSON::ParserError => exception | ||
throw :halt, [422, exception.to_s] | ||
invalid_payload!(exception.to_s) | ||
end | ||
end | ||
|
||
helpers do | ||
def unknown_project! | ||
throw :halt, [404, "Unknown project `#{params[:project]}'"] | ||
end | ||
|
||
def invalid_payload!(msg=nil) | ||
throw :halt, [422, msg || 'No payload given'] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters