Skip to content

Commit 4d6028b

Browse files
committed
Merge branch 'allow-multiple-app-slugs' of https://github.com/appharbor/github-services into appharbor-allow-multiple-app-slugs
2 parents 47847ff + 5a237c3 commit 4d6028b

3 files changed

Lines changed: 40 additions & 19 deletions

File tree

docs/appharbor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Install Notes
88

99
1. Go to your application's main page on AppHarbor and find the "Create build URL". Example: https://appharbor.com/application/{application_slug}/build?authorization={token}
1010

11-
2. "token" is the value of the "authorization" parameter.
11+
2. "Token" is the value of the "authorization" parameter.
1212

13-
3. "application_slug" is your application's unique identifier.
13+
3. "Application Slugs" is a list of unique application identifiers delimited by "," (i.e. "foo" or "foo,bar") that pushes should trigger builds on.
1414

1515
4. If your GitHub repository is private you need to add the "apphb" GitHub user as a collaborator. This enables AppHarbor to download the source code.

services/appharbor.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ class Service::AppHarbor < Service
22
string :application_slug, :token
33

44
def receive_push
5-
slug = data['application_slug']
5+
slugs = data['application_slugs']
66
token = data['token']
77

8-
raise_config_error 'Missing application slug' if slug.to_s.empty?
8+
raise_config_error 'Missing application slug' if slugs.to_s.empty?
99
raise_config_error 'Missing token' if token.to_s.empty?
1010

11+
slugs.split(",").each{|slug| post_appharbor_message(slug, token)}
12+
end
13+
14+
private
15+
16+
def post_appharbor_message(slug, token)
1117
create_build_url = "https://appharbor.com/application/#{slug}/build?authorization=#{token}"
1218

1319
commit = distinct_commits.last

test/appharbor_test.rb

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,43 @@ def setup
55
@stubs = Faraday::Adapter::Test::Stubs.new
66
end
77

8-
def test_push
9-
application_slug = 'foo'
10-
token = 'bar'
8+
def test_single_slug_push
9+
test_push 'foo', 'bar'
10+
end
11+
12+
def test_multiple_slugs_push
13+
test_push 'foo,bar', 'baz'
14+
end
1115

12-
@stubs.post "/application/#{application_slug}/build" do |env|
13-
assert_equal token, env[:params]['authorization']
14-
assert_equal 'application/json', env[:request_headers]['accept']
16+
def service(*args)
17+
super Service::AppHarbor, *args
18+
end
1519

16-
branches = JSON.parse(env[:body])['branches']
17-
assert_equal 1, branches.size
20+
private
1821

19-
branch = branches[payload['ref'].sub(/\Arefs\/heads\//, '')]
20-
assert_not_nil branch
21-
assert_equal payload['after'], branch['commit_id']
22-
assert_equal payload['commits'].select{|c| c['id'] == payload['after']}.first['message'], branch['commit_message']
22+
def test_push(application_slugs, token)
23+
application_slugs.split(",").each do |slug|
24+
@stubs.post "/application/#{slug}/build" do |env|
25+
verify_appharbor_payload(token, env)
26+
end
2327
end
2428

25-
svc = service({'token' => token, 'application_slug' => application_slug}, payload)
29+
svc = service({'token' => token, 'application_slugs' => application_slugs}, payload)
2630
svc.receive_push
31+
32+
@stubs.verify_stubbed_calls
2733
end
2834

29-
def service(*args)
30-
super Service::AppHarbor, *args
35+
def verify_appharbor_payload(token, env)
36+
assert_equal token, env[:params]['authorization']
37+
assert_equal 'application/json', env[:request_headers]['accept']
38+
39+
branches = JSON.parse(env[:body])['branches']
40+
assert_equal 1, branches.size
41+
42+
branch = branches[payload['ref'].sub(/\Arefs\/heads\//, '')]
43+
assert_not_nil branch
44+
assert_equal payload['after'], branch['commit_id']
45+
assert_equal payload['commits'].select{|c| c['id'] == payload['after']}.first['message'], branch['commit_message']
3146
end
3247
end

0 commit comments

Comments
 (0)