improve webhook tips

pull/330/head
vapao 2021-04-28 10:28:34 +08:00
parent 20f28fd64c
commit b84a156454
3 changed files with 24 additions and 10 deletions

View File

@ -7,6 +7,7 @@ from .views import *
urlpatterns = [
path('', AppView.as_view()),
path('kit/key/', kit_key),
path('deploy/', DeployView.as_view()),
path('deploy/<int:d_id>/versions/', get_versions),
]

View File

@ -8,6 +8,7 @@ from libs import JsonParser, Argument, json_response
from apps.app.models import App, Deploy, DeployExtend1, DeployExtend2
from apps.config.models import Config
from apps.app.utils import fetch_versions, remove_repo
from apps.setting.utils import AppSetting
import subprocess
import json
import os
@ -15,12 +16,6 @@ import os
class AppView(View):
def get(self, request):
# v2.3.14 临时数据初始化
app = App.objects.first()
if app and hasattr(app, 'sort_id') and app.sort_id == 0:
for app in App.objects.all():
app.sort_id = app.id
app.save()
query = {}
if not request.user.is_supper:
query['id__in'] = request.user.deploy_perms['apps']
@ -181,3 +176,8 @@ def get_versions(request, d_id):
return json_response(error='该应用不支持此操作')
branches, tags = fetch_versions(deploy)
return json_response({'branches': branches, 'tags': tags})
def kit_key(request):
api_key = AppSetting.get_default('api_key')
return json_response(api_key)

View File

@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import { observer } from 'mobx-react';
import { Modal, Form, Input, Select, Radio, Button, message } from 'antd';
import { Modal, Form, Input, Select, Radio, Button, Alert, message } from 'antd';
import { LoadingOutlined, SyncOutlined } from '@ant-design/icons';
import { http } from 'libs';
import store from './store';
@ -13,11 +13,14 @@ export default observer(function AutoDeploy() {
const [branches, setBranches] = useState([]);
const [branch, setBranch] = useState();
const [url, setURL] = useState();
const [key, setKey] = useState();
useEffect(() => {
if (store.deploy.extend === '1') {
fetchVersions()
}
http.get('/api/app/kit/key/')
.then(res => setKey(res))
}, [])
useEffect(() => {
@ -36,9 +39,9 @@ export default observer(function AutoDeploy() {
.finally(() => setFetching(false))
}
function copyToClipBoard() {
function copyToClipBoard(data) {
const t = document.createElement('input');
t.value = url;
t.value = data;
document.body.appendChild(t);
t.select();
document.execCommand('copy');
@ -54,6 +57,7 @@ export default observer(function AutoDeploy() {
title="Webhook"
footer={null}
onCancel={() => store.autoVisible = false}>
<Alert showIcon type="info" style={{width: 440, margin: '0 auto 24px'}} message="Webhook可以用来与Gitlab或Gitee结合实现触发后自动发布。"/>
<Form labelCol={{span: 6}} wrapperCol={{span: 16}}>
<Form.Item required label="触发方式">
<Radio.Group value={type} onChange={e => setType(e.target.value)}>
@ -96,7 +100,16 @@ export default observer(function AutoDeploy() {
</Form.Item>
) : (
<Form.Item label="Webhook URL" extra="点击复制链接目前仅支持Gitee和Gitlab。">
<div className={styles.webhook} onClick={copyToClipBoard}>{url}</div>
<div className={styles.webhook} onClick={() => copyToClipBoard(url)}>{url}</div>
</Form.Item>
)}
{key ? (
<Form.Item label="Secret Token" tooltip="调用该Webhook接口的访问凭据在Gitee中为WebHook 密码。" extra="点击复制">
<div className={styles.webhook} onClick={() => copyToClipBoard(key)}>{key}</div>
</Form.Item>
) : (
<Form.Item label="Secret Token" tooltip="调用该Webhook接口的访问凭据在Gitee中为WebHook密码。">
<div style={{color: '#ff4d4f'}}>请在系统管理/系统设置/开放服务设置中设置</div>
</Form.Item>
)}
</Form>