Skip to content
Snippets Groups Projects
Commit 100cb214 authored by Tim Jaacks's avatar Tim Jaacks
Browse files

merge_into_manifest: add merge_status check before merge attempt

We had some cases where the merge job added rebases of a commit where rebasing
was not necessary at all, e.g.:
https://gitlab.com/garz-fricke/yocto/layers/meta-guf-machine/-/jobs/1270293595

This is obviously a known issue in GitLab concerning the HTTP return value of
the merge endpoint:
https://gitlab.com/gitlab-org/gitlab/-/issues/196962

Suggested workaround is to manually check merge_status and wait until it is
ready before attempting to merge the MR.
parent 1a8abc1d
No related branches found
No related tags found
1 merge request!39merge_into_manifest: add merge_status check before merge attempt
Pipeline #8181 passed with stage
in 17 seconds
...@@ -3,6 +3,7 @@ import common ...@@ -3,6 +3,7 @@ import common
import argparse import argparse
import sys import sys
import time
from gitlab import ( from gitlab import (
Gitlab, Gitlab,
GitlabGetError, GitlabGetError,
...@@ -76,12 +77,25 @@ def merge_into_manifest(manifest_project, master_branch, project, commit): ...@@ -76,12 +77,25 @@ def merge_into_manifest(manifest_project, master_branch, project, commit):
mr.notes.create({"body": "Source merge request: %s" % source_mr.web_url}) mr.notes.create({"body": "Source merge request: %s" % source_mr.web_url})
source_mr.notes.create({"body": "Integration merge request: %s" % mr.web_url}) source_mr.notes.create({"body": "Integration merge request: %s" % mr.web_url})
# Attempt to merge, reintegrate if necessary # Loop until MR has been merged successfully
manifest_revision = mr.sha manifest_revision = mr.sha
merged = False merged = False
while not merged: while not merged:
# Wait until GitLab has checked merge status
print("Waiting until merge status has been checked", end="", flush=True)
unchecked_states = ["unchecked", "checking", "cannot_be_merged_recheck"]
while mr.merge_status in unchecked_states:
print(".", end="", flush=True)
time.sleep(1)
mr = manifest_project.mergerequests.get(mr.iid)
print("")
# Attempt to merge
merged = accept_merge_request(manifest_project, mr) merged = accept_merge_request(manifest_project, mr)
if not merged: if not merged:
# Merge failed, reintegrate the source merge request into the manifest.
# Note: if reintegration is necessary here, the source merge request was # Note: if reintegration is necessary here, the source merge request was
# merged without running the pipeline on the latest manifest, i.e. some # merged without running the pipeline on the latest manifest, i.e. some
# other project has been merged in between. Automatic rebase is not # other project has been merged in between. Automatic rebase is not
...@@ -97,6 +111,7 @@ def merge_into_manifest(manifest_project, master_branch, project, commit): ...@@ -97,6 +111,7 @@ def merge_into_manifest(manifest_project, master_branch, project, commit):
project=project, project=project,
merge_request=source_mr, merge_request=source_mr,
) )
mr = manifest_project.mergerequests.get(mr.iid)
print("Successfully merged") print("Successfully merged")
......
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