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']
|
commit_msg = request.head_commit['message']
|
||||||
repo_url = request.repository['clone_url']
|
repo_url = request.repository['clone_url']
|
||||||
branch_name = request.ref.split('/')[-1]
|
branch_name = request.ref.split('/')[-1]
|
||||||
logging.info(f'branch: {branch_name}')
|
logging.debug()
|
||||||
# stop early if asked
|
# stop early if asked
|
||||||
if commit_msg.lower().startswith('[skip ci]'):
|
if commit_msg.lower().startswith('[skip ci]'):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
@@ -51,9 +51,7 @@ def handle_event(request: GiteaRequest):
|
|||||||
detail='skipping ci'
|
detail='skipping ci'
|
||||||
)
|
)
|
||||||
# clone repository
|
# clone repository
|
||||||
logging.info('cloning repository: {repo_url}')
|
|
||||||
local_repo_dir = clone_repository(repo_url)
|
local_repo_dir = clone_repository(repo_url)
|
||||||
logging.info(f'local_repo_dir: {local_repo_dir}')
|
|
||||||
# locate runner script
|
# locate runner script
|
||||||
runner_script_path = local_repo_dir / 'runner_script.yml'
|
runner_script_path = local_repo_dir / 'runner_script.yml'
|
||||||
if not runner_script_path.exists():
|
if not runner_script_path.exists():
|
||||||
@@ -61,12 +59,21 @@ def handle_event(request: GiteaRequest):
|
|||||||
status_code=200,
|
status_code=200,
|
||||||
detail="no runner_script.yml in repository root"
|
detail="no runner_script.yml in repository root"
|
||||||
)
|
)
|
||||||
# load runner commands
|
# load runner script
|
||||||
runner_script = load_runner_script(path=runner_script_path)
|
runner_script = load_runner_script(path=runner_script_path)
|
||||||
# extract branch name
|
# determine pipeline to run
|
||||||
for pipeline_name, pipeline_step in runner_script.pipelines.items():
|
if branch_name not in runner_script.pipelines.keys():
|
||||||
print(pipeline_name)
|
# run default
|
||||||
print(pipeline_step)
|
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
|
# send response
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|||||||
Reference in New Issue
Block a user