public
Fork of pjhyett/github-services
Description: Official GitHub Services Integration
Homepage: http://github.com/blog/53-github-services-ipo
Clone URL: git://github.com/tekkub/github-services.git
100755 54 lines (47 sloc) 1.567 kb
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def build_cia_commit(repository, branch, sha1, commit, size = 1)
  log = commit['message']
  log << " (+#{size} more commits...)" if size > 1
 
  dt = DateTime.parse(commit['timestamp']).new_offset
  timestamp = Time.send(:gm, dt.year, dt.month, dt.day, dt.hour, dt.min, dt.sec).to_i
 
  files = commit['modified'] + commit['added'] + commit['removed']
 
  <<-MSG
<message>
<generator>
<name>github</name>
<version>1</version>
<url>http://www.github.com</url>
</generator>
<source>
<project>#{repository}</project>
<branch>#{branch}</branch>
</source>
<timestamp>#{timestamp}</timestamp>
<body>
<commit>
<author>#{commit['author']['name']}</author>
<revision>#{sha1[0..6]}</revision>
<log>#{log}</log>
<url>#{commit['url']}</url>
<files>
<file> #{files.join("</file>\n<file>")} </file>
</files>
</commit>
</body>
</message>
MSG
end
 
service :cia do |data, payload|
  server = XMLRPC::Client.new2("http://cia.navi.cx")
 
  repository = payload['repository']['name']
  branch = payload['ref'].split('/').last
  commits = payload['commits']
 
  if commits.size > 5
    message = build_cia_commit(repository, branch, payload['after'], commits[payload['after']], commits.size - 1)
    server.call("hub.deliver", message)
  else
    commits.each do |sha1, commit|
      message = build_cia_commit(repository, branch, sha1, commit)
      server.call("hub.deliver", message)
    end
  end
end