Skip to content
This repository was archived by the owner on Jan 31, 2019. It is now read-only.

Commit 6bc9206

Browse files
committed
merge jaconda patch
1 parent 1ac3cc9 commit 6bc9206

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ Thanks to the following people for making this possible
3232
- Teng Siong Ong
3333
- Nick Plante
3434
- Pedro Morais
35+
- Anton Mironov

docs/github_payload

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

33
{
44
"data" => {
5-
"token" => "token",
6-
"url" => "https://youraccount.talkerapp.com/rooms/ROOM_ID",
5+
"api_token" => "API token",
6+
"room_id" => "Room ID",
77
"digest" => 1
88
},
99

docs/jaconda

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Jaconda
2+
========
3+
4+
Install Notes
5+
-------------
6+
7+
1. Room ID should be numerical ID of your room, could be found in address bar
8+
2. API token should be on your Account page
9+
3. if Digest is checked, all commits will be compressed in one message
10+
11+
Developer Notes
12+
---------------
13+
14+
data
15+
- room_id
16+
- api_token
17+
- digest (boolean)
18+
19+
payload
20+
- refer to docs/github_payload

services/jaconda.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
service :jaconda do |data, payload|
2+
throw(:halt, 400) if data['api_token'].to_s == '' || data['room_id'].to_s == ''
3+
4+
repository = CGI.escapeHTML(payload['repository']['name'])
5+
branch = CGI.escapeHTML(payload['ref'].split('/').last)
6+
commits = payload['commits']
7+
api_token = data['api_token']
8+
room_id = data['room_id']
9+
url = URI.parse("http://#{api_token}:X@jaconda.im/api/rooms/#{room_id}/messages.json")
10+
11+
before, after = payload['before'][0..6], payload['after'][0..6]
12+
compare_url = payload['repository']['url'] + "/compare/#{before}...#{after}"
13+
14+
if data['digest'].to_i == 1 && commits.size > 1
15+
commit = commits.first
16+
message = "<i>Commit <a href='#{commit["url"]}'>#{commit["id"][0..6]}</a> on #{repository}/#{branch} by #{CGI.escapeHTML(commit["author"]["name"])}</i><br /><br />"
17+
message += CGI.escapeHTML(commit["message"])
18+
message += "<br /><br /><i>(+#{commits.size - 1} <a href='#{compare_url}'>more commits</a>)</i>"
19+
20+
res = Net::HTTP.post_form(url, {:text => message})
21+
throw(:halt, [res.code.to_i, res.body.to_s]) unless res.is_a?(Net::HTTPSuccess)
22+
else
23+
commits.each do |commit|
24+
message = "<i>Commit <a href='#{commit["url"]}'>#{commit["id"][0..6]}</a> on #{repository}/#{branch} by #{CGI.escapeHTML(commit["author"]["name"])}</i><br /><br />"
25+
message += CGI.escapeHTML(commit["message"])
26+
27+
res = Net::HTTP.post_form(url, {:text => message})
28+
throw(:halt, [res.code.to_i, res.body.to_s]) unless res.is_a?(Net::HTTPSuccess)
29+
end
30+
end
31+
true
32+
end

0 commit comments

Comments
 (0)