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

CI: deploy_gitlab_ci: Reimplement merge

parent 57563653
No related branches found
No related tags found
No related merge requests found
...@@ -7,10 +7,13 @@ import sys ...@@ -7,10 +7,13 @@ import sys
import os import os
from gitlab import Gitlab from gitlab import Gitlab
# from accept_merge_request import accept_merge_request from accept_merge_request import accept_merge_request
from create_merge_request import create_merge_request from create_merge_request import create_merge_request
from get_merge_requests import get_merge_requests from get_merge_requests import get_merge_requests
from update_submodule import update_submodule_and_include_ref from update_submodule import (
update_submodule_and_include_ref,
get_submodule_project_path_and_revision,
)
from integrate_into_manifest import update_manifest, update_srcrev from integrate_into_manifest import update_manifest, update_srcrev
from ruamel.yaml import YAML from ruamel.yaml import YAML
...@@ -36,33 +39,19 @@ def read_keys_from_gitlab_ci_yml(gitlab_ci_yml): ...@@ -36,33 +39,19 @@ def read_keys_from_gitlab_ci_yml(gitlab_ci_yml):
return {"recipe": recipe, "masterbranch": masterbranch} return {"recipe": recipe, "masterbranch": masterbranch}
def old(): def create_integration_merge_request(project, integration_branch_name, source_mr=None):
# TODO create_merge_request():
# Get source merge request
mrs = get_merge_requests(
submodule_project,
# TODO should this be submodule_project's default branch?
target_branch="master",
commit=revision,
)
if not mrs:
sys.exit(
"ERROR: could not determine source merge request for commit %s" % revision
)
source_mr = mrs[0]
# Create merge request # Create merge request
# This should be optional # This should be optional
mr, created = create_merge_request( mr, created = create_merge_request(
project, integration_branch, project.default_branch project, integration_branch_name, project.default_branch
) )
if created: if created:
common.crosslink_merge_requests(source_mr, mr) if source_mr is not None:
common.crosslink_merge_requests(source_mr, mr)
print("Created new merge request:\n%s" % mr.web_url) print("Created new merge request:\n%s" % mr.web_url)
else: else:
print("Existing integration merge request:\n%s" % mr.web_url) print("Existing integration merge request:\n%s" % mr.web_url)
return integration_branch, integration_commit, mr return mr
def main(): def main():
...@@ -166,9 +155,10 @@ def main(): ...@@ -166,9 +155,10 @@ def main():
commit_and_push=(p != args.project), commit_and_push=(p != args.project),
) )
if integration_branch_name is not None: if integration_branch_name is not None:
# TODO # ======================================
# if create_merge_request: # Store the references for creating the integration
# create_merge_request # commit in the manifest later
# ======================================
project_integration[p] = { project_integration[p] = {
"project": gitlab_project, "project": gitlab_project,
"repo": project_repo, "repo": project_repo,
...@@ -187,8 +177,10 @@ def main(): ...@@ -187,8 +177,10 @@ def main():
print("No integration done, changes are already included in all projects.") print("No integration done, changes are already included in all projects.")
sys.exit(0) sys.exit(0)
# =======================================================
# Now create the integration commit in the manifest # Now create the integration commit in the manifest
# for all subprojects at once # for all subprojects at once
# =======================================================
manifest_project = project_integration[args.project] manifest_project = project_integration[args.project]
manifest_file_abs = os.path.join( manifest_file_abs = os.path.join(
manifest_project["repo"].working_tree_dir, args.manifest_file manifest_project["repo"].working_tree_dir, args.manifest_file
...@@ -258,7 +250,9 @@ def main(): ...@@ -258,7 +250,9 @@ def main():
manifest_project["repo"].git.add(args.srcrev_file) manifest_project["repo"].git.add(args.srcrev_file)
logging.debug(srcrev) logging.debug(srcrev)
# TODO commit # ========================================================
# Now commit and push the changes to the manifest repo
# ========================================================
# Make an API request to create the gitlab.user object # Make an API request to create the gitlab.user object
gitlab = manifest_project["project"].manager.gitlab gitlab = manifest_project["project"].manager.gitlab
gitlab.auth() gitlab.auth()
...@@ -277,36 +271,62 @@ def main(): ...@@ -277,36 +271,62 @@ def main():
) )
) )
sys.exit(0)
if not args.merge: if not args.merge:
print(
"Skipping automatic merge in MR context. If you like to extend the "
"integration MR by hand, please do it now. Afterwards you can either merge "
"it by hand or re-run this job on the master branch after the source MR "
"has been merged."
)
sys.exit(0) sys.exit(0)
# ============================================
# Create merge requests if needed
# ============================================
# Get source merge request ( the one in the gitlab-ci repo)
submodule_project_path, _ = get_submodule_project_path_and_revision(
manifest_project["project"], args.submodule, args.branch
)
submodule_project = common.get_project(gitlab, submodule_project_path)
mrs = get_merge_requests(
submodule_project,
# TODO should this be submodule_project's default branch?
target_branch="master",
commit=args.revision,
)
if not mrs:
sys.exit(
"ERROR: could not determine source merge request for commit %s"
% args.revision
)
source_mr = mrs[0]
for p in args.projects + [args.project]:
integration = project_integration[p]
logging.debug("Create MR in %s", integration["project"].name)
integration["mr"] = create_integration_merge_request(
integration["project"], integration["branch"], source_mr
)
# =================================================
# Now merge them all
# =================================================
# The manifest needs to be merged at last # The manifest needs to be merged at last
# TODO this is currently not used for p in args.projects + [args.project]:
# merge_requests.append(merge_request_manifest) integration = project_integration[p]
# for mr in merge_requests: mr = integration["mr"]
# logging.debug("Merge %s", mr) logging.debug("Merge %s!%s", p, mr.iid)
# # Wait until GitLab has checked merge status
# common.wait_until_merge_status_is_set(project, mr) # Wait until GitLab has checked merge status
common.wait_until_merge_status_is_set(integration["project"], mr)
# # Attempt to merge
# merged = accept_merge_request(project, mr, rebase=True) # Attempt to merge
# TODO if this has rebased the integration commit needs to be adapted
# if not merged: # change the sequence
# sys.exit( merged = accept_merge_request(integration["project"], mr, rebase=True)
# "Integration MR could not be merged. You have two possibilities to fix "
# "this:\n" if not merged:
# " 1. Checkout the MR and rebase it on the current master manually, or\n" sys.exit(
# " 2. Delete the MR (Edit -> Delete in the MR UI)\n" "Integration MR could not be merged. You have two possibilities to fix "
# "In either case restart this job afterwards in order to get it merged." "this:\n"
# ) " 1. Checkout the MR and rebase it on the current master manually, or\n"
" 2. Delete the MR (Edit -> Delete in the MR UI)\n"
"In either case restart this job afterwards in order to get it merged."
)
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