mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
Check for trailers only after first empty line
This commit is contained in:
@@ -56,13 +56,33 @@ public class ChangesetDescriptionTrailerProvider implements ChangesetPreProcesso
|
||||
private final List<Trailer> trailers = new ArrayList<>();
|
||||
private final StringBuilder newDescription = new StringBuilder();
|
||||
|
||||
boolean foundEmptyLine;
|
||||
|
||||
@Override
|
||||
public void process(Changeset changeset) {
|
||||
|
||||
try (Scanner scanner = new Scanner(changeset.getDescription())) {
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
handleLine(scanner, scanner.nextLine());
|
||||
}
|
||||
}
|
||||
changeset.addTrailers(trailers);
|
||||
changeset.setDescription(newDescription.toString());
|
||||
}
|
||||
|
||||
public void handleLine(Scanner scanner, String line) {
|
||||
if (line.isEmpty()) {
|
||||
handleEmptyLine(scanner, line);
|
||||
return;
|
||||
}
|
||||
|
||||
if (foundEmptyLine && checkForTrailer(line)) {
|
||||
return;
|
||||
}
|
||||
appendLine(scanner, line);
|
||||
}
|
||||
|
||||
public boolean checkForTrailer(String line) {
|
||||
Matcher matcher = TRAILER_PATTERN.matcher(line);
|
||||
if (matcher.matches()) {
|
||||
String type = matcher.group(1);
|
||||
@@ -70,17 +90,16 @@ public class ChangesetDescriptionTrailerProvider implements ChangesetPreProcesso
|
||||
String mail = matcher.group(3);
|
||||
if (SUPPORTED_TRAILER_TYPES.contains(type)) {
|
||||
createTrailer(type, name, mail);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void handleEmptyLine(Scanner scanner, String line) {
|
||||
foundEmptyLine = true;
|
||||
appendLine(scanner, line);
|
||||
}
|
||||
} else {
|
||||
appendLine(scanner, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
changeset.addTrailers(trailers);
|
||||
changeset.setDescription(newDescription.toString());
|
||||
}
|
||||
|
||||
public void appendLine(Scanner scanner, String line) {
|
||||
newDescription.append(line);
|
||||
|
||||
@@ -89,7 +89,7 @@ class ChangesetDescriptionTrailerProviderTest {
|
||||
@Test
|
||||
void shouldConvertTrailerWithSigner() {
|
||||
Person person = createPerson("Tricia McMillan", "trillian@hitchhiker.org");
|
||||
Changeset changeset = createChangeset("zaphod beeblebrox\n\nSigned-off-by: Tricia McMillan <trillian@hitchhiker.org>");
|
||||
Changeset changeset = createChangeset("zaphod beeblebrox\n\n\nSigned-off-by: Tricia McMillan <trillian@hitchhiker.org>");
|
||||
|
||||
changesetDescriptionTrailers.createPreProcessor(REPOSITORY).process(changeset);
|
||||
Collection<Trailer> trailers = changeset.getTrailers();
|
||||
@@ -98,7 +98,7 @@ class ChangesetDescriptionTrailerProviderTest {
|
||||
|
||||
assertThat(trailer.getTrailerType()).isEqualTo("Signed-off-by");
|
||||
assertThat(trailer.getPerson()).isEqualTo(person);
|
||||
assertThat(changeset.getDescription()).isEqualTo("zaphod beeblebrox\n\n");
|
||||
assertThat(changeset.getDescription()).isEqualTo("zaphod beeblebrox\n\n\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user