Fix minor issues

This commit is contained in:
René Pfeuffer
2020-12-01 18:10:38 +01:00
parent f5106e864d
commit 121e7bd638
4 changed files with 86 additions and 39 deletions

View File

@@ -35,7 +35,6 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevWalk;
import sonia.scm.NotFoundException;
import sonia.scm.event.ScmEventBus;
import sonia.scm.repository.GitUtil;
import sonia.scm.repository.InternalRepositoryException;
@@ -62,6 +61,8 @@ import java.util.Set;
import static java.util.Collections.emptyList;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static sonia.scm.ContextEntry.ContextBuilder.entity;
import static sonia.scm.NotFoundException.notFound;
public class GitTagCommand extends AbstractGitCommand implements TagCommand {
private final GPG gpg;
@@ -97,7 +98,7 @@ public class GitTagCommand extends AbstractGitCommand implements TagCommand {
ObjectId taggedCommitObjectId = git.getRepository().resolve(revision);
if (taggedCommitObjectId == null) {
throw new NotFoundException("revision", revision);
throw notFound(entity("revision", revision).in(repository));
}
try (RevWalk walk = new RevWalk(git.getRepository())) {
@@ -179,46 +180,46 @@ public class GitTagCommand extends AbstractGitCommand implements TagCommand {
return new RepositoryHookEvent(context, this.context.getRepository(), RepositoryHookType.PRE_RECEIVE);
}
private static class TagHookContextProvider extends HookContextProvider {
private final List<Tag> newTags;
private final List<Tag> deletedTags;
private static class TagHookContextProvider extends HookContextProvider {
private final List<Tag> newTags;
private final List<Tag> deletedTags;
private TagHookContextProvider(List<Tag> newTags, List<Tag> deletedTags) {
this.newTags = newTags;
this.deletedTags = deletedTags;
}
private TagHookContextProvider(List<Tag> newTags, List<Tag> deletedTags) {
this.newTags = newTags;
this.deletedTags = deletedTags;
}
static TagHookContextProvider createHookEvent(Tag newTag) {
return new TagHookContextProvider(singletonList(newTag), emptyList());
}
static TagHookContextProvider createHookEvent(Tag newTag) {
return new TagHookContextProvider(singletonList(newTag), emptyList());
}
static TagHookContextProvider deleteHookEvent(Tag deletedTag) {
return new TagHookContextProvider(emptyList(), singletonList(deletedTag));
}
static TagHookContextProvider deleteHookEvent(Tag deletedTag) {
return new TagHookContextProvider(emptyList(), singletonList(deletedTag));
}
@Override
public Set<HookFeature> getSupportedFeatures() {
return singleton(HookFeature.TAG_PROVIDER);
}
@Override
public Set<HookFeature> getSupportedFeatures() {
return singleton(HookFeature.TAG_PROVIDER);
}
@Override
public HookTagProvider getTagProvider() {
return new HookTagProvider() {
@Override
public List<Tag> getCreatedTags() {
return newTags;
}
@Override
public HookTagProvider getTagProvider() {
return new HookTagProvider() {
@Override
public List<Tag> getCreatedTags() {
return newTags;
}
@Override
public List<Tag> getDeletedTags() {
return deletedTags;
}
};
}
@Override
public List<Tag> getDeletedTags() {
return deletedTags;
}
};
}
@Override
public HookChangesetProvider getChangesetProvider() {
return r -> new HookChangesetResponse(emptyList());
@Override
public HookChangesetProvider getChangesetProvider() {
return r -> new HookChangesetResponse(emptyList());
}
}
}
}

View File

@@ -43,6 +43,8 @@ import java.nio.file.Path;
import java.util.List;
import java.util.regex.Pattern;
import static sonia.scm.repository.spi.UserFormatter.getUserStringFor;
@SuppressWarnings("java:S3252") // it is ok for javahg classes to access static method of subtype
public class HgModifyCommand implements ModifyCommand {
@@ -110,7 +112,7 @@ public class HgModifyCommand implements ModifyCommand {
LOG.trace("commit changes in working copy");
CommitCommand.on(workingRepository)
.user(String.format("%s <%s>", request.getAuthor().getName(), request.getAuthor().getMail()))
.user(getUserStringFor(request.getAuthor()))
.message(request.getCommitMessage()).execute();
List<Changeset> execute = pullModifyChangesToCentralRepository(request, workingCopy);

View File

@@ -33,9 +33,12 @@ import sonia.scm.repository.Tag;
import sonia.scm.repository.api.TagCreateRequest;
import sonia.scm.repository.api.TagDeleteRequest;
import sonia.scm.repository.work.WorkingCopy;
import sonia.scm.user.User;
import java.io.IOException;
import static sonia.scm.repository.spi.UserFormatter.getUserStringFor;
public class HgTagCommand extends AbstractCommand implements TagCommand {
public static final String DEFAULT_BRANCH_NAME = "default";
@@ -56,7 +59,7 @@ public class HgTagCommand extends AbstractCommand implements TagCommand {
}
com.aragost.javahg.commands.TagCommand.on(workingCopy.getWorkingRepository())
.rev(rev)
.user(SecurityUtils.getSubject().getPrincipal().toString())
.user(getUserStringFor(SecurityUtils.getSubject().getPrincipals().oneByType(User.class)))
.execute(request.getName());
pullChangesIntoCentralRepository(workingCopy, DEFAULT_BRANCH_NAME);
return new Tag(request.getName(), rev);
@@ -67,7 +70,7 @@ public class HgTagCommand extends AbstractCommand implements TagCommand {
public void delete(TagDeleteRequest request) {
try (WorkingCopy<Repository, Repository> workingCopy = workingCopyFactory.createWorkingCopy(getContext(), DEFAULT_BRANCH_NAME)) {
com.aragost.javahg.commands.TagCommand.on(workingCopy.getWorkingRepository())
.user(SecurityUtils.getSubject().getPrincipal().toString())
.user(getUserStringFor(SecurityUtils.getSubject().getPrincipals().oneByType(User.class)))
.remove()
.execute(request.getName());

View File

@@ -0,0 +1,41 @@
/*
* 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.spi;
import sonia.scm.repository.Person;
import sonia.scm.user.User;
final class UserFormatter {
private UserFormatter() {
}
static String getUserStringFor(User user) {
return getUserStringFor(new Person(user.getName(), user.getMail()));
}
static String getUserStringFor(Person person) {
return String.format("%s <%s>", person.getName(), person.getMail());
}
}