diff --git a/integrate_into_manifest.py b/integrate_into_manifest.py index 43cc3eb969db08bdee967da370e520272e302c18..69992332b1cf0d429fe8179194b13d19973280ad 100755 --- a/integrate_into_manifest.py +++ b/integrate_into_manifest.py @@ -16,8 +16,7 @@ def integrate_into_manifest( integration_base, manifest_file, project, - branch, - commit=None, + merge_request, ): gitlab = manifest_project.manager.gitlab @@ -39,7 +38,9 @@ def integrate_into_manifest( sys.exit("ERROR: branch '%s' not found" % integration_base) # Create integration branch (delete former one if already exists) - integration_branch = common.integration_branch_name(project.name, branch) + integration_branch = common.integration_branch_name( + project.name, merge_request.source_branch + ) integration_base = None for ref in manifest_repo.references: if integration_branch == ref.name: @@ -59,26 +60,11 @@ def integrate_into_manifest( sys.exit("ERROR: project '%s' not found in manifest" % project.path) project_node = project_nodes[0] - # Get current project revision + # Get current project revision from manifest old_revision = project_node.get("revision") - # Get project revision - if commit: - try: - project_commit = project.commits.get(commit) - except GitlabGetError as e: - sys.exit( - "ERROR: could not get commit '%s' for project '%s': %s" - % (commit, project.name, e) - ) - # project_commit is a Gitlab.ProjectCommit object here - new_revision = project_commit.id - commit_message = project_commit.message - else: - project_commit = common.get_latest_commit(project, branch) - # project_commit is a simple dictionary here - new_revision = project_commit["id"] - commit_message = project_commit["message"] + # Get new project revision from merge request + new_revision = merge_request.sha # Update manifest file # We are doing this using a plain text replace action. Unfortunately @@ -93,15 +79,11 @@ def integrate_into_manifest( # Construct commit object and commit change author = Actor(gitlab.user.username, gitlab.user.email) - commit_link = project.web_url + "/-/commit/" + new_revision + message = "Integrate %s/%s\n" % (project.path, merge_request.source_branch) + for commit in merge_request.commits(): + message += "\nCommit: %s\n\n%s" % (commit.web_url, commit.message) manifest_repo.index.add([manifest_file]) - manifest_repo.index.commit( - "Integrate %s/%s\n\n" % (project.path, branch) - + "Commit: %s\n\n" % (commit_link) - + commit_message, - author=author, - committer=author, - ) + manifest_repo.index.commit(message, author=author, committer=author) # Push commit try: @@ -159,18 +141,11 @@ def main(): required=True, ) parser.add_argument( - "--branch", - help="""project branch to be integrated""", - dest="branch", + "--merge-request", + help="""project merge request IID containing the changes to be integrated""", + dest="merge_request", required=True, ) - parser.add_argument( - "--commit", - help="""project commit""", - dest="commit", - default=None, - required=False, - ) parser.add_argument( "--save-revision-to", help="""path to a file where the new manifest revision is stored""", @@ -184,14 +159,20 @@ def main(): manifest_project = common.get_project(gitlab, args.manifest_project) project = common.get_project(gitlab, args.project) + try: + merge_request = project.mergerequests.get(args.merge_request) + except GitlabGetError as e: + sys.exit( + "ERROR: could not get %s!%s: %s" + % (project.name, args.merge_request, e.error_message) + ) manifest_revision = integrate_into_manifest( manifest_project=manifest_project, integration_base=args.integration_base, manifest_file=args.manifest_file, project=project, - branch=args.branch, - commit=args.commit, + merge_request=merge_request, ) if args.revision_file: diff --git a/merge_into_manifest.py b/merge_into_manifest.py index a6482dc59d2fe6804829637634d9a9a34a83c5c2..edf0330ca87a8cd7ff3b639b56c132f703049f9b 100755 --- a/merge_into_manifest.py +++ b/merge_into_manifest.py @@ -95,8 +95,7 @@ def merge_into_manifest(manifest_project, master_branch, project, commit): integration_base=target_branch, manifest_file=common.manifest_file, project=project, - branch=original_branch, - commit=commit, + merge_request=source_mr, ) print("Successfully merged")