add branch validation to queue
This commit is contained in:
@@ -3,6 +3,8 @@ from flask_login import login_required, current_user
|
||||
from app.models import Job
|
||||
from app import db
|
||||
import json
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
jobs_bp = Blueprint('jobs', __name__, url_prefix='/jobs')
|
||||
|
||||
@@ -15,18 +17,75 @@ def submit():
|
||||
@login_required
|
||||
def submit_step1():
|
||||
branch_name = request.form.get('branch_name')
|
||||
# TODO: Implement branch checkout and scenario detection
|
||||
# For now, return mock scenarios
|
||||
scenarios = [
|
||||
'Scenario_1_Basic_Test',
|
||||
'Scenario_2_Advanced_Test',
|
||||
'Scenario_3_Integration_Test',
|
||||
'Scenario_4_Performance_Test',
|
||||
'Scenario_5_Security_Test'
|
||||
]
|
||||
return render_template('jobs/submit_step2.html', branch_name=branch_name, scenarios=scenarios)
|
||||
|
||||
if not branch_name:
|
||||
flash('Branch name is required', 'error')
|
||||
return redirect(url_for('jobs.submit'))
|
||||
|
||||
# Validate branch exists on remote
|
||||
try:
|
||||
# Get SSH password from environment variable
|
||||
ssh_password = os.environ.get('SSH_PASSWORD', 'default_password')
|
||||
ssh_host = os.environ.get('SSH_HOST', 'remote_host')
|
||||
ssh_user = os.environ.get('SSH_USER', 'asf')
|
||||
|
||||
# First, clone the repository
|
||||
clone_cmd = f"sshpass -p '{ssh_password}' ssh -o StrictHostKeyChecking=no {ssh_user}@{ssh_host} './TPF/gitea_repo_controller.sh clone'"
|
||||
clone_result = subprocess.run(clone_cmd, shell=True, capture_output=True, text=True, timeout=60)
|
||||
|
||||
# Then, checkout the branch
|
||||
checkout_cmd = f"sshpass -p '{ssh_password}' ssh -o StrictHostKeyChecking=no {ssh_user}@{ssh_host} './TPF/gitea_repo_controller.sh checkout {branch_name}'"
|
||||
checkout_result = subprocess.run(checkout_cmd, shell=True, capture_output=True, text=True, timeout=60)
|
||||
|
||||
# Check if checkout was successful (no "fatal:" in output)
|
||||
if "fatal:" in checkout_result.stdout or "fatal:" in checkout_result.stderr or checkout_result.returncode != 0:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': f'Branch "{branch_name}" not found on remote. Please push the branch first.',
|
||||
'output': checkout_result.stdout + checkout_result.stderr
|
||||
})
|
||||
|
||||
# If successful, get available scenarios (mock for now)
|
||||
scenarios = [
|
||||
'Scenario_1_Basic_Test',
|
||||
'Scenario_2_Advanced_Test',
|
||||
'Scenario_3_Integration_Test',
|
||||
'Scenario_4_Performance_Test',
|
||||
'Scenario_5_Security_Test'
|
||||
]
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'scenarios': scenarios,
|
||||
'message': f'Branch "{branch_name}" validated successfully'
|
||||
})
|
||||
|
||||
except subprocess.TimeoutExpired:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': 'Branch validation timed out. Please try again.',
|
||||
'output': ''
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': f'Error validating branch: {str(e)}',
|
||||
'output': ''
|
||||
})
|
||||
|
||||
@jobs_bp.route('/submit/step2', methods=['POST'])
|
||||
@jobs_bp.route('/submit/step2-validated', methods=['POST'])
|
||||
@login_required
|
||||
def submit_step2_validated():
|
||||
branch_name = request.form.get('branch_name')
|
||||
scenarios_json = request.form.get('scenarios')
|
||||
|
||||
try:
|
||||
scenarios = json.loads(scenarios_json)
|
||||
except:
|
||||
flash('Invalid scenarios data', 'error')
|
||||
return redirect(url_for('jobs.submit'))
|
||||
|
||||
return render_template('jobs/submit_step2.html', branch_name=branch_name, scenarios=scenarios)
|
||||
@login_required
|
||||
def submit_step2():
|
||||
branch_name = request.form.get('branch_name')
|
||||
|
||||
Reference in New Issue
Block a user