Browse Source

仓库钩子工作结束 开始修复最后的一个bug

docker-svn
witersen 3 years ago
parent
commit
720b4221ce
  1. 79
      01.web/src/views/repositoryInfo/index.vue
  2. 11
      02.php/app/controller/Svnrep.php
  3. 58
      02.php/app/service/Svnrep.php
  4. 9
      02.php/config/svn.php
  5. 6
      02.php/server/install.php
  6. 1
      02.php/templete/hooks/01/hookDescription
  7. 1
      02.php/templete/hooks/01/hookName
  8. 15
      02.php/templete/hooks/01/pre-commit

79
01.web/src/views/repositoryInfo/index.vue

@ -621,25 +621,14 @@
<TabPane label="常用钩子"> <TabPane label="常用钩子">
<Scroll> <Scroll>
<List :border="true"> <List :border="true">
<ListItem> <ListItem v-for="(item, index) in recommendHooks" :key="index">
<ListItemMeta <ListItemMeta
title="Precommit hook" :title="item.hookName"
description="This is description, this is description." :description="item.hookDescription"
/> />
<template slot="action"> <template slot="action">
<li> <li>
<span>查看</span> <span @click="ViewRecommendHook(item.hookName)">查看</span>
</li>
</template>
</ListItem>
<ListItem>
<ListItemMeta
title="Precommit hook"
description="This is description, this is description."
/>
<template slot="action">
<li>
<span>查看</span>
</li> </li>
</template> </template>
</ListItem> </ListItem>
@ -657,6 +646,7 @@
<Modal v-model="modalStudyRepHook" :title="titleModalStudyRepHook"> <Modal v-model="modalStudyRepHook" :title="titleModalStudyRepHook">
<Input <Input
v-model="tempSelectRepHookTmpl" v-model="tempSelectRepHookTmpl"
readonly
:rows="15" :rows="15"
show-word-limit show-word-limit
type="textarea" type="textarea"
@ -667,6 +657,21 @@
> >
</div> </div>
</Modal> </Modal>
<!-- 对话框-推荐钩子内容查看 -->
<Modal v-model="modalRecommendHook" title="常用钩子">
<Input
v-model="tempSelectRepHookRecommend"
readonly
:rows="15"
show-word-limit
type="textarea"
/>
<div slot="footer">
<Button type="primary" ghost @click="modalRecommendHook = false"
>取消</Button
>
</div>
</Modal>
<!-- 对话框-钩子内容编辑 --> <!-- 对话框-钩子内容编辑 -->
<Modal v-model="modalEditRepHook" :title="titleModalEditRepHook"> <Modal v-model="modalEditRepHook" :title="titleModalEditRepHook">
<Input <Input
@ -906,6 +911,8 @@ export default {
modalEditRepHook: false, modalEditRepHook: false,
// //
modalStudyRepHook: false, modalStudyRepHook: false,
//
modalRecommendHook: false,
/** /**
* 排序数据 * 排序数据
@ -1012,6 +1019,8 @@ export default {
tempSelectRepHookCon: "", tempSelectRepHookCon: "",
// //
tempSelectRepHookTmpl: "", tempSelectRepHookTmpl: "",
//
tempSelectRepHookRecommend: "",
/** /**
* 对话框标题 * 对话框标题
@ -1094,6 +1103,9 @@ export default {
*/ */
breadRepPath: [], breadRepPath: [],
//
recommendHooks: [],
/** /**
* 表格 * 表格
*/ */
@ -2431,8 +2443,10 @@ export default {
this.modalRepHooks = true; this.modalRepHooks = true;
// //
this.currentRepName = rep_name; this.currentRepName = rep_name;
// //
this.GetRepHooks(); this.GetRepHooks();
//
this.GetRecommendHooks();
}, },
/** /**
* 获取仓库的钩子和对应的内容列表 * 获取仓库的钩子和对应的内容列表
@ -2460,6 +2474,27 @@ export default {
that.$Message.error("出错了 请联系管理员!"); that.$Message.error("出错了 请联系管理员!");
}); });
}, },
/**
* 获取推荐钩子
*/
GetRecommendHooks() {
var that = this;
var data = {};
that.$axios
.post("/api.php?c=Svnrep&a=GetRecommendHooks&t=web", data)
.then(function (response) {
var result = response.data;
if (result.status == 1) {
that.recommendHooks = result.data;
} else {
that.$Message.error(result.message);
}
})
.catch(function (error) {
console.log(error);
that.$Message.error("出错了 请联系管理员!");
});
},
/** /**
* 移除仓库钩子 * 移除仓库钩子
*/ */
@ -2516,6 +2551,18 @@ export default {
// //
this.modalEditRepHook = true; this.modalEditRepHook = true;
}, },
/**
* 查看推荐仓库钩子内容
*/
ViewRecommendHook(hookName) {
var temp = this.recommendHooks.filter(
(item) => item.hookName = hookName
);
//
this.tempSelectRepHookRecommend = temp[0].hookContent;
//
this.modalRecommendHook = true;
},
EditRepHook() { EditRepHook() {
var that = this; var that = this;
that.loadingEditRepHook = true; that.loadingEditRepHook = true;

11
02.php/app/controller/Svnrep.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:05 * @Date: 2022-04-24 23:37:05
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-10 21:53:20 * @LastEditTime: 2022-05-11 11:45:59
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -279,4 +279,13 @@ class Svnrep extends Base
$result = $this->ServiceSvnrep->EditRepHook(); $result = $this->ServiceSvnrep->EditRepHook();
json2($result); json2($result);
} }
/**
* 获取常用钩子列表
*/
public function GetRecommendHooks()
{
$result = $this->ServiceSvnrep->GetRecommendHooks();
json2($result);
}
} }

58
02.php/app/service/Svnrep.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:05 * @Date: 2022-04-24 23:37:05
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-11 02:19:00 * @LastEditTime: 2022-05-11 13:39:47
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -77,7 +77,7 @@ class Svnrep extends Base
$status = $this->SVNAdminRep->SetRepAuthz($this->authzContent, $this->payload['rep_name'], '/'); $status = $this->SVNAdminRep->SetRepAuthz($this->authzContent, $this->payload['rep_name'], '/');
if ($status != '1') { if ($status != '1') {
// FunShellExec('echo \'' . $status . '\' > ' . $this->config_svn['svn_authz_file']); // FunShellExec('echo \'' . $status . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $status); 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/'; $hooksPath = $this->config_svn['rep_base_path'] . $this->payload['rep_name'] . '/hooks/';
//使用echo写入文件 当出现不规则的不成对的 ' " 等会出问题 当然也会包括其他问题 //使用echo写入文件 当出现不规则的不成对的 ' " 等会出问题 当然也会包括其他问题
FunFilePutContents($hooksPath . $this->payload['fileName'],$this->payload['content']); FunFilePutContents($hooksPath . $this->payload['fileName'], $this->payload['content']);
return message(); 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);
}
} }

9
02.php/config/svn.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:06 * @Date: 2022-04-24 23:37:06
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-08 23:33:10 * @LastEditTime: 2022-05-11 11:32:27
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -64,6 +64,11 @@ return [
*/ */
'svnserve_service_file' => '/usr/lib/systemd/system/svnserve.service', '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_base_path' => $templete_base_path,
/** /**
* 初始化仓库结构模板 * 初始化仓库结构模板目录
*/ */
'templete_init_struct' => $templete_base_path . '01/', 'templete_init_struct' => $templete_base_path . '01/',
]; ];

6
02.php/server/install.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-05-08 13:31:07 * @Date: 2022-05-08 13:31:07
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-09 17:39:28 * @LastEditTime: 2022-05-11 13:46:48
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -278,6 +278,10 @@ CON;
//创建SVN仓库父目录 //创建SVN仓库父目录
is_dir($this->config_svn['rep_base_path']) ? '' : mkdir($this->config_svn['rep_base_path'], 0700, true); 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); is_dir($this->config_svn['backup_base_path']) ? '' : mkdir($this->config_svn['backup_base_path'], 0700, true);

1
02.php/templete/hooks/01/hookDescription

@ -0,0 +1 @@
SVN 提交必须填写备注钩子

1
02.php/templete/hooks/01/hookName

@ -0,0 +1 @@
pre-commit

15
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
Loading…
Cancel
Save