Skip to content

Commit 99f027b

Browse files
committed
feat(*): 新增触发器远程推送部署;
1 parent 655792c commit 99f027b

File tree

4 files changed

+65
-9
lines changed

4 files changed

+65
-9
lines changed

packages/devops-admin/src/api/deploy.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ export function createDeployToken({ permissions, expire, source }) {
2222
/**
2323
* 部署访问策略
2424
*/
25-
export async function deploy2remote(deploy_url, deploy_token, { policies, functions, comment }) {
25+
export async function deploy2remote(deploy_url, deploy_token, { policies, functions, comment, triggers }) {
2626
const _data = {
2727
deploy_token,
2828
policies: policies,
2929
functions: functions,
30+
triggers: triggers,
3031
comment
3132
}
3233
const res = await axios.post(deploy_url, _data)

packages/devops-admin/src/router/async.js

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export const asyncRoutes = [
8383
meta: {
8484
title: '访问策略',
8585
icon: 'eye',
86+
noCache: true,
8687
permissions: ['policy.read']
8788
}
8889
},

packages/devops-admin/src/views/deploy/components/deploy-panel.vue

+61-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
v-for="item in targets"
1919
:key="item._id"
2020
:label="item.label"
21-
:value="item"
21+
:value="item._id"
2222
/>
2323
</el-select>
2424
</el-form-item>
@@ -32,6 +32,11 @@
3232
{{ func.name }} - {{ func.label }}
3333
</el-tag>
3434
</el-form-item>
35+
<el-form-item v-if="triggers && triggers.length" label="部署触发器" size="normal">
36+
<el-tag v-for="tri in triggers" :key="tri._id" type="default" size="mini" style="margin-right: 10px;">
37+
{{ tri.name }} - {{ tri.event }}
38+
</el-tag>
39+
</el-form-item>
3540
<el-form-item label="部署说明" prop="comment">
3641
<el-input
3742
v-model="form.comment"
@@ -82,30 +87,79 @@ export default {
8287
form: this.defaultForm(),
8388
// 部署目标
8489
targets: [],
85-
formRules
90+
formRules,
91+
internal_functions: [],
92+
triggers: []
8693
}
8794
},
8895
computed: {
8996
visible() {
9097
return this.value
98+
},
99+
selected_target() {
100+
if (!this.form.target) {
101+
return null
102+
}
103+
const [found] = this.targets.filter(it => it._id === this.form.target)
104+
return found
105+
}
106+
},
107+
watch: {
108+
functions() {
109+
if (this.functions) {
110+
this.internal_functions = [...this.functions]
111+
this.loadTriggers()
112+
}
91113
}
92114
},
93115
async mounted() {
94-
const r = await db.collection('deploy_targets').get()
95-
if (!r.ok) throw new Error('get targets failed')
96-
97-
this.targets = r.data
116+
this.load()
117+
},
118+
activated() {
119+
this.load()
98120
},
99121
methods: {
122+
async load() {
123+
const r = await db.collection('deploy_targets').get()
124+
if (!r.ok) throw new Error('get targets failed')
125+
126+
this.targets = r.data
127+
},
128+
async loadTriggers() {
129+
this.triggers = []
130+
if (!this.internal_functions?.length) {
131+
return
132+
}
133+
const func_ids = this.internal_functions.map(func => func._id)
134+
const r = await db.collection('__triggers')
135+
.where({
136+
func_id: db.command.in(func_ids)
137+
})
138+
.get()
139+
140+
if (r.ok) {
141+
this.triggers = r.data
142+
}
143+
},
100144
deploy() {
145+
if (!this.functions?.length && !this.policies?.length) {
146+
this.$message.error('无可部署内容')
147+
return
148+
}
149+
150+
if (!this.selected_target) {
151+
this.$message.error('无推送目标选中')
152+
}
153+
101154
this.$refs['dataForm'].validate(async(valid) => {
102155
if (!valid) { return }
103156
const data = {
104157
policies: this.policies,
105158
functions: this.functions,
159+
triggers: this.triggers,
106160
comment: this.form.comment
107161
}
108-
const target = this.form.target
162+
const target = this.selected_target
109163
const r = await deploy2remote(target.url, target.token, data)
110164
if (r.code === 0) {
111165
this.$message.success('操作成功!')

packages/devops-admin/src/views/development/functions.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ export default {
260260
},
261261
created() {
262262
this.getList()
263-
this.getAllTags()
264263
},
265264
methods: {
266265
/** 获取所有标签 */
@@ -323,6 +322,7 @@ export default {
323322
324323
this.total = total
325324
this.listLoading = false
325+
this.getAllTags()
326326
},
327327
// 搜索
328328
handleFilter() {

0 commit comments

Comments
 (0)