public
Description: A very simple CommitBot that triggers Git-based buildbot runs
Homepage:
Clone URL: git://github.com/jamtur01/github-buildbot-commitbot.git
github-buildbot-commitbot / github-buildbot-commitbot.rb
100644 78 lines (63 sloc) 2.226 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Github-Builbot CommitBot
# v0.1 - 22/08/2008: Initial release
# - heavily draws on Adam Jacob's Github Commit Email Bot
 
# License:: GNU General Public License version 2 or later
#
# This program and entire repository is free software; you can
# redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software
# Foundation; either version 2 of the License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
 
require 'rubygems'
require 'json'
require 'open-uri'
require 'socket'
 
Merb::Config.use { |c|
  c[:project] = "Puppet",
  c[:buildhost] = "BuildBot",
  c[:git_dir] = "/sources/puppet/.git",
  c[:git_buildbot] = "/buildbot/git_buildbot.py",
  c[:tmp_commit_file] = "/tmp/commit",
  c[:framework] = {},
  c[:session_store] = 'none',
  c[:exception_details] = true
}
 
Merb::Router.prepare do |r|
  r.resources :commit
  r.match('/').to(:controller => 'commit', :action =>'index')
end
 
class Commit < Merb::Controller
 
  def index
    results = "I accept github post-commits for #{Merb::Config[:project]}"
    results << " and send them to #{Merb::Config[:buildhost]}. POST to /commit."
    results
  end
 
  def create
    # parse and assign variables
    ch = JSON.parse(params[:payload])
    before = ch['before']
    after = ch['after']
    ref = ch['ref']
 
    # Set Git directory
    ENV['GIT_DIR'] = Merb::Config[:git_dir]
 
    # Fetch commits
    %x{git fetch origin}
 
    # create commit
    c = "#{before} " + "#{after} " + "#{ref}"
 
    # Write temporary commit to file
    f = File.open(Merb::Config[:tmp_commit_file], 'w')
    f.write(c)
    f.close
 
    # Process change
    %x{#{Merb::Config[:git_buildbot]} < #{Merb::Config[:tmp_commit_file]}}
 
  end
end