Skip to content
Snippets Groups Projects
Commit daa4cbee authored by Jonas Höppner's avatar Jonas Höppner
Browse files

CI: Move the loop to check if a revision is related to another to common

parent 3e491ba0
No related branches found
No related tags found
1 merge request!107CI: deploy_gitlab_ci: Move one-time code to own function as reference
......@@ -46,20 +46,10 @@ def check_if_integration_branch_is_up_to_date(
integration_base_id = integration_base_branch.commit["id"]
parent = integration_branch.commit
parent = manifest_project.commits.get(parent["id"], retry_transient_errors=True)
# Loop over the commits until the integration_branch head id is found
while True:
# The integration branch is up to date if its parent is the integration base
logging.debug(parent.id)
if parent.id == integration_base_id:
return True
if len(parent.parent_ids) == 0:
break
parent_id = parent.parent_ids[0] # Assume linear history
parent = manifest_project.commits.get(parent_id, retry_transient_errors=True)
return False
return common.is_commit_parent_of_project_commit(
manifest_project, integration_branch.commit["id"], integration_base_id
)
def main():
......
......@@ -255,3 +255,34 @@ def get_repository_file_obj(project: Project, filename, ref=None):
return None
fileobj = fileobj[0]
return fileobj
def is_commit_parent_of_project_commit(project: Project, project_commit, commit):
"""Walks through the commits of project, starting with project_commit
and compares its sha with the given commit.
Both commits are specified as sha
"""
try:
_ = project.commits.get(commit, retry_transient_errors=True)
except GitlabGetError as e:
raise Exception(
"Failed to find commit {} in {}".format(project_commit, project.name)
) from e
# Loop over the parent commits until commit is found
parent_id = project_commit
while True:
try:
parent = project.commits.get(parent_id, retry_transient_errors=True)
except GitlabGetError as e:
raise Exception(
"Failed to find commit {} in {}".format(parent_id, project.name)
) from e
# The integration branch is up to date if its parent is the integration base
logging.debug(parent.id)
if parent.id == commit:
return True
if len(parent.parent_ids) == 0:
return False
parent_id = parent.parent_ids[0] # Assume linear history
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment