加入git同步

This commit is contained in:
marvzhang
2020-02-17 18:12:59 +08:00
parent a52c94c7cc
commit f83a041cd1
572 changed files with 117651 additions and 4443 deletions

View File

@@ -197,7 +197,8 @@ export default {
ignoreFileRegexList: [
'__pycache__',
'md5.txt',
'.pyc'
'.pyc',
'.git'
],
activeFileNode: {},
dirDialogVisible: false,

View File

@@ -58,13 +58,25 @@
<el-form-item :label="$t('Remark')">
<el-input type="textarea" v-model="spiderForm.remark" :placeholder="$t('Remark')" :disabled="isView"/>
</el-form-item>
<el-form-item v-if="spiderForm.type === 'customized' && !isView" :label="$t('Is Scrapy')" prop="is_scrapy">
<el-switch
v-model="spiderForm.is_scrapy"
active-color="#13ce66"
@change="onIsScrapyChange"
/>
</el-form-item>
<el-row>
<el-col :span="6">
<el-form-item v-if="spiderForm.type === 'customized' && !isView" :label="$t('Is Scrapy')" prop="is_scrapy">
<el-switch
v-model="spiderForm.is_scrapy"
active-color="#13ce66"
@change="onIsScrapyChange"
/>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item v-if="!isView" :label="$t('Is Git')" prop="is_git">
<el-switch
v-model="spiderForm.is_git"
active-color="#13ce66"
/>
</el-form-item>
</el-col>
</el-row>
</el-form>
</el-row>
<el-row class="button-container" v-if="!isView">

View File

@@ -0,0 +1,239 @@
<template>
<div class="git-settings">
<h3 class="title">{{$t('Git Settings')}}</h3>
<el-form
class="git-settings-form"
label-width="150px"
:model="spiderForm"
ref="git-settings-form"
>
<el-form-item
:label="$t('Git URL')"
prop="git_url"
required
>
<el-input
v-model="spiderForm.git_url"
:placeholder="$t('Git URL')"
@blur="onGitUrlChange"
>
</el-input>
</el-form-item>
<el-form-item
:label="$t('Has Credential')"
prop="git_has_credential"
>
<el-switch
v-model="spiderForm.git_has_credential"
size="small"
active-color="#67C23A"
/>
</el-form-item>
<el-form-item
v-if="spiderForm.git_has_credential"
:label="$t('Git Username')"
prop="git_username"
>
<el-input
v-model="spiderForm.git_username"
:placeholder="$t('Git Username')"
>
</el-input>
</el-form-item>
<el-form-item
v-if="spiderForm.git_has_credential"
:label="$t('Git Password')"
prop="git_password"
>
<el-input
v-model="spiderForm.git_password"
:placeholder="$t('Git Password')"
type="password"
>
</el-input>
</el-form-item>
<el-form-item
:label="$t('Git Branch')"
prop="git_branch"
required
>
<el-select
v-model="spiderForm.git_branch"
:placeholder="$t('Git Branch')"
:disabled="!spiderForm.git_url || isGitBranchesLoading"
>
<el-option
v-for="op in gitBranches"
:key="op"
:value="op"
:label="op"
/>
</el-select>
</el-form-item>
<el-form-item
:label="$t('Auto Sync')"
prop="git_auto_sync"
>
<el-switch
v-model="spiderForm.git_auto_sync"
size="small"
active-color="#67C23A"
/>
</el-form-item>
<el-form-item
v-if="spiderForm.git_auto_sync"
:label="$t('Sync Frequency')"
prop="git_sync_frequency"
required
>
<el-select
v-model="spiderForm.git_sync_frequency"
:placeholder="$t('Sync Frequency')"
>
<el-option
v-for="op in syncFrequencies"
:key="op.value"
:value="op.value"
:label="op.label"
/>
</el-select>
</el-form-item>
</el-form>
<div class="action-wrapper">
<el-button
size="small"
type="warning"
:disabled="isGitResetLoading"
:icon="isGitResetLoading ? 'el-icon-loading' : 'el-icon-refresh-left'"
@click="onReset"
>
{{$t('Reset')}}
</el-button>
<el-button
size="small"
type="danger"
:icon="isGitSyncLoading ? 'el-icon-loading' : 'el-icon-refresh'"
:disabled="!spiderForm.git_url || isGitSyncLoading"
@click="onSync"
>
{{$t('Sync')}}
</el-button>
<el-button size="small" type="success" @click="onSave" icon="el-icon-check">
{{$t('Save')}}
</el-button>
</div>
</div>
</template>
<script>
import {
mapState
} from 'vuex'
export default {
name: 'GitSettings',
data () {
return {
gitBranches: [],
isGitBranchesLoading: false,
isGitSyncLoading: false,
isGitResetLoading: false,
syncFrequencies: [
{ label: '1m', value: '0 * * * * *' },
{ label: '5m', value: '0 0/5 * * * *' },
{ label: '15m', value: '0 0/15 * * * *' },
{ label: '30m', value: '0 0/30 * * * *' },
{ label: '1h', value: '0 0 * * * *' },
{ label: '6h', value: '0 0 0/6 * * *' },
{ label: '12h', value: '0 0 0/12 * * *' },
{ label: '1d', value: '0 0 0 0 * *' }
]
}
},
computed: {
...mapState('spider', [
'spiderForm'
])
},
methods: {
onSave () {
this.$refs['git-settings-form'].validate(async valid => {
if (!valid) return
const res = await this.$store.dispatch('spider/editSpider')
if (!res.data.error) {
this.$message.success(this.$t('Spider info has been saved successfully'))
}
})
this.$st.sendEv('爬虫详情', 'Git 设置', '保存')
},
async onGitUrlChange () {
if (!this.spiderForm.git_url) return
this.isGitBranchesLoading = true
const res = await this.$request.get('/git/branches', { url: this.spiderForm.git_url })
this.gitBranches = res.data.data
if (!this.spiderForm.git_branch && this.gitBranches.length > 0) {
this.$set(this.spiderForm, 'git_branch', this.gitBranches[0])
}
this.isGitBranchesLoading = false
},
async onSync () {
this.isGitSyncLoading = true
try {
const res = await this.$request.post(`/spiders/${this.spiderForm._id}/git/sync`)
if (!res.data.error) {
this.$message.success(this.$t('Git has been synchronized successfully'))
}
} finally {
this.isGitSyncLoading = false
}
},
onReset () {
this.$confirm(
this.$t('This would delete all files of the spider. Are you sure to continue?'),
this.$t('Notification'),
{
confirmButtonText: this.$t('Confirm'),
cancelButtonText: this.$t('Cancel'),
type: 'warning'
})
.then(async () => {
this.isGitResetLoading = true
try {
const res = await this.$request.post(`/spiders/${this.spiderForm._id}/git/reset`)
if (!res.data.error) {
this.$message.success(this.$t('Git has been reset successfully'))
}
} finally {
this.isGitResetLoading = false
}
})
}
},
async created () {
if (this.spiderForm.git_url) {
this.onGitUrlChange()
}
}
}
</script>
<style scoped>
.git-settings {
color: #606266;
}
.git-settings .git-settings-form {
width: 640px;
}
.git-settings .title {
border-bottom: 1px solid #DCDFE6;
padding-bottom: 15px;
}
.git-settings .action-wrapper {
width: 640px;
text-align: right;
margin-top: 10px;
}
</style>

View File

@@ -73,6 +73,10 @@ export default {
'Create File': '新建文件',
'Add Node': '添加节点',
'Add Project': '添加项目',
'Sync': '同步',
'Auto Sync': '自动同步',
'Sync Frequency': '同步频率',
'Reset': '重置',
// 主页
'Total Tasks': '总任务数',
@@ -197,6 +201,13 @@ export default {
'Variable Value': '变量值',
'Parameter Edit': '参数编辑',
'Add Scrapy Spider': '添加 Scrapy 爬虫',
'Is Git': '是否为 Git',
'Git Settings': 'Git 设置',
'Git URL': 'Git URL',
'Git Branch': 'Git 分支',
'Git Username': 'Git 用户名',
'Git Password': 'Git 密码',
'Has Credential': '需要验证',
// 爬虫列表
'Name': '名称',
@@ -528,6 +539,9 @@ docker run -d --restart always --name crawlab_worker \\
'In this tab you can configure your notification settings.': '在这个标签中您可以<br>配置您的消息通知配置',
'Here you can add/edit/delete global environment variables which will be passed into your spider programs.': '这里您可以添加/修改/删除全局环境变量它们会被传入爬虫程序中',
'You are running on a mobile device, which is not optimized yet. Please try with a laptop or desktop.': '您正在没有优化过的移动端上浏览我们建议您用电脑来访问',
'Git has been synchronized successfully': 'Git 已经成功同步',
'Git has been reset successfully': 'Git 已经成功重置',
'This would delete all files of the spider. Are you sure to continue?': '重置将删除该爬虫所有文件您希望继续吗',
// 其他
'Star crawlab-team/crawlab on GitHub': ' GitHub 上为 Crawlab 加星吧'

View File

@@ -22,6 +22,9 @@
<el-tab-pane :label="$t('Overview')" name="overview">
<spider-overview/>
</el-tab-pane>
<el-tab-pane v-if="isGit" :label="$t('Git Settings')" name="git-settings">
<git-settings/>
</el-tab-pane>
<el-tab-pane v-if="isScrapy" :label="$t('Scrapy Settings')" name="scrapy-settings">
<spider-scrapy/>
</el-tab-pane>
@@ -55,10 +58,12 @@ import SpiderStats from '../../components/Stats/SpiderStats'
import ConfigList from '../../components/Config/ConfigList'
import SpiderSchedules from './SpiderSchedules'
import SpiderScrapy from '../../components/Scrapy/SpiderScrapy'
import GitSettings from '../../components/Settings/GitSettings'
export default {
name: 'SpiderDetail',
components: {
GitSettings,
SpiderScrapy,
SpiderSchedules,
ConfigList,
@@ -179,6 +184,9 @@ export default {
},
isScrapy () {
return this.isCustomized && this.spiderForm.is_scrapy
},
isGit () {
return this.spiderForm.is_git
}
},
methods: {