The Unified and Autonomous Development Platform
Disregard order of "fixed between" criteria of issue query
Robin Shen1f3b9dd11b95
diff --git a/server-core/src/main/java/io/onedev/server/search/entity/issue/FixedBetweenCriteria.java b/server-core/src/main/java/io/onedev/server/search/entity/issue/FixedBetweenCriteria.javaindex 636c7b15b6..24361f4a76 100644--- a/server-core/src/main/java/io/onedev/server/search/entity/issue/FixedBetweenCriteria.java+++ b/server-core/src/main/java/io/onedev/server/search/entity/issue/FixedBetweenCriteria.java@@ -22,6 +22,7 @@ import org.eclipse.jgit.revwalk.RevWalk;import io.onedev.server.OneDev;import io.onedev.server.OneException;import io.onedev.server.entitymanager.IssueManager;+import io.onedev.server.git.GitUtils;import io.onedev.server.model.Build;import io.onedev.server.model.Issue;import io.onedev.server.model.Project;@@ -37,30 +38,31 @@ public class FixedBetweenCriteria extends IssueCriteria {private final Project project;- private final int sinceType;+ private final int firstType;- private final String sinceValue;+ private final String firstValue;- private final ObjectId sinceCommitId;+ private final ObjectId firstCommitId;- private final int untilType;+ private final int secondType;- private final String untilValue;+ private final String secondValue;- private final ObjectId untilCommitId;+ private final ObjectId secondCommitId;- public FixedBetweenCriteria(@Nullable Project project, int sinceType, String sinceValue, int untilType, String untilValue) {- this.sinceType = sinceType;- this.sinceValue = sinceValue;- this.untilType = untilType;- this.untilValue = untilValue;-- ProjectAwareCommitId since = getCommitId(project, sinceType, sinceValue);- ProjectAwareCommitId until = getCommitId(project, untilType, untilValue);- sinceCommitId = since.getCommitId();- untilCommitId = until.getCommitId();- if (since.getProject().equals(until.getProject())) {- this.project = since.getProject();+ public FixedBetweenCriteria(@Nullable Project project, int firstType, String firstValue,+ int secondType, String secondValue) {+ this.firstType = firstType;+ this.firstValue = firstValue;+ this.secondType = secondType;+ this.secondValue = secondValue;++ ProjectAwareCommitId first = getCommitId(project, firstType, firstValue);+ ProjectAwareCommitId second = getCommitId(project, secondType, secondValue);+ firstCommitId = first.getCommitId();+ secondCommitId = second.getCommitId();+ if (first.getProject().equals(second.getProject())) {+ this.project = first.getProject();} else {throw new OneException("'" + getRuleName(IssueQueryLexer.FixedBetween)+ "' should be used for same projects");@@ -81,15 +83,19 @@ public class FixedBetweenCriteria extends IssueCriteria {Set<Long> fixedIssueNumbers = new HashSet<>();Repository repository = project.getRepository();- try (RevWalk revWalk = new RevWalk(repository)) {- revWalk.markStart(revWalk.parseCommit(untilCommitId));- revWalk.markUninteresting(revWalk.parseCommit(sinceCommitId));-- RevCommit commit;- while ((commit = revWalk.next()) != null)- fixedIssueNumbers.addAll(IssueUtils.parseFixedIssues(project, commit.getFullMessage()));- } catch (IOException e) {- throw new RuntimeException(e);+ ObjectId mergeBaseId = GitUtils.getMergeBase(repository, firstCommitId, secondCommitId);+ if (mergeBaseId != null) {+ try (RevWalk revWalk = new RevWalk(repository)) {+ revWalk.markStart(revWalk.parseCommit(secondCommitId));+ revWalk.markStart(revWalk.parseCommit(firstCommitId));+ revWalk.markUninteresting(revWalk.parseCommit(mergeBaseId));++ RevCommit commit;+ while ((commit = revWalk.next()) != null)+ fixedIssueNumbers.addAll(IssueUtils.parseFixedIssues(project, commit.getFullMessage()));+ } catch (IOException e) {+ throw new RuntimeException(e);+ }}Predicate issuePredicate;@@ -109,22 +115,25 @@ public class FixedBetweenCriteria extends IssueCriteria {public boolean matches(Issue issue, User user) {if (project.equals(issue.getProject())) {Repository repository = issue.getProject().getRepository();- try (RevWalk revWalk = new RevWalk(repository)) {- revWalk.markStart(revWalk.parseCommit(untilCommitId));- revWalk.markUninteresting(revWalk.parseCommit(sinceCommitId));-- RevCommit commit;- while ((commit = revWalk.next()) != null) {- if (IssueUtils.parseFixedIssues(project, commit.getFullMessage()).contains(issue.getNumber()))- return true;+ ObjectId mergeBaseId = GitUtils.getMergeBase(repository, firstCommitId, secondCommitId);+ if (mergeBaseId != null) {+ try (RevWalk revWalk = new RevWalk(repository)) {+ revWalk.markStart(revWalk.parseCommit(secondCommitId));+ revWalk.markStart(revWalk.parseCommit(firstCommitId));+ revWalk.markUninteresting(revWalk.parseCommit(mergeBaseId));++ RevCommit commit;+ while ((commit = revWalk.next()) != null) {+ if (IssueUtils.parseFixedIssues(project, commit.getFullMessage()).contains(issue.getNumber()))+ return true;+ }+ return false;+ } catch (IOException e) {+ throw new RuntimeException(e);}- return false;- } catch (IOException e) {- throw new RuntimeException(e);- }- } else {- return false;+ }}+ return false;}@Override@@ -135,9 +144,9 @@ public class FixedBetweenCriteria extends IssueCriteria {@Overridepublic String toString() {return getRuleName(IssueQueryLexer.FixedBetween) + " "- + getRuleName(sinceType) + " " + quote(sinceValue) + " "+ + getRuleName(firstType) + " " + quote(firstValue) + " "+ getRuleName(IssueQueryLexer.And) + " "- + getRuleName(untilType) + " " + quote(untilValue);+ + getRuleName(secondType) + " " + quote(secondValue);}}diff --git a/server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQuery.java b/server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQuery.javaindex cc70665e79..e2cf20d784 100644--- a/server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQuery.java+++ b/server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQuery.java@@ -169,15 +169,15 @@ public class IssueQuery extends EntityQuery<Issue> {@Overridepublic IssueCriteria visitFixedBetweenCriteria(FixedBetweenCriteriaContext ctx) {- RevisionCriteriaContext sinceRevision = ctx.revisionCriteria(0);- int sinceType = sinceRevision.revisionType.getType();- String sinceValue = getValue(sinceRevision.Quoted().getText());+ RevisionCriteriaContext firstRevision = ctx.revisionCriteria(0);+ int firstType = firstRevision.revisionType.getType();+ String firstValue = getValue(firstRevision.Quoted().getText());- RevisionCriteriaContext untilRevision = ctx.revisionCriteria(1);- int untilType = untilRevision.revisionType.getType();- String untilValue = getValue(untilRevision.Quoted().getText());+ RevisionCriteriaContext secondRevision = ctx.revisionCriteria(1);+ int secondType = secondRevision.revisionType.getType();+ String secondValue = getValue(secondRevision.Quoted().getText());- return new FixedBetweenCriteria(project, sinceType, sinceValue, untilType, untilValue);+ return new FixedBetweenCriteria(project, firstType, firstValue, secondType, secondValue);}@Override