mv default.zsh -> on-push.zsh + default script

master
Izimic 2020-12-23 07:44:05 +01:00
parent 2bd074191a
commit f8ccfbad22
2 changed files with 18 additions and 12 deletions

View File

@ -6,8 +6,9 @@ VERSION = 0.1
port = 3000 port = 3000
storage = "webhooksd-data" storage = "webhooksd-data"
scriptfile = "default.zsh" scriptfile_default = "on-push.zsh"
jsonfile = "payload.json" jsonfile = "payload.json"
scriptname = "on-push"
args = [] of String args = [] of String
@ -31,8 +32,8 @@ OptionParser.parse do |parser|
storage = s storage = s
end end
parser.on "-e SCRIPT", "--script=SCRIPT", "Default: #{scriptfile}" do |s| parser.on "-e SCRIPT", "--script=SCRIPT", "Default: #{scriptfile_default}" do |s|
scriptfile = s scriptfile_default = s
end end
parser.invalid_option do |flag| parser.invalid_option do |flag|
@ -51,6 +52,11 @@ OptionParser.parse do |parser|
end end
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| server = HTTP::Server.new do |context|
if context.request.method != "POST" || context.request.path != "/" if context.request.method != "POST" || context.request.path != "/"
context.response.status = HTTP::Status::NOT_FOUND context.response.status = HTTP::Status::NOT_FOUND
@ -58,24 +64,24 @@ server = HTTP::Server.new do |context|
payload = Payload.new(context.request) payload = Payload.new(context.request)
path_project = storage + "/" + payload.project path_project = storage + "/" + payload.project
path_scriptfile = "../../../" + scriptfile path_scriptfile = path_project + "/" + scriptname
path_jsonfile = path_project + "/" + jsonfile path_jsonfile = path_project + "/" + jsonfile
scriptfile = scriptname
status = false status = false
if File.exists?(path_project) == false if File.exists?(path_project) == false
STDERR.puts "ERROR: Project #{payload.project} not found" STDERR.puts "ERROR: Project #{payload.project} not found"
status = false status = false
else else
if File.exists?(scriptfile) == false if File.exists?(path_scriptfile) == false
p scriptfile scriptfile = path_project + "/../../../" + scriptfile_default
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
end end
File.write(path_jsonfile, payload.content)
status = Process.run command: "zsh", args: [scriptfile], shell: true,
error: STDERR, output: STDOUT, chdir: path_project
end end
context.response.content_type = "text/plain" context.response.content_type = "text/plain"