@Test
public void test_example() {
- ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("sonarqube"));
-
- ComponentDto longLivingBranch = db.components()
- .insertProjectBranch(project, b -> b.setKey("feature/bar").setBranchType(org.sonar.db.component.BranchType.LONG));
+ ComponentDto project = db.components().insertMainBranch(p -> p.setDbKey("sonarqube"));
db.getDbClient().snapshotDao().insert(db.getSession(),
- newAnalysis(longLivingBranch).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime()));
- db.measures().insertLiveMeasure(longLivingBranch, qualityGateStatus, m -> m.setData("OK"));
+ newAnalysis(project).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime()));
+ db.measures().insertLiveMeasure(project, qualityGateStatus, m -> m.setData("ERROR"));
ComponentDto shortLivingBranch = db.components()
- .insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(SHORT).setMergeBranchUuid(longLivingBranch.uuid()));
+ .insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(SHORT).setMergeBranchUuid(project.uuid()));
db.getDbClient().snapshotDao().insert(db.getSession(),
newAnalysis(shortLivingBranch).setLast(true).setCreatedAt(parseDateTime("2017-04-03T13:37:00+0100").getTime()));
db.measures().insertLiveMeasure(shortLivingBranch, qualityGateStatus, m -> m.setData("OK"));
@Test
public void test_with_SCAN_EXCUTION_permission() {
- ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("sonarqube"));
-
- ComponentDto longLivingBranch = db.components()
- .insertProjectBranch(project, b -> b.setKey("feature/bar").setBranchType(org.sonar.db.component.BranchType.LONG));
+ ComponentDto project = db.components().insertMainBranch(p -> p.setDbKey("sonarqube"));
db.getDbClient().snapshotDao().insert(db.getSession(),
- newAnalysis(longLivingBranch).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime()));
- db.measures().insertLiveMeasure(longLivingBranch, qualityGateStatus, m -> m.setData("OK"));
+ newAnalysis(project).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime()));
+ db.measures().insertLiveMeasure(project, qualityGateStatus, m -> m.setData("ERROR"));
ComponentDto shortLivingBranch = db.components()
- .insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(SHORT).setMergeBranchUuid(longLivingBranch.uuid()));
+ .insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(SHORT).setMergeBranchUuid(project.uuid()));
db.getDbClient().snapshotDao().insert(db.getSession(),
newAnalysis(shortLivingBranch).setLast(true).setCreatedAt(parseDateTime("2017-04-03T13:37:00+0100").getTime()));
db.measures().insertLiveMeasure(shortLivingBranch, qualityGateStatus, m -> m.setData("OK"));
*/
@Immutable
public class ProjectPullRequests {
-
+ private static final BinaryOperator<PullRequestInfo> PICK_MOST_RECENT_ANALYSIS = (a, b) -> a.getAnalysisDate() < b.getAnalysisDate() ? b : a;
private final Map<String, PullRequestInfo> pullRequestsByBranchName;
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;
+ this.pullRequestsByBranchName = pullRequestInfos.stream().collect(Collectors.toMap(PullRequestInfo::getBranch, Function.identity(), PICK_MOST_RECENT_ANALYSIS));
}
@CheckForNull