Search in sources :

Example 1 with Feedback

use of com.google.copybara.feedback.Feedback in project copybara by google.

the class Core method feedback.

@SuppressWarnings("unused")
@StarlarkMethod(name = "feedback", doc = "Defines a migration of changes' metadata, that can be invoked via the Copybara command" + " in the same way as a regular workflow migrates the change itself.\n" + "\n" + "It is considered change metadata any information associated with a change" + " (pending or submitted) that is not core to the change itself. A few examples:\n" + "<ul>\n" + "  <li> Comments: Present in any code review system. Examples: GitHub PRs or" + " Gerrit     code reviews.</li>\n" + "  <li> Labels: Used in code review systems for approvals and/or CI results.    " + " Examples: GitHub labels, Gerrit code review labels.</li>\n" + "</ul>\n" + "For the purpose of this workflow, it is not considered metadata the commit" + " message in Git, or any of the contents of the file tree.\n" + "\n", parameters = { @Param(name = "name", doc = "The name of the feedback workflow.", positional = false, named = true), @Param(name = "origin", doc = "The trigger of a feedback migration.", positional = false, named = true), @Param(name = "destination", doc = "Where to write change metadata to. This is usually a code review system like " + "Gerrit or GitHub PR.", positional = false, named = true), @Param(name = "actions", doc = "" + "A list of feedback actions to perform, with the following semantics:\n" + "  - There is no guarantee of the order of execution.\n" + "  - Actions need to be independent from each other.\n" + "  - Failure in one action might prevent other actions from executing.\n", defaultValue = "[]", positional = false, named = true), @Param(name = "description", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, named = true, positional = false, doc = "A description of what this workflow achieves", defaultValue = "None") }, useStarlarkThread = true)
@UsesFlags({ FeedbackOptions.class })
public /*TODO(danielromero): Add default values*/
NoneType feedback(String workflowName, Trigger trigger, EndpointProvider<?> destination, net.starlark.java.eval.Sequence<?> feedbackActions, Object description, StarlarkThread thread) throws EvalException {
    ImmutableList<Action> actions = convertFeedbackActions(feedbackActions, printHandler);
    Feedback migration = new Feedback(workflowName, convertFromNoneable(description, null), mainConfigFile, trigger, destination.getEndpoint(), actions, generalOptions);
    Module module = Module.ofInnermostEnclosingStarlarkFunction(thread);
    registerGlobalMigration(workflowName, migration, module);
    return Starlark.NONE;
}
Also used : StarlarkAction(com.google.copybara.action.StarlarkAction) Action(com.google.copybara.action.Action) Feedback(com.google.copybara.feedback.Feedback) LabelsAwareModule(com.google.copybara.config.LabelsAwareModule) FolderModule(com.google.copybara.folder.FolderModule) Module(net.starlark.java.eval.Module) StarlarkMethod(net.starlark.java.annot.StarlarkMethod) UsesFlags(com.google.copybara.doc.annotations.UsesFlags)

Example 2 with Feedback

use of com.google.copybara.feedback.Feedback in project copybara by google.

the class FeedbackTest method testDescription.

@Test
public void testDescription() throws Exception {
    String config = "" + "def test_action(ctx):\n" + "    return ctx.success()\n" + "\n" + "core.feedback(\n" + "    name = 'default',\n" + "    description = 'Do foo with bar',\n" + "    origin = testing.dummy_trigger(),\n" + "    destination = testing.dummy_endpoint(),\n" + "    actions = [test_action],\n" + ")";
    Feedback feedback = (Feedback) loadConfig(config).getMigration("default");
    assertThat(feedback.getDescription()).isEqualTo("Do foo with bar");
}
Also used : Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Example 3 with Feedback

use of com.google.copybara.feedback.Feedback in project copybara by google.

the class FeedbackTest method testRefReturnsFirst.

@Test
public void testRefReturnsFirst() throws Exception {
    Feedback feedback = feedback("" + "def test_action(ctx):\n" + "    ctx.console.info('Ref: ' + str(ctx.refs[0]))\n" + "    return ctx.success()\n" + "\n", "test_action");
    feedback.run(workdir, ImmutableList.of("12345", "67890"));
    console.assertThat().matchesNext(MessageType.INFO, ".*Ref: 12345").matchesNext(MessageType.INFO, ".*Action 'test_action' returned success.*").containsNoMoreMessages();
}
Also used : Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Example 4 with Feedback

use of com.google.copybara.feedback.Feedback in project copybara by google.

the class FeedbackTest method testErrorResultThrowsValidationException.

@Test
public void testErrorResultThrowsValidationException() throws Exception {
    Feedback feedback = feedback("" + "def test_action(ctx):\n" + "    return ctx.error('This is an error')\n", "test_action");
    ValidationException expected = assertThrows(ValidationException.class, () -> feedback.run(workdir, ImmutableList.of()));
    assertThat(expected).hasMessageThat().contains("Feedback migration 'default' action 'test_action' returned error: " + "This is an error. Aborting execution.");
    console.assertThat().equalsNext(MessageType.ERROR, "Action 'test_action' returned error: This is an error");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Example 5 with Feedback

use of com.google.copybara.feedback.Feedback in project copybara by google.

the class FeedbackTest method testActionsMustReturnResult.

@Test
public void testActionsMustReturnResult() throws Exception {
    Feedback feedback = feedback("" + "def test_action(ctx):\n" + "    ctx.console.info('Bad action')\n" + "\n", "test_action");
    ValidationException expected = assertThrows(ValidationException.class, () -> feedback.run(workdir, ImmutableList.of()));
    assertThat(expected).hasMessageThat().contains("Actions must return a result via built-in functions: success(), " + "error(), noop() return, but 'test_action' returned: None");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Feedback(com.google.copybara.feedback.Feedback) Test(org.junit.Test)

Aggregations

Feedback (com.google.copybara.feedback.Feedback)29 Test (org.junit.Test)23 ValidationException (com.google.copybara.exception.ValidationException)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)2 DestinationRef (com.google.copybara.DestinationEffect.DestinationRef)1 Action (com.google.copybara.action.Action)1 StarlarkAction (com.google.copybara.action.StarlarkAction)1 LabelsAwareModule (com.google.copybara.config.LabelsAwareModule)1 UsesFlags (com.google.copybara.doc.annotations.UsesFlags)1 FolderModule (com.google.copybara.folder.FolderModule)1 ChangeMigrationFinishedEvent (com.google.copybara.monitor.EventMonitor.ChangeMigrationFinishedEvent)1 MockRequestAssertion (com.google.copybara.testing.git.GitTestUtil.MockRequestAssertion)1 StarlarkMethod (net.starlark.java.annot.StarlarkMethod)1 Module (net.starlark.java.eval.Module)1