mirror of https://github.com/openspug/spug
improve webhook tips
parent
20f28fd64c
commit
b84a156454
|
@ -7,6 +7,7 @@ from .views import *
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', AppView.as_view()),
|
path('', AppView.as_view()),
|
||||||
|
path('kit/key/', kit_key),
|
||||||
path('deploy/', DeployView.as_view()),
|
path('deploy/', DeployView.as_view()),
|
||||||
path('deploy/<int:d_id>/versions/', get_versions),
|
path('deploy/<int:d_id>/versions/', get_versions),
|
||||||
]
|
]
|
||||||
|
|
|
@ -8,6 +8,7 @@ from libs import JsonParser, Argument, json_response
|
||||||
from apps.app.models import App, Deploy, DeployExtend1, DeployExtend2
|
from apps.app.models import App, Deploy, DeployExtend1, DeployExtend2
|
||||||
from apps.config.models import Config
|
from apps.config.models import Config
|
||||||
from apps.app.utils import fetch_versions, remove_repo
|
from apps.app.utils import fetch_versions, remove_repo
|
||||||
|
from apps.setting.utils import AppSetting
|
||||||
import subprocess
|
import subprocess
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
@ -15,12 +16,6 @@ import os
|
||||||
|
|
||||||
class AppView(View):
|
class AppView(View):
|
||||||
def get(self, request):
|
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 = {}
|
query = {}
|
||||||
if not request.user.is_supper:
|
if not request.user.is_supper:
|
||||||
query['id__in'] = request.user.deploy_perms['apps']
|
query['id__in'] = request.user.deploy_perms['apps']
|
||||||
|
@ -181,3 +176,8 @@ def get_versions(request, d_id):
|
||||||
return json_response(error='该应用不支持此操作')
|
return json_response(error='该应用不支持此操作')
|
||||||
branches, tags = fetch_versions(deploy)
|
branches, tags = fetch_versions(deploy)
|
||||||
return json_response({'branches': branches, 'tags': tags})
|
return json_response({'branches': branches, 'tags': tags})
|
||||||
|
|
||||||
|
|
||||||
|
def kit_key(request):
|
||||||
|
api_key = AppSetting.get_default('api_key')
|
||||||
|
return json_response(api_key)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { observer } from 'mobx-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 { LoadingOutlined, SyncOutlined } from '@ant-design/icons';
|
||||||
import { http } from 'libs';
|
import { http } from 'libs';
|
||||||
import store from './store';
|
import store from './store';
|
||||||
|
@ -13,11 +13,14 @@ export default observer(function AutoDeploy() {
|
||||||
const [branches, setBranches] = useState([]);
|
const [branches, setBranches] = useState([]);
|
||||||
const [branch, setBranch] = useState();
|
const [branch, setBranch] = useState();
|
||||||
const [url, setURL] = useState();
|
const [url, setURL] = useState();
|
||||||
|
const [key, setKey] = useState();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (store.deploy.extend === '1') {
|
if (store.deploy.extend === '1') {
|
||||||
fetchVersions()
|
fetchVersions()
|
||||||
}
|
}
|
||||||
|
http.get('/api/app/kit/key/')
|
||||||
|
.then(res => setKey(res))
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -36,9 +39,9 @@ export default observer(function AutoDeploy() {
|
||||||
.finally(() => setFetching(false))
|
.finally(() => setFetching(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyToClipBoard() {
|
function copyToClipBoard(data) {
|
||||||
const t = document.createElement('input');
|
const t = document.createElement('input');
|
||||||
t.value = url;
|
t.value = data;
|
||||||
document.body.appendChild(t);
|
document.body.appendChild(t);
|
||||||
t.select();
|
t.select();
|
||||||
document.execCommand('copy');
|
document.execCommand('copy');
|
||||||
|
@ -54,6 +57,7 @@ export default observer(function AutoDeploy() {
|
||||||
title="Webhook"
|
title="Webhook"
|
||||||
footer={null}
|
footer={null}
|
||||||
onCancel={() => store.autoVisible = false}>
|
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 labelCol={{span: 6}} wrapperCol={{span: 16}}>
|
||||||
<Form.Item required label="触发方式">
|
<Form.Item required label="触发方式">
|
||||||
<Radio.Group value={type} onChange={e => setType(e.target.value)}>
|
<Radio.Group value={type} onChange={e => setType(e.target.value)}>
|
||||||
|
@ -96,7 +100,16 @@ export default observer(function AutoDeploy() {
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
) : (
|
) : (
|
||||||
<Form.Item label="Webhook URL" extra="点击复制链接,目前仅支持Gitee和Gitlab。">
|
<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.Item>
|
||||||
)}
|
)}
|
||||||
</Form>
|
</Form>
|
||||||
|
|
Loading…
Reference in New Issue