mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-04 13:49:14 +02:00
Enhance contributor API (#1966)
This adds a core API to handle contributors in changesets for plugins.
This commit is contained in:
@@ -24,20 +24,14 @@
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import sonia.scm.plugin.Extension;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.Scanner;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Extension
|
||||
public class ChangesetDescriptionContributorProvider implements ChangesetPreProcessorFactory {
|
||||
|
||||
private static final Collection<String> SUPPORTED_CONTRIBUTOR_TYPES = ImmutableSet.of("Co-authored-by", "Reviewed-by", "Signed-off-by", "Committed-by");
|
||||
private static final Pattern CONTRIBUTOR_PATTERN = Pattern.compile("^([\\w-]*):\\W*(.*)\\W+<(.*)>\\W*$");
|
||||
|
||||
@Override
|
||||
public ChangesetPreProcessor createPreProcessor(Repository repository) {
|
||||
return new ContributorChangesetPreProcessor();
|
||||
@@ -82,17 +76,13 @@ public class ChangesetDescriptionContributorProvider implements ChangesetPreProc
|
||||
}
|
||||
|
||||
private boolean checkForContributor(String line) {
|
||||
Matcher matcher = CONTRIBUTOR_PATTERN.matcher(line);
|
||||
if (matcher.matches()) {
|
||||
String type = matcher.group(1);
|
||||
String name = matcher.group(2);
|
||||
String mail = matcher.group(3);
|
||||
if (SUPPORTED_CONTRIBUTOR_TYPES.contains(type)) {
|
||||
createContributor(type, name, mail);
|
||||
return true;
|
||||
}
|
||||
Optional<Contributor> contributor = Contributor.fromCommitLine(line);
|
||||
if (contributor.isPresent()) {
|
||||
changeset.addContributor(contributor.get());
|
||||
return true;
|
||||
} else{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handleEmptyLine(Scanner scanner, String line) {
|
||||
@@ -106,9 +96,5 @@ public class ChangesetDescriptionContributorProvider implements ChangesetPreProc
|
||||
newDescription.append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
private void createContributor(String type, String name, String mail) {
|
||||
changeset.addContributor(new Contributor(type, new Person(name, mail)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user