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
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"