diff --git a/check_if_integration_branch_is_up_to_date.py b/check_if_integration_branch_is_up_to_date.py
index 9b926ce8ce322c0629b7fd59b258b1d7ae57b996..a465ae5d0aaa204d261d0b1aecb6a9c66b2b7224 100755
--- a/check_if_integration_branch_is_up_to_date.py
+++ b/check_if_integration_branch_is_up_to_date.py
@@ -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():
diff --git a/common.py b/common.py
index 2322972f156a4af69205453b0cfb11cfa073183f..9963bf7da34bd09a0a29e6c45ab5094f79e630dd 100755
--- a/common.py
+++ b/common.py
@@ -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