diff --git a/default.zsh b/on-push.zsh similarity index 100% rename from default.zsh rename to on-push.zsh diff --git a/src/webhooksd.cr b/src/webhooksd.cr index 254954c..585421a 100644 --- a/src/webhooksd.cr +++ b/src/webhooksd.cr @@ -6,8 +6,9 @@ VERSION = 0.1 port = 3000 storage = "webhooksd-data" -scriptfile = "default.zsh" +scriptfile_default = "on-push.zsh" jsonfile = "payload.json" +scriptname = "on-push" args = [] of String @@ -31,8 +32,8 @@ OptionParser.parse do |parser| storage = s end - parser.on "-e SCRIPT", "--script=SCRIPT", "Default: #{scriptfile}" do |s| - scriptfile = s + parser.on "-e SCRIPT", "--script=SCRIPT", "Default: #{scriptfile_default}" do |s| + scriptfile_default = s end parser.invalid_option do |flag| @@ -51,6 +52,11 @@ OptionParser.parse do |parser| end end +if File.exists?(scriptfile_default) == false + STDERR.puts "ERROR: Script #{scriptfile_default} not found" + exit 1 +end + server = HTTP::Server.new do |context| if context.request.method != "POST" || context.request.path != "/" context.response.status = HTTP::Status::NOT_FOUND @@ -58,24 +64,24 @@ server = HTTP::Server.new do |context| payload = Payload.new(context.request) path_project = storage + "/" + payload.project - path_scriptfile = "../../../" + scriptfile + path_scriptfile = path_project + "/" + scriptname path_jsonfile = path_project + "/" + jsonfile + scriptfile = scriptname + status = false if File.exists?(path_project) == false STDERR.puts "ERROR: Project #{payload.project} not found" status = false else - if File.exists?(scriptfile) == false - p scriptfile - STDERR.puts "ERROR: Scriptfile not found" - status = false - else - File.write(path_jsonfile, payload.content) - status = Process.run command: "zsh", args: [path_scriptfile], shell: true, - error: STDERR, output: STDOUT, chdir: path_project + if File.exists?(path_scriptfile) == false + scriptfile = path_project + "/../../../" + scriptfile_default end + + File.write(path_jsonfile, payload.content) + status = Process.run command: "zsh", args: [scriptfile], shell: true, + error: STDERR, output: STDOUT, chdir: path_project end context.response.content_type = "text/plain"