-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommit_monitor.rb
More file actions
49 lines (41 loc) · 1.15 KB
/
commit_monitor.rb
File metadata and controls
49 lines (41 loc) · 1.15 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
require 'rubygems'
require 'bundler/setup'
require 'sinatra'
require 'json'
require 'fileutils'
require 'lib/git_repo_manager'
require 'lib/global_logger'
repo_manager = nil
configure do
repos = File.join(`pwd`.chomp, 'data/repos')
config = 'config/repos.yml'
repo_manager = ForkGITRepoManager.new(config, repos)
end
configure :test do
local_repos = File.join(`pwd`.chomp, 'spec/files/test_repos')
test_config = 'spec/files/config/repos.yml'
repo_manager = ForkGITRepoManager.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 403, 'Payload missing'
end
end
end
# pingable url to make sure the app is running
get "/status" do
"OK"
end