aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch
diff options
context:
space:
mode:
authorJanos Gyerik <janos.gyerik@sonarsource.com>2018-03-20 12:04:52 +0100
committerSonarTech <sonartech@sonarsource.com>2018-03-22 12:37:49 +0100
commit3f0ffe9d73d75508598e990e102b52300de2ec85 (patch)
tree265f47e77ad2296cb43771cb4e3c4fe762c25568 /sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch
parent82a1cb0b4a6ea692624b290b15080fdf7d1b475c (diff)
downloadsonarqube-3f0ffe9d73d75508598e990e102b52300de2ec85.tar.gz
sonarqube-3f0ffe9d73d75508598e990e102b52300de2ec85.zip
BRANCH-55 Fix bug with multiple pr with same branch name (#8)
* Add PullRequestInfo.analysisDate * When multiple PR by branch name, pick by the latest analysis date * Do not obfuscate ProjectPullRequestsLoaderImpl * Add test for pull request on pull request based on a non-main long branch
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectPullRequests.java16
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/PullRequestInfo.java16
2 files changed, 22 insertions, 10 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectPullRequests.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectPullRequests.java
index a9f4c2c3d07..f236faff0e0 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectPullRequests.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectPullRequests.java
@@ -21,6 +21,7 @@ package org.sonar.scanner.scan.branch;
import java.util.List;
import java.util.Map;
+import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
@@ -32,18 +33,23 @@ import javax.annotation.concurrent.Immutable;
@Immutable
public class ProjectPullRequests {
- private final Map<String, PullRequestInfo> pullRequestsById;
+ private final Map<String, PullRequestInfo> pullRequestsByBranchName;
- public ProjectPullRequests(List<PullRequestInfo> pullRequestsById) {
- this.pullRequestsById = pullRequestsById.stream().collect(Collectors.toMap(PullRequestInfo::getBranch, Function.identity()));
+ public ProjectPullRequests(List<PullRequestInfo> pullRequestInfos) {
+ BinaryOperator<PullRequestInfo> mergeFunction = pickMostRecentAnalysis();
+ this.pullRequestsByBranchName = pullRequestInfos.stream().collect(Collectors.toMap(PullRequestInfo::getBranch, Function.identity(), mergeFunction));
+ }
+
+ private static BinaryOperator<PullRequestInfo> pickMostRecentAnalysis() {
+ return (a, b) -> a.getAnalysisDate() < b.getAnalysisDate() ? b : a;
}
@CheckForNull
public PullRequestInfo get(String branch) {
- return pullRequestsById.get(branch);
+ return pullRequestsByBranchName.get(branch);
}
public boolean isEmpty() {
- return pullRequestsById.isEmpty();
+ return pullRequestsByBranchName.isEmpty();
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/PullRequestInfo.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/PullRequestInfo.java
index 6ccc3656fb5..ecbc48ec5de 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/PullRequestInfo.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/PullRequestInfo.java
@@ -28,18 +28,20 @@ import javax.annotation.concurrent.Immutable;
*/
@Immutable
public class PullRequestInfo {
- private final String id;
+ private final String key;
private final String branch;
private final String base;
+ private final long analysisDate;
- public PullRequestInfo(String id, String branch, @Nullable String base) {
- this.id = id;
+ public PullRequestInfo(String key, String branch, @Nullable String base, long analysisDate) {
+ this.key = key;
this.branch = branch;
this.base = base;
+ this.analysisDate = analysisDate;
}
- public String getId() {
- return id;
+ public String getKey() {
+ return key;
}
public String getBranch() {
@@ -50,4 +52,8 @@ public class PullRequestInfo {
public String getBase() {
return base;
}
+
+ public long getAnalysisDate() {
+ return analysisDate;
+ }
}