mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
Unite trailer detection and message update
The detection of trailers and removing them from the message should be in one place, not divided between classes.
This commit is contained in:
@@ -313,4 +313,12 @@ public class Changeset extends BasicPropertiesAware implements ModelObject {
|
|||||||
public void setTrailers(Collection<Trailer> trailers) {
|
public void setTrailers(Collection<Trailer> trailers) {
|
||||||
this.trailers = trailers;
|
this.trailers = trailers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addTrailers(Collection<Trailer> trailers) {
|
||||||
|
if (this.trailers == null) {
|
||||||
|
this.trailers = new ArrayList<>(trailers);
|
||||||
|
} else {
|
||||||
|
this.trailers.addAll(trailers);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package sonia.scm.repository;
|
|
||||||
|
|
||||||
import sonia.scm.plugin.Extension;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Extension
|
|
||||||
public class ChangesetTrailerPreProcessorFactory implements ChangesetPreProcessorFactory {
|
|
||||||
|
|
||||||
private final Set<ChangesetTrailerProvider> changesetTrailerProviderSet;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public ChangesetTrailerPreProcessorFactory(Set<ChangesetTrailerProvider> changesetTrailerProviderSet) {
|
|
||||||
this.changesetTrailerProviderSet = changesetTrailerProviderSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChangesetPreProcessor createPreProcessor(Repository repository) {
|
|
||||||
return changeset -> {
|
|
||||||
Collection<Trailer> existingTrailers = changeset.getTrailers();
|
|
||||||
List<Trailer> collectedTrailers;
|
|
||||||
if (existingTrailers == null && existingTrailers.isEmpty()) {
|
|
||||||
collectedTrailers = new ArrayList<>();
|
|
||||||
} else {
|
|
||||||
collectedTrailers = new ArrayList<>(existingTrailers);
|
|
||||||
}
|
|
||||||
changesetTrailerProviderSet.stream()
|
|
||||||
.flatMap(changesetTrailers -> changesetTrailers.getTrailers(repository, changeset).stream())
|
|
||||||
.forEach(collectedTrailers::add);
|
|
||||||
changeset.setTrailers(collectedTrailers);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package sonia.scm.repository;
|
|
||||||
|
|
||||||
import sonia.scm.plugin.ExtensionPoint;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@ExtensionPoint
|
|
||||||
public interface ChangesetTrailerProvider {
|
|
||||||
List<Trailer> getTrailers(Repository repository, Changeset changeset);
|
|
||||||
}
|
|
||||||
@@ -27,36 +27,38 @@ package sonia.scm.api.v2.resources;
|
|||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import sonia.scm.plugin.Extension;
|
import sonia.scm.plugin.Extension;
|
||||||
import sonia.scm.repository.Changeset;
|
import sonia.scm.repository.Changeset;
|
||||||
import sonia.scm.repository.ChangesetTrailerProvider;
|
import sonia.scm.repository.ChangesetPreProcessor;
|
||||||
|
import sonia.scm.repository.ChangesetPreProcessorFactory;
|
||||||
import sonia.scm.repository.Person;
|
import sonia.scm.repository.Person;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
import sonia.scm.repository.Trailer;
|
import sonia.scm.repository.Trailer;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.regex.MatchResult;
|
import java.util.regex.MatchResult;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static java.util.Optional.empty;
|
|
||||||
import static java.util.Optional.of;
|
|
||||||
|
|
||||||
@Extension
|
@Extension
|
||||||
public class ChangesetDescriptionTrailerProvider implements ChangesetTrailerProvider {
|
public class ChangesetDescriptionTrailerProvider implements ChangesetPreProcessorFactory {
|
||||||
|
|
||||||
private static final Collection<String> SUPPORTED_TRAILER_TYPES = ImmutableSet.of("Co-authored-by", "Reviewed-by", "Signed-off-by", "Committed-by");
|
private static final Collection<String> SUPPORTED_TRAILER_TYPES = ImmutableSet.of("Co-authored-by", "Reviewed-by", "Signed-off-by", "Committed-by");
|
||||||
private static final Pattern PERSON_PATTERN = Pattern.compile("^\\W*(.*)\\W+<(.*)>\\W*$");
|
private static final Pattern PERSON_PATTERN = Pattern.compile("^\\W*(.*)\\W+<(.*)>\\W*$");
|
||||||
|
|
||||||
@Inject
|
@Override
|
||||||
public ChangesetDescriptionTrailerProvider() {}
|
public ChangesetPreProcessor createPreProcessor(Repository repository) {
|
||||||
|
return new TrailerChangesetPreProcessor();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TrailerChangesetPreProcessor implements ChangesetPreProcessor {
|
||||||
|
|
||||||
|
private final List<Trailer> trailers = new ArrayList<>();
|
||||||
|
private final StringBuilder newDescription = new StringBuilder();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Trailer> getTrailers(Repository repository, Changeset changeset) {
|
public void process(Changeset changeset) {
|
||||||
List<Trailer> trailers = new ArrayList<>();
|
|
||||||
|
|
||||||
try (Scanner scanner = new Scanner(changeset.getDescription())) {
|
try (Scanner scanner = new Scanner(changeset.getDescription())) {
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
@@ -66,23 +68,34 @@ public class ChangesetDescriptionTrailerProvider implements ChangesetTrailerProv
|
|||||||
if (typeAndUser.length == 2) {
|
if (typeAndUser.length == 2) {
|
||||||
String type = typeAndUser[0];
|
String type = typeAndUser[0];
|
||||||
String person = typeAndUser[1];
|
String person = typeAndUser[1];
|
||||||
if (SUPPORTED_TRAILER_TYPES.contains(type)) {
|
if (!SUPPORTED_TRAILER_TYPES.contains(type) || !createTrailer(type, person)) {
|
||||||
Optional<Trailer> trailer = createTrailer(type, person);
|
appendLine(scanner, line);
|
||||||
trailer.ifPresent(trailers::add);
|
}
|
||||||
|
} else {
|
||||||
|
appendLine(scanner, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
changeset.addTrailers(trailers);
|
||||||
return trailers;
|
changeset.setDescription(newDescription.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<Trailer> createTrailer(String type, String person) {
|
public void appendLine(Scanner scanner, String line) {
|
||||||
|
newDescription.append(line);
|
||||||
|
if (scanner.hasNextLine()) {
|
||||||
|
newDescription.append('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean createTrailer(String type, String person) {
|
||||||
Matcher matcher = PERSON_PATTERN.matcher(person.trim());
|
Matcher matcher = PERSON_PATTERN.matcher(person.trim());
|
||||||
if (matcher.matches()) {
|
if (matcher.matches()) {
|
||||||
MatchResult matchResult = matcher.toMatchResult();
|
MatchResult matchResult = matcher.toMatchResult();
|
||||||
return of(new Trailer(type, new Person(matchResult.group(1), matchResult.group(2))));
|
trailers.add(new Trailer(type, new Person(matchResult.group(1), matchResult.group(2))));
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return empty();
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,24 +74,6 @@ public abstract class DefaultChangesetToChangesetDtoMapper extends HalAppenderMa
|
|||||||
|
|
||||||
abstract PersonDto map(Person person);
|
abstract PersonDto map(Person person);
|
||||||
|
|
||||||
@AfterMapping
|
|
||||||
void removeTrailerFromChangesetDescription(@MappingTarget ChangesetDto target) {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
try (Scanner scanner = new Scanner(target.getDescription())) {
|
|
||||||
while (scanner.hasNextLine()) {
|
|
||||||
String line = scanner.nextLine();
|
|
||||||
if (!line.contains("-by:")) {
|
|
||||||
builder.append(line);
|
|
||||||
if (scanner.hasNextLine()) {
|
|
||||||
builder.append("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
target.setDescription(builder.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@ObjectFactory
|
@ObjectFactory
|
||||||
ChangesetDto createDto(@Context Repository repository, Changeset source) {
|
ChangesetDto createDto(@Context Repository repository, Changeset source) {
|
||||||
String namespace = repository.getNamespace();
|
String namespace = repository.getNamespace();
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ import sonia.scm.repository.Branch;
|
|||||||
import sonia.scm.repository.Branches;
|
import sonia.scm.repository.Branches;
|
||||||
import sonia.scm.repository.Changeset;
|
import sonia.scm.repository.Changeset;
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
import sonia.scm.repository.ChangesetTrailerProvider;
|
|
||||||
import sonia.scm.repository.NamespaceAndName;
|
import sonia.scm.repository.NamespaceAndName;
|
||||||
import sonia.scm.repository.Person;
|
import sonia.scm.repository.Person;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
@@ -115,10 +114,6 @@ public class BranchRootResourceTest extends RepositoryTestBase {
|
|||||||
@Mock
|
@Mock
|
||||||
private TagCollectionToDtoMapper tagCollectionToDtoMapper;
|
private TagCollectionToDtoMapper tagCollectionToDtoMapper;
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Set<ChangesetTrailerProvider> changesetTrailers;
|
|
||||||
|
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private DefaultChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
private DefaultChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,178 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sonia.scm.api.v2.resources;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import sonia.scm.repository.Changeset;
|
||||||
|
import sonia.scm.repository.Person;
|
||||||
|
import sonia.scm.repository.Repository;
|
||||||
|
import sonia.scm.repository.RepositoryTestData;
|
||||||
|
import sonia.scm.repository.Trailer;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class ChangesetDescriptionTrailerProviderTest {
|
||||||
|
|
||||||
|
private static final Repository REPOSITORY = RepositoryTestData.createHeartOfGold();
|
||||||
|
|
||||||
|
private final ChangesetDescriptionTrailerProvider changesetDescriptionTrailers = new ChangesetDescriptionTrailerProvider();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnEmptyList() {
|
||||||
|
Changeset changeset = createChangeset("zaphod beeblebrox");
|
||||||
|
|
||||||
|
changesetDescriptionTrailers.createPreProcessor(REPOSITORY).process(changeset);
|
||||||
|
Collection<Trailer> trailers = changeset.getTrailers();
|
||||||
|
|
||||||
|
assertThat(trailers).isNotNull();
|
||||||
|
assertThat(trailers).isEmpty();
|
||||||
|
assertThat(changeset.getDescription()).isEqualTo("zaphod beeblebrox");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldConvertTrailerWithCoAuthors() {
|
||||||
|
Person person = createPerson("Arthur Dent", "dent@hitchhiker.org");
|
||||||
|
Changeset changeset = createChangeset("zaphod beeblebrox\n\nCo-authored-by: Arthur Dent <dent@hitchhiker.org>");
|
||||||
|
|
||||||
|
changesetDescriptionTrailers.createPreProcessor(REPOSITORY).process(changeset);
|
||||||
|
Collection<Trailer> trailers = changeset.getTrailers();
|
||||||
|
|
||||||
|
Trailer trailer = trailers.iterator().next();
|
||||||
|
assertThat(trailer.getTrailerType()).isEqualTo("Co-authored-by");
|
||||||
|
assertThat(trailer.getPerson()).isEqualTo(person);
|
||||||
|
assertThat(changeset.getDescription()).isEqualTo("zaphod beeblebrox\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldConvertTrailerWithReviewers() {
|
||||||
|
Person person = createPerson("Tricia McMillan", "trillian@hitchhiker.org");
|
||||||
|
Changeset changeset = createChangeset("zaphod beeblebrox\n\nReviewed-by: Tricia McMillan <trillian@hitchhiker.org>");
|
||||||
|
|
||||||
|
changesetDescriptionTrailers.createPreProcessor(REPOSITORY).process(changeset);
|
||||||
|
Collection<Trailer> trailers = changeset.getTrailers();
|
||||||
|
|
||||||
|
Trailer trailer = trailers.iterator().next();
|
||||||
|
|
||||||
|
assertThat(trailer.getTrailerType()).isEqualTo("Reviewed-by");
|
||||||
|
assertThat(trailer.getPerson()).isEqualTo(person);
|
||||||
|
assertThat(changeset.getDescription()).isEqualTo("zaphod beeblebrox\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
@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>");
|
||||||
|
|
||||||
|
changesetDescriptionTrailers.createPreProcessor(REPOSITORY).process(changeset);
|
||||||
|
Collection<Trailer> trailers = changeset.getTrailers();
|
||||||
|
|
||||||
|
Trailer trailer = trailers.iterator().next();
|
||||||
|
|
||||||
|
assertThat(trailer.getTrailerType()).isEqualTo("Signed-off-by");
|
||||||
|
assertThat(trailer.getPerson()).isEqualTo(person);
|
||||||
|
assertThat(changeset.getDescription()).isEqualTo("zaphod beeblebrox\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldConvertTrailerWithCommitter() {
|
||||||
|
Person person = createPerson("Tricia McMillan", "trillian@hitchhiker.org");
|
||||||
|
Changeset changeset = createChangeset("zaphod beeblebrox\n\nCommitted-by: Tricia McMillan <trillian@hitchhiker.org>");
|
||||||
|
|
||||||
|
changesetDescriptionTrailers.createPreProcessor(REPOSITORY).process(changeset);
|
||||||
|
Collection<Trailer> trailers = changeset.getTrailers();
|
||||||
|
|
||||||
|
Trailer trailer = trailers.iterator().next();
|
||||||
|
|
||||||
|
assertThat(trailer.getTrailerType()).isEqualTo("Committed-by");
|
||||||
|
assertThat(trailer.getPerson()).isEqualTo(person);
|
||||||
|
assertThat(changeset.getDescription()).isEqualTo("zaphod beeblebrox\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldConvertMixedTrailers() {
|
||||||
|
Changeset changeset = createChangeset("zaphod beeblebrox\n\n" +
|
||||||
|
"Committed-by: Tricia McMillan <trillian@hitchhiker.org>\n" +
|
||||||
|
"Signed-off-by: Artur Dent <dent@hitchhiker.org>");
|
||||||
|
|
||||||
|
changesetDescriptionTrailers.createPreProcessor(REPOSITORY).process(changeset);
|
||||||
|
Collection<Trailer> trailers = changeset.getTrailers();
|
||||||
|
|
||||||
|
Iterator<Trailer> trailerIterator = trailers.iterator();
|
||||||
|
Trailer firstTrailer = trailerIterator.next();
|
||||||
|
Trailer secondTrailer = trailerIterator.next();
|
||||||
|
|
||||||
|
assertThat(firstTrailer.getTrailerType()).isEqualTo("Committed-by");
|
||||||
|
assertThat(firstTrailer.getPerson())
|
||||||
|
.isEqualTo(createPerson("Tricia McMillan", "trillian@hitchhiker.org"));
|
||||||
|
|
||||||
|
assertThat(secondTrailer.getTrailerType()).isEqualTo("Signed-off-by");
|
||||||
|
assertThat(secondTrailer.getPerson())
|
||||||
|
.isEqualTo(createPerson("Artur Dent", "dent@hitchhiker.org"));
|
||||||
|
|
||||||
|
assertThat(changeset.getDescription()).isEqualTo("zaphod beeblebrox\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldNotTouchUnknownTrailers() {
|
||||||
|
String originalCommitMessage = "zaphod beeblebrox\n\n" +
|
||||||
|
"Some-strange-tag: Tricia McMillan <trillian@hitchhiker.org>";
|
||||||
|
Changeset changeset = createChangeset(originalCommitMessage);
|
||||||
|
|
||||||
|
changesetDescriptionTrailers.createPreProcessor(REPOSITORY).process(changeset);
|
||||||
|
Collection<Trailer> trailers = changeset.getTrailers();
|
||||||
|
|
||||||
|
assertThat(trailers).isEmpty();
|
||||||
|
assertThat(changeset.getDescription()).isEqualTo(originalCommitMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldIgnoreKnownTrailersWithIllegalNameFormat() {
|
||||||
|
String originalCommitMessage = "zaphod beeblebrox\n\n" +
|
||||||
|
"Committed-by: Tricia McMillan";
|
||||||
|
Changeset changeset = createChangeset(originalCommitMessage);
|
||||||
|
|
||||||
|
changesetDescriptionTrailers.createPreProcessor(REPOSITORY).process(changeset);
|
||||||
|
Collection<Trailer> trailers = changeset.getTrailers();
|
||||||
|
|
||||||
|
assertThat(trailers).isEmpty();
|
||||||
|
assertThat(changeset.getDescription()).isEqualTo(originalCommitMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Changeset createChangeset(String commitMessage) {
|
||||||
|
Changeset changeset = new Changeset();
|
||||||
|
changeset.setDescription(commitMessage);
|
||||||
|
return changeset;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Person createPerson(String name, String mail) {
|
||||||
|
return new Person(name, mail);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
/*
|
|
||||||
* MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package sonia.scm.api.v2.resources;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
|
||||||
import sonia.scm.repository.Changeset;
|
|
||||||
import sonia.scm.repository.Repository;
|
|
||||||
import sonia.scm.repository.RepositoryTestData;
|
|
||||||
import sonia.scm.repository.Trailer;
|
|
||||||
import sonia.scm.user.DisplayUser;
|
|
||||||
import sonia.scm.user.User;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
|
||||||
class ChangesetDescriptionTrailersTest {
|
|
||||||
|
|
||||||
private static final Repository REPOSITORY = RepositoryTestData.createHeartOfGold();
|
|
||||||
|
|
||||||
private final ChangesetDescriptionTrailerProvider changesetDescriptionTrailers = new ChangesetDescriptionTrailerProvider();
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void shouldReturnEmptyList() {
|
|
||||||
Changeset changeset = createChangeset("zaphod beeblebrox");
|
|
||||||
|
|
||||||
List<Trailer> trailer = changesetDescriptionTrailers.getTrailers(REPOSITORY, changeset);
|
|
||||||
|
|
||||||
assertThat(trailer).isNotNull();
|
|
||||||
assertThat(trailer).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void shouldReturnTrailerWithCoAuthors() {
|
|
||||||
DisplayUser displayUser = createDisplayUser("Arthur Dent", "dent@hitchhiker.org");
|
|
||||||
Changeset changeset = createChangeset("zaphod beeblebrox\n\nCo-authored-by: Arthur Dent <dent@hitchhiker.org>");
|
|
||||||
|
|
||||||
List<Trailer> Trailer = changesetDescriptionTrailers.getTrailers(REPOSITORY, changeset);
|
|
||||||
|
|
||||||
Trailer first = Trailer.get(0);
|
|
||||||
assertThat(first.getTrailerType()).isEqualTo("Co-authored-by");
|
|
||||||
assertThat(first.getPerson().getName()).isEqualTo(displayUser.getDisplayName());
|
|
||||||
assertThat(first.getPerson().getMail()).isEqualTo(displayUser.getMail());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void shouldReturnTrailerWithReviewers() {
|
|
||||||
DisplayUser displayUser = createDisplayUser("Tricia McMillan", "trillian@hitchhiker.org");
|
|
||||||
Changeset changeset = createChangeset("zaphod beeblebrox\nReviewed-by: Tricia McMillan <trillian@hitchhiker.org>");
|
|
||||||
|
|
||||||
List<Trailer> trailer = changesetDescriptionTrailers.getTrailers(REPOSITORY, changeset);
|
|
||||||
|
|
||||||
Trailer Trailer = trailer.get(0);
|
|
||||||
|
|
||||||
assertThat(Trailer.getTrailerType()).isEqualTo("Reviewed-by");
|
|
||||||
assertThat(Trailer.getPerson().getName()).isEqualTo(displayUser.getDisplayName());
|
|
||||||
assertThat(Trailer.getPerson().getMail()).isEqualTo(displayUser.getMail());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void shouldReturnTrailerWithSigner() {
|
|
||||||
DisplayUser displayUser = createDisplayUser("Tricia McMillan", "trillian@hitchhiker.org");
|
|
||||||
Changeset changeset = createChangeset("zaphod beeblebrox\nSigned-off-by: Tricia McMillan <trillian@hitchhiker.org>");
|
|
||||||
|
|
||||||
List<Trailer> trailer = changesetDescriptionTrailers.getTrailers(REPOSITORY, changeset);
|
|
||||||
|
|
||||||
Trailer Trailer = trailer.get(0);
|
|
||||||
|
|
||||||
assertThat(Trailer.getTrailerType()).isEqualTo("Signed-off-by");
|
|
||||||
assertThat(Trailer.getPerson().getName()).isEqualTo(displayUser.getDisplayName());
|
|
||||||
assertThat(Trailer.getPerson().getMail()).isEqualTo(displayUser.getMail());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void shouldReturnTrailerWithCommitter() {
|
|
||||||
DisplayUser displayUser = createDisplayUser("Tricia McMillan", "trillian@hitchhiker.org");
|
|
||||||
Changeset changeset = createChangeset("zaphod beeblebrox\nCommitted-by: Tricia McMillan <trillian@hitchhiker.org>");
|
|
||||||
|
|
||||||
List<Trailer> trailer = changesetDescriptionTrailers.getTrailers(REPOSITORY, changeset);
|
|
||||||
|
|
||||||
Trailer Trailer = trailer.get(0);
|
|
||||||
|
|
||||||
assertThat(Trailer.getTrailerType()).isEqualTo("Committed-by");
|
|
||||||
assertThat(Trailer.getPerson().getName()).isEqualTo(displayUser.getDisplayName());
|
|
||||||
assertThat(Trailer.getPerson().getMail()).isEqualTo(displayUser.getMail());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Changeset createChangeset(String commitMessage) {
|
|
||||||
Changeset changeset = new Changeset();
|
|
||||||
changeset.setDescription(commitMessage);
|
|
||||||
return changeset;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DisplayUser createDisplayUser(String name, String mail) {
|
|
||||||
return DisplayUser.from(new User(name, name, mail));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -43,7 +43,6 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import sonia.scm.repository.Changeset;
|
import sonia.scm.repository.Changeset;
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
import sonia.scm.repository.ChangesetTrailerProvider;
|
|
||||||
import sonia.scm.repository.NamespaceAndName;
|
import sonia.scm.repository.NamespaceAndName;
|
||||||
import sonia.scm.repository.Person;
|
import sonia.scm.repository.Person;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
@@ -57,7 +56,6 @@ import java.net.URI;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -87,9 +85,6 @@ public class ChangesetRootResourceTest extends RepositoryTestBase {
|
|||||||
@Mock
|
@Mock
|
||||||
private LogCommandBuilder logCommandBuilder;
|
private LogCommandBuilder logCommandBuilder;
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Set<ChangesetTrailerProvider> changesetTrailers;
|
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private ChangesetCollectionToDtoMapper changesetCollectionToDtoMapper;
|
private ChangesetCollectionToDtoMapper changesetCollectionToDtoMapper;
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ import sonia.scm.ContextEntry;
|
|||||||
import sonia.scm.NotFoundException;
|
import sonia.scm.NotFoundException;
|
||||||
import sonia.scm.repository.Changeset;
|
import sonia.scm.repository.Changeset;
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
import sonia.scm.repository.ChangesetTrailerProvider;
|
|
||||||
import sonia.scm.repository.InternalRepositoryException;
|
import sonia.scm.repository.InternalRepositoryException;
|
||||||
import sonia.scm.repository.NamespaceAndName;
|
import sonia.scm.repository.NamespaceAndName;
|
||||||
import sonia.scm.repository.Person;
|
import sonia.scm.repository.Person;
|
||||||
@@ -60,7 +59,6 @@ import java.net.URISyntaxException;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -91,9 +89,6 @@ public class FileHistoryResourceTest extends RepositoryTestBase {
|
|||||||
|
|
||||||
private FileHistoryCollectionToDtoMapper fileHistoryCollectionToDtoMapper;
|
private FileHistoryCollectionToDtoMapper fileHistoryCollectionToDtoMapper;
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Set<ChangesetTrailerProvider> changesetTrailers;
|
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private DefaultChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
private DefaultChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ import org.mockito.junit.MockitoJUnitRunner;
|
|||||||
import sonia.scm.NotFoundException;
|
import sonia.scm.NotFoundException;
|
||||||
import sonia.scm.repository.Changeset;
|
import sonia.scm.repository.Changeset;
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
import sonia.scm.repository.ChangesetTrailerProvider;
|
|
||||||
import sonia.scm.repository.NamespaceAndName;
|
import sonia.scm.repository.NamespaceAndName;
|
||||||
import sonia.scm.repository.Person;
|
import sonia.scm.repository.Person;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
@@ -65,7 +64,6 @@ import java.net.URISyntaxException;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -109,9 +107,6 @@ public class IncomingRootResourceTest extends RepositoryTestBase {
|
|||||||
|
|
||||||
private IncomingChangesetCollectionToDtoMapper incomingChangesetCollectionToDtoMapper;
|
private IncomingChangesetCollectionToDtoMapper incomingChangesetCollectionToDtoMapper;
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Set<ChangesetTrailerProvider> changesetTrailers;
|
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private DefaultChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
private DefaultChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user