use of com.google.copybara.exception.EmptyChangeException in project copybara by google.
the class GerritOrigin method resolve.
@Override
public GitRevision resolve(@Nullable String reference) throws RepoException, ValidationException {
generalOptions.console().progress("Git Origin: Initializing local repo");
checkCondition(!Strings.isNullOrEmpty(reference), "Expecting a change number as reference");
GerritChange change = GerritChange.resolve(getRepository(), repoUrl, reference, this.generalOptions);
if (change == null) {
GitRevision gitRevision = GitRepoType.GIT.resolveRef(getRepository(), repoUrl, reference, this.generalOptions, describeVersion, partialFetch);
return describeVersion ? getRepository().addDescribeVersion(gitRevision) : gitRevision;
}
GerritApi api = gerritOptions.newGerritApi(repoUrl);
ChangeInfo response = api.getChange(Integer.toString(change.getChange()), new GetChangeInput(ImmutableSet.of(DETAILED_ACCOUNTS, DETAILED_LABELS)));
if (branch != null && !branch.equals(response.getBranch())) {
throw new EmptyChangeException(String.format("Skipping import of change %s for branch %s. Only tracking changes for branch %s", change.getChange(), response.getBranch(), branch));
}
ImmutableMultimap.Builder<String, String> labels = ImmutableMultimap.builder();
labels.put(GerritChange.GERRIT_CHANGE_BRANCH, response.getBranch());
if (response.getTopic() != null) {
labels.put(GerritChange.GERRIT_CHANGE_TOPIC, response.getTopic());
}
labels.put(GerritChange.GERRIT_COMPLETE_CHANGE_ID_LABEL, response.getId());
for (Entry<String, List<AccountInfo>> e : response.getReviewers().entrySet()) {
for (AccountInfo info : e.getValue()) {
if (info.getEmail() != null) {
labels.put("GERRIT_" + e.getKey() + "_EMAIL", info.getEmail());
}
}
}
if (response.getOwner().getEmail() != null) {
labels.put(GerritChange.GERRIT_OWNER_EMAIL_LABEL, response.getOwner().getEmail());
}
GitRevision gitRevision = change.fetch(labels.build());
return describeVersion ? getRepository().addDescribeVersion(gitRevision) : gitRevision;
}
use of com.google.copybara.exception.EmptyChangeException in project copybara by google.
the class GitHubPrOrigin method checkRequiredLabels.
/**
* Check that the PR has all the labels provided in the `required_labels` param
*/
private void checkRequiredLabels(GitHubApi api, String project, PullRequest prData) throws ValidationException, RepoException {
Set<String> requiredLabels = getRequiredLabels();
Set<String> retryableLabels = getRetryableLabels();
if (forceImport() || requiredLabels.isEmpty()) {
return;
}
int retryCount = 0;
Set<String> requiredButNotPresent;
do {
Issue issue;
try (ProfilerTask ignore = generalOptions.profiler().start("github_api_get_issue")) {
issue = api.getIssue(project, prData.getNumber());
}
requiredButNotPresent = Sets.newHashSet(requiredLabels);
requiredButNotPresent.removeAll(Collections2.transform(issue.getLabels(), Label::getName));
// If we got all the labels we want or none of the ones we didn't get are retryable, return.
if (requiredButNotPresent.isEmpty() || Collections.disjoint(requiredButNotPresent, retryableLabels)) {
break;
}
Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS);
retryCount++;
} while (retryCount < RETRY_COUNT);
if (!requiredButNotPresent.isEmpty()) {
throw new EmptyChangeException(String.format("Cannot migrate http://github.com/%s/pull/%d because it is missing the following" + " labels: %s", project, prData.getNumber(), requiredButNotPresent));
}
}
use of com.google.copybara.exception.EmptyChangeException in project copybara by google.
the class FeedbackTest method testNoopResultThrowsEmptyChangeException.
@Test
public void testNoopResultThrowsEmptyChangeException() throws Exception {
Feedback feedback = feedback("" + "def test_action_1(ctx):\n" + " return ctx.noop('No effect 1')\n" + "\n" + "def test_action_2(ctx):\n" + " return ctx.noop('No effect 2')\n" + "\n", "test_action_1", "test_action_2");
EmptyChangeException expected = assertThrows(EmptyChangeException.class, () -> feedback.run(workdir, ImmutableList.of()));
assertThat(expected).hasMessageThat().contains("Feedback migration 'default' was noop. " + "Detailed messages: [No effect 1, No effect 2]");
console.assertThat().equalsNext(MessageType.INFO, "Action 'test_action_1' returned noop: No effect 1").equalsNext(MessageType.INFO, "Action 'test_action_2' returned noop: No effect 2");
}
use of com.google.copybara.exception.EmptyChangeException in project copybara by google.
the class FeedbackTest method testNoActionsThrowsEmptyChangeException.
@Test
public void testNoActionsThrowsEmptyChangeException() throws Exception {
Feedback feedback = feedback("");
EmptyChangeException expected = assertThrows(EmptyChangeException.class, () -> feedback.run(workdir, ImmutableList.of()));
assertThat(expected).hasMessageThat().contains("Feedback migration 'default' was noop. Detailed messages: actions field is empty");
}
use of com.google.copybara.exception.EmptyChangeException in project copybara by google.
the class WorkflowTest method testSquashAlreadyMigratedSameChange.
@Test
public void testSquashAlreadyMigratedSameChange() throws Exception {
origin.addSimpleChange(/*timestamp*/
1);
skylarkWorkflow("default", SQUASH).run(workdir, ImmutableList.of(HEAD));
// Disable force so that we get an error
options.setForce(false);
EmptyChangeException thrown = assertThrows(EmptyChangeException.class, () -> skylarkWorkflow("default", SQUASH).run(workdir, ImmutableList.of(HEAD)));
assertThat(thrown).hasMessageThat().contains("'0' has been already migrated");
}
Aggregations