mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25: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:
@@ -44,7 +44,6 @@ import sonia.scm.repository.Branch;
|
||||
import sonia.scm.repository.Branches;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.ChangesetTrailerProvider;
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.repository.Repository;
|
||||
@@ -115,10 +114,6 @@ public class BranchRootResourceTest extends RepositoryTestBase {
|
||||
@Mock
|
||||
private TagCollectionToDtoMapper tagCollectionToDtoMapper;
|
||||
|
||||
@Mock
|
||||
private Set<ChangesetTrailerProvider> changesetTrailers;
|
||||
|
||||
|
||||
@InjectMocks
|
||||
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 sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.ChangesetTrailerProvider;
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.repository.Repository;
|
||||
@@ -57,7 +56,6 @@ import java.net.URI;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -87,9 +85,6 @@ public class ChangesetRootResourceTest extends RepositoryTestBase {
|
||||
@Mock
|
||||
private LogCommandBuilder logCommandBuilder;
|
||||
|
||||
@Mock
|
||||
private Set<ChangesetTrailerProvider> changesetTrailers;
|
||||
|
||||
@InjectMocks
|
||||
private ChangesetCollectionToDtoMapper changesetCollectionToDtoMapper;
|
||||
|
||||
|
||||
@@ -44,7 +44,6 @@ import sonia.scm.ContextEntry;
|
||||
import sonia.scm.NotFoundException;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.ChangesetTrailerProvider;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.Person;
|
||||
@@ -60,7 +59,6 @@ import java.net.URISyntaxException;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -91,9 +89,6 @@ public class FileHistoryResourceTest extends RepositoryTestBase {
|
||||
|
||||
private FileHistoryCollectionToDtoMapper fileHistoryCollectionToDtoMapper;
|
||||
|
||||
@Mock
|
||||
private Set<ChangesetTrailerProvider> changesetTrailers;
|
||||
|
||||
@InjectMocks
|
||||
private DefaultChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.NotFoundException;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.ChangesetTrailerProvider;
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.repository.Repository;
|
||||
@@ -65,7 +64,6 @@ import java.net.URISyntaxException;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -109,9 +107,6 @@ public class IncomingRootResourceTest extends RepositoryTestBase {
|
||||
|
||||
private IncomingChangesetCollectionToDtoMapper incomingChangesetCollectionToDtoMapper;
|
||||
|
||||
@Mock
|
||||
private Set<ChangesetTrailerProvider> changesetTrailers;
|
||||
|
||||
@InjectMocks
|
||||
private DefaultChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user