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,32 +56,51 @@ public class ChangesetDescriptionTrailerProvider implements ChangesetPreProcesso
|
|||||||
private final List<Trailer> trailers = new ArrayList<>();
|
private final List<Trailer> trailers = new ArrayList<>();
|
||||||
private final StringBuilder newDescription = new StringBuilder();
|
private final StringBuilder newDescription = new StringBuilder();
|
||||||
|
|
||||||
|
boolean foundEmptyLine;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(Changeset changeset) {
|
public void process(Changeset changeset) {
|
||||||
|
|
||||||
try (Scanner scanner = new Scanner(changeset.getDescription())) {
|
try (Scanner scanner = new Scanner(changeset.getDescription())) {
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
String line = scanner.nextLine();
|
handleLine(scanner, scanner.nextLine());
|
||||||
|
|
||||||
Matcher matcher = TRAILER_PATTERN.matcher(line);
|
|
||||||
if (matcher.matches()) {
|
|
||||||
String type = matcher.group(1);
|
|
||||||
String name = matcher.group(2);
|
|
||||||
String mail = matcher.group(3);
|
|
||||||
if (SUPPORTED_TRAILER_TYPES.contains(type)) {
|
|
||||||
createTrailer(type, name, mail);
|
|
||||||
} else {
|
|
||||||
appendLine(scanner, line);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
appendLine(scanner, line);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
changeset.addTrailers(trailers);
|
changeset.addTrailers(trailers);
|
||||||
changeset.setDescription(newDescription.toString());
|
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);
|
||||||
|
String name = matcher.group(2);
|
||||||
|
String mail = matcher.group(3);
|
||||||
|
if (SUPPORTED_TRAILER_TYPES.contains(type)) {
|
||||||
|
createTrailer(type, name, mail);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleEmptyLine(Scanner scanner, String line) {
|
||||||
|
foundEmptyLine = true;
|
||||||
|
appendLine(scanner, line);
|
||||||
|
}
|
||||||
|
|
||||||
public void appendLine(Scanner scanner, String line) {
|
public void appendLine(Scanner scanner, String line) {
|
||||||
newDescription.append(line);
|
newDescription.append(line);
|
||||||
if (scanner.hasNextLine()) {
|
if (scanner.hasNextLine()) {
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ class ChangesetDescriptionTrailerProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
void shouldConvertTrailerWithSigner() {
|
void shouldConvertTrailerWithSigner() {
|
||||||
Person person = createPerson("Tricia McMillan", "trillian@hitchhiker.org");
|
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);
|
changesetDescriptionTrailers.createPreProcessor(REPOSITORY).process(changeset);
|
||||||
Collection<Trailer> trailers = changeset.getTrailers();
|
Collection<Trailer> trailers = changeset.getTrailers();
|
||||||
@@ -98,7 +98,7 @@ class ChangesetDescriptionTrailerProviderTest {
|
|||||||
|
|
||||||
assertThat(trailer.getTrailerType()).isEqualTo("Signed-off-by");
|
assertThat(trailer.getTrailerType()).isEqualTo("Signed-off-by");
|
||||||
assertThat(trailer.getPerson()).isEqualTo(person);
|
assertThat(trailer.getPerson()).isEqualTo(person);
|
||||||
assertThat(changeset.getDescription()).isEqualTo("zaphod beeblebrox\n\n");
|
assertThat(changeset.getDescription()).isEqualTo("zaphod beeblebrox\n\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user