forked from github/github-services
/
appharbor.rb
36 lines (29 loc) · 973 Bytes
/
appharbor.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Service::AppHarbor < Service
string :application_slug, :token
white_list :application_slug
def receive_push
slugs = data['application_slug']
token = data['token']
raise_config_error 'Missing application slug' if slugs.to_s.empty?
raise_config_error 'Missing token' if token.to_s.empty?
slugs.split(",").each do |slug|
slug.strip!
post_appharbor_message(slug, token)
end
end
private
def post_appharbor_message(slug, token)
return unless commit = distinct_commits.last
create_build_url = "https://appharbor.com/applications/#{slug}/builds?authorization=#{token}"
appharbor_message = {
:branches => {
ref_name => {
:commit_id => commit['id'],
:commit_message => commit['message'],
:download_url => commit['url'].sub('commit', 'tarball')
}
}
}
http_post create_build_url, appharbor_message.to_json, 'Accept' => 'application/json'
end
end