updated to handle default and custom branch names

This commit is contained in:
brb
2023-07-06 16:42:54 +02:00
parent 84b409356b
commit 43e4b9788a
+15 -8
View File
@@ -43,7 +43,7 @@ def handle_event(request: GiteaRequest):
commit_msg = request.head_commit['message']
repo_url = request.repository['clone_url']
branch_name = request.ref.split('/')[-1]
logging.info(f'branch: {branch_name}')
logging.debug()
# stop early if asked
if commit_msg.lower().startswith('[skip ci]'):
raise HTTPException(
@@ -51,9 +51,7 @@ def handle_event(request: GiteaRequest):
detail='skipping ci'
)
# clone repository
logging.info('cloning repository: {repo_url}')
local_repo_dir = clone_repository(repo_url)
logging.info(f'local_repo_dir: {local_repo_dir}')
# locate runner script
runner_script_path = local_repo_dir / 'runner_script.yml'
if not runner_script_path.exists():
@@ -61,12 +59,21 @@ def handle_event(request: GiteaRequest):
status_code=200,
detail="no runner_script.yml in repository root"
)
# load runner commands
# load runner script
runner_script = load_runner_script(path=runner_script_path)
# extract branch name
for pipeline_name, pipeline_step in runner_script.pipelines.items():
print(pipeline_name)
print(pipeline_step)
# determine pipeline to run
if branch_name not in runner_script.pipelines.keys():
# run default
if 'default' not in runner_script.pipelines.keys():
raise HTTPException(
status_code=404,
detail='no pipelines defined in runner_script.yml'
)
pipeline = runner_script.pipelines['default']
else:
# run custom
pipeline = runner_script.pipelines[branch_name]
print(pipeline)
# send response
raise HTTPException(