updated to handle default and custom branch names
This commit is contained in:
+15
-8
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user