Skip to content

Commit

Permalink
Expose tag options in github_destination
Browse files Browse the repository at this point in the history
Expose GitDestination's tag fields.

Update mockito to remove deprecated calls.

BUG=199114493
PiperOrigin-RevId: 396457885
Change-Id: I2009968d268025a97b20ae2446f7588e8f1a1f4a
  • Loading branch information
hsudhof committed Sep 24, 2021
1 parent 82a9e24 commit 0df1231
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
4 changes: 3 additions & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2322,7 +2322,7 @@ Name | Type | Description

Creates a commit in a GitHub repository branch (for example master). For creating PullRequest use git.github_pr_destination.

`destination git.github_destination(url, push='master', fetch=None, pr_branch_to_update=None, partial_fetch=False, delete_pr_branch=False, integrates=None, api_checker=None, primary_branch_migration=False)`
`destination git.github_destination(url, push='master', fetch=None, pr_branch_to_update=None, partial_fetch=False, delete_pr_branch=False, integrates=None, api_checker=None, primary_branch_migration=False, tag_name=None, tag_msg=None)`


#### Parameters:
Expand All @@ -2338,6 +2338,8 @@ delete_pr_branch | `bool` or `NoneType`<br><p>When `pr_branch_to_update` is enab
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>
api_checker | `checker` or `NoneType`<br><p>A checker for the Gerrit API endpoint provided for after_migration hooks. This field is not required if the workflow hooks don't use the origin/destination endpoints.</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>
tag_name | `string` or `NoneType`<br><p>A template string that specifies to a tag name. If the tag already exists, copybara will only overwrite it if the --git-tag-overwrite flag is set.<br>Note that tag creation is best-effort and the migration will succeed even if the tag cannot be created. Usage: Users can use a string or a string with a label. For instance ${label}_tag_name. And the value of label must be in changes' label list. Otherwise, tag won't be created.</p>
tag_msg | `string` or `NoneType`<br><p>A template string that refers to the commit msg for a tag. If set, copybara willcreate an annotated tag with this custom message<br>Usage: Labels in the string will be resolved. E.g .${label}_message.By default, the tag will be created with the labeled commit's message.</p>



Expand Down
38 changes: 36 additions & 2 deletions java/com/google/copybara/git/GitModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,38 @@ public GitDestination destination(
+ "fails, it will fall back to the param's declared value.\n"
+ "This is intended to help migrating to the new standard of using 'main' without "
+ "breaking users relying on the legacy default."),
@Param(
name = "tag_name",
allowedTypes = {
@ParamType(type = String.class),
@ParamType(type = NoneType.class),
},
named = true,
positional = false,
doc =
"A template string that specifies to a tag name. If the tag already exists, "
+ "copybara will only overwrite it if the --git-tag-overwrite flag is set."
+ "\nNote that tag creation is "
+ "best-effort and the migration will succeed even if the tag cannot be "
+ "created. "
+ "Usage: Users can use a string or a string with a label. "
+ "For instance ${label}_tag_name. And the value of label must be "
+ "in changes' label list. Otherwise, tag won't be created.",
defaultValue = "None"),
@Param(
name = "tag_msg",
allowedTypes = {
@ParamType(type = String.class),
@ParamType(type = NoneType.class),
},
named = true,
positional = false,
doc =
"A template string that refers to the commit msg for a tag. If set, copybara will"
+ "create an annotated tag with this custom message\n"
+ "Usage: Labels in the string will be resolved. E.g .${label}_message."
+ "By default, the tag will be created with the labeled commit's message.",
defaultValue = "None"),
},
useStarlarkThread = true)
@UsesFlags(GitDestinationOptions.class)
Expand All @@ -1371,6 +1403,8 @@ public GitDestination gitHubDestination(
Object integrates,
Object checker,
Boolean primaryBranchMigration,
Object tagName,
Object tagMsg,
StarlarkThread thread)
throws EvalException {
GitDestinationOptions destinationOptions = options.get(GitDestinationOptions.class);
Expand Down Expand Up @@ -1409,8 +1443,8 @@ public GitDestination gitHubDestination(
resolvedPush,
partialFetch,
primaryBranchMigration,
/*tagName*/ null,
/*tagMsg*/ null,
convertFromNoneable(tagName, null),
convertFromNoneable(tagMsg, null),
destinationOptions,
options.get(GitOptions.class),
generalOptions,
Expand Down
22 changes: 19 additions & 3 deletions javatests/com/google/copybara/git/GitHubDestinationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;

import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -89,7 +89,7 @@ public class GitHubDestinationTest {
private Path workdir;
private GitTestUtil gitUtil;
private GitRepository remote;

@Before
public void setup() throws Exception {
console = new TestingConsole();
Expand Down Expand Up @@ -216,7 +216,7 @@ public void testPrToUpdateIngoredForInitHistory() throws Exception {
assertThat(destinationResult.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");

// This is a migration of two changes (use the same ref because mocks)
verifyNoMoreInteractions(gitUtil.httpTransport());
verifyNoInteractions(gitUtil.httpTransport());
GitTesting.assertThatCheckout(remote, primaryBranch)
.containsFile("test.txt", "some content")
.containsNoMoreFiles();
Expand Down Expand Up @@ -482,6 +482,22 @@ public void testWithLabelNotFound() throws Exception {
Assert.assertTrue(e.getMessage().contains("Template 'other_${no_such_label}' has an error"));
}

@Test
public void testLabelIsPropagated()
throws ValidationException {
options.setForce(force);
GitDestination dest = skylark.eval("result",
String.format("result = git.github_destination(\n"
+ " url = '%s',\n"
+ " fetch = '%s',\n"
+ " push = '%s',\n"
+ " tag_name = 'guten_tag',\n"
+ " tag_msg = 'tag msg',\n"
+ ")", url, fetch, push));
assertThat(dest.describe(Glob.ALL_FILES).get("tagName")).contains("guten_tag");
assertThat(dest.describe(Glob.ALL_FILES).get("tagMsg")).contains("tag msg");
}

private void addFiles(GitRepository remote, String branch, String msg, Map<String, String> files)
throws IOException, RepoException {
Path temp = Files.createTempDirectory("temp");
Expand Down
2 changes: 1 addition & 1 deletion repositories.maven.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def copybara_maven_repositories():
"junit:junit:4.13",
"net.bytebuddy:byte-buddy-agent:1.9.10",
"net.bytebuddy:byte-buddy:1.9.10",
"org.mockito:mockito-core:2.28.2",
"org.mockito:mockito-core:3.12.4",
"org.objenesis:objenesis:1.0",
],
repositories = [
Expand Down

0 comments on commit 0df1231

Please sign in to comment.