Skip to content

Commit

Permalink
feat(*): 新增触发器远程推送部署;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Aug 7, 2021
1 parent 655792c commit 99f027b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/devops-admin/src/api/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ export function createDeployToken({ permissions, expire, source }) {
/**
* 部署访问策略
*/
export async function deploy2remote(deploy_url, deploy_token, { policies, functions, comment }) {
export async function deploy2remote(deploy_url, deploy_token, { policies, functions, comment, triggers }) {
const _data = {
deploy_token,
policies: policies,
functions: functions,
triggers: triggers,
comment
}
const res = await axios.post(deploy_url, _data)
Expand Down
1 change: 1 addition & 0 deletions packages/devops-admin/src/router/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const asyncRoutes = [
meta: {
title: '访问策略',
icon: 'eye',
noCache: true,
permissions: ['policy.read']
}
},
Expand Down
68 changes: 61 additions & 7 deletions packages/devops-admin/src/views/deploy/components/deploy-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
v-for="item in targets"
:key="item._id"
:label="item.label"
:value="item"
:value="item._id"
/>
</el-select>
</el-form-item>
Expand All @@ -32,6 +32,11 @@
{{ func.name }} - {{ func.label }}
</el-tag>
</el-form-item>
<el-form-item v-if="triggers && triggers.length" label="部署触发器" size="normal">
<el-tag v-for="tri in triggers" :key="tri._id" type="default" size="mini" style="margin-right: 10px;">
{{ tri.name }} - {{ tri.event }}
</el-tag>
</el-form-item>
<el-form-item label="部署说明" prop="comment">
<el-input
v-model="form.comment"
Expand Down Expand Up @@ -82,30 +87,79 @@ export default {
form: this.defaultForm(),
// 部署目标
targets: [],
formRules
formRules,
internal_functions: [],
triggers: []
}
},
computed: {
visible() {
return this.value
},
selected_target() {
if (!this.form.target) {
return null
}
const [found] = this.targets.filter(it => it._id === this.form.target)
return found
}
},
watch: {
functions() {
if (this.functions) {
this.internal_functions = [...this.functions]
this.loadTriggers()
}
}
},
async mounted() {
const r = await db.collection('deploy_targets').get()
if (!r.ok) throw new Error('get targets failed')
this.targets = r.data
this.load()
},
activated() {
this.load()
},
methods: {
async load() {
const r = await db.collection('deploy_targets').get()
if (!r.ok) throw new Error('get targets failed')
this.targets = r.data
},
async loadTriggers() {
this.triggers = []
if (!this.internal_functions?.length) {
return
}
const func_ids = this.internal_functions.map(func => func._id)
const r = await db.collection('__triggers')
.where({
func_id: db.command.in(func_ids)
})
.get()
if (r.ok) {
this.triggers = r.data
}
},
deploy() {
if (!this.functions?.length && !this.policies?.length) {
this.$message.error('无可部署内容')
return
}
if (!this.selected_target) {
this.$message.error('无推送目标选中')
}
this.$refs['dataForm'].validate(async(valid) => {
if (!valid) { return }
const data = {
policies: this.policies,
functions: this.functions,
triggers: this.triggers,
comment: this.form.comment
}
const target = this.form.target
const target = this.selected_target
const r = await deploy2remote(target.url, target.token, data)
if (r.code === 0) {
this.$message.success('操作成功!')
Expand Down
2 changes: 1 addition & 1 deletion packages/devops-admin/src/views/development/functions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ export default {
},
created() {
this.getList()
this.getAllTags()
},
methods: {
/** 获取所有标签 */
Expand Down Expand Up @@ -323,6 +322,7 @@ export default {
this.total = total
this.listLoading = false
this.getAllTags()
},
// 搜索
handleFilter() {
Expand Down

0 comments on commit 99f027b

Please sign in to comment.