From aea4336b8116d47adf6cc97ca6f62955ef790d37 Mon Sep 17 00:00:00 2001 From: vapao Date: Sun, 25 Jun 2023 18:17:23 +0800 Subject: [PATCH] [pipeline]update --- spug_api/apps/pipeline/views.py | 12 +++-- spug_api/libs/gitlib.py | 8 ++- spug_api/requirements.txt | 17 +++---- spug_web/src/pages/pipeline/modules/Build.js | 53 +++++++++++++++++++- 4 files changed, 73 insertions(+), 17 deletions(-) diff --git a/spug_api/apps/pipeline/views.py b/spug_api/apps/pipeline/views.py index 8d752dd..32163d1 100644 --- a/spug_api/apps/pipeline/views.py +++ b/spug_api/apps/pipeline/views.py @@ -95,12 +95,18 @@ class DoView(View): item['_targets'] = [{'id': x, 'name': host_map[x]} for x in item['destination']['targets']] if item['module'] == 'parameter': - dynamic_params = item.get('dynamic_params') + if item.get('dynamic_params'): + dynamic_params.extend(item['dynamic_params']) + elif item['module'] == 'build': + if item.get('git_commit') == 'selective': + dynamic_params.append({'variable': 'git_commit', 'name': 'Git提交', 'type': 'select', 'options': [{'value': 1, 'label': 1}], 'required': True}) + elif item.get('git_tag') == 'selective': + dynamic_params.append({'variable': 'tag_', 'name': 'Git标签', 'type': 'text', 'required': True}) elif item['module'] == 'data_upload': tmp = {'variable': item['id'], 'name': item['name'], 'type': 'upload', 'required': True} - if 'accept' in item: + if item.get('accept'): tmp['accept'] = item['accept'] - if 'size' in item: + if item.get('size'): tmp['size'] = item['size'] dynamic_params.append(tmp) diff --git a/spug_api/libs/gitlib.py b/spug_api/libs/gitlib.py index f7a7dde..101ff57 100644 --- a/spug_api/libs/gitlib.py +++ b/spug_api/libs/gitlib.py @@ -187,9 +187,13 @@ class RemoteGit: os.chmod(ask_file.name, 0o755) env.update(GIT_SSH=ask_file.name) - command = f'git ls-remote -h {url} HEAD' + command = f'git ls-remote -h {url}' res = subprocess.run(command, shell=True, capture_output=True, env=env) - return res.returncode == 0, res.stderr.decode() + if res.returncode == 0: + lines = res.stdout.decode().strip().split('\n') + branches = [x.split('/')[-1] for x in lines] + return True, branches + return False, res.stderr.decode() def fetch_branches_tags(self): body = f'set -e\ncd {self.path}\n' diff --git a/spug_api/requirements.txt b/spug_api/requirements.txt index 36d1780..24a14f3 100644 --- a/spug_api/requirements.txt +++ b/spug_api/requirements.txt @@ -1,12 +1,7 @@ -apscheduler==3.7.0 -Django==2.2.28 -asgiref==3.2.10 -channels==2.3.1 -channels_redis==2.4.1 -paramiko==2.11.0 -django-redis==4.10.0 -requests==2.22.0 -GitPython==3.0.8 -python-ldap==3.4.0 -openpyxl==3.0.3 +apscheduler==3.10.1 +Django==4.2.2 +paramiko==3.2.0 +django-redis==5.2.0 +requests==2.31.0 +openpyxl==3.1.2 user_agents==2.2.0 \ No newline at end of file diff --git a/spug_web/src/pages/pipeline/modules/Build.js b/spug_web/src/pages/pipeline/modules/Build.js index 09ed051..493c0c6 100644 --- a/spug_web/src/pages/pipeline/modules/Build.js +++ b/spug_web/src/pages/pipeline/modules/Build.js @@ -16,8 +16,10 @@ import css from './index.module.less'; function Build(props) { const [form] = Form.useForm() const [tips, setTips] = useState() + const [branches, setBranches] = useState([]) useEffect(() => { + checkGit() props.setHandler(() => handleSave) if (credStore.records.length === 0) credStore.fetchRecords() // eslint-disable-next-line react-hooks/exhaustive-deps @@ -27,6 +29,14 @@ function Build(props) { const data = form.getFieldsValue() if (!data.name) return message.error('请输入节点名称') if (!data.condition) return message.error('请选择节点的执行条件') + if (!data.git_url) return message.error('请输入Git仓库地址') + if (!data.git_mode) return message.error('请选择构建分支/Tag') + if (data.git_mode === 'branch') { + if (!data.git_branch) return message.error('请选择构建分支') + if (!data.git_commit) return message.error('请选择构建分支规则') + } else if (!data.git_tag) { + return message.error('请选择构建Tag规则') + } if (!data.target) return message.error('请选择构建主机') if (!data.workspace) return message.error('请输入工作目录') if (!data.command) return message.error('请输入构建命令') @@ -39,7 +49,9 @@ function Build(props) { if (!data.git_url) return http.post('/api/credential/check/', {id: data.credential_id, type: 'git', data: data.git_url}) .then(res => { - if (!res.is_pass) { + if (res.is_pass) { + setBranches(res.message) + } else { setTips(res.message) } }) @@ -88,6 +100,45 @@ function Build(props) {
{tips}
) : null} + + + + + + + {({getFieldValue}) => + getFieldValue('git_mode') === 'branch' ? ( + + + + + + + + + ) : ( + + + + ) + } + + +