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;
}
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");
}
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();
}
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");
}
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");
}
Aggregations