Skip to content

Commit b781a2f

Browse files
committed
Merge pull request github#286 from shiningpanda/master
ShiningPanda Service
2 parents 289c7d0 + 4e0c7bf commit b781a2f

File tree

3 files changed

+244
-0
lines changed

3 files changed

+244
-0
lines changed

docs/shiningpanda

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ShiningPanda
2+
============
3+
4+
ShiningPanda is the first Hosted Continuous Integration service dedicated to Python.
5+
6+
It allows you to build, test and deploy your projects in a matter of minutes!
7+
8+
See https://www.shiningpanda.com for more information.
9+
10+
Install Notes
11+
-------------
12+
13+
1. Workspace - This your workspace key. For instance if your Jenkins URL is https://jenkins.shiningpanda.com/shiningpanda.org, then your workspace key is "shiningpanda.org".
14+
2. Job - This is the name of the job you want to trigger upon commit. For instance if the URL of your job in Jenkins is https://jenkins.shiningpanda.com/shiningpanda.org/job/selenose/, then your job name is selenose.
15+
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.
16+
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 have to be properly URL-escaped.
17+
18+
Developer Notes
19+
---------------
20+
21+
data
22+
- workspace
23+
- job
24+
- token
25+
- parameters (optional)
26+
27+
payload
28+
- refer to docs/github_payload

services/shiningpanda.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
class Service::ShiningPanda < Service
2+
string :workspace, :job, :token, :parameters
3+
4+
def receive_push
5+
if workspace.empty?
6+
raise_config_error 'Workspace not set'
7+
end
8+
if job.empty?
9+
raise_config_error "Job not set"
10+
end
11+
if token.empty?
12+
raise_config_error "Token not set"
13+
end
14+
if query.has_key?('token')
15+
raise_config_error "Illegal parameter: token"
16+
end
17+
if query.has_key?('cause')
18+
raise_config_error "Illegal parameter: cause"
19+
end
20+
Rack::Utils.parse_query(data['parameters']).each do |key, values|
21+
if !values.is_a?(String) and values.length > 1
22+
raise_config_error "Only one parameter value allowed for " + key
23+
end
24+
end
25+
query[:token] = token
26+
query[:cause] = "Triggered by a push of #{payload['pusher']['name']} (commit: #{payload['after']})"
27+
http_post url, query
28+
end
29+
30+
def cleanup(key)
31+
( data.has_key?(key) and data[key] != nil ) ? data[key] : ''
32+
end
33+
34+
def workspace
35+
@workspace ||= cleanup('workspace').strip
36+
end
37+
38+
def job
39+
@job ||= cleanup('job').strip
40+
end
41+
42+
def token
43+
@token ||= cleanup('token').strip
44+
end
45+
46+
def parameters
47+
@parameters ||= Rack::Utils.parse_nested_query(cleanup('parameters'))
48+
end
49+
50+
def query
51+
@query ||= parameters.clone
52+
end
53+
54+
def url
55+
@url ||= "https://jenkins.shiningpanda.com/#{workspace}/job/#{job}/#{parameters.empty? ? 'build' : 'buildWithParameters'}"
56+
end
57+
58+
end

test/shiningpanda_test.rb

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
require File.expand_path('../helper', __FILE__)
2+
3+
class ShiningPandaTest < Service::TestCase
4+
def setup
5+
@stubs = Faraday::Adapter::Test::Stubs.new
6+
end
7+
8+
def test_receive_push_without_parameters
9+
@stubs.post '/shiningpanda.org/job/pygments/build' do |env|
10+
form = Rack::Utils.parse_query(env[:body])
11+
assert_equal 'PWFm8c2T', form['token']
12+
assert_equal 'Triggered by a push of omansion (commit: 83d9205e73c25092ce7cb7ce530d2414e6d068cb)', form['cause']
13+
end
14+
svc = service(data, payload)
15+
svc.receive_push
16+
end
17+
18+
def test_receive_push_with_parameters
19+
@stubs.post '/shiningpanda.org/job/pygments/buildWithParameters' do |env|
20+
form = Rack::Utils.parse_query(env[:body])
21+
assert_equal 'PWFm8c2T', form['token']
22+
assert_equal 'Triggered by a push of omansion (commit: 83d9205e73c25092ce7cb7ce530d2414e6d068cb)', form['cause']
23+
assert_equal 'bar', form['foo']
24+
end
25+
svc = service(data.merge({'parameters' => 'foo=bar'}), payload)
26+
svc.receive_push
27+
end
28+
29+
def test_workspace_missing
30+
svc = service({ 'job' => 'pygments', 'token' => 'PWFm8c2T' }, payload)
31+
assert_raise Service::ConfigurationError do
32+
svc.receive_push
33+
end
34+
end
35+
36+
def test_workspace_nil
37+
svc = service(data.merge({'workspace' => nil}), payload)
38+
assert_raise Service::ConfigurationError do
39+
svc.receive_push
40+
end
41+
end
42+
43+
def test_workspace_blank
44+
svc = service(data.merge({'workspace' => ''}), payload)
45+
assert_raise Service::ConfigurationError do
46+
svc.receive_push
47+
end
48+
end
49+
50+
def test_job_missing
51+
svc = service({ 'workspace' => 'shiningpanda.org', 'token' => 'PWFm8c2T' }, payload)
52+
assert_raise Service::ConfigurationError do
53+
svc.receive_push
54+
end
55+
end
56+
57+
def test_job_nil
58+
svc = service(data.merge({'job' => nil}), payload)
59+
assert_raise Service::ConfigurationError do
60+
svc.receive_push
61+
end
62+
end
63+
64+
def test_job_blank
65+
svc = service(data.merge({'job' => ''}), payload)
66+
assert_raise Service::ConfigurationError do
67+
svc.receive_push
68+
end
69+
end
70+
71+
def test_token_missing
72+
svc = service({ 'workspace' => 'shiningpanda.org', 'job' => 'pygments' }, payload)
73+
assert_raise Service::ConfigurationError do
74+
svc.receive_push
75+
end
76+
end
77+
78+
def test_token_nil
79+
svc = service(data.merge({'token' => nil}), payload)
80+
assert_raise Service::ConfigurationError do
81+
svc.receive_push
82+
end
83+
end
84+
85+
def test_token_blank
86+
svc = service(data.merge({'token' => ''}), payload)
87+
assert_raise Service::ConfigurationError do
88+
svc.receive_push
89+
end
90+
end
91+
92+
def test_url_without_parameters
93+
svc = service(data, payload)
94+
assert_equal "https://jenkins.shiningpanda.com/shiningpanda.org/job/pygments/build", svc.url
95+
end
96+
97+
def test_url_nil_parameters
98+
svc = service(data.merge({'parameters' => nil}), payload)
99+
assert_equal "https://jenkins.shiningpanda.com/shiningpanda.org/job/pygments/build", svc.url
100+
end
101+
102+
def test_url_blank_parameters
103+
svc = service(data.merge({'parameters' => ''}), payload)
104+
assert_equal "https://jenkins.shiningpanda.com/shiningpanda.org/job/pygments/build", svc.url
105+
end
106+
107+
def test_url_with_parameters
108+
svc = service(data.merge({'parameters' => 'foo=bar'}), payload)
109+
assert_equal "https://jenkins.shiningpanda.com/shiningpanda.org/job/pygments/buildWithParameters", svc.url
110+
end
111+
112+
def test_url_strip_workspace
113+
svc = service(data.merge({'workspace' => ' shiningpanda.org '}), payload)
114+
assert_equal "https://jenkins.shiningpanda.com/shiningpanda.org/job/pygments/build", svc.url
115+
end
116+
117+
def test_url_strip_job
118+
svc = service(data.merge({'job' => ' pygments '}), payload)
119+
assert_equal "https://jenkins.shiningpanda.com/shiningpanda.org/job/pygments/build", svc.url
120+
end
121+
122+
def test_strip_token
123+
@stubs.post '/shiningpanda.org/job/pygments/build' do |env|
124+
assert_equal 'PWFm8c2T', Rack::Utils.parse_query(env[:body])['token']
125+
end
126+
svc = service(data.merge({'token' => ' PWFm8c2T '}), payload)
127+
svc.receive_push
128+
end
129+
130+
def test_multi_valued_parameter
131+
svc = service(data.merge({'parameters' => 'foo=bar&foo=toto'}), payload)
132+
assert_raise Service::ConfigurationError do
133+
svc.receive_push
134+
end
135+
end
136+
137+
def service(*args)
138+
super Service::ShiningPanda, *args
139+
end
140+
141+
def payload
142+
{
143+
'after' => '83d9205e73c25092ce7cb7ce530d2414e6d068cb',
144+
'pusher' => {
145+
'name' => 'omansion',
146+
}
147+
}
148+
end
149+
150+
def data
151+
{
152+
'workspace' => 'shiningpanda.org',
153+
'job' => 'pygments',
154+
'token' => 'PWFm8c2T',
155+
}
156+
end
157+
end
158+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy