From e5c53323a5bb695d80fde5cc3185a97efc360b8b Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 30 Oct 2023 01:00:54 +0800 Subject: [PATCH] =?UTF-8?q?gogs=20=E9=A1=B9=E7=9B=AE=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=BB=86=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/gogs/index.py | 24 +++++++++++++++++++++++- plugins/gogs/js/gogs.js | 10 ++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/plugins/gogs/index.py b/plugins/gogs/index.py index 7eec258c5..550bd3a67 100755 --- a/plugins/gogs/index.py +++ b/plugins/gogs/index.py @@ -821,7 +821,7 @@ def projectScriptSelf_Create(): if os.path.exists(abs_file): return mw.returnJson(False, '脚本已经存在!') - mw.writeFile(abs_file, "#!/bin/bash\n") + mw.writeFile(abs_file, "#!/bin/bash\necho `date +'%Y-%m-%d %H:%M:%S'`\n") rdata = {} rdata['abs_file'] = abs_file @@ -885,6 +885,26 @@ def projectScriptSelf_Logs(): return mw.returnJson(False, '日志不存在!') +def projectScriptSelf_Run(): + args = getArgs() + data = checkArgs(args, ['user', 'name', 'file']) + if not data[0]: + return data[1] + + user = args['user'] + name = args['name'] + '.git' + file = args['file'] + + custom_hooks = getRootPath() + '/' + user + '/' + \ + name + '/custom_hooks' + self_path = custom_hooks + '/self/' + file + self_logs_path = custom_hooks + '/self_logs/' + file + '.log' + + shell = "sh -x " + self_path + " 2>" + self_logs_path + mw.execShell(shell) + return mw.returnJson(True, '执行成功!') + + def projectScriptSelf_Rename(): args = getArgs() data = checkArgs(args, ['user', 'name', 'o_file', 'n_file']) @@ -1031,6 +1051,8 @@ if __name__ == "__main__": print(projectScriptSelf_Del()) elif func == 'project_script_self_logs': print(projectScriptSelf_Logs()) + elif func == 'project_script_self_run': + print(projectScriptSelf_Run()) elif func == 'project_script_self_rename': print(projectScriptSelf_Rename()) elif func == 'project_script_self_enable': diff --git a/plugins/gogs/js/gogs.js b/plugins/gogs/js/gogs.js index edd087b7a..ef6a0cb6c 100755 --- a/plugins/gogs/js/gogs.js +++ b/plugins/gogs/js/gogs.js @@ -534,6 +534,7 @@ function projectScriptSelfRender(user, name){ '删除' + ' | ' + '编辑' + ' | ' + '日志' + ' | ' + + '手动' + ' | ' + '重命名' + ''; } @@ -574,6 +575,15 @@ function projectScriptSelfRender(user, name){ }); }); + $('#gogs_self_table .run').click(function(){ + var i = $(this).data('index'); + var file = data[i]["name"]; + gogsPost('project_script_self_run', {'user':user,'name':name,'file':file}, function(data){ + var rdata = $.parseJSON(data.data); + layer.msg(rdata.msg,{icon:data.status?1:2,time:2000,shade: [0.3, '#000']}); + }); + }); + $('#gogs_self_table .rename').click(function(){ var i = $(this).data('index');