From d08ba45f5fd5aaf1aee078d13e2044d896efde29 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 30 Oct 2023 00:25:45 +0800 Subject: [PATCH] update --- plugins/gogs/hook/self_hook.tpl | 12 +++++++++++ plugins/gogs/index.py | 35 ++++++++++++++++++++++++++------- plugins/gogs/js/gogs.js | 5 +++-- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/plugins/gogs/hook/self_hook.tpl b/plugins/gogs/hook/self_hook.tpl index 05a7907cf..7338b357e 100644 --- a/plugins/gogs/hook/self_hook.tpl +++ b/plugins/gogs/hook/self_hook.tpl @@ -1,2 +1,14 @@ #!/bin/bash +H_DIR={$HOOK_DIR} +HL_DIR={$HOOK_LOGS_DIR} + + +SH_LIST=`cd ${H_DIR} && ls | grep ".sh"` + +for sh_f in $SH_LIST; do + ABS_FILE=${H_DIR}/${sh_f} + ABS_LOGS=${HL_DIR}/${sh_f}.log + echo "sh ${ABS_FILE} 2>${ABS_LOGS}" + sh -x ${ABS_FILE} 2>${ABS_LOGS} +done \ No newline at end of file diff --git a/plugins/gogs/index.py b/plugins/gogs/index.py index 4e58b824b..7eec258c5 100755 --- a/plugins/gogs/index.py +++ b/plugins/gogs/index.py @@ -766,11 +766,15 @@ def projectScriptSelf(): custom_hooks = getRootPath() + '/' + user + '/' + \ name + '/custom_hooks' - self_path = custom_hooks + '/self' + self_path = custom_hooks + '/self' if not os.path.exists(self_path): os.mkdir(self_path) + self_logs_path = custom_hooks + '/self_logs' + if not os.path.exists(self_logs_path): + os.mkdir(self_logs_path) + self_hook_file = custom_hooks + '/self_hook.sh' self_hook_exist = False if os.path.exists(self_hook_file): @@ -834,8 +838,9 @@ def projectScriptSelf_Del(): name = args['name'] + '.git' file = args['file'] - self_path = path = getRootPath() + '/' + user + '/' + \ - name + '/custom_hooks/self' + custom_hooks = getRootPath() + '/' + user + '/' + \ + name + '/custom_hooks' + self_path = custom_hooks + '/self' if not os.path.exists(self_path): os.mkdir(self_path) @@ -846,6 +851,12 @@ def projectScriptSelf_Del(): return mw.returnJson(False, '脚本已经删除!') os.remove(abs_file) + + # 日志也删除 + log_file = custom_hooks + '/self_logs/' + file + '.log' + if os.path.exists(log_file): + os.remove(log_file) + return mw.returnJson(True, '脚本删除成功!') @@ -869,7 +880,7 @@ def projectScriptSelf_Logs(): if os.path.exists(logs_file): rdata = {} rdata['path'] = logs_file - return mw.returnJson(True, '脚本已经删除!', rdata) + return mw.returnJson(True, 'ok', rdata) return mw.returnJson(False, '日志不存在!') @@ -885,8 +896,9 @@ def projectScriptSelf_Rename(): o_file = args['o_file'] n_file = args['n_file'] - self_path = path = getRootPath() + '/' + user + '/' + \ - name + '/custom_hooks/self' + custom_hooks = getRootPath() + '/' + user + '/' + \ + name + '/custom_hooks' + self_path = custom_hooks + '/self' if not os.path.exists(self_path): os.mkdir(self_path) @@ -898,6 +910,12 @@ def projectScriptSelf_Rename(): n_file_abs = self_path + '/' + n_file + '.sh' os.rename(o_file_abs, n_file_abs) + + # 日志也删除 + log_file = custom_hooks + '/self_logs/' + o_file + '.sh.log' + if os.path.exists(log_file): + os.remove(log_file) + return mw.returnJson(True, '重命名成功!') @@ -918,8 +936,11 @@ def projectScriptSelf_Enable(): if enable == '1': content = mw.readFile(self_hook_tpl) + content = content.replace('{$HOOK_DIR}', custom_path + '/self') + content = content.replace( + '{$HOOK_LOGS_DIR}', custom_path + '/self_logs') mw.writeFile(self_file, content) - mw.execShell("chmod 777" + self_file) + mw.execShell("chmod 777 " + self_file) return mw.returnJson(True, '开启成功!') else: if os.path.exists(self_file): diff --git a/plugins/gogs/js/gogs.js b/plugins/gogs/js/gogs.js index a621635f8..edd087b7a 100755 --- a/plugins/gogs/js/gogs.js +++ b/plugins/gogs/js/gogs.js @@ -399,7 +399,7 @@ function gogsRepoListPage(page, search){ gogsPost('project_script_run', {'user':user,'name':name}, function(data){ var data = $.parseJSON(data.data); - layer.msg(data.msg,{icon:data.status?2:1,time:2000,shade: [0.3, '#000']}); + layer.msg(data.msg,{icon:data.status?1:2,time:2000,shade: [0.3, '#000']}); }); }); @@ -565,8 +565,9 @@ function projectScriptSelfRender(user, name){ var file = data[i]["name"]; gogsPost('project_script_self_logs', {'user':user,'name':name,'file':file}, function(data){ var rdata = $.parseJSON(data.data); + // console.log(rdata); if (rdata['status']){ - onlineEditFile(0, rdata['path']); + onlineEditFile(0, rdata['data']['path']); } else { layer.msg(rdata.msg,{icon:data.status?2:1,time:2000,shade: [0.3, '#000']}); }