The Unified and Autonomous Development Platform
Make UserInfo serializable. Add skip parameter for log command.
robin shineeac1debe9220
diff --git a/commons.git/src/main/java/com/pmease/commons/git/Git.java b/commons.git/src/main/java/com/pmease/commons/git/Git.javaindex a34752264b..b34bf5d0d8 100644--- a/commons.git/src/main/java/com/pmease/commons/git/Git.java+++ b/commons.git/src/main/java/com/pmease/commons/git/Git.java@@ -106,7 +106,7 @@ public class Git implements Serializable {}public Commit showRevision(String revision) {- List<Commit> commits = new LogCommand(repoDir).toRev(revision).maxCommits(1).call();+ List<Commit> commits = new LogCommand(repoDir).toRev(revision).maxCount(1).call();Preconditions.checkState(commits.size() == 1);return commits.get(0);}@@ -280,13 +280,13 @@ public class Git implements Serializable {}public List<Commit> log(@Nullable String fromRev, @Nullable String toRev,- @Nullable String path, int maxCommits) {+ @Nullable String path, int maxCount, int skip) {return new LogCommand(repoDir).fromRev(fromRev).toRev(toRev)- .path(path).maxCommits(maxCommits).call();+ .path(path).maxCount(maxCount).skip(skip).call();}public Commit retrieveLastCommmit(String revision, @Nullable String path) {- return log(null, revision, path, 1).get(0);+ return log(null, revision, path, 1, 0).get(0);}/**diff --git a/commons.git/src/main/java/com/pmease/commons/git/UserInfo.java b/commons.git/src/main/java/com/pmease/commons/git/UserInfo.javaindex 1b08712672..72495b5a3e 100644--- a/commons.git/src/main/java/com/pmease/commons/git/UserInfo.java+++ b/commons.git/src/main/java/com/pmease/commons/git/UserInfo.java@@ -1,10 +1,12 @@package com.pmease.commons.git;+import java.io.Serializable;import java.util.Date;import com.google.common.base.Objects;-public class UserInfo {+@SuppressWarnings("serial")+public class UserInfo implements Serializable {private final String name;diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/LogCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/LogCommand.javaindex 64f818b9ac..4d09f7dfa1 100644--- a/commons.git/src/main/java/com/pmease/commons/git/command/LogCommand.java+++ b/commons.git/src/main/java/com/pmease/commons/git/command/LogCommand.java@@ -25,7 +25,9 @@ public class LogCommand extends GitCommand<List<Commit>> {private String path;- private int maxCommits;+ private int maxCount;++ private int skip;public LogCommand(File repoDir) {super(repoDir);@@ -46,11 +48,16 @@ public class LogCommand extends GitCommand<List<Commit>> {return this;}- public LogCommand maxCommits(int maxCommits) {- this.maxCommits = maxCommits;+ public LogCommand maxCount(int maxCount) {+ this.maxCount = maxCount;return this;}+ public LogCommand skip(int skip) {+ this.skip = skip;+ return this;+ }+@Overridepublic List<Commit> call() {Commandline cmd = cmd();@@ -69,8 +76,10 @@ public class LogCommand extends GitCommand<List<Commit>> {cmd.addArgs(toRev);}- if (maxCommits != 0)- cmd.addArgs("-" + maxCommits);+ if (maxCount != 0)+ cmd.addArgs("-" + maxCount);+ if (skip != 0)+ cmd.addArgs("--skip=" + skip);cmd.addArgs("--");if (path != null)diff --git a/commons.git/src/test/java/com/pmease/commons/git/command/LogCommandTest.java b/commons.git/src/test/java/com/pmease/commons/git/command/LogCommandTest.javaindex 3a388db9bd..ab330b6ed6 100644--- a/commons.git/src/test/java/com/pmease/commons/git/command/LogCommandTest.java+++ b/commons.git/src/test/java/com/pmease/commons/git/command/LogCommandTest.java@@ -59,7 +59,7 @@ public class LogCommandTest extends AbstractGitTest {bareGit.addNote("master", "hello\nworld");- List<Commit> commits = bareGit.log(null, "master", null, 0);+ List<Commit> commits = bareGit.log(null, "master", null, 0, 0);assertEquals(commits.size(), 6);assertEquals(commits.get(0).getSubject(), "add dir/file");assertEquals(commits.get(0).getMessage(), "add dir/file\n\nadd dir/file to test files under a directory");@@ -77,14 +77,14 @@ public class LogCommandTest extends AbstractGitTest {workGit.add("dir/file2").commit("add dir/file2", false, false);workGit.merge("dev", null, null, null);- commits = workGit.log(null, "master", null, 0);+ commits = workGit.log(null, "master", null, 0, 0);assertEquals(commits.get(0).getParentHashes().size(), 2);- commits = workGit.log(null, "master", "a", 0);+ commits = workGit.log(null, "master", "a", 0, 0);assertEquals(commits.size(), 3);- commits = workGit.log("dev", "master", "dir", 0);+ commits = workGit.log("dev", "master", "dir", 0, 0);assertEquals(commits.size(), 2);assertEquals(workGit.showRevision(commits.get(0).getHash()).getHash(), commits.get(0).getHash());@@ -120,7 +120,7 @@ public class LogCommandTest extends AbstractGitTest {git.add("b2");git.commit("move b to b2", false, false);- List<Commit> commits = git.log("master~3", "master", null, 0);+ List<Commit> commits = git.log("master~3", "master", null, 0, 0);FileChange change = commits.get(0).getFileChanges().get(0);assertEquals("RENAME\tb->b2", change.toString());change = commits.get(2).getFileChanges().get(1);diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranchPatterns.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranchPatterns.javaindex 6576df5f6a..6e00e4539e 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranchPatterns.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranchPatterns.java@@ -1,19 +1,11 @@package com.pmease.gitop.core.gatekeeper;-import javax.validation.constraints.NotNull;+import org.hibernate.validator.constraints.NotEmpty;import com.pmease.commons.editable.annotation.Editable;-import com.pmease.commons.loader.AppLoader;-import com.pmease.commons.util.namedentity.EntityLoader;-import com.pmease.commons.util.namedentity.EntityMatcher;-import com.pmease.commons.util.namedentity.EntityPatternSet;-import com.pmease.commons.util.pattern.PatternSetMatcher;-import com.pmease.commons.util.pattern.WildcardPathMatcher;-import com.pmease.gitop.core.manager.BranchManager;-import com.pmease.gitop.model.Project;+import com.pmease.commons.util.pattern.WildcardUtils;import com.pmease.gitop.model.PullRequest;import com.pmease.gitop.model.gatekeeper.BranchGateKeeper;-import com.pmease.gitop.model.gatekeeper.GateKeeper;import com.pmease.gitop.model.gatekeeper.checkresult.CheckResult;@SuppressWarnings("serial")@@ -23,8 +15,14 @@ public class IfSubmittedToSpecifiedBranchPatterns extends BranchGateKeeper {private String branchPatterns;- @Editable- @NotNull+ @Editable(name="Specify branch patterns to match. Below is some examples:"+ + "<ul>"+ + "<li><i>dev/*</i>: matches all branches directly under dev."+ + "<li><i>dev/**</i>: matches all branches under dev recursively."+ + "<li><i>**</i>: matches all branches."+ + "<li><i>**/bugfix</i>: matches all branches whose last segment is bugfix."+ + "<li><i>-dev/**, **</i>: matches all branches except those under dev.")+ @NotEmptypublic String getBranchPatterns() {return branchPatterns;}@@ -35,33 +33,10 @@ public class IfSubmittedToSpecifiedBranchPatterns extends BranchGateKeeper {@Overridepublic CheckResult doCheck(PullRequest request) {- Project project = request.getTarget().getProject();- BranchManager branchManager = AppLoader.getInstance(BranchManager.class);- EntityLoader entityLoader = branchManager.asEntityLoader(project);- EntityMatcher entityMatcher = new EntityMatcher(entityLoader, new WildcardPathMatcher());- PatternSetMatcher patternSetMatcher = new PatternSetMatcher(entityMatcher);-- EntityPatternSet patternSet = EntityPatternSet.fromStored(getBranchPatterns(), entityLoader);-- if (patternSetMatcher.matches(getBranchPatterns(), request.getTarget().getName()))- return accepted("Target branch matches pattern '" + patternSet + "'.");+ if (WildcardUtils.matchPath(getBranchPatterns(), request.getTarget().getName()))+ return accepted("Target branch matches pattern '" + branchPatterns + "'.");else- return rejected("Target branch does not match pattern '" + patternSet + "'.");- }-- @Override- protected GateKeeper trim(Project project) {- BranchManager branchManager = AppLoader.getInstance(BranchManager.class);- EntityLoader entityLoader = branchManager.asEntityLoader(project);- EntityPatternSet patternSet = EntityPatternSet.fromStored(getBranchPatterns(), entityLoader);- patternSet.trim(project);-- if (patternSet.getStored().isEmpty()) {- return null;- } else {- setBranchPatterns(patternSet.toString());- return this;- }+ return rejected("Target branch does not match pattern '" + branchPatterns + "'.");}}diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranches.java b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranches.javaindex 27ef6aa66d..7d34332c86 100644--- a/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranches.java+++ b/gitop.core/src/main/java/com/pmease/gitop/core/gatekeeper/IfSubmittedToSpecifiedBranches.java@@ -7,6 +7,8 @@ import java.util.List;import javax.validation.constraints.NotNull;import javax.validation.constraints.Size;+import org.apache.commons.lang3.StringUtils;+import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitop.core.Gitop;import com.pmease.gitop.core.editable.BranchChoice;@@ -38,11 +40,15 @@ public class IfSubmittedToSpecifiedBranches extends BranchGateKeeper {@Overridepublic CheckResult doCheck(PullRequest request) {- String reason = "Submitted to branch '" + request.getTarget().getName() + "'.";+ List<String> branchNames = new ArrayList<>();+ BranchManager branchManager = Gitop.getInstance(BranchManager.class);+ for (Long branchId: branchIds)+ branchNames.add(branchManager.load(branchId).getName());+if (branchIds.contains(request.getTarget().getId()))- return accepted(reason);+ return accepted("Target branch is one of '" + StringUtils.join(branchNames, ", ") + "'.");else- return rejected(reason);+ return rejected("Target branch is not one of '" + StringUtils.join(branchNames, ", ") + "'.");}@Overridediff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/SourceBlobPage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/SourceBlobPage.javaindex fbba6c3f27..2de6f4918f 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/SourceBlobPage.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/SourceBlobPage.java@@ -48,7 +48,7 @@ public class SourceBlobPage extends AbstractFilePage {protected Commit load() {Git git = getProject().code();List<String> paths = getPaths();- List<Commit> commits = git.log(null, getRevision(), Joiner.on("/").join(paths), 1);+ List<Commit> commits = git.log(null, getRevision(), Joiner.on("/").join(paths), 1, 0);return Iterables.getFirst(commits, null);}};@@ -58,7 +58,7 @@ public class SourceBlobPage extends AbstractFilePage {@Overrideprotected List<GitPerson> load() {Git git = getProject().code();- List<Commit> commits = git.log(null, getRevision(), getFilePath(), 0);+ List<Commit> commits = git.log(null, getRevision(), getFilePath(), 0, 0);Set<GitPerson> users = Sets.newHashSet();for (Commit each : commits) {GitPerson person = new GitPerson(each.getAuthor().getName(), each.getAuthor().getEmail());diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tree/SourceTreePanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tree/SourceTreePanel.javaindex 0784104017..e543d04b59 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tree/SourceTreePanel.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tree/SourceTreePanel.java@@ -56,7 +56,7 @@ public class SourceTreePanel extends AbstractSourcePagePanel {protected Commit load() {Git git = getProject().code();List<String> paths = getPaths();- List<Commit> commits = git.log(null, getRevision(), Joiner.on("/").join(paths), 1);+ List<Commit> commits = git.log(null, getRevision(), Joiner.on("/").join(paths), 1, 0);Commit c = Iterables.getFirst(commits, null);if (c == null) {throw new EntityNotFoundException("Unable to get commit for revision " + getRevision());diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/util/GitUtils.java b/gitop.web/src/main/java/com/pmease/gitop/web/util/GitUtils.javaindex a40a268509..8d17124dda 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/util/GitUtils.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/util/GitUtils.java@@ -57,7 +57,7 @@ public class GitUtils {}public static @Nullable Commit getLastCommit(Git git, String revision, String path) {- List<Commit> commits = git.log(null, revision, path, 1);+ List<Commit> commits = git.log(null, revision, path, 1, 0);return Iterables.getFirst(commits, null);}}