The Unified and Autonomous Development Platform
Use last target/source to create new pull request
robin shineee948aa34dca
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequest.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequest.javaindex 5a41bc3291..54473c517b 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequest.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequest.java@@ -350,8 +350,13 @@ public class PullRequest extends AbstractEntity {this.sourceBranch = sourceBranch;}+ @Nullablepublic DepotAndBranch getSource() {- return new DepotAndBranch(getSourceDepot(), getSourceBranch());+ Depot sourceDepot = getSourceDepot();+ if (sourceDepot != null)+ return new DepotAndBranch(sourceDepot, getSourceBranch());+ else+ return null;}public String getTargetRef() {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestManager.javaindex 42f6e3e3b0..09185b9a8b 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestManager.java@@ -6,6 +6,7 @@ import java.util.List;import javax.annotation.Nullable;import com.pmease.commons.hibernate.dao.EntityManager;+import com.pmease.gitplex.core.entity.Account;import com.pmease.gitplex.core.entity.Depot;import com.pmease.gitplex.core.entity.PullRequest;import com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy;@@ -28,6 +29,9 @@ public interface PullRequestManager extends EntityManager<PullRequest> {@NullablePullRequest find(String uuid);++ @Nullable+ PullRequest findLatest(Depot depot, Account submitter);/*** Integrate specified pull request.@@ -76,4 +80,5 @@ public interface PullRequestManager extends EntityManager<PullRequest> {void restoreSourceBranch(PullRequest request, @Nullable String note);int countOpen(Depot depot);+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.javaindex 1bc89ba5e4..1e4cd219ed 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java@@ -1,8 +1,6 @@package com.pmease.gitplex.core.manager.impl;-import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.ofOpen;-import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.ofSource;-import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.ofTarget;+import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.*;import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.MERGE_ALWAYS;import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.MERGE_IF_NECESSARY;import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.MERGE_WITH_SQUASH;@@ -35,6 +33,7 @@ import org.eclipse.jgit.revwalk.RevWalk;import org.eclipse.jgit.transport.RefSpec;import org.hibernate.Query;import org.hibernate.criterion.Criterion;+import org.hibernate.criterion.Order;import org.hibernate.criterion.Restrictions;import org.hibernate.resource.transaction.spi.TransactionStatus;import org.slf4j.Logger;@@ -621,7 +620,18 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequestreturn find(EntityCriteria.of(PullRequest.class).add(ofTarget(target)).add(ofSource(source)).add(ofOpen()));}-++ @Sessional+ @Override+ public PullRequest findLatest(Depot depot, Account submitter) {+ EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);+ criteria.add(ofOpen());+ criteria.add(Restrictions.or(ofSourceDepot(depot), ofTargetDepot(depot)));+ criteria.add(ofSubmitter(submitter));+ criteria.addOrder(Order.desc("id"));+ return find(criteria);+ }+@Sessional@Overridepublic Collection<PullRequest> findAllOpenTo(DepotAndBranch target, @Nullable Depot sourceDepot) {@@ -748,5 +758,5 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequestunitOfWork.doAsync(newCheckRunnable(requestId, subject));}}-+}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.javaindex 6474b8cc05..d49fc4f620 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java@@ -116,10 +116,20 @@ public class NewRequestPage extends PullRequestPage implements CommentSupport {if (getDepot().getDefaultBranch() == null)throw new RestartResponseException(NoBranchesPage.class, paramsOf(getDepot()));- if (params.get("target").toString() != null) {- target = new DepotAndBranch(params.get("target").toString());+ Account currentUser = getLoginUser();+ if (currentUser == null)+ throw new RestartResponseAtInterceptPageException(LoginPage.class);++ PullRequest prevRequest = null;+ String targetParam = params.get("target").toString();+ String sourceParam = params.get("source").toString();+ if (targetParam != null) {+ target = new DepotAndBranch(targetParam);} else {- if (getDepot().getForkedFrom() != null) {+ prevRequest = GitPlex.getInstance(PullRequestManager.class).findLatest(getDepot(), getLoginUser());+ if (prevRequest != null && prevRequest.getTarget().getObjectId(false) != null) {+ target = prevRequest.getTarget();+ } else if (getDepot().getForkedFrom() != null) {target = new DepotAndBranch(getDepot().getForkedFrom(),getDepot().getForkedFrom().getDefaultBranch());} else {@@ -127,21 +137,25 @@ public class NewRequestPage extends PullRequestPage implements CommentSupport {}}- if (params.get("source").toString() != null) {- source = new DepotAndBranch(params.get("source").toString());+ if (sourceParam != null) {+ source = new DepotAndBranch(sourceParam);} else {- if (getDepot().getForkedFrom() != null) {+ if (prevRequest == null)+ prevRequest = GitPlex.getInstance(PullRequestManager.class).findLatest(getDepot(), getLoginUser());+ if (prevRequest != null && prevRequest.getSource().getObjectId(false) != null) {+ source = prevRequest.getSource();+ } else if (getDepot().getForkedFrom() != null) {source = new DepotAndBranch(getDepot(), getDepot().getDefaultBranch());} else {source = new DepotAndBranch(getDepot(), getDepot().getDefaultBranch());}}- Account currentUser = getLoginUser();- if (currentUser == null)- throw new RestartResponseAtInterceptPageException(LoginPage.class);-- PullRequest pullRequest = GitPlex.getInstance(PullRequestManager.class).findOpen(target, source);+ PullRequest pullRequest;+ if (prevRequest != null && source.equals(prevRequest.getSource()) && target.equals(prevRequest.getTarget()) && prevRequest.isOpen())+ pullRequest = prevRequest;+ else+ pullRequest = GitPlex.getInstance(PullRequestManager.class).findOpen(target, source);if (pullRequest == null) {pullRequest = new PullRequest();