use of com.google.copybara.templatetoken.LabelTemplate.LabelNotFoundException in project copybara by google.
the class TemplateMessage method transform.
@Override
public TransformationStatus transform(TransformWork work) throws IOException, ValidationException {
String newMsg;
try {
newMsg = labelTemplate.resolve(work::getLabel);
} catch (LabelNotFoundException e) {
if (ignoreIfLabelNotFound) {
return TransformationStatus.success();
}
throw new ValidationException(String.format("Cannot find label '%s' in message:\n %s\nor any of the original commit messages", e.getLabel(), work.getMessage()));
}
if (!replaceMessage) {
newMsg += (newLine ? "\n" : "") + work.getMessage();
}
work.setMessage(newMsg);
return TransformationStatus.success();
}
use of com.google.copybara.templatetoken.LabelTemplate.LabelNotFoundException in project copybara by google.
the class LabelTemplateTest method testNotFound.
@Test
public void testNotFound() {
LabelNotFoundException exception = assertThrows(LabelNotFoundException.class, () -> new LabelTemplate("Foo${LABEL}${OTHER}").resolve(e -> e.equals("LABEL") ? "VAL" : null));
assertThat(exception.getLabel()).isEqualTo("OTHER");
}
use of com.google.copybara.templatetoken.LabelTemplate.LabelNotFoundException in project copybara by google.
the class MetadataSquashNotes method transform.
@Override
public TransformationStatus transform(TransformWork work) throws IOException, ValidationException {
StringBuilder sb;
try {
sb = new StringBuilder(prefixTemplate.resolve(work::getLabel));
} catch (LabelNotFoundException e) {
throw new ValidationException(String.format("Cannot find label '%s' in message:\n %s\nor any of the original commit messages", e.getLabel(), work.getMessage()));
}
if (max == 0) {
// Don't force changes to be computed if we don't want any change back.
work.setMessage(sb.toString());
return TransformationStatus.success();
}
int counter = 0;
List<? extends Change<?>> changes = work.getChanges().getCurrent();
if (oldestFirst) {
changes = Lists.reverse(changes);
}
if (!useMerge) {
changes = changes.stream().filter(e -> !e.isMerge()).collect(Collectors.toList());
}
for (int i = 0; i < changes.size(); i++) {
Change<?> c = changes.get(i);
if (counter == max) {
break;
}
ArrayList<String> summary = new ArrayList<>();
if (compact) {
sb.append(" - ");
if (showRef) {
summary.add(c.getRef());
}
if (showDescription) {
summary.add(cutIfLong(c.firstLineMessage()));
}
if (showAuthor) {
summary.add("by " + c.getMappedAuthor().toString());
}
sb.append(summary.stream().collect(Collectors.joining(" ")));
sb.append("\n");
} else {
sb.append("--\n");
if (showRef) {
summary.add(c.getRef());
} else {
summary.add(String.format("Change %s of %s", i + 1, changes.size()));
}
if (showAuthor) {
summary.add("by " + c.getAuthor().toString());
}
sb.append(summary.stream().collect(Collectors.joining(" ")));
if (showDescription) {
sb.append(":\n\n");
sb.append(c.getMessage());
}
sb.append("\n");
}
counter++;
}
if (changes.size() > max) {
sb.append(" (And ").append(changes.size() - max).append(" more changes)\n");
}
work.setMessage(sb.toString());
return TransformationStatus.success();
}
Aggregations