From 720b4221cefb7502e57cf81e57e488875ad4eb53 Mon Sep 17 00:00:00 2001 From: witersen <1801168257@qq.com> Date: Wed, 11 May 2022 13:48:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=93=E5=BA=93=E9=92=A9=E5=AD=90=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E7=BB=93=E6=9D=9F=20=E5=BC=80=E5=A7=8B=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=9C=80=E5=90=8E=E7=9A=84=E4=B8=80=E4=B8=AAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 01.web/src/views/repositoryInfo/index.vue | 79 ++++++++++++++++++----- 02.php/app/controller/Svnrep.php | 11 +++- 02.php/app/service/Svnrep.php | 58 ++++++++++++++++- 02.php/config/svn.php | 9 ++- 02.php/server/install.php | 6 +- 02.php/templete/hooks/01/hookDescription | 1 + 02.php/templete/hooks/01/hookName | 1 + 02.php/templete/hooks/01/pre-commit | 15 +++++ 8 files changed, 157 insertions(+), 23 deletions(-) create mode 100644 02.php/templete/hooks/01/hookDescription create mode 100644 02.php/templete/hooks/01/hookName create mode 100644 02.php/templete/hooks/01/pre-commit diff --git a/01.web/src/views/repositoryInfo/index.vue b/01.web/src/views/repositoryInfo/index.vue index 3fa0b32..d3c199e 100644 --- a/01.web/src/views/repositoryInfo/index.vue +++ b/01.web/src/views/repositoryInfo/index.vue @@ -621,25 +621,14 @@ - + - - - - @@ -657,6 +646,7 @@ + + + +
+ +
+
item.hookName = hookName + ); + //设置当前选中的内容到输入框 + this.tempSelectRepHookRecommend = temp[0].hookContent; + // 展示输入框 + this.modalRecommendHook = true; + }, EditRepHook() { var that = this; that.loadingEditRepHook = true; diff --git a/02.php/app/controller/Svnrep.php b/02.php/app/controller/Svnrep.php index b2a4575..d4fea5f 100644 --- a/02.php/app/controller/Svnrep.php +++ b/02.php/app/controller/Svnrep.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:05 * @LastEditors: witersen - * @LastEditTime: 2022-05-10 21:53:20 + * @LastEditTime: 2022-05-11 11:45:59 * @Description: QQ:1801168257 */ @@ -279,4 +279,13 @@ class Svnrep extends Base $result = $this->ServiceSvnrep->EditRepHook(); json2($result); } + + /** + * 获取常用钩子列表 + */ + public function GetRecommendHooks() + { + $result = $this->ServiceSvnrep->GetRecommendHooks(); + json2($result); + } } diff --git a/02.php/app/service/Svnrep.php b/02.php/app/service/Svnrep.php index edddede..fe8468c 100644 --- a/02.php/app/service/Svnrep.php +++ b/02.php/app/service/Svnrep.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:05 * @LastEditors: witersen - * @LastEditTime: 2022-05-11 02:19:00 + * @LastEditTime: 2022-05-11 13:39:47 * @Description: QQ:1801168257 */ @@ -77,7 +77,7 @@ class Svnrep extends Base $status = $this->SVNAdminRep->SetRepAuthz($this->authzContent, $this->payload['rep_name'], '/'); if ($status != '1') { // FunShellExec('echo \'' . $status . '\' > ' . $this->config_svn['svn_authz_file']); - + FunFilePutContents($this->config_svn['svn_authz_file'], $status); } @@ -1525,8 +1525,60 @@ class Svnrep extends Base $hooksPath = $this->config_svn['rep_base_path'] . $this->payload['rep_name'] . '/hooks/'; //使用echo写入文件 当出现不规则的不成对的 ' " 等会出问题 当然也会包括其他问题 - FunFilePutContents($hooksPath . $this->payload['fileName'],$this->payload['content']); + FunFilePutContents($hooksPath . $this->payload['fileName'], $this->payload['content']); return message(); } + + /** + * 获取常用钩子列表 + */ + public function GetRecommendHooks() + { + $list = []; + + $recommend_hook_path = $this->config_svn['recommend_hook_path']; + if (!is_dir($recommend_hook_path)) { + return message(200, 0, '未创建自定义钩子目录'); + } + + $dirs = scandir($recommend_hook_path); + + foreach ($dirs as $dir) { + if ($dir == '.' || $dir == '..') { + continue; + } + + if (!is_dir($recommend_hook_path . $dir)) { + continue; + } + + $dirFiles = scandir($recommend_hook_path . $dir); + + if (!in_array('hookDescription', $dirFiles) || !in_array('hookName', $dirFiles)) { + continue; + } + + $hookName = FunShellExec(sprintf("cat '%s'", $recommend_hook_path . $dir . '/hookName')); + $hookName = $hookName['result']; + + if (!file_exists($recommend_hook_path . $dir . '/' . trim($hookName))) { + continue; + } + + $hookContent = FunShellExec(sprintf("cat '%s'", $recommend_hook_path . $dir . '/' . $hookName)); + $hookContent = $hookContent['result']; + + $hookDescription = FunShellExec(sprintf("cat '%s'", $recommend_hook_path . $dir . '/hookDescription')); + $hookDescription = $hookDescription['result']; + + array_push($list, [ + 'hookName' => $hookName, + 'hookContent' => $hookContent, + 'hookDescription' => $hookDescription + ]); + } + + return message(200, 1, '成功', $list); + } } diff --git a/02.php/config/svn.php b/02.php/config/svn.php index 31d144a..8313bc9 100644 --- a/02.php/config/svn.php +++ b/02.php/config/svn.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:06 * @LastEditors: witersen - * @LastEditTime: 2022-05-08 23:33:10 + * @LastEditTime: 2022-05-11 11:32:27 * @Description: QQ:1801168257 */ @@ -64,6 +64,11 @@ return [ */ 'svnserve_service_file' => '/usr/lib/systemd/system/svnserve.service', + /** + * 推荐钩子目录 + */ + 'recommend_hook_path' => $home_path . 'hooks/', + /** * 备份目录 */ @@ -90,7 +95,7 @@ return [ 'templete_base_path' => $templete_base_path, /** - * 初始化仓库结构模板 + * 初始化仓库结构模板目录 */ 'templete_init_struct' => $templete_base_path . '01/', ]; diff --git a/02.php/server/install.php b/02.php/server/install.php index 1a0fb01..fbca6dd 100644 --- a/02.php/server/install.php +++ b/02.php/server/install.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-05-08 13:31:07 * @LastEditors: witersen - * @LastEditTime: 2022-05-09 17:39:28 + * @LastEditTime: 2022-05-11 13:46:48 * @Description: QQ:1801168257 */ @@ -278,6 +278,10 @@ CON; //创建SVN仓库父目录 is_dir($this->config_svn['rep_base_path']) ? '' : mkdir($this->config_svn['rep_base_path'], 0700, true); + //创建推荐钩子目录 + is_dir($this->config_svn['recommend_hook_path']) ? '' : mkdir($this->config_svn['recommend_hook_path'], 0700, true); + shell_exec(sprintf("cp -r '%s' '%s'", $templete_path . '/hooks', $this->config_svn['recommend_hook_path'])); + //创建备份目录 is_dir($this->config_svn['backup_base_path']) ? '' : mkdir($this->config_svn['backup_base_path'], 0700, true); diff --git a/02.php/templete/hooks/01/hookDescription b/02.php/templete/hooks/01/hookDescription new file mode 100644 index 0000000..2868213 --- /dev/null +++ b/02.php/templete/hooks/01/hookDescription @@ -0,0 +1 @@ +SVN 提交必须填写备注钩子 \ No newline at end of file diff --git a/02.php/templete/hooks/01/hookName b/02.php/templete/hooks/01/hookName new file mode 100644 index 0000000..e42b23c --- /dev/null +++ b/02.php/templete/hooks/01/hookName @@ -0,0 +1 @@ +pre-commit \ No newline at end of file diff --git a/02.php/templete/hooks/01/pre-commit b/02.php/templete/hooks/01/pre-commit new file mode 100644 index 0000000..8a58d7c --- /dev/null +++ b/02.php/templete/hooks/01/pre-commit @@ -0,0 +1,15 @@ +#!/bin/sh + +REPOS="$1" +TXN="$2" + +# SVN 提交必须填写备注钩子 +LOGMSG=`$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c` +if [ "$LOGMSG" -lt 4 ] +then + echo -e "\nLog message cann‘t be empty! you must input more than 4 chars 4 Chinese characters as comment!\\n 日志消息不能为空!您必须输入超过4个字符或4个汉字以上作为注释!\\n" 1>&2 +exit 1 +fi + +# All checks passed, so allow the commit. +exit 0