use of com.google.copybara.DestinationEffect in project copybara by google.
the class Mirror method run.
@Override
public void run(Path workdir, @Nullable String sourceRef) throws RepoException, IOException, ValidationException {
mirrorOptions.mirror(origin, destination, refspec, prune);
// More fine grain events based on the references created/updated/deleted:
generalOptions.eventMonitor().onChangeMigrationFinished(new ChangeMigrationFinishedEvent(ImmutableList.of(new DestinationEffect(Type.UPDATED, "Refspecs " + refspec + " mirrored successfully", // references
ImmutableList.of(), new DestinationRef(getOriginDestinationRef(destination), "mirror", /*url=*/
null), ImmutableList.of()))));
}
use of com.google.copybara.DestinationEffect in project copybara by google.
the class GerritDestinationTest method testProcessPushOutput_new.
@Test
public void testProcessPushOutput_new() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
GerritProcessPushOutput process = new GerritProcessPushOutput(LogConsole.readWriteConsole(System.in, new PrintStream(out), /*verbose=*/
false));
fakeOneCommitInDestination();
ImmutableList<DestinationEffect> result = process.process(GERRIT_RESPONSE, /*newReview*/
true, repo(), Changes.EMPTY.getCurrent());
assertThat(out.toString()).contains("INFO: New Gerrit review created at https://some.url.google.com/1234");
assertThat(result).hasSize(2);
assertThat(result.get(0).getErrors()).isEmpty();
assertThat(result.get(0).getType()).isEqualTo(Type.CREATED);
assertThat(result.get(0).getDestinationRef().getType()).isEqualTo("commit");
assertThat(result.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
assertThat(result.get(1).getSummary()).contains("New Gerrit review created at https://some.url.google.com/1234");
assertThat(result.get(1).getType()).isEqualTo(Type.CREATED);
assertThat(result.get(1).getDestinationRef().getId()).isEqualTo("1234");
assertThat(result.get(1).getDestinationRef().getType()).isEqualTo("gerrit_review");
assertThat(result.get(1).getDestinationRef().getUrl()).isEqualTo("https://some.url.google.com/1234");
}
use of com.google.copybara.DestinationEffect in project copybara by google.
the class GerritDestinationTest method testProcessPushOutput_existing.
@Test
public void testProcessPushOutput_existing() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
GerritProcessPushOutput process = new GerritProcessPushOutput(LogConsole.readWriteConsole(System.in, new PrintStream(out), /*verbose=*/
false));
fakeOneCommitInDestination();
ImmutableList<DestinationEffect> result = process.process(GERRIT_RESPONSE, /*newReview*/
false, repo(), Changes.EMPTY.getCurrent());
assertThat(out.toString()).contains("INFO: Updated existing Gerrit review at https://some.url.google.com/1234");
assertThat(result).hasSize(2);
assertThat(result.get(0).getErrors()).isEmpty();
assertThat(result.get(0).getType()).isEqualTo(Type.CREATED);
assertThat(result.get(0).getDestinationRef().getType()).isEqualTo("commit");
assertThat(result.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
assertThat(result.get(1).getSummary()).contains("Updated existing Gerrit review at https://some.url.google.com/1234");
assertThat(result.get(1).getType()).isEqualTo(Type.UPDATED);
assertThat(result.get(1).getDestinationRef().getId()).isEqualTo("1234");
assertThat(result.get(1).getDestinationRef().getType()).isEqualTo("gerrit_review");
assertThat(result.get(1).getDestinationRef().getUrl()).isEqualTo("https://some.url.google.com/1234");
}
use of com.google.copybara.DestinationEffect in project copybara by google.
the class ActionContext method recordEffect.
@StarlarkMethod(name = "record_effect", doc = "Records an effect of the current action.", parameters = { @Param(name = "summary", doc = "The summary of this effect", named = true), @Param(name = "origin_refs", allowedTypes = { @ParamType(type = Sequence.class, generic1 = OriginRef.class) }, doc = "The origin refs", named = true), @Param(name = "destination_ref", doc = "The destination ref", named = true), @Param(name = "errors", allowedTypes = { @ParamType(type = Sequence.class, generic1 = String.class) }, defaultValue = "[]", doc = "An optional list of errors", named = true), @Param(name = "type", doc = "The type of migration effect:<br>" + "<ul>" + "<li><b>'CREATED'</b>: A new review or change was created.</li>" + "<li><b>'UPDATED'</b>: An existing review or change was updated.</li>" + "<li><b>'NOOP'</b>: The change was a noop.</li>" + "<li><b>'NOOP_AGAINST_PENDING_CHANGE'</b>: The change was a noop, relative" + "to an existing pending change.</li>" + "<li><b>'INSUFFICIENT_APPROVALS'</b>: The effect couldn't happen because " + "the change doesn't have enough approvals.</li>" + "<li><b>'ERROR'</b>: A user attributable error happened that prevented " + "the destination from creating/updating the change. " + "<li><b>'STARTED'</b>: The initial effect of a migration that depends on a " + "previous one. This allows to have 'dependant' migrations defined by users.\n" + "An example of this: a workflow migrates code from a Gerrit review to a " + "GitHub PR, and a feedback migration migrates the test results from a CI in " + "GitHub back to the Gerrit change.\n" + "This effect would be created on the former one.</li>" + "</ul>", defaultValue = "\"UPDATED\"", named = true) })
public void recordEffect(String summary, // <OriginRef>
Sequence<?> originRefs, DestinationRef destinationRef, // <String>
Sequence<?> errors, String typeStr) throws EvalException {
DestinationEffect.Type type = SkylarkUtil.stringToEnum("type", typeStr, DestinationEffect.Type.class);
newDestinationEffects.add(new DestinationEffect(type, summary, Sequence.cast(originRefs, OriginRef.class, "origin_refs"), destinationRef, Sequence.cast(errors, String.class, "errors")));
}
use of com.google.copybara.DestinationEffect in project copybara by google.
the class Feedback method run.
@Override
public void run(Path workdir, ImmutableList<String> sourceRefs) throws RepoException, ValidationException {
ImmutableList.Builder<ActionResult> allResultsBuilder = ImmutableList.builder();
String suffix = Joiner.on('_').join(sourceRefs).replaceAll("([/ ])", "_");
String root = "run/" + name + "/" + suffix.substring(0, Math.min(suffix.length(), 20));
try (ProfilerTask ignore = profiler().start(root)) {
for (Action action : actions) {
ArrayList<DestinationEffect> effects = new ArrayList<>();
try (ProfilerTask ignore2 = profiler().start(action.getName())) {
SkylarkConsole console = new SkylarkConsole(generalOptions.console());
eventMonitors().dispatchEvent(m -> m.onChangeMigrationStarted(new ChangeMigrationStartedEvent()));
FeedbackMigrationContext context = new FeedbackMigrationContext(this, action, generalOptions.cliLabels(), sourceRefs, console);
action.run(context);
effects.addAll(context.getNewDestinationEffects());
ActionResult actionResult = context.getActionResult();
allResultsBuilder.add(actionResult);
// First error aborts the execution of the other actions
ValidationException.checkCondition(actionResult.getResult() != Result.ERROR, "Feedback migration '%s' action '%s' returned error: %s. Aborting execution.", name, action.getName(), actionResult.getMsg());
} finally {
eventMonitors().dispatchEvent(m -> m.onChangeMigrationFinished(new ChangeMigrationFinishedEvent(ImmutableList.copyOf(effects), getOriginDescription(), getDestinationDescription())));
}
}
}
ImmutableList<ActionResult> allResults = allResultsBuilder.build();
// This check also returns true if there are no actions
if (allResults.stream().allMatch(a -> a.getResult() == Result.NO_OP)) {
String detailedMessage = allResults.isEmpty() ? "actions field is empty" : allResults.stream().map(ActionResult::getMsg).collect(ImmutableList.toImmutableList()).toString();
throw new EmptyChangeException(String.format("Feedback migration '%s' was noop. Detailed messages: %s", name, detailedMessage));
}
}
Aggregations