mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-01 00:19:44 +02:00
Compute trailers in changeset pre processing
Doing so, the trailers are available for other plugins inspecting changesets, not only for the frontend.
This commit is contained in:
@@ -31,6 +31,7 @@ import sonia.scm.util.Util;
|
||||
import sonia.scm.util.ValidationUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -79,6 +80,11 @@ public class Changeset extends BasicPropertiesAware implements ModelObject {
|
||||
*/
|
||||
private List<String> tags;
|
||||
|
||||
/**
|
||||
* Trailers for this changeset like reviewers or co-authors
|
||||
*/
|
||||
private Collection<Trailer> trailers;
|
||||
|
||||
public Changeset() {}
|
||||
|
||||
public Changeset(String id, Long date, Person author)
|
||||
@@ -225,6 +231,10 @@ public class Changeset extends BasicPropertiesAware implements ModelObject {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public Collection<Trailer> getTrailers() {
|
||||
return trailers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the changeset is valid.
|
||||
*
|
||||
@@ -300,4 +310,7 @@ public class Changeset extends BasicPropertiesAware implements ModelObject {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public void setTrailers(Collection<Trailer> trailers) {
|
||||
this.trailers = trailers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class ChangesetAuthor extends React.Component<Props> {
|
||||
}
|
||||
|
||||
getCoAuthorsFromChangeset() {
|
||||
return this.props.changeset.trailerPersons.filter(p => p.trailerType === "Co-authored-by");
|
||||
return this.props.changeset.trailers.filter(p => p.trailerType === "Co-authored-by").map(trailer => trailer.person);
|
||||
}
|
||||
|
||||
renderCoAuthors() {
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.mapstruct.MappingTarget;
|
||||
import org.mapstruct.ObjectFactory;
|
||||
import sonia.scm.repository.Branch;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetTrailerProvider;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.Tag;
|
||||
@@ -44,10 +43,8 @@ import sonia.scm.repository.api.RepositoryServiceFactory;
|
||||
import sonia.scm.web.EdisonHalAppender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -73,23 +70,10 @@ public abstract class DefaultChangesetToChangesetDtoMapper extends HalAppenderMa
|
||||
@Inject
|
||||
private TagCollectionToDtoMapper tagCollectionToDtoMapper;
|
||||
|
||||
@Inject
|
||||
private Set<ChangesetTrailerProvider> changesetTrailerProviderSet;
|
||||
|
||||
abstract TrailerDto map(Trailer trailer);
|
||||
|
||||
abstract PersonDto map(Person person);
|
||||
|
||||
@AfterMapping
|
||||
void appendTrailerPersons(Changeset changeset, @MappingTarget ChangesetDto target, @Context Repository repository) {
|
||||
List<TrailerDto> collectedTrailers = new ArrayList<>();
|
||||
changesetTrailerProviderSet.stream()
|
||||
.flatMap(changesetTrailers -> changesetTrailers.getTrailers(repository, changeset).stream())
|
||||
.map(this::map)
|
||||
.forEach(collectedTrailers::add);
|
||||
target.setTrailers(collectedTrailers);
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
void removeTrailerFromChangesetDescription(@MappingTarget ChangesetDto target) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
Reference in New Issue
Block a user