Skip to content

Support gitlab_mr_destination #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2240,7 +2240,7 @@ Name | Type | Description

Creates a commit in a git repository using the transformed worktree.<br><br>For GitHub use git.github_destination. For creating Pull Requests in GitHub, use git.github_pr_destination. For creating a Gerrit change use git.gerrit_destination.<br><br>Given that Copybara doesn't ask for user/password in the console when doing the push to remote repos, you have to use ssh protocol, have the credentials cached or use a credential manager.

`destination` `git.destination(url, push='master', tag_name=None, tag_msg=None, fetch=None, partial_fetch=False, integrates=None, primary_branch_migration=False, checker=None)`
`destination` `git.destination(url, push='master', tag_name=None, tag_msg=None, fetch=None, partial_fetch=False, integrates=None, primary_branch_migration=False, checker=None, push_options=None)`


#### Parameters:
Expand All @@ -2256,6 +2256,7 @@ partial_fetch | `bool`<br><p>This is an experimental feature that only works for
integrates | `sequence of git_integrate` or `NoneType`<br><p>Integrate changes from a url present in the migrated change label. Defaults to a semi-fake merge if COPYBARA_INTEGRATE_REVIEW label is present in the message</p>
primary_branch_migration | `bool`<br><p>When enabled, copybara will ignore the 'push' and 'fetch' params if either is 'master' or 'main' and instead try to establish the default git branch. If this fails, it will fall back to the param's declared value.<br>This is intended to help migrating to the new standard of using 'main' without breaking users relying on the legacy default.</p>
checker | `checker` or `NoneType`<br><p>A checker that can check leaks or other checks in the commit created. </p>
push_options | `sequence` or `NoneType`<br><p>A sequence of git push options that can pass into push command. Defaults to none which represents no push options.</p>



Expand Down
4 changes: 4 additions & 0 deletions java/com/google/copybara/ModuleSupplier.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import com.google.copybara.git.GitHubDestinationOptions;
import com.google.copybara.git.GitHubOptions;
import com.google.copybara.git.GitHubPrOriginOptions;
import com.google.copybara.git.GitLabDestinationOptions;
import com.google.copybara.git.GitLabOptions;
import com.google.copybara.git.GitMirrorOptions;
import com.google.copybara.git.GitModule;
import com.google.copybara.git.GitOptions;
Expand Down Expand Up @@ -129,6 +131,8 @@ protected Options newOptions() {
new GitHubOptions(generalOptions, gitOptions),
new GitHubDestinationOptions(),
new GerritOptions(generalOptions, gitOptions),
new GitLabOptions(generalOptions, gitOptions),
new GitLabDestinationOptions(),
new GitMirrorOptions(),
new HgOptions(generalOptions),
new HgOriginOptions(),
Expand Down
2 changes: 1 addition & 1 deletion java/com/google/copybara/Origin.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ default Optional<Baseline<R>> findBaseline(R startRevision, String label)
*/
default ImmutableList<R> findBaselinesWithoutLabel(R startRevision, int limit)
throws RepoException, ValidationException {
throw new ValidationException("Origin does't support this workflow mode");
throw new ValidationException("Origin doesn't support this workflow mode");
}

class FindLatestWithLabel<R extends Revision> implements ChangesVisitor {
Expand Down
2 changes: 2 additions & 0 deletions java/com/google/copybara/git/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ java_library(
"//java/com/google/copybara/exception",
"//java/com/google/copybara/git/github:api",
"//java/com/google/copybara/git/github:util",
"//java/com/google/copybara/git/gitlab:api",
"//java/com/google/copybara/git/gitlab:util",
"//java/com/google/copybara/jcommander:validators",
"//java/com/google/copybara/monitor",
"//java/com/google/copybara/profiler",
Expand Down
3 changes: 2 additions & 1 deletion java/com/google/copybara/git/GerritDestination.java
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,8 @@ static GerritDestination newGerritDestination(
gerritSubmit,
primaryBranchMigrationMode),
integrates,
checker),
checker,
ImmutableList.of()),
submit);
}

Expand Down
14 changes: 11 additions & 3 deletions java/com/google/copybara/git/GitDestination.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ static class MessageInfo {
@Nullable private String resolvedPrimary = null;
private final Iterable<GitIntegrateChanges> integrates;
private final WriteHook writerHook;
private final Iterable<String> pushOptions;
@Nullable private final Checker checker;
private final LazyResourceLoader<GitRepository> localRepo;

Expand All @@ -126,7 +127,8 @@ static class MessageInfo {
GeneralOptions generalOptions,
WriteHook writerHook,
Iterable<GitIntegrateChanges> integrates,
@Nullable Checker checker) {
@Nullable Checker checker,
Iterable<String> pushOptions) {
this.repoUrl = checkNotNull(repoUrl);
this.fetch = checkNotNull(fetch);
this.push = checkNotNull(push);
Expand All @@ -140,6 +142,7 @@ static class MessageInfo {
this.integrates = checkNotNull(integrates);
this.writerHook = checkNotNull(writerHook);
this.checker = checker;
this.pushOptions = checkNotNull(pushOptions);
this.localRepo = memoized(ignored -> destinationOptions.localGitRepo(repoUrl));
}

Expand Down Expand Up @@ -191,7 +194,8 @@ public Writer<GitRevision> newWriter(WriterContext writerContext) throws Validat
destinationOptions.rebaseWhenBaseline(),
gitOptions.visitChangePageSize,
gitOptions.gitTagOverwrite,
checker);
checker,
pushOptions);
}

/**
Expand Down Expand Up @@ -242,6 +246,7 @@ public static class WriterImpl<S extends WriterState>
private final int visitChangePageSize;
private final boolean gitTagOverwrite;
@Nullable private final Checker checker;
private final Iterable<String> pushOptions;

/** Create a new git.destination writer */
WriterImpl(
Expand All @@ -265,7 +270,8 @@ public static class WriterImpl<S extends WriterState>
boolean rebase,
int visitChangePageSize,
boolean gitTagOverwrite,
Checker checker) {
Checker checker,
Iterable<String> pushOptions) {
this.skipPush = skipPush;
this.repoUrl = checkNotNull(repoUrl);
this.remoteFetch = checkNotNull(remoteFetch);
Expand All @@ -289,6 +295,7 @@ public static class WriterImpl<S extends WriterState>
this.visitChangePageSize = visitChangePageSize;
this.gitTagOverwrite = gitTagOverwrite;
this.checker = checker;
this.pushOptions = pushOptions;
}

@Override
Expand Down Expand Up @@ -659,6 +666,7 @@ public ImmutableList<DestinationEffect> write(TransformResult transformResult,
String serverResponse = generalOptions.repoTask(
"push",
() -> scratchClone.push()
.pushOptions(pushOptions)
.withRefspecs(repoUrl,
tagName != null
? ImmutableList.of(scratchClone.createRefSpec(
Expand Down
3 changes: 2 additions & 1 deletion java/com/google/copybara/git/GitHubPrDestination.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ public Writer<GitRevision> newWriter(WriterContext writerContext) throws Validat
destinationOptions.rebaseWhenBaseline(),
gitOptions.visitChangePageSize,
gitOptions.gitTagOverwrite,
checker) {
checker,
ImmutableList.of()) {
@Override
public ImmutableList<DestinationEffect> write(
TransformResult transformResult, Glob destinationFiles, Console console)
Expand Down
43 changes: 43 additions & 0 deletions java/com/google/copybara/git/GitLabDestinationOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2022 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.copybara.git;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.copybara.Option;

/**
* Options related to GitLab destination
*
* <p>Intentionally empty so that we have the necessary infrastructure when
* we add gitlab options.
*/
@Parameters(separators = "=")
public final class GitLabDestinationOptions implements Option {

static final String GITLAB_DESTINATION_MR_BRANCH = "--gitlab-destination-mr-branch";

@Parameter(names = GITLAB_DESTINATION_MR_BRANCH,
description = "If set, uses this branch for creating the merge request instead of using a"
+ " generated one")
public String destinationMrBranch = null;

@Parameter(names = "--gitlab-destination-mr-create",
description = "If the merge request should be created", arity = 1)
public boolean createMergeRequest = true;

}
Loading