-
Notifications
You must be signed in to change notification settings - Fork 1
/
commit_monitor.rb
48 lines (40 loc) · 1.16 KB
/
commit_monitor.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
37
38
39
40
41
42
43
44
45
46
47
48
require 'rubygems'
require 'bundler/setup'
require 'sinatra'
require 'json'
require 'fileutils'
require 'git_repo_manager'
repo_manager = nil
configure(:production) do
repos = File.join(Dir.pwd, 'data', 'repos')
config = File.join('config', 'repos.yml')
repo_manager = GITRepoManager.new(config, repos)
end
configure(:test) do
local_repos = File.join(Dir.pwd, 'spec', 'files', 'test_repos')
test_config = File.join('spec', 'files', 'config', 'repos.yml')
repo_manager = GITRepoManager.new(test_config, local_repos)
end
# Repositories are single-threaded
set :lock
repo_manager.submodules.each do |submodule_name|
path = "/#{submodule_name}"
get path do
halt 403, 'Payload only accepted via POST'
end
post path do
if params[:payload]
payload = JSON.parse(params[:payload])
$logger.info "Received payload from #{payload["repository"]["url"]}"
payload["ref"].match(/\/([^\/]+)$/)
message = repo_manager.update_submodule(payload["repository"]["url"], $1, payload["after"])
message.to_s
else
halt 400, 'Payload missing'
end
end
end
# pingable url to make sure the app is running
get "/status" do
"OK"
end