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

Include all project commits in integration branch commit message

* Before, only the latest commit was included
* Use merge request ID instead of branch name and commit in the argument list
parent b89ed96c
No related branches found
No related tags found
1 merge request!11Include all project commits in integration branch commit message
Pipeline #8073 passed with stage
in 1 minute and 18 seconds
...@@ -16,8 +16,7 @@ def integrate_into_manifest( ...@@ -16,8 +16,7 @@ def integrate_into_manifest(
integration_base, integration_base,
manifest_file, manifest_file,
project, project,
branch, merge_request,
commit=None,
): ):
gitlab = manifest_project.manager.gitlab gitlab = manifest_project.manager.gitlab
...@@ -39,7 +38,9 @@ def integrate_into_manifest( ...@@ -39,7 +38,9 @@ def integrate_into_manifest(
sys.exit("ERROR: branch '%s' not found" % integration_base) sys.exit("ERROR: branch '%s' not found" % integration_base)
# Create integration branch (delete former one if already exists) # 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 integration_base = None
for ref in manifest_repo.references: for ref in manifest_repo.references:
if integration_branch == ref.name: if integration_branch == ref.name:
...@@ -59,26 +60,11 @@ def integrate_into_manifest( ...@@ -59,26 +60,11 @@ def integrate_into_manifest(
sys.exit("ERROR: project '%s' not found in manifest" % project.path) sys.exit("ERROR: project '%s' not found in manifest" % project.path)
project_node = project_nodes[0] project_node = project_nodes[0]
# Get current project revision # Get current project revision from manifest
old_revision = project_node.get("revision") old_revision = project_node.get("revision")
# Get project revision # Get new project revision from merge request
if commit: new_revision = merge_request.sha
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"]
# Update manifest file # Update manifest file
# We are doing this using a plain text replace action. Unfortunately # We are doing this using a plain text replace action. Unfortunately
...@@ -93,15 +79,11 @@ def integrate_into_manifest( ...@@ -93,15 +79,11 @@ def integrate_into_manifest(
# Construct commit object and commit change # Construct commit object and commit change
author = Actor(gitlab.user.username, gitlab.user.email) 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.add([manifest_file])
manifest_repo.index.commit( manifest_repo.index.commit(message, author=author, committer=author)
"Integrate %s/%s\n\n" % (project.path, branch)
+ "Commit: %s\n\n" % (commit_link)
+ commit_message,
author=author,
committer=author,
)
# Push commit # Push commit
try: try:
...@@ -159,18 +141,11 @@ def main(): ...@@ -159,18 +141,11 @@ def main():
required=True, required=True,
) )
parser.add_argument( parser.add_argument(
"--branch", "--merge-request",
help="""project branch to be integrated""", help="""project merge request IID containing the changes to be integrated""",
dest="branch", dest="merge_request",
required=True, required=True,
) )
parser.add_argument(
"--commit",
help="""project commit""",
dest="commit",
default=None,
required=False,
)
parser.add_argument( parser.add_argument(
"--save-revision-to", "--save-revision-to",
help="""path to a file where the new manifest revision is stored""", help="""path to a file where the new manifest revision is stored""",
...@@ -184,14 +159,20 @@ def main(): ...@@ -184,14 +159,20 @@ def main():
manifest_project = common.get_project(gitlab, args.manifest_project) manifest_project = common.get_project(gitlab, args.manifest_project)
project = common.get_project(gitlab, args.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_revision = integrate_into_manifest(
manifest_project=manifest_project, manifest_project=manifest_project,
integration_base=args.integration_base, integration_base=args.integration_base,
manifest_file=args.manifest_file, manifest_file=args.manifest_file,
project=project, project=project,
branch=args.branch, merge_request=merge_request,
commit=args.commit,
) )
if args.revision_file: if args.revision_file:
......
...@@ -95,8 +95,7 @@ def merge_into_manifest(manifest_project, master_branch, project, commit): ...@@ -95,8 +95,7 @@ def merge_into_manifest(manifest_project, master_branch, project, commit):
integration_base=target_branch, integration_base=target_branch,
manifest_file=common.manifest_file, manifest_file=common.manifest_file,
project=project, project=project,
branch=original_branch, merge_request=source_mr,
commit=commit,
) )
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