Skip to content

Commit

Permalink
add ShiningPanda hook service
Browse files Browse the repository at this point in the history
  • Loading branch information
omansion committed Apr 9, 2012
1 parent 791bd99 commit 4ec87ab
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/shiningpanda
@@ -0,0 +1,28 @@
ShiningPanda
============

ShiningPanda is the first Hosted Continuous Integration service dedicated to Python.

It allows you to build, test and deploy your projects in a matter of minutes!

See https://www.shiningpanda.com for more information.

Install Notes
-------------

1. Workspace - This is your workspace key. If your Jenkins URL is https://jenkins.shiningpanda.com/shiningpanda.org, then your workspace key is "shiningpanda.org".
2. Job - This is the name of the job you want to trigger upon commit.
3. Token - This is the value of the "Authentication Token" field of the "Trigger builds remotely (e.g., from scripts)" option in the "Build Triggers" section of your job configuration.
4. Parameters (optional) - If your job takes parameters, this is the query string built from the parameters and their value (for instance "arg1=foo&arg2=bar"). All parameters need to be properly URL-escaped.

Developer Notes
---------------

data
- workspace
- job
- token
- parameters

payload
- refer to docs/github_payload
26 changes: 26 additions & 0 deletions services/shiningpanda.rb
@@ -0,0 +1,26 @@
class Service::ShiningPanda < Service
string :workspace, :job, :token, :parameters

def receive_push
if data['workspace'].to_s.empty?
raise_config_error "Workspace not set"
end
if data['job'].to_s.empty?
raise_config_error "Job not set"
end
if data['token'].to_s.empty?
raise_config_error "Token not set"
end
http.ssl[:verify] = true
http_post url, \
:from => 'github', \
:token => data['token'].strip, \
:payload => payload.to_json
end

def url
"https://jenkins.shiningpanda.com/#{data['workspace'].strip}/job/#{data['job'].strip}/" \
+ ( data['parameters'].to_s.empty? ? "build" : "buildWithParameters?#{data['parameters']}" )
end

end
90 changes: 90 additions & 0 deletions test/shiningpanda_test.rb
@@ -0,0 +1,90 @@
require File.expand_path('../helper', __FILE__)

class ShiningPandaTest < Service::TestCase
def setup
@stubs = Faraday::Adapter::Test::Stubs.new
end

def test_post_payload
@stubs.post '/shiningpanda.org/job/pygments/build' do |env|
form = Rack::Utils.parse_query(env[:body])
assert_equal 'github', form['from']
assert_equal 'PWFm8c2T', form['token']
assert_equal 'payload_content', JSON.parse(form['payload'])
end
svc = service(data, 'payload_content')
svc.receive_push
end

def test_requires_workspace
svc = service :push, { 'job' => 'pygments', 'token' => 'PWFm8c2T' }, 'payload'
assert_raise Service::ConfigurationError do
svc.receive_push
end
end

def test_requires_job
svc = service :push, { 'workspace' => 'shiningpanda.org', 'token' => 'PWFm8c2T' }, 'payload'
assert_raise Service::ConfigurationError do
svc.receive_push
end
end

def test_requires_token
svc = service :push, { 'workspace' => 'shiningpanda.org', 'job' => 'pygments' }, 'payload'
assert_raise Service::ConfigurationError do
svc.receive_push
end
end

def test_without_parameters
svc = service(data, payload)
assert_equal "https://jenkins.shiningpanda.com/shiningpanda.org/job/pygments/build", svc.url
end

def test_blank_parameters
svc = service(data.merge({'parameters' => ''}), payload)
assert_equal "https://jenkins.shiningpanda.com/shiningpanda.org/job/pygments/build", svc.url
end

def test_with_parameters
svc = service(data.merge({'parameters' => 'foo=bar'}), payload)
assert_equal "https://jenkins.shiningpanda.com/shiningpanda.org/job/pygments/buildWithParameters?foo=bar", svc.url
end

def test_strip_workspace
svc = service(data.merge({'workspace' => ' shiningpanda.org '}), payload)
assert_equal "https://jenkins.shiningpanda.com/shiningpanda.org/job/pygments/build", svc.url
end

def test_strip_job
svc = service(data.merge({'job' => ' pygments '}), payload)
assert_equal "https://jenkins.shiningpanda.com/shiningpanda.org/job/pygments/build", svc.url
end

def test_strip_token
svc = service(data.merge({'token' => ' PWFm8c2T '}), payload)
assert_equal "https://jenkins.shiningpanda.com/shiningpanda.org/job/pygments/build?token=PWFm8c2T", svc.url
end

def test_strip_token
@stubs.post '/shiningpanda.org/job/pygments/build' do |env|
assert_equal 'PWFm8c2T', Rack::Utils.parse_query(env[:body])['token']
end
svc = service(data.merge({'token' => ' PWFm8c2T '}), 'payload_content')
svc.receive_push
end

def service(*args)
super Service::ShiningPanda, *args
end

def data
{
'workspace' => 'shiningpanda.org',
'job' => 'pygments',
'token' => 'PWFm8c2T',
}
end
end

0 comments on commit 4ec87ab

Please sign in to comment.