U 更改project_name为project_id作为触发webhook的标识

This commit is contained in:
张臻 2020-08-21 10:31:36 +08:00
parent aadf9ad9c5
commit fbb83a093b
9 changed files with 41 additions and 23 deletions

View File

@ -135,9 +135,7 @@ func (deploy Deploy) Publish(gp *core.Goploy) *core.Response {
return &core.Response{Code: core.Error, Message: err.Error()}
}
project, err := model.Project{
ID: reqData.ProjectID,
}.GetData()
project, err := model.Project{ID: reqData.ProjectID}.GetData()
if err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
@ -171,7 +169,10 @@ func (deploy Deploy) Publish(gp *core.Goploy) *core.Response {
// Webhook connect
func (deploy Deploy) Webhook(gp *core.Goploy) *core.Response {
projectName := gp.URLQuery.Get("project_name")
projectID, err := strconv.ParseInt(gp.URLQuery.Get("project_id"), 10, 64)
if err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
}
// other event is blocked in deployMiddleware
type ReqData struct {
Ref string `json:"ref" validate:"required"`
@ -180,11 +181,8 @@ func (deploy Deploy) Webhook(gp *core.Goploy) *core.Response {
if err := verify(gp.Body, &reqData); err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
}
branch := strings.Split(reqData.Ref, "/")[2]
project, err := model.Project{
Name: projectName,
}.GetDataByName()
project, err := model.Project{ID: projectID}.GetData()
if err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
}
@ -197,7 +195,7 @@ func (deploy Deploy) Webhook(gp *core.Goploy) *core.Response {
return &core.Response{Code: core.Deny, Message: "Webhook auto deploy turn off, go to project setting turn on"}
}
if project.Branch != branch {
if branch := strings.Split(reqData.Ref, "/")[2]; project.Branch != branch {
return &core.Response{Code: core.Deny, Message: "Receive branch:" + branch + " push event, not equal to current branch"}
}

View File

@ -7,4 +7,5 @@
* [后端](develop/backend.md)
* 常见问题
* [安装问题](question/install.md)
* [使用问题](question/use.md)
* [使用问题](question/use.md)
* [更新日志](changelog/index.md)

14
docs/changelog/index.md Normal file
View File

@ -0,0 +1,14 @@
# 更新日志
## 1.0.1
*2020-08-21*
### 新特性
- namespace
- 新增空间概念
### 优化
- 自动构建
- 更改project_name为project_id作为触发webhook的标识

View File

@ -29,6 +29,7 @@ func main() {
/_/ /____/
`)
install()
println(time.Now().String())
godotenv.Load(core.GlobalPath + ".env")
core.CreateValidator()
model.Init()

View File

@ -26,7 +26,6 @@ func HasPublishAuth(gp *core.Goploy) error {
// FilterEvent check the webhook event has publish auth
func FilterEvent(gp *core.Goploy) error {
if XGitHubEvent := gp.Request.Header.Get("X-GitHub-Event"); len(XGitHubEvent) != 0 && XGitHubEvent == "push" {
return nil
} else if XGitLabEvent := gp.Request.Header.Get("X-Gitlab-Event"); len(XGitLabEvent) != 0 && XGitLabEvent == "Push Hook" {

File diff suppressed because one or more lines are too long

View File

@ -16,9 +16,7 @@ func projectTask() {
core.Log(core.ERROR, "get project task list error, detail:"+err.Error())
}
for _, projectTask := range projectTasks {
project, err := model.Project{
ID: projectTask.ProjectID,
}.GetData()
project, err := model.Project{ID: projectTask.ProjectID}.GetData()
if err != nil {
core.Log(core.ERROR, "publish task has no project, detail:"+err.Error())

View File

@ -88,6 +88,14 @@ export function edit(data) {
})
}
export function setAutoDeploy(data) {
return request({
url: '/project/setAutoDeploy',
method: 'post',
data
})
}
export function remove(id) {
return request({
url: '/project/remove',

View File

@ -16,6 +16,7 @@
:data="tableData"
style="width: 100%"
>
<el-table-column prop="id" label="ID" width="100" />
<el-table-column prop="name" label="项目名称" width="200" />
<el-table-column prop="url" label="项目地址" width="350">
<template slot-scope="scope">
@ -72,16 +73,16 @@
<el-tabs v-model="formProps.tab" @tab-click="handleTabClick">
<el-tab-pane label="基本配置" name="base">
<el-form-item label="项目名称" prop="name">
<el-input v-model.trim="formData.name" autocomplete="off" />
<el-input v-model.trim="formData.name" autocomplete="off" placeholder="goploy" />
</el-form-item>
<el-form-item label="项目地址" prop="url">
<el-row type="flex">
<el-input v-model.trim="formData.url" autocomplete="off" @change="formProps.branch = []" />
<el-input v-model.trim="formData.url" autocomplete="off" placeholder="支持HTTPS、HTTP、SSH" @change="formProps.branch = []" />
<el-button :icon="formProps.lsBranchLoading ? 'el-icon-loading' : 'el-icon-view'" type="success" :disabled="formProps.lsBranchLoading" @click="getRemoteBranchList">测试连接</el-button>
</el-row>
</el-form-item>
<el-form-item label="部署路径" prop="path">
<el-input v-model.trim="formData.path" autocomplete="off" />
<el-input v-model.trim="formData.path" autocomplete="off" placeholder="/var/www/goploy" />
</el-form-item>
<el-form-item label="环境" prop="environment">
<el-select v-model="formData.environment" placeholder="选择环境" style="width:100%">
@ -238,8 +239,8 @@
</el-radio-group>
<el-row v-show="autoDeployFormData.autoDeploy===1" style="margin: 10px">
前往GitLabGitHub或Gitee的webhook可前往谷歌查找各自webhook所在的位置<br>
填入连接<span style="color: red">http(s)://(IP)/deploy/webhook?project_name={{ autoDeployFormProps.name }}</span><br>
勾选push event即可
填入连接<span style="color: red">http(s)://(IP)/deploy/webhook?project_id={{ autoDeployFormData.id }}</span><br>
勾选push event即可, (gitlab可以选对应的分支)
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
@ -470,8 +471,7 @@ export default {
]
},
autoDeployFormProps: {
disabled: false,
name: ''
disabled: false
},
autoDeployFormData: {
id: 0,
@ -566,7 +566,6 @@ export default {
handleAutoDeploy(data) {
this.dialogAutoDeployVisible = true
this.autoDeployFormProps.name = data.name
this.autoDeployFormData.id = data.id
this.autoDeployFormData.autoDeploy = data.autoDeploy
},