@@ -86,7 +86,7 @@ public class MeasureSensor implements Sensor { | |||
private void saveMeasure(SensorContext context, InputComponent component, String metricKey, String value) { | |||
org.sonar.api.batch.measure.Metric<Serializable> metric = metricFinder.findByKey(metricKey); | |||
if (metric == null) { | |||
throw new IllegalStateException("Unknow metric with key: " + metricKey); | |||
throw new IllegalStateException("Unknown metric with key: " + metricKey); | |||
} | |||
NewMeasure<Serializable> newMeasure = context.newMeasure() | |||
.forMetric(metric) |
@@ -70,22 +70,6 @@ public interface AnalysisMetadataHolder { | |||
@CheckForNull | |||
Analysis getBaseAnalysis(); | |||
/** | |||
* Convenience method equivalent to do the check using {@link #getBranch()} | |||
* | |||
* @throws IllegalStateException if branch has not been set | |||
*/ | |||
boolean isShortLivingBranch(); | |||
/** | |||
* Convenience method equivalent to do the check using {@link #getBranch()} | |||
* | |||
* @throws IllegalStateException if branch has not been set | |||
*/ | |||
default boolean isSLBorPR() { | |||
return isShortLivingBranch() || isPullRequest(); | |||
} | |||
/** | |||
* Convenience method equivalent to do the check using {@link #getBranch()} | |||
* |
@@ -246,13 +246,6 @@ public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder | |||
return Optional.ofNullable(scmRevision.getProperty()); | |||
} | |||
@Override | |||
public boolean isShortLivingBranch() { | |||
checkState(this.branch.isInitialized(), BRANCH_NOT_SET); | |||
Branch prop = branch.getProperty(); | |||
return prop != null && prop.getType() == BranchType.SHORT; | |||
} | |||
@Override | |||
public boolean isLongLivingBranch() { | |||
checkState(this.branch.isInitialized(), BRANCH_NOT_SET); |
@@ -67,7 +67,7 @@ public class MergeAndTargetBranchComponentUuids { | |||
initForMergeBranch(mergeBranchUuid, dbSession); | |||
if (analysisMetadataHolder.isSLBorPR()) { | |||
if (analysisMetadataHolder.isPullRequest()) { | |||
initForTargetBranch(mergeBranchUuid, dbSession); | |||
} else { | |||
hasTargetBranchAnalysis = false; |
@@ -50,18 +50,17 @@ public class SiblingComponentsWithOpenIssues { | |||
private void loadUuidsByKey() { | |||
String currentBranchUuid = treeRootHolder.getRoot().getUuid(); | |||
String longLivingReferenceBranchUuid; | |||
String referenceBranchUuid; | |||
if (metadataHolder.isSLBorPR()) { | |||
longLivingReferenceBranchUuid = metadataHolder.getBranch().getMergeBranchUuid(); | |||
if (metadataHolder.isPullRequest()) { | |||
referenceBranchUuid = metadataHolder.getBranch().getMergeBranchUuid(); | |||
} else { | |||
longLivingReferenceBranchUuid = currentBranchUuid; | |||
referenceBranchUuid = currentBranchUuid; | |||
} | |||
uuidsByKey = new HashMap<>(); | |||
try (DbSession dbSession = dbClient.openSession(false)) { | |||
List<KeyWithUuidDto> components = dbClient.componentDao().selectAllSiblingComponentKeysHavingOpenIssues(dbSession, | |||
longLivingReferenceBranchUuid, currentBranchUuid); | |||
List<KeyWithUuidDto> components = dbClient.componentDao().selectAllSiblingComponentKeysHavingOpenIssues(dbSession, referenceBranchUuid, currentBranchUuid); | |||
for (KeyWithUuidDto dto : components) { | |||
uuidsByKey.computeIfAbsent(removeBranchAndPullRequestFromKey(dto.key()), s -> new HashSet<>()).add(dto.uuid()); | |||
} |
@@ -77,7 +77,7 @@ import org.sonar.ce.task.projectanalysis.issue.RuleRepositoryImpl; | |||
import org.sonar.ce.task.projectanalysis.issue.RuleTagsCopier; | |||
import org.sonar.ce.task.projectanalysis.issue.ScmAccountToUser; | |||
import org.sonar.ce.task.projectanalysis.issue.ScmAccountToUserLoader; | |||
import org.sonar.ce.task.projectanalysis.issue.ShortBranchOrPullRequestTrackerExecution; | |||
import org.sonar.ce.task.projectanalysis.issue.PullRequestTrackerExecution; | |||
import org.sonar.ce.task.projectanalysis.issue.SiblingsIssueMerger; | |||
import org.sonar.ce.task.projectanalysis.issue.SiblingsIssuesLoader; | |||
import org.sonar.ce.task.projectanalysis.issue.TrackerBaseInputFactory; | |||
@@ -278,7 +278,7 @@ public final class ProjectAnalysisTaskContainerPopulator implements ContainerPop | |||
ClosedIssuesInputFactory.class, | |||
Tracker.class, | |||
TrackerExecution.class, | |||
ShortBranchOrPullRequestTrackerExecution.class, | |||
PullRequestTrackerExecution.class, | |||
MergeBranchTrackerExecution.class, | |||
ComponentIssuesLoader.class, | |||
BaseIssuesLoader.class, |
@@ -149,7 +149,7 @@ public class IssueCounter extends IssueVisitor { | |||
@Override | |||
public void onIssue(Component component, DefaultIssue issue) { | |||
currentCounters.add(issue); | |||
if (analysisMetadataHolder.isSLBorPR()) { | |||
if (analysisMetadataHolder.isPullRequest()) { | |||
currentCounters.addOnPeriod(issue); | |||
} else if (periodHolder.hasPeriod()) { | |||
Period period = periodHolder.getPeriod(); | |||
@@ -197,7 +197,7 @@ public class IssueCounter extends IssueVisitor { | |||
} | |||
private void addNewMeasures(Component component) { | |||
if (!periodHolder.hasPeriod() && !analysisMetadataHolder.isSLBorPR()) { | |||
if (!periodHolder.hasPeriod() && !analysisMetadataHolder.isPullRequest()) { | |||
return; | |||
} | |||
double unresolvedVariations = (double) currentCounters.counterForPeriod().unresolved; |
@@ -30,22 +30,22 @@ import org.sonar.db.component.BranchType; | |||
import static java.util.Collections.emptyMap; | |||
public class IssueTrackingDelegator { | |||
private final ShortBranchOrPullRequestTrackerExecution shortBranchOrPullRequestTracker; | |||
private final PullRequestTrackerExecution pullRequestTracker; | |||
private final TrackerExecution tracker; | |||
private final AnalysisMetadataHolder analysisMetadataHolder; | |||
private final MergeBranchTrackerExecution mergeBranchTracker; | |||
public IssueTrackingDelegator(ShortBranchOrPullRequestTrackerExecution shortBranchOrPullRequestTracker, MergeBranchTrackerExecution longBranchTracker, | |||
public IssueTrackingDelegator(PullRequestTrackerExecution pullRequestTracker, MergeBranchTrackerExecution longBranchTracker, | |||
TrackerExecution tracker, AnalysisMetadataHolder analysisMetadataHolder) { | |||
this.shortBranchOrPullRequestTracker = shortBranchOrPullRequestTracker; | |||
this.pullRequestTracker = pullRequestTracker; | |||
this.mergeBranchTracker = longBranchTracker; | |||
this.tracker = tracker; | |||
this.analysisMetadataHolder = analysisMetadataHolder; | |||
} | |||
public TrackingResult track(Component component) { | |||
if (analysisMetadataHolder.isSLBorPR()) { | |||
return standardResult(shortBranchOrPullRequestTracker.track(component)); | |||
if (analysisMetadataHolder.isPullRequest()) { | |||
return standardResult(pullRequestTracker.track(component)); | |||
} else if (isFirstAnalysisSecondaryLongLivingBranch()) { | |||
Tracking<DefaultIssue, DefaultIssue> tracking = mergeBranchTracker.track(component); | |||
return new TrackingResult(tracking.getMatchedRaws(), emptyMap(), Stream.empty(), tracking.getUnmatchedRaws()); |
@@ -81,7 +81,7 @@ public class NewEffortAggregator extends IssueVisitor { | |||
@Override | |||
public void onIssue(Component component, DefaultIssue issue) { | |||
if (issue.resolution() == null && issue.effortInMinutes() != null) { | |||
if (analysisMetadataHolder.isSLBorPR()) { | |||
if (analysisMetadataHolder.isPullRequest()) { | |||
counter.add(issue, 0L); | |||
} else if (periodHolder.hasPeriod()) { | |||
counter.add(issue, periodHolder.getPeriod().getSnapshotDate()); | |||
@@ -91,7 +91,7 @@ public class NewEffortAggregator extends IssueVisitor { | |||
@Override | |||
public void afterComponent(Component component) { | |||
if (periodHolder.hasPeriod() || analysisMetadataHolder.isSLBorPR()) { | |||
if (periodHolder.hasPeriod() || analysisMetadataHolder.isPullRequest()) { | |||
computeMeasure(component, newMaintainabilityEffortMetric, counter.maintainabilitySum); | |||
computeMeasure(component, newReliabilityEffortMetric, counter.reliabilitySum); | |||
computeMeasure(component, newSecurityEffortMetric, counter.securitySum); |
@@ -33,14 +33,14 @@ import org.sonar.core.issue.tracking.Tracker; | |||
import org.sonar.core.issue.tracking.Tracking; | |||
import org.sonar.core.util.stream.MoreCollectors; | |||
public class ShortBranchOrPullRequestTrackerExecution { | |||
public class PullRequestTrackerExecution { | |||
private final TrackerBaseInputFactory baseInputFactory; | |||
private final TrackerRawInputFactory rawInputFactory; | |||
private final TrackerMergeOrTargetBranchInputFactory mergeInputFactory; | |||
private final Tracker<DefaultIssue, DefaultIssue> tracker; | |||
private final NewLinesRepository newLinesRepository; | |||
public ShortBranchOrPullRequestTrackerExecution(TrackerBaseInputFactory baseInputFactory, TrackerRawInputFactory rawInputFactory, | |||
public PullRequestTrackerExecution(TrackerBaseInputFactory baseInputFactory, TrackerRawInputFactory rawInputFactory, | |||
TrackerMergeOrTargetBranchInputFactory mergeInputFactory, Tracker<DefaultIssue, DefaultIssue> tracker, NewLinesRepository newLinesRepository) { | |||
this.baseInputFactory = baseInputFactory; | |||
this.rawInputFactory = rawInputFactory; |
@@ -106,7 +106,7 @@ public class NewReliabilityAndSecurityRatingMeasuresVisitor extends PathAwareVis | |||
} | |||
private void computeAndSaveMeasures(Component component, Path<Counter> path) { | |||
if (!periodHolder.hasPeriod() && !analysisMetadataHolder.isSLBorPR()) { | |||
if (!periodHolder.hasPeriod() && !analysisMetadataHolder.isPullRequest()) { | |||
return; | |||
} | |||
initRatingsToA(path); | |||
@@ -131,7 +131,7 @@ public class NewReliabilityAndSecurityRatingMeasuresVisitor extends PathAwareVis | |||
.stream() | |||
.filter(issue -> issue.resolution() == null) | |||
.filter(issue -> issue.type().equals(BUG) || issue.type().equals(VULNERABILITY)) | |||
.forEach(issue -> path.current().processIssue(issue, analysisMetadataHolder.isSLBorPR(), periodHolder)); | |||
.forEach(issue -> path.current().processIssue(issue, analysisMetadataHolder.isPullRequest(), periodHolder)); | |||
} | |||
private static void addToParent(Path<Counter> path) { | |||
@@ -153,8 +153,8 @@ public class NewReliabilityAndSecurityRatingMeasuresVisitor extends PathAwareVis | |||
newRatingValueByMetric.forEach((metric, rating) -> rating.increment(otherCounter.newRatingValueByMetric.get(metric))); | |||
} | |||
void processIssue(Issue issue, boolean isSLBorPR, PeriodHolder periodHolder) { | |||
if (isSLBorPR || isOnPeriod((DefaultIssue) issue, periodHolder.getPeriod())) { | |||
void processIssue(Issue issue, boolean isPR, PeriodHolder periodHolder) { | |||
if (isPR || isOnPeriod((DefaultIssue) issue, periodHolder.getPeriod())) { | |||
Rating rating = RATING_BY_SEVERITY.get(issue.severity()); | |||
if (issue.type().equals(BUG)) { | |||
newRatingValueByMetric.get(NEW_RELIABILITY_RATING_KEY).increment(rating); |
@@ -60,7 +60,7 @@ public class ScmInfoDbLoader { | |||
} | |||
private Optional<String> getFileUUid(Component file) { | |||
if (!analysisMetadataHolder.isFirstAnalysis() && !analysisMetadataHolder.isSLBorPR()) { | |||
if (!analysisMetadataHolder.isFirstAnalysis() && !analysisMetadataHolder.isPullRequest()) { | |||
return Optional.of(file.getUuid()); | |||
} | |||
@@ -48,7 +48,7 @@ public class NewLinesRepository { | |||
} | |||
public boolean newLinesAvailable() { | |||
return analysisMetadataHolder.isSLBorPR() || periodHolder.hasPeriod(); | |||
return analysisMetadataHolder.isPullRequest() || periodHolder.hasPeriod(); | |||
} | |||
public Optional<Set<Integer>> getNewLines(Component file) { | |||
@@ -66,7 +66,7 @@ public class NewLinesRepository { | |||
* if a line is new or not. | |||
*/ | |||
private Optional<Set<Integer>> computeNewLinesFromScm(Component component) { | |||
if (!periodHolder.hasPeriod() && !analysisMetadataHolder.isSLBorPR()) { | |||
if (!periodHolder.hasPeriod() && !analysisMetadataHolder.isPullRequest()) { | |||
return Optional.empty(); | |||
} | |||
@@ -79,8 +79,8 @@ public class NewLinesRepository { | |||
Changeset[] allChangesets = scmInfo.getAllChangesets(); | |||
Set<Integer> lines = new HashSet<>(); | |||
// in SLB/PRs, we consider changes introduced in this analysis as new, hence subtracting 1. | |||
long referenceDate = analysisMetadataHolder.isSLBorPR() ? analysisMetadataHolder.getAnalysisDate() - 1 : periodHolder.getPeriod().getSnapshotDate(); | |||
// in PRs, we consider changes introduced in this analysis as new, hence subtracting 1. | |||
long referenceDate = analysisMetadataHolder.isPullRequest() ? analysisMetadataHolder.getAnalysisDate() - 1 : periodHolder.getPeriod().getSnapshotDate(); | |||
for (int i=0; i<allChangesets.length; i++) { | |||
if (isLineInPeriod(allChangesets[i].getDate(), referenceDate)) { | |||
lines.add(i+1); | |||
@@ -98,7 +98,7 @@ public class NewLinesRepository { | |||
} | |||
private Optional<Set<Integer>> getChangedLinesFromReport(Component file) { | |||
if (analysisMetadataHolder.isSLBorPR()) { | |||
if (analysisMetadataHolder.isPullRequest()) { | |||
return reportChangedLinesCache.computeIfAbsent(file, this::readFromReport); | |||
} | |||
@@ -56,7 +56,7 @@ public class SourceLinesDiffImpl implements SourceLinesDiff { | |||
private List<String> getDBLines(Component component) { | |||
try (DbSession dbSession = dbClient.openSession(false)) { | |||
String uuid; | |||
if (analysisMetadataHolder.isSLBorPR()) { | |||
if (analysisMetadataHolder.isPullRequest()) { | |||
uuid = mergeAndTargetBranchComponentUuids.getTargetBranchComponentUuid(component.getDbKey()); | |||
if (uuid == null) { | |||
uuid = mergeAndTargetBranchComponentUuids.getMergeBranchComponentUuid(component.getDbKey()); |
@@ -97,7 +97,7 @@ public class BuildComponentTreeStep implements ComputationStep { | |||
Component reportTreeRoot = builder.buildProject(reportProject, relativePathFromScmRoot); | |||
if (analysisMetadataHolder.isSLBorPR()) { | |||
if (analysisMetadataHolder.isPullRequest()) { | |||
Component changedComponentTreeRoot = builder.buildChangedComponentTreeRoot(reportTreeRoot); | |||
treeRootHolder.setRoots(changedComponentTreeRoot, reportTreeRoot); | |||
} else { |
@@ -85,7 +85,7 @@ public class LoadDuplicationsFromReportStep implements ComputationStep { | |||
if (input.getOtherFileRef() != 0) { | |||
checkArgument(input.getOtherFileRef() != file.getReportAttributes().getRef(), "file and otherFile references can not be the same"); | |||
Component otherComponent = treeRootHolder.getReportTreeComponentByRef(input.getOtherFileRef()); | |||
if (analysisMetadataHolder.isSLBorPR() && otherComponent.getStatus() == Component.Status.SAME) { | |||
if (analysisMetadataHolder.isPullRequest() && otherComponent.getStatus() == Component.Status.SAME) { | |||
return new InExtendedProjectDuplicate(otherComponent, convert(input.getRange())); | |||
} else { | |||
return new InProjectDuplicate(otherComponent, convert(input.getRange())); |
@@ -54,7 +54,7 @@ public class LoadQualityGateStep implements ComputationStep { | |||
qualityGate = Optional.of(getOrganizationDefaultQualityGate()); | |||
} | |||
if (analysisMetadataHolder.isSLBorPR()) { | |||
if (analysisMetadataHolder.isPullRequest()) { | |||
qualityGate = filterQGForSLB(qualityGate); | |||
} | |||
@@ -71,8 +71,8 @@ public class QualityGateEventsStep implements ComputationStep { | |||
@Override | |||
public void execute(ComputationStep.Context context) { | |||
// no notification on short living branch and pull request as there is no real Quality Gate on those | |||
if (analysisMetadataHolder.isSLBorPR()) { | |||
// no notification on pull requests as there is no real Quality Gate on those | |||
if (analysisMetadataHolder.isPullRequest()) { | |||
return; | |||
} | |||
new DepthTraversalTypeAwareCrawler( |
@@ -60,7 +60,6 @@ import static java.util.stream.Collectors.toMap; | |||
import static java.util.stream.StreamSupport.stream; | |||
import static org.sonar.core.util.stream.MoreCollectors.toSet; | |||
import static org.sonar.db.component.BranchType.PULL_REQUEST; | |||
import static org.sonar.db.component.BranchType.SHORT; | |||
/** | |||
* Reads issues from disk cache and send related notifications. For performance reasons, | |||
@@ -94,7 +93,7 @@ public class SendIssueNotificationsStep implements ComputationStep { | |||
@Override | |||
public void execute(ComputationStep.Context context) { | |||
BranchType branchType = analysisMetadataHolder.getBranch().getType(); | |||
if (branchType == PULL_REQUEST || branchType == SHORT) { | |||
if (branchType == PULL_REQUEST) { | |||
return; | |||
} | |||
@@ -38,7 +38,6 @@ import org.sonar.ce.task.step.ComputationStep; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.BranchDto; | |||
import org.sonar.db.component.BranchType; | |||
import org.sonar.db.component.ComponentDao; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.SnapshotDto; | |||
@@ -54,7 +53,7 @@ import static org.sonar.api.utils.DateUtils.formatDateTime; | |||
* <li>module key already exists in another project (same module key cannot exists in different projects)</li> | |||
* <li>module key is already used as a project key</li> | |||
* <li>date of the analysis is before last analysis</li> | |||
* <li>short living branch or PR targets a branch that still contains modules</li> | |||
* <li>PR targets a branch that still contains modules</li> | |||
* </ol> | |||
*/ | |||
public class ValidateProjectStep implements ComputationStep { | |||
@@ -88,7 +87,7 @@ public class ValidateProjectStep implements ComputationStep { | |||
} | |||
private void validateTargetBranch(DbSession session) { | |||
if (!analysisMetadataHolder.isSLBorPR()) { | |||
if (!analysisMetadataHolder.isPullRequest()) { | |||
return; | |||
} | |||
String mergeBranchUuid = analysisMetadataHolder.getBranch().getMergeBranchUuid(); | |||
@@ -96,9 +95,8 @@ public class ValidateProjectStep implements ComputationStep { | |||
if (moduleCount > 0) { | |||
Optional<BranchDto> opt = dbClient.branchDao().selectByUuid(session, mergeBranchUuid); | |||
checkState(opt.isPresent(), "Merge branch '%s' does not exist", mergeBranchUuid); | |||
String type = analysisMetadataHolder.getBranch().getType() == BranchType.PULL_REQUEST ? "pull request" : "short-lived branch"; | |||
throw MessageException.of(String.format( | |||
"Due to an upgrade, you need first to re-analyze the target branch '%s' before analyzing this %s.", opt.get().getKey(), type)); | |||
"Due to an upgrade, you need first to re-analyze the target branch '%s' before analyzing this pull request.", opt.get().getKey())); | |||
} | |||
} | |||
@@ -397,48 +397,6 @@ public class AnalysisMetadataHolderImplTest { | |||
underTest.setRootComponentRef(9); | |||
} | |||
@Test | |||
public void getIsShortLivingBranch_throws_ISE_when_holder_is_not_initialized() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Branch has not been set"); | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); | |||
underTest.isShortLivingBranch(); | |||
} | |||
@Test | |||
public void getIsShortLivingBranch_returns_true() { | |||
Branch branch = mock(Branch.class); | |||
when(branch.getType()).thenReturn(BranchType.SHORT); | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); | |||
underTest.setBranch(branch); | |||
assertThat(underTest.isShortLivingBranch()).isTrue(); | |||
} | |||
@Test | |||
public void getIsSLBorPR_returns_true() { | |||
Branch branch = mock(Branch.class); | |||
when(branch.getType()).thenReturn(BranchType.SHORT); | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); | |||
underTest.setBranch(branch); | |||
assertThat(underTest.isSLBorPR()).isTrue(); | |||
} | |||
@Test | |||
public void getIsSLBorPR_returns_false() { | |||
Branch branch = mock(Branch.class); | |||
when(branch.getType()).thenReturn(BranchType.LONG); | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); | |||
underTest.setBranch(branch); | |||
assertThat(underTest.isSLBorPR()).isFalse(); | |||
} | |||
@Test | |||
public void getPullRequestBranch_returns_true() { | |||
Branch branch = mock(Branch.class); |
@@ -142,7 +142,7 @@ public class PostProjectAnalysisTasksExecutorTest { | |||
new PostProjectAnalysisTasksExecutor( | |||
ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader, | |||
system2, new PostProjectAnalysisTask[] {postProjectAnalysisTask1, postProjectAnalysisTask2}) | |||
.finished(allStepsExecuted); | |||
.finished(allStepsExecuted); | |||
inOrder.verify(postProjectAnalysisTask1).finished(taskContextCaptor.capture()); | |||
inOrder.verify(postProjectAnalysisTask1).getDescription(); | |||
@@ -280,7 +280,7 @@ public class PostProjectAnalysisTasksExecutorTest { | |||
analysisMetadataHolder.setBranch(new Branch() { | |||
@Override | |||
public BranchType getType() { | |||
return BranchType.SHORT; | |||
return BranchType.BRANCH; | |||
} | |||
@Override | |||
@@ -326,7 +326,7 @@ public class PostProjectAnalysisTasksExecutorTest { | |||
org.sonar.api.ce.posttask.Branch branch = taskContextCaptor.getValue().getProjectAnalysis().getBranch().get(); | |||
assertThat(branch.isMain()).isFalse(); | |||
assertThat(branch.getName()).hasValue("feature/foo"); | |||
assertThat(branch.getType()).isEqualTo(BranchImpl.Type.SHORT); | |||
assertThat(branch.getType()).isEqualTo(BranchImpl.Type.BRANCH); | |||
} | |||
@Test | |||
@@ -430,7 +430,7 @@ public class PostProjectAnalysisTasksExecutorTest { | |||
new PostProjectAnalysisTasksExecutor( | |||
ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader, | |||
system2, new PostProjectAnalysisTask[] {logStatisticsTask}) | |||
.finished(allStepsExecuted); | |||
.finished(allStepsExecuted); | |||
verify(logStatisticsTask).finished(taskContextCaptor.capture()); | |||
@@ -458,7 +458,7 @@ public class PostProjectAnalysisTasksExecutorTest { | |||
new PostProjectAnalysisTasksExecutor( | |||
ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader, | |||
system2, new PostProjectAnalysisTask[] {postProjectAnalysisTask1, postProjectAnalysisTask2, postProjectAnalysisTask3}) | |||
.finished(allStepsExecuted); | |||
.finished(allStepsExecuted); | |||
inOrder.verify(postProjectAnalysisTask1).finished(taskContextCaptor.capture()); | |||
inOrder.verify(postProjectAnalysisTask1).getDescription(); |
@@ -84,16 +84,6 @@ public class BranchPersisterImplTest { | |||
underTest.persist(dbTester.getSession()); | |||
} | |||
@Test | |||
public void persist_fails_with_ISE_if_no_component_for_short_branches() { | |||
analysisMetadataHolder.setBranch(createBranch(BranchType.SHORT, false, "foo")); | |||
treeRootHolder.setRoot(BRANCH); | |||
expectMissingComponentISE(); | |||
underTest.persist(dbTester.getSession()); | |||
} | |||
@Test | |||
public void persist_fails_with_ISE_if_no_component_for_pull_request() { | |||
analysisMetadataHolder.setBranch(createBranch(BranchType.PULL_REQUEST, false, "12")); |
@@ -45,15 +45,15 @@ public class MergeAndTargetBranchComponentUuidsTest { | |||
private MergeAndTargetBranchComponentUuids underTest; | |||
private Branch branch = mock(Branch.class); | |||
private ComponentDto longBranch1; | |||
private ComponentDto longBranch1File; | |||
private ComponentDto shortBranch1File; | |||
private ComponentDto shortBranch2File; | |||
private ComponentDto branch1; | |||
private ComponentDto branch1File; | |||
private ComponentDto pr1File; | |||
private ComponentDto pr2File; | |||
private Project project; | |||
private ComponentDto shortBranch1; | |||
private ComponentDto shortBranch2; | |||
private ComponentDto longBranch2; | |||
private ComponentDto longBranch2File; | |||
private ComponentDto pr1; | |||
private ComponentDto pr2; | |||
private ComponentDto branch2; | |||
private ComponentDto branch2File; | |||
@Before | |||
public void setUp() { | |||
@@ -64,40 +64,40 @@ public class MergeAndTargetBranchComponentUuidsTest { | |||
ComponentDto projectDto = db.components().insertMainBranch(); | |||
when(project.getUuid()).thenReturn(projectDto.uuid()); | |||
longBranch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey("longBranch1")); | |||
longBranch2 = db.components().insertProjectBranch(projectDto, b -> b.setKey("longBranch2")); | |||
shortBranch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey("shortBranch1").setBranchType(BranchType.SHORT).setMergeBranchUuid(longBranch1.uuid())); | |||
shortBranch2 = db.components().insertProjectBranch(projectDto, b -> b.setKey("shortBranch2").setBranchType(BranchType.SHORT).setMergeBranchUuid(longBranch1.uuid())); | |||
longBranch1File = ComponentTesting.newFileDto(longBranch1, null, "file").setUuid("long1File"); | |||
longBranch2File = ComponentTesting.newFileDto(longBranch2, null, "file").setUuid("long2File"); | |||
shortBranch1File = ComponentTesting.newFileDto(shortBranch1, null, "file").setUuid("file1"); | |||
shortBranch2File = ComponentTesting.newFileDto(shortBranch2, null, "file").setUuid("file2"); | |||
db.components().insertComponents(longBranch1File, shortBranch1File, shortBranch2File, longBranch2File); | |||
branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey("branch1")); | |||
branch2 = db.components().insertProjectBranch(projectDto, b -> b.setKey("branch2")); | |||
pr1 = db.components().insertProjectBranch(projectDto, b -> b.setKey("pr1").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid())); | |||
pr2 = db.components().insertProjectBranch(projectDto, b -> b.setKey("pr2").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid())); | |||
branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File"); | |||
branch2File = ComponentTesting.newFileDto(branch2, null, "file").setUuid("branch2File"); | |||
pr1File = ComponentTesting.newFileDto(pr1, null, "file").setUuid("file1"); | |||
pr2File = ComponentTesting.newFileDto(pr2, null, "file").setUuid("file2"); | |||
db.components().insertComponents(branch1File, pr1File, pr2File, branch2File); | |||
} | |||
@Test | |||
public void should_support_db_key_when_looking_for_merge_component() { | |||
when(branch.getMergeBranchUuid()).thenReturn(longBranch1.uuid()); | |||
when(branch.getType()).thenReturn(BranchType.SHORT); | |||
when(branch.getMergeBranchUuid()).thenReturn(branch1.uuid()); | |||
when(branch.getType()).thenReturn(BranchType.PULL_REQUEST); | |||
when(branch.getTargetBranchName()).thenReturn("notAnalyzedBranch"); | |||
db.components().insertSnapshot(newAnalysis(longBranch1)); | |||
assertThat(underTest.getMergeBranchComponentUuid(shortBranch1File.getDbKey())).isEqualTo(longBranch1File.uuid()); | |||
assertThat(underTest.getTargetBranchComponentUuid(shortBranch1File.getDbKey())).isNull(); | |||
db.components().insertSnapshot(newAnalysis(branch1)); | |||
assertThat(underTest.getMergeBranchComponentUuid(pr1File.getDbKey())).isEqualTo(branch1File.uuid()); | |||
assertThat(underTest.getTargetBranchComponentUuid(pr1File.getDbKey())).isNull(); | |||
assertThat(underTest.hasMergeBranchAnalysis()).isTrue(); | |||
assertThat(underTest.hasTargetBranchAnalysis()).isFalse(); | |||
assertThat(underTest.areTargetAndMergeBranchesDifferent()).isTrue(); | |||
assertThat(underTest.getMergeBranchName()).isEqualTo("longBranch1"); | |||
assertThat(underTest.getMergeBranchName()).isEqualTo("branch1"); | |||
} | |||
@Test | |||
public void should_support_db_key_when_looking_for_target_component() { | |||
when(branch.getMergeBranchUuid()).thenReturn(longBranch1.uuid()); | |||
when(branch.getTargetBranchName()).thenReturn("shortBranch2"); | |||
when(branch.getType()).thenReturn(BranchType.SHORT); | |||
db.components().insertSnapshot(newAnalysis(longBranch1)); | |||
db.components().insertSnapshot(newAnalysis(shortBranch2)); | |||
assertThat(underTest.getMergeBranchComponentUuid(shortBranch1File.getDbKey())).isEqualTo(longBranch1File.uuid()); | |||
assertThat(underTest.getTargetBranchComponentUuid(shortBranch1File.getDbKey())).isEqualTo(shortBranch2File.uuid()); | |||
when(branch.getMergeBranchUuid()).thenReturn(branch1.uuid()); | |||
when(branch.getTargetBranchName()).thenReturn("branch2"); | |||
when(branch.getType()).thenReturn(BranchType.PULL_REQUEST); | |||
db.components().insertSnapshot(newAnalysis(branch1)); | |||
db.components().insertSnapshot(newAnalysis(branch2)); | |||
assertThat(underTest.getMergeBranchComponentUuid(pr1File.getDbKey())).isEqualTo(branch1File.uuid()); | |||
assertThat(underTest.getTargetBranchComponentUuid(pr1File.getDbKey())).isEqualTo(branch2File.uuid()); | |||
assertThat(underTest.hasMergeBranchAnalysis()).isTrue(); | |||
assertThat(underTest.hasTargetBranchAnalysis()).isTrue(); | |||
assertThat(underTest.areTargetAndMergeBranchesDifferent()).isTrue(); | |||
@@ -105,42 +105,42 @@ public class MergeAndTargetBranchComponentUuidsTest { | |||
@Test | |||
public void should_support_key_when_looking_for_merge_component() { | |||
when(branch.getMergeBranchUuid()).thenReturn(longBranch1.uuid()); | |||
when(branch.getType()).thenReturn(BranchType.SHORT); | |||
when(branch.getMergeBranchUuid()).thenReturn(branch1.uuid()); | |||
when(branch.getType()).thenReturn(BranchType.PULL_REQUEST); | |||
when(branch.getTargetBranchName()).thenReturn("notAnalyzedBranch"); | |||
db.components().insertSnapshot(newAnalysis(longBranch1)); | |||
assertThat(underTest.getMergeBranchComponentUuid(shortBranch1File.getKey())).isEqualTo(longBranch1File.uuid()); | |||
db.components().insertSnapshot(newAnalysis(branch1)); | |||
assertThat(underTest.getMergeBranchComponentUuid(pr1File.getKey())).isEqualTo(branch1File.uuid()); | |||
} | |||
@Test | |||
public void return_null_if_file_doesnt_exist() { | |||
when(branch.getMergeBranchUuid()).thenReturn(longBranch1.uuid()); | |||
when(branch.getType()).thenReturn(BranchType.SHORT); | |||
when(branch.getMergeBranchUuid()).thenReturn(branch1.uuid()); | |||
when(branch.getType()).thenReturn(BranchType.PULL_REQUEST); | |||
when(branch.getTargetBranchName()).thenReturn("notAnalyzedBranch"); | |||
db.components().insertSnapshot(newAnalysis(longBranch1)); | |||
db.components().insertSnapshot(newAnalysis(branch1)); | |||
assertThat(underTest.getMergeBranchComponentUuid("doesnt exist")).isNull(); | |||
} | |||
@Test | |||
public void skip_init_if_no_merge_branch_analysis() { | |||
when(branch.getMergeBranchUuid()).thenReturn(longBranch1.uuid()); | |||
when(branch.getType()).thenReturn(BranchType.SHORT); | |||
when(branch.getMergeBranchUuid()).thenReturn(branch1.uuid()); | |||
when(branch.getType()).thenReturn(BranchType.PULL_REQUEST); | |||
when(branch.getTargetBranchName()).thenReturn("notAnalyzedBranch"); | |||
assertThat(underTest.getMergeBranchComponentUuid(shortBranch1File.getDbKey())).isNull(); | |||
assertThat(underTest.getMergeBranchComponentUuid(pr1File.getDbKey())).isNull(); | |||
} | |||
@Test | |||
public void should_skip_target_components_init_on_long_branches() { | |||
when(branch.getMergeBranchUuid()).thenReturn(longBranch1.uuid()); | |||
public void should_skip_target_components_init_on_branches() { | |||
when(branch.getMergeBranchUuid()).thenReturn(branch1.uuid()); | |||
when(branch.getType()).thenReturn(BranchType.LONG); | |||
when(branch.getTargetBranchName()).thenThrow(new IllegalStateException("Unsupported on long branches")); | |||
db.components().insertSnapshot(newAnalysis(longBranch1)); | |||
when(branch.getTargetBranchName()).thenThrow(new IllegalStateException("Unsupported on branches")); | |||
db.components().insertSnapshot(newAnalysis(branch1)); | |||
assertThat(underTest.getMergeBranchComponentUuid(longBranch2File.getDbKey())).isEqualTo(longBranch1File.uuid()); | |||
assertThat(underTest.getTargetBranchComponentUuid(longBranch2File.getDbKey())).isNull(); | |||
assertThat(underTest.getMergeBranchComponentUuid(branch2File.getDbKey())).isEqualTo(branch1File.uuid()); | |||
assertThat(underTest.getTargetBranchComponentUuid(branch2File.getDbKey())).isNull(); | |||
assertThat(underTest.hasMergeBranchAnalysis()).isTrue(); | |||
assertThat(underTest.hasTargetBranchAnalysis()).isFalse(); | |||
assertThat(underTest.areTargetAndMergeBranchesDifferent()).isTrue(); | |||
assertThat(underTest.getMergeBranchName()).isEqualTo("longBranch1"); | |||
assertThat(underTest.getMergeBranchName()).isEqualTo("branch1"); | |||
} | |||
} |
@@ -21,6 +21,7 @@ package org.sonar.ce.task.projectanalysis.component; | |||
import javax.annotation.Nullable; | |||
import org.junit.Before; | |||
import org.junit.Ignore; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | |||
@@ -130,7 +131,9 @@ public class SiblingComponentsWithOpenIssuesTest { | |||
} | |||
@Test | |||
@Ignore | |||
public void should_find_sibling_components_with_open_issues_for_short1() { | |||
// TODO fix this test class | |||
setRoot(long1short1); | |||
setBranch(BranchType.SHORT, long1.uuid()); | |||
@@ -127,7 +127,7 @@ public class IntegrateIssuesVisitorTest { | |||
private ComponentIssuesLoader issuesLoader = new ComponentIssuesLoader(dbTester.getDbClient(), ruleRepositoryRule, activeRulesHolderRule, new MapSettings().asConfig(), System2.INSTANCE); | |||
private IssueTrackingDelegator trackingDelegator; | |||
private TrackerExecution tracker; | |||
private ShortBranchOrPullRequestTrackerExecution shortBranchTracker; | |||
private PullRequestTrackerExecution shortBranchTracker; | |||
private MergeBranchTrackerExecution mergeBranchTracker; | |||
private ActiveRulesHolder activeRulesHolder = new AlwaysActiveRulesHolderImpl(); | |||
private IssueCache issueCache; | |||
@@ -148,7 +148,7 @@ public class IntegrateIssuesVisitorTest { | |||
TrackerMergeOrTargetBranchInputFactory mergeInputFactory = new TrackerMergeOrTargetBranchInputFactory(issuesLoader, mergeBranchComponentsUuids, dbClient); | |||
ClosedIssuesInputFactory closedIssuesInputFactory = new ClosedIssuesInputFactory(issuesLoader, dbClient, movedFilesRepository); | |||
tracker = new TrackerExecution(baseInputFactory, rawInputFactory, closedIssuesInputFactory, new Tracker<>(), issuesLoader, analysisMetadataHolder); | |||
shortBranchTracker = new ShortBranchOrPullRequestTrackerExecution(baseInputFactory, rawInputFactory, mergeInputFactory, new Tracker<>(), newLinesRepository); | |||
shortBranchTracker = new PullRequestTrackerExecution(baseInputFactory, rawInputFactory, mergeInputFactory, new Tracker<>(), newLinesRepository); | |||
mergeBranchTracker = new MergeBranchTrackerExecution(rawInputFactory, mergeInputFactory, new Tracker<>()); | |||
trackingDelegator = new IssueTrackingDelegator(shortBranchTracker, mergeBranchTracker, tracker, analysisMetadataHolder); |
@@ -311,10 +311,10 @@ public class IssueCounterTest { | |||
} | |||
@Test | |||
public void count_all_issues_as_new_issues_if_pr_or_slb() { | |||
public void count_all_issues_as_new_issues_if_pr() { | |||
periodsHolder.setPeriod(null); | |||
Branch branch = mock(Branch.class); | |||
when(branch.getType()).thenReturn(BranchType.SHORT); | |||
when(branch.getType()).thenReturn(BranchType.PULL_REQUEST); | |||
analysisMetadataHolder.setBranch(branch); | |||
underTest.beforeComponent(FILE1); |
@@ -37,7 +37,7 @@ import static org.mockito.Mockito.when; | |||
public class IssueTrackingDelegatorTest { | |||
@Mock | |||
private ShortBranchOrPullRequestTrackerExecution shortBranchTracker; | |||
private PullRequestTrackerExecution shortBranchTracker; | |||
@Mock | |||
private MergeBranchTrackerExecution mergeBranchTracker; | |||
@Mock | |||
@@ -62,7 +62,6 @@ public class IssueTrackingDelegatorTest { | |||
@Test | |||
public void delegate_regular_tracker() { | |||
when(analysisMetadataHolder.isShortLivingBranch()).thenReturn(false); | |||
when(analysisMetadataHolder.getBranch()).thenReturn(mock(Branch.class)); | |||
underTest.track(component); | |||
@@ -88,26 +87,12 @@ public class IssueTrackingDelegatorTest { | |||
} | |||
@Test | |||
public void delegate_short_branch_tracker() { | |||
Branch branch = mock(Branch.class); | |||
when(branch.getType()).thenReturn(BranchType.SHORT); | |||
when(analysisMetadataHolder.getBranch()).thenReturn(mock(Branch.class)); | |||
when(analysisMetadataHolder.isSLBorPR()).thenReturn(true); | |||
underTest.track(component); | |||
verify(shortBranchTracker).track(component); | |||
verifyZeroInteractions(tracker); | |||
verifyZeroInteractions(mergeBranchTracker); | |||
} | |||
@Test | |||
public void delegate_pull_request_tracker() { | |||
Branch branch = mock(Branch.class); | |||
when(branch.getType()).thenReturn(BranchType.PULL_REQUEST); | |||
when(analysisMetadataHolder.getBranch()).thenReturn(mock(Branch.class)); | |||
when(analysisMetadataHolder.isSLBorPR()).thenReturn(true); | |||
when(analysisMetadataHolder.isPullRequest()).thenReturn(true); | |||
underTest.track(component); | |||
@@ -47,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder; | |||
public class ShortBranchOrPullRequestTrackerExecutionTest { | |||
public class PullRequestTrackerExecutionTest { | |||
static final String FILE_UUID = "FILE_UUID"; | |||
static final String FILE_KEY = "FILE_KEY"; | |||
static final int FILE_REF = 2; | |||
@@ -66,7 +66,7 @@ public class ShortBranchOrPullRequestTrackerExecutionTest { | |||
@Mock | |||
private NewLinesRepository newLinesRepository; | |||
private ShortBranchOrPullRequestTrackerExecution underTest; | |||
private PullRequestTrackerExecution underTest; | |||
private List<DefaultIssue> rawIssues = new ArrayList<>(); | |||
private List<DefaultIssue> baseIssues = new ArrayList<>(); | |||
@@ -83,7 +83,7 @@ public class ShortBranchOrPullRequestTrackerExecutionTest { | |||
when(mergeFactory.createForTargetBranch(FILE)).thenReturn(createInput(targetBranchIssues)); | |||
Tracker<DefaultIssue, DefaultIssue> tracker = new Tracker<>(); | |||
underTest = new ShortBranchOrPullRequestTrackerExecution(baseFactory, rawFactory, mergeFactory, tracker, newLinesRepository); | |||
underTest = new PullRequestTrackerExecution(baseFactory, rawFactory, mergeFactory, tracker, newLinesRepository); | |||
} | |||
@Test |
@@ -570,15 +570,11 @@ public class NotificationFactoryTest { | |||
Branch mainBranch = mock(Branch.class); | |||
when(mainBranch.isMain()).thenReturn(true); | |||
when(mainBranch.getType()).thenReturn(BranchType.LONG); | |||
Branch shortBranch = mock(Branch.class); | |||
when(shortBranch.isMain()).thenReturn(false); | |||
when(shortBranch.getType()).thenReturn(BranchType.SHORT); | |||
Branch pr = mock(Branch.class); | |||
when(pr.isMain()).thenReturn(false); | |||
when(pr.getType()).thenReturn(BranchType.PULL_REQUEST); | |||
return new Object[][] { | |||
{mainBranch}, | |||
{shortBranch}, | |||
{pr} | |||
}; | |||
} |
@@ -77,7 +77,7 @@ public class SourceLinesDiffImplTest { | |||
mockLineHashesInDb(2, CONTENT); | |||
setLineHashesInReport(component, CONTENT); | |||
when(analysisMetadataHolder.isSLBorPR()).thenReturn(true); | |||
when(analysisMetadataHolder.isPullRequest()).thenReturn(true); | |||
when(mergeAndTargetBranchComponentUuids.getTargetBranchComponentUuid(component.getKey())).thenReturn("uuid_2"); | |||
assertThat(underTest.computeMatchingLines(component)).containsExactly(1, 2, 3, 4, 5, 6, 7); | |||
@@ -91,7 +91,7 @@ public class SourceLinesDiffImplTest { | |||
mockLineHashesInDb(2, CONTENT); | |||
setLineHashesInReport(component, CONTENT); | |||
when(analysisMetadataHolder.isSLBorPR()).thenReturn(true); | |||
when(analysisMetadataHolder.isPullRequest()).thenReturn(true); | |||
when(mergeAndTargetBranchComponentUuids.getMergeBranchComponentUuid(component.getKey())).thenReturn("uuid_2"); | |||
assertThat(underTest.computeMatchingLines(component)).containsExactly(1, 2, 3, 4, 5, 6, 7); |
@@ -195,11 +195,6 @@ public class BuildComponentTreeStepTest { | |||
verifyComponentByRef(FILE_1_REF, "generated", REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1, null); | |||
} | |||
@DataProvider | |||
public static Object[][] shortLivingBranchAndPullRequest() { | |||
return new Object[][] {{BranchType.SHORT}, {BranchType.PULL_REQUEST}}; | |||
} | |||
@Test | |||
public void generate_keys_when_using_existing_branch() { | |||
ComponentDto projectDto = dbTester.components().insertMainBranch(); |
@@ -56,27 +56,9 @@ public class LoadQualityGateStepTest { | |||
@Before | |||
public void setUp() { | |||
when(analysisMetadataHolder.isShortLivingBranch()).thenReturn(false); | |||
when(analysisMetadataHolder.getOrganization()).thenReturn(mock(Organization.class)); | |||
} | |||
@Test | |||
public void filter_conditions_on_short_living_branch() { | |||
Metric newMetric = new MetricImpl(1, "new_key", "name", Metric.MetricType.INT); | |||
Metric metric = new MetricImpl(2, "key", "name", Metric.MetricType.INT); | |||
Condition variation = new Condition(newMetric, Condition.Operator.GREATER_THAN.getDbValue(), "1.0"); | |||
Condition condition = new Condition(metric, Condition.Operator.GREATER_THAN.getDbValue(), "1.0"); | |||
when(analysisMetadataHolder.isSLBorPR()).thenReturn(true); | |||
QualityGate defaultGate = new QualityGate(1, "qg", Arrays.asList(variation, condition)); | |||
when(qualityGateService.findDefaultQualityGate(any(Organization.class))).thenReturn(defaultGate); | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(mutableQualityGateHolder.getQualityGate().get().getConditions()).containsExactly(variation); | |||
} | |||
@Test | |||
public void filter_conditions_on_pull_request() { | |||
Metric newMetric = new MetricImpl(1, "new_key", "name", Metric.MetricType.INT); | |||
@@ -84,7 +66,7 @@ public class LoadQualityGateStepTest { | |||
Condition variation = new Condition(newMetric, Condition.Operator.GREATER_THAN.getDbValue(), "1.0"); | |||
Condition condition = new Condition(metric, Condition.Operator.GREATER_THAN.getDbValue(), "1.0"); | |||
when(analysisMetadataHolder.isSLBorPR()).thenReturn(true); | |||
when(analysisMetadataHolder.isPullRequest()).thenReturn(true); | |||
QualityGate defaultGate = new QualityGate(1, "qg", Arrays.asList(variation, condition)); | |||
when(qualityGateService.findDefaultQualityGate(any(Organization.class))).thenReturn(defaultGate); | |||
@@ -270,25 +270,6 @@ public class QualityGateEventsStepTest { | |||
reset(measureRepository, eventRepository, notificationService); | |||
} | |||
@Test | |||
public void no_alert_on_short_living_branches() { | |||
Branch shortBranch = mock(Branch.class); | |||
when(shortBranch.getType()).thenReturn(BranchType.SHORT); | |||
analysisMetadataHolder.setBranch(shortBranch); | |||
TreeRootHolder treeRootHolder = mock(TreeRootHolder.class); | |||
MetricRepository metricRepository = mock(MetricRepository.class); | |||
MeasureRepository measureRepository = mock(MeasureRepository.class); | |||
EventRepository eventRepository = mock(EventRepository.class); | |||
NotificationService notificationService = mock(NotificationService.class); | |||
QualityGateEventsStep underTest = new QualityGateEventsStep(treeRootHolder, metricRepository, measureRepository, | |||
eventRepository, notificationService, analysisMetadataHolder); | |||
underTest.execute(new TestComputationStepContext()); | |||
verifyZeroInteractions(treeRootHolder, metricRepository, measureRepository, eventRepository, notificationService); | |||
} | |||
@Test | |||
public void no_alert_on_pull_request_branches() { | |||
Branch shortBranch = mock(Branch.class); |
@@ -97,7 +97,6 @@ import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builde | |||
import static org.sonar.ce.task.projectanalysis.step.SendIssueNotificationsStep.NOTIF_TYPES; | |||
import static org.sonar.db.component.BranchType.LONG; | |||
import static org.sonar.db.component.BranchType.PULL_REQUEST; | |||
import static org.sonar.db.component.BranchType.SHORT; | |||
import static org.sonar.db.component.ComponentTesting.newBranchDto; | |||
import static org.sonar.db.component.ComponentTesting.newFileDto; | |||
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; | |||
@@ -202,12 +201,12 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { | |||
Integer[] backDatedEfforts = IntStream.range(0, 1 + random.nextInt(10)).mapToObj(i -> 10 + random.nextInt(100)).toArray(Integer[]::new); | |||
Duration expectedEffort = Duration.create(stream(efforts).mapToInt(i -> i).sum()); | |||
List<DefaultIssue> issues = concat(stream(efforts) | |||
.map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)) | |||
.setCreationDate(new Date(ANALYSE_DATE))), | |||
.map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)) | |||
.setCreationDate(new Date(ANALYSE_DATE))), | |||
stream(backDatedEfforts) | |||
.map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)) | |||
.setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS)))) | |||
.collect(toList()); | |||
.collect(toList()); | |||
shuffle(issues); | |||
DiskCache<DefaultIssue>.DiskAppender issueCache = this.issueCache.newAppender(); | |||
issues.forEach(issueCache::append); | |||
@@ -268,22 +267,6 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { | |||
verifyStatistics(context, 1, 0, 0); | |||
} | |||
@Test | |||
public void do_not_send_global_new_issues_notification_on_short_branch() { | |||
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); | |||
ComponentDto branch = setUpBranch(project, SHORT); | |||
issueCache.newAppender().append( | |||
new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE))).close(); | |||
when(notificationService.hasProjectSubscribersForTypes(project.uuid(), NOTIF_TYPES)).thenReturn(true); | |||
analysisMetadataHolder.setProject(Project.from(project)); | |||
analysisMetadataHolder.setBranch(newBranch(SHORT)); | |||
TestComputationStepContext context = new TestComputationStepContext(); | |||
underTest.execute(context); | |||
verifyZeroInteractions(notificationService, newIssuesNotificationMock); | |||
} | |||
@Test | |||
public void do_not_send_global_new_issues_notification_on_pull_request() { | |||
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); | |||
@@ -356,14 +339,14 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { | |||
Integer[] assignedToOther = IntStream.range(0, 3).mapToObj(i -> 10).toArray(Integer[]::new); | |||
List<DefaultIssue> issues = concat(stream(assigned) | |||
.map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)) | |||
.setAssigneeUuid(perceval.getUuid()) | |||
.setCreationDate(new Date(ANALYSE_DATE))), | |||
.map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)) | |||
.setAssigneeUuid(perceval.getUuid()) | |||
.setCreationDate(new Date(ANALYSE_DATE))), | |||
stream(assignedToOther) | |||
.map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)) | |||
.setAssigneeUuid(arthur.getUuid()) | |||
.setCreationDate(new Date(ANALYSE_DATE)))) | |||
.collect(toList()); | |||
.collect(toList()); | |||
shuffle(issues); | |||
IssueCache issueCache = new IssueCache(temp.newFile(), System2.INSTANCE); | |||
DiskCache<DefaultIssue>.DiskAppender newIssueCache = issueCache.newAppender(); | |||
@@ -429,14 +412,14 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { | |||
Integer[] backDatedEfforts = IntStream.range(0, 1 + random.nextInt(10)).mapToObj(i -> 10 + random.nextInt(100)).toArray(Integer[]::new); | |||
Duration expectedEffort = Duration.create(stream(efforts).mapToInt(i -> i).sum()); | |||
List<DefaultIssue> issues = concat(stream(efforts) | |||
.map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)) | |||
.setAssigneeUuid(user.getUuid()) | |||
.setCreationDate(new Date(ANALYSE_DATE))), | |||
.map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)) | |||
.setAssigneeUuid(user.getUuid()) | |||
.setCreationDate(new Date(ANALYSE_DATE))), | |||
stream(backDatedEfforts) | |||
.map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)) | |||
.setAssigneeUuid(user.getUuid()) | |||
.setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS)))) | |||
.collect(toList()); | |||
.collect(toList()); | |||
shuffle(issues); | |||
DiskCache<DefaultIssue>.DiskAppender issueCache = this.issueCache.newAppender(); | |||
issues.forEach(issueCache::append); |
@@ -64,25 +64,8 @@ public class ValidateProjectStepTest { | |||
.setAnalysisDate(new Date(DEFAULT_ANALYSIS_TIME)) | |||
.setBranch(DEFAULT_BRANCH); | |||
DbClient dbClient = dbTester.getDbClient(); | |||
ValidateProjectStep underTest = new ValidateProjectStep(dbClient, treeRootHolder, analysisMetadataHolder); | |||
@Test | |||
public void fail_if_slb_is_targeting_master_with_modules() { | |||
ComponentDto masterProject = dbTester.components().insertMainBranch(); | |||
dbClient.componentDao().insert(dbTester.getSession(), ComponentTesting.newModuleDto(masterProject)); | |||
setBranch(BranchType.SHORT, masterProject.uuid()); | |||
dbTester.getSession().commit(); | |||
treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("DEFG") | |||
.setKey("branch") | |||
.build()); | |||
thrown.expect(MessageException.class); | |||
thrown.expectMessage("Due to an upgrade, you need first to re-analyze the target branch 'master' before analyzing this short-lived branch."); | |||
underTest.execute(new TestComputationStepContext()); | |||
} | |||
private DbClient dbClient = dbTester.getDbClient(); | |||
private ValidateProjectStep underTest = new ValidateProjectStep(dbClient, treeRootHolder, analysisMetadataHolder); | |||
@Test | |||
public void fail_if_pr_is_targeting_branch_with_modules() { | |||
@@ -101,19 +84,6 @@ public class ValidateProjectStepTest { | |||
underTest.execute(new TestComputationStepContext()); | |||
} | |||
@Test | |||
public void dont_fail_if_slb_is_targeting_branch_without_modules() { | |||
ComponentDto masterProject = dbTester.components().insertMainBranch(); | |||
setBranch(BranchType.SHORT, masterProject.uuid()); | |||
dbTester.getSession().commit(); | |||
treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("DEFG") | |||
.setKey("branch") | |||
.build()); | |||
underTest.execute(new TestComputationStepContext()); | |||
} | |||
@Test | |||
public void dont_fail_for_long_forked_from_master_with_modules() { | |||
ComponentDto masterProject = dbTester.components().insertMainBranch(); |
@@ -250,12 +250,6 @@ public class AnalysisMetadataHolderRule extends ExternalResource implements Muta | |||
return Optional.ofNullable(scmRevision.getProperty()); | |||
} | |||
@Override | |||
public boolean isShortLivingBranch() { | |||
Branch property = this.branch.getProperty(); | |||
return property != null && property.getType() == BranchType.SHORT; | |||
} | |||
@Override | |||
public boolean isLongLivingBranch() { | |||
Branch property = this.branch.getProperty(); |
@@ -194,11 +194,6 @@ public class MutableAnalysisMetadataHolderRule extends ExternalResource implemen | |||
return delegate.getScmRevision(); | |||
} | |||
@Override | |||
public boolean isShortLivingBranch() { | |||
return delegate.isShortLivingBranch(); | |||
} | |||
@Override | |||
public boolean isLongLivingBranch() { | |||
return delegate.isLongLivingBranch(); |
@@ -31,6 +31,8 @@ public enum BranchType { | |||
*/ | |||
SHORT, | |||
BRANCH, | |||
/** | |||
* Pull request | |||
*/ |
@@ -61,7 +61,7 @@ public class BranchDaoTest { | |||
BranchDto dto = new BranchDto(); | |||
dto.setProjectUuid("U1"); | |||
dto.setUuid("U2"); | |||
dto.setBranchType(BranchType.SHORT); | |||
dto.setBranchType(BranchType.LONG); | |||
dto.setKey("feature/foo"); | |||
underTest.insert(dbSession, dto); | |||
@@ -70,7 +70,7 @@ public class BranchDaoTest { | |||
assertThat(map).contains( | |||
entry("projectUuid", "U1"), | |||
entry("uuid", "U2"), | |||
entry("branchType", "SHORT"), | |||
entry("branchType", "LONG"), | |||
entry("kee", "feature/foo"), | |||
entry("mergeBranchUuid", null), | |||
entry("pullRequestBinary", null), | |||
@@ -125,20 +125,12 @@ public class BranchDaoTest { | |||
}; | |||
} | |||
@DataProvider | |||
public static Object[][] nonLongBranchType() { | |||
return new Object[][] { | |||
{BranchType.SHORT}, | |||
{BranchType.PULL_REQUEST} | |||
}; | |||
} | |||
@Test | |||
public void insert_branch_with_all_fields_and_max_length_values() { | |||
BranchDto dto = new BranchDto(); | |||
dto.setProjectUuid(repeat("a", 50)); | |||
dto.setUuid(repeat("b", 50)); | |||
dto.setBranchType(BranchType.SHORT); | |||
dto.setBranchType(BranchType.LONG); | |||
dto.setKey(repeat("c", 255)); | |||
dto.setMergeBranchUuid(repeat("d", 50)); | |||
@@ -234,7 +226,7 @@ public class BranchDaoTest { | |||
// the fields that can't be updated. New values are ignored. | |||
dto.setProjectUuid("ignored"); | |||
dto.setBranchType(BranchType.SHORT); | |||
dto.setBranchType(BranchType.LONG); | |||
underTest.upsert(dbSession, dto); | |||
BranchDto loaded = underTest.selectByBranchKey(dbSession, "U1", "foo").get(); | |||
@@ -270,7 +262,7 @@ public class BranchDaoTest { | |||
// the fields that can't be updated. New values are ignored. | |||
dto.setProjectUuid("ignored"); | |||
dto.setBranchType(BranchType.SHORT); | |||
dto.setBranchType(BranchType.LONG); | |||
underTest.upsert(dbSession, dto); | |||
BranchDto loaded = underTest.selectByPullRequestKey(dbSession, "U1", "foo").get(); | |||
@@ -351,7 +343,7 @@ public class BranchDaoTest { | |||
BranchDto featureBranch = new BranchDto(); | |||
featureBranch.setProjectUuid("U1"); | |||
featureBranch.setUuid("U2"); | |||
featureBranch.setBranchType(BranchType.SHORT); | |||
featureBranch.setBranchType(BranchType.LONG); | |||
featureBranch.setKey("feature/foo"); | |||
featureBranch.setMergeBranchUuid("U3"); | |||
underTest.insert(dbSession, featureBranch); | |||
@@ -380,7 +372,7 @@ public class BranchDaoTest { | |||
BranchDto featureBranch = new BranchDto(); | |||
featureBranch.setProjectUuid("U1"); | |||
featureBranch.setUuid("U2"); | |||
featureBranch.setBranchType(BranchType.SHORT); | |||
featureBranch.setBranchType(BranchType.LONG); | |||
featureBranch.setKey("feature/foo"); | |||
featureBranch.setMergeBranchUuid("U3"); | |||
underTest.insert(dbSession, featureBranch); |
@@ -71,6 +71,7 @@ import static org.assertj.core.api.Assertions.tuple; | |||
import static org.sonar.api.resources.Qualifiers.APP; | |||
import static org.sonar.api.resources.Qualifiers.PROJECT; | |||
import static org.sonar.api.utils.DateUtils.parseDate; | |||
import static org.sonar.db.component.BranchType.LONG; | |||
import static org.sonar.db.component.BranchType.PULL_REQUEST; | |||
import static org.sonar.db.component.ComponentTesting.newBranchDto; | |||
import static org.sonar.db.component.ComponentTesting.newDirectory; | |||
@@ -218,10 +219,9 @@ public class ComponentDaoTest { | |||
} | |||
@Test | |||
@UseDataProvider("branchBranchTypes") | |||
public void selectByKeyAndBranch(BranchType branchType) { | |||
public void selectByKeyAndBranch() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch").setBranchType(branchType)); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch").setBranchType(LONG)); | |||
ComponentDto file = db.components().insertComponent(newFileDto(branch)); | |||
assertThat(underTest.selectByKeyAndBranch(dbSession, project.getKey(), "master").get().uuid()).isEqualTo(project.uuid()); | |||
@@ -231,14 +231,6 @@ public class ComponentDaoTest { | |||
assertThat(underTest.selectByKeyAndBranch(dbSession, file.getKey(), "unknown")).isNotPresent(); | |||
} | |||
@DataProvider | |||
public static Object[][] branchBranchTypes() { | |||
return new Object[][]{ | |||
{BranchType.SHORT}, | |||
{BranchType.LONG} | |||
}; | |||
} | |||
@Test | |||
public void selectByKeyAndPullRequest() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
@@ -1625,12 +1617,12 @@ public class ComponentDaoTest { | |||
long recentTime = 3_000_000_000L; | |||
// project with only a non-main and old analyzed branch | |||
ComponentDto oldProject = db.components().insertMainBranch(); | |||
ComponentDto oldProjectBranch = db.components().insertProjectBranch(oldProject, newBranchDto(oldProject).setBranchType(BranchType.SHORT)); | |||
ComponentDto oldProjectBranch = db.components().insertProjectBranch(oldProject, newBranchDto(oldProject).setBranchType(BranchType.LONG)); | |||
db.components().insertSnapshot(oldProjectBranch, s -> s.setLast(true).setCreatedAt(aLongTimeAgo)); | |||
// project with only a old main branch and a recent non-main branch | |||
ComponentDto recentProject = db.components().insertMainBranch(); | |||
ComponentDto recentProjectBranch = db.components().insertProjectBranch(recentProject, newBranchDto(recentProject).setBranchType(BranchType.SHORT)); | |||
ComponentDto recentProjectBranch = db.components().insertProjectBranch(recentProject, newBranchDto(recentProject).setBranchType(BranchType.LONG)); | |||
db.components().insertSnapshot(recentProjectBranch, s -> s.setCreatedAt(recentTime).setLast(true)); | |||
db.components().insertSnapshot(recentProjectBranch, s -> s.setCreatedAt(aLongTimeAgo).setLast(false)); | |||
@@ -198,7 +198,7 @@ public class IssueDaoTest { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto projectBranch = db.components().insertProjectBranch(project, | |||
b -> b.setKey("feature/foo") | |||
.setBranchType(BranchType.SHORT)); | |||
.setBranchType(BranchType.LONG)); | |||
ComponentDto file = db.components().insertComponent(newFileDto(projectBranch)); | |||
@@ -220,7 +220,7 @@ public class IssueDaoTest { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto projectBranch = db.components().insertProjectBranch(project, | |||
b -> b.setKey("feature/foo") | |||
.setBranchType(BranchType.SHORT)); | |||
.setBranchType(BranchType.LONG)); | |||
ComponentDto file = db.components().insertComponent(newFileDto(projectBranch)); | |||
IssueDto fpIssue = db.issues().insert(rule, projectBranch, file, i -> i.setStatus("RESOLVED").setResolution("FALSE-POSITIVE")); |
@@ -1220,7 +1220,7 @@ public class AuthorizationDaoTest { | |||
@Test | |||
public void keepAuthorizedLoginsOnProject_return_correct_users_on_branch() { | |||
ComponentDto project = db.components().insertPrivateProject(organization); | |||
ComponentDto branch = db.components().insertProjectBranch(project, c -> c.setBranchType(random.nextBoolean() ? BranchType.SHORT : BranchType.LONG)); | |||
ComponentDto branch = db.components().insertProjectBranch(project, c -> c.setBranchType(BranchType.LONG)); | |||
GroupDto userGroup = db.users().insertGroup(organization, "USERS"); | |||
GroupDto adminGroup = db.users().insertGroup(organization, "ADMIN"); |
@@ -26,14 +26,14 @@ import static org.sonar.api.rules.RuleType.BUG; | |||
import static org.sonar.api.rules.RuleType.CODE_SMELL; | |||
import static org.sonar.api.rules.RuleType.VULNERABILITY; | |||
public class BranchStatistics { | |||
public class PrStatistics { | |||
private final String branchUuid; | |||
private final long bugs; | |||
private final long vulnerabilities; | |||
private final long codeSmells; | |||
public BranchStatistics(String branchUuid, Map<String, Long> issueCountByType) { | |||
public PrStatistics(String branchUuid, Map<String, Long> issueCountByType) { | |||
this.branchUuid = branchUuid; | |||
this.bugs = getNonNullValue(issueCountByType, BUG); | |||
this.vulnerabilities = getNonNullValue(issueCountByType, VULNERABILITY); |
@@ -49,7 +49,7 @@ public final class Branch { | |||
} | |||
public enum Type { | |||
LONG, SHORT, PULL_REQUEST | |||
LONG, SHORT, PULL_REQUEST, BRANCH | |||
} | |||
@Override |
@@ -44,7 +44,7 @@ public class QGChangeEventTest { | |||
.setDbKey("foo") | |||
.setUuid("bar"); | |||
private BranchDto branch = new BranchDto() | |||
.setBranchType(BranchType.SHORT) | |||
.setBranchType(BranchType.BRANCH) | |||
.setUuid("bar") | |||
.setProjectUuid("doh") | |||
.setMergeBranchUuid("zop"); | |||
@@ -124,7 +124,7 @@ public class QGChangeEventTest { | |||
QGChangeEvent underTest = new QGChangeEvent(project, branch, analysis, configuration, previousStatus, supplier); | |||
assertThat(underTest.toString()) | |||
.isEqualTo("QGChangeEvent{project=bar:foo, branch=SHORT:bar:doh:zop, analysis=pto:8999999765" + | |||
.isEqualTo("QGChangeEvent{project=bar:foo, branch=BRANCH:bar:doh:zop, analysis=pto:8999999765" + | |||
", projectConfiguration=" + configuration.toString() + | |||
", previousStatus=" + previousStatus + | |||
", qualityGateSupplier=" + supplier + "}"); |
@@ -60,7 +60,7 @@ import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY; | |||
import static org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY; | |||
import static org.sonar.core.platform.EditionProvider.Edition.DEVELOPER; | |||
import static org.sonar.db.component.BranchType.LONG; | |||
import static org.sonar.db.component.BranchType.SHORT; | |||
import static org.sonar.db.component.BranchType.PULL_REQUEST; | |||
public class TelemetryDataLoaderImplTest { | |||
@Rule | |||
@@ -145,20 +145,20 @@ public class TelemetryDataLoaderImplTest { | |||
} | |||
@Test | |||
public void take_biggest_long_living_branches() { | |||
public void take_largest_branches() { | |||
server.setId("AU-TpxcB-iU5OvuD2FL7").setVersion("7.5.4"); | |||
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey(NCLOC_KEY)); | |||
ComponentDto project = db.components().insertMainBranch(db.getDefaultOrganization()); | |||
ComponentDto longBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(LONG)); | |||
ComponentDto shortBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(SHORT)); | |||
ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(LONG)); | |||
ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST)); | |||
db.measures().insertLiveMeasure(project, ncloc, m -> m.setValue(10d)); | |||
db.measures().insertLiveMeasure(longBranch, ncloc, m -> m.setValue(20d)); | |||
db.measures().insertLiveMeasure(shortBranch, ncloc, m -> m.setValue(30d)); | |||
db.measures().insertLiveMeasure(branch1, ncloc, m -> m.setValue(20d)); | |||
db.measures().insertLiveMeasure(pr, ncloc, m -> m.setValue(30d)); | |||
projectMeasuresIndexer.indexOnStartup(emptySet()); | |||
TelemetryData data = communityUnderTest.load(); | |||
assertThat(data.getNcloc()).isEqualTo(20l); | |||
assertThat(data.getNcloc()).isEqualTo(20L); | |||
} | |||
@Test |
@@ -66,7 +66,6 @@ import static org.mockito.Mockito.verifyZeroInteractions; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.core.util.stream.MoreCollectors.toArrayList; | |||
import static org.sonar.db.component.BranchType.LONG; | |||
import static org.sonar.db.component.BranchType.SHORT; | |||
import static org.sonar.db.component.ComponentTesting.newBranchDto; | |||
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; | |||
@@ -147,7 +146,7 @@ public class WebhookQGChangeEventListenerTest { | |||
public void onIssueChanges_calls_webhook_for_changeEvent_with_webhook_enabled(@Nullable EvaluatedQualityGate newQualityGate) { | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertPublicProject(organization); | |||
ComponentAndBranch branch = insertProjectBranch(project, BranchType.SHORT, "foo"); | |||
ComponentAndBranch branch = insertProjectBranch(project, BranchType.LONG, "foo"); | |||
SnapshotDto analysis = insertAnalysisTask(branch); | |||
Configuration configuration = mock(Configuration.class); | |||
mockPayloadSupplierConsumedByWebhooks(); | |||
@@ -166,7 +165,7 @@ public class WebhookQGChangeEventListenerTest { | |||
new Project(project.uuid(), project.getKey(), project.name()), | |||
null, | |||
new Analysis(analysis.getUuid(), analysis.getCreatedAt(), analysis.getRevision()), | |||
new Branch(false, "foo", Branch.Type.SHORT), | |||
new Branch(false, "foo", Branch.Type.LONG), | |||
newQualityGate, | |||
null, | |||
properties)); | |||
@@ -193,8 +192,8 @@ public class WebhookQGChangeEventListenerTest { | |||
} | |||
@Test | |||
public void onIssueChanges_calls_webhook_on_short_branch() { | |||
onIssueChangesCallsWebhookOnBranch(SHORT); | |||
public void onIssueChanges_calls_webhook_on_pr() { | |||
onIssueChangesCallsWebhookOnBranch(BranchType.PULL_REQUEST); | |||
} | |||
public void onIssueChangesCallsWebhookOnBranch(BranchType branchType) { |
@@ -844,7 +844,7 @@ public class IssueIndex { | |||
.collect(MoreCollectors.toList(projectUuids.size())); | |||
} | |||
public List<BranchStatistics> searchBranchStatistics(String projectUuid, List<String> branchUuids) { | |||
public List<PrStatistics> searchBranchStatistics(String projectUuid, List<String> branchUuids) { | |||
if (branchUuids.isEmpty()) { | |||
return Collections.emptyList(); | |||
} | |||
@@ -864,7 +864,7 @@ public class IssueIndex { | |||
.field(FIELD_ISSUE_TYPE))); | |||
SearchResponse response = request.get(); | |||
return ((StringTerms) response.getAggregations().get("branchUuids")).getBuckets().stream() | |||
.map(bucket -> new BranchStatistics(bucket.getKeyAsString(), | |||
.map(bucket -> new PrStatistics(bucket.getKeyAsString(), | |||
((StringTerms) bucket.getAggregations().get("types")).getBuckets() | |||
.stream() | |||
.collect(uniqueIndex(StringTerms.Bucket::getKeyAsString, InternalTerms.Bucket::getDocCount)))) |
@@ -300,9 +300,9 @@ public class IssueIndexTest { | |||
newDoc(branch3).setType(CODE_SMELL).setResolution(null), newDoc(branch3).setType(CODE_SMELL).setResolution(null), | |||
newDoc(fileOnBranch3).setType(CODE_SMELL).setResolution(null), newDoc(fileOnBranch3).setType(CODE_SMELL).setResolution(RESOLUTION_FIXED)); | |||
List<BranchStatistics> branchStatistics = underTest.searchBranchStatistics(project.uuid(), asList(branch1.uuid(), branch2.uuid(), branch3.uuid())); | |||
List<PrStatistics> prStatistics = underTest.searchBranchStatistics(project.uuid(), asList(branch1.uuid(), branch2.uuid(), branch3.uuid())); | |||
assertThat(branchStatistics).extracting(BranchStatistics::getBranchUuid, BranchStatistics::getBugs, BranchStatistics::getVulnerabilities, BranchStatistics::getCodeSmells) | |||
assertThat(prStatistics).extracting(PrStatistics::getBranchUuid, PrStatistics::getBugs, PrStatistics::getVulnerabilities, PrStatistics::getCodeSmells) | |||
.containsExactlyInAnyOrder( | |||
tuple(branch1.uuid(), 1L, 1L, 1L), | |||
tuple(branch3.uuid(), 0L, 0L, 3L)); | |||
@@ -320,10 +320,10 @@ public class IssueIndexTest { | |||
branchUuids.add(branch.uuid()); | |||
}); | |||
List<BranchStatistics> branchStatistics = underTest.searchBranchStatistics(project.uuid(), branchUuids); | |||
List<PrStatistics> prStatistics = underTest.searchBranchStatistics(project.uuid(), branchUuids); | |||
assertThat(branchStatistics) | |||
.extracting(BranchStatistics::getBranchUuid, BranchStatistics::getBugs, BranchStatistics::getVulnerabilities, BranchStatistics::getCodeSmells) | |||
assertThat(prStatistics) | |||
.extracting(PrStatistics::getBranchUuid, PrStatistics::getBugs, PrStatistics::getVulnerabilities, PrStatistics::getCodeSmells) | |||
.hasSize(15) | |||
.containsAll(expectedResult); | |||
} |
@@ -59,7 +59,7 @@ public class ProjectBadgesSupport { | |||
.setExampleValue(KEY_PROJECT_EXAMPLE_001); | |||
action | |||
.createParam(PARAM_BRANCH) | |||
.setDescription("Long living branch key") | |||
.setDescription("Branch key") | |||
.setExampleValue(KEY_BRANCH_EXAMPLE_001); | |||
} | |||
@@ -39,7 +39,7 @@ import org.sonar.db.measure.LiveMeasureDto; | |||
import org.sonar.db.permission.OrganizationPermission; | |||
import org.sonar.db.protobuf.DbProjectBranches; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.issue.index.BranchStatistics; | |||
import org.sonar.server.issue.index.PrStatistics; | |||
import org.sonar.server.issue.index.IssueIndex; | |||
import org.sonar.server.user.UserSession; | |||
import org.sonarqube.ws.ProjectPullRequests; | |||
@@ -109,8 +109,8 @@ public class ListAction implements PullRequestWsAction { | |||
.selectByUuids(dbSession, pullRequests.stream().map(BranchDto::getMergeBranchUuid).filter(Objects::nonNull).collect(toList())) | |||
.stream().collect(uniqueIndex(BranchDto::getUuid)); | |||
Map<String, BranchStatistics> branchStatisticsByBranchUuid = issueIndex.searchBranchStatistics(project.uuid(), pullRequestUuids).stream() | |||
.collect(uniqueIndex(BranchStatistics::getBranchUuid, Function.identity())); | |||
Map<String, PrStatistics> branchStatisticsByBranchUuid = issueIndex.searchBranchStatistics(project.uuid(), pullRequestUuids).stream() | |||
.collect(uniqueIndex(PrStatistics::getBranchUuid, Function.identity())); | |||
Map<String, LiveMeasureDto> qualityGateMeasuresByComponentUuids = dbClient.liveMeasureDao() | |||
.selectByComponentUuidsAndMetricKeys(dbSession, pullRequestUuids, singletonList(ALERT_STATUS_KEY)).stream() | |||
.collect(uniqueIndex(LiveMeasureDto::getComponentUuid)); | |||
@@ -135,7 +135,7 @@ public class ListAction implements PullRequestWsAction { | |||
} | |||
private static void addPullRequest(ProjectPullRequests.ListWsResponse.Builder response, BranchDto branch, Map<String, BranchDto> mergeBranchesByUuid, | |||
@Nullable LiveMeasureDto qualityGateMeasure, BranchStatistics branchStatistics, @Nullable String analysisDate) { | |||
@Nullable LiveMeasureDto qualityGateMeasure, PrStatistics prStatistics, @Nullable String analysisDate) { | |||
Optional<BranchDto> mergeBranch = Optional.ofNullable(mergeBranchesByUuid.get(branch.getMergeBranchUuid())); | |||
ProjectPullRequests.PullRequest.Builder builder = ProjectPullRequests.PullRequest.newBuilder(); | |||
@@ -160,18 +160,18 @@ public class ListAction implements PullRequestWsAction { | |||
} | |||
ofNullable(analysisDate).ifPresent(builder::setAnalysisDate); | |||
setQualityGate(builder, qualityGateMeasure, branchStatistics); | |||
setQualityGate(builder, qualityGateMeasure, prStatistics); | |||
response.addPullRequests(builder); | |||
} | |||
private static void setQualityGate(ProjectPullRequests.PullRequest.Builder builder, @Nullable LiveMeasureDto qualityGateMeasure, @Nullable BranchStatistics branchStatistics) { | |||
private static void setQualityGate(ProjectPullRequests.PullRequest.Builder builder, @Nullable LiveMeasureDto qualityGateMeasure, @Nullable PrStatistics prStatistics) { | |||
ProjectPullRequests.Status.Builder statusBuilder = ProjectPullRequests.Status.newBuilder(); | |||
if (qualityGateMeasure != null) { | |||
ofNullable(qualityGateMeasure.getDataAsString()).ifPresent(statusBuilder::setQualityGateStatus); | |||
} | |||
statusBuilder.setBugs(branchStatistics == null ? 0L : branchStatistics.getBugs()); | |||
statusBuilder.setVulnerabilities(branchStatistics == null ? 0L : branchStatistics.getVulnerabilities()); | |||
statusBuilder.setCodeSmells(branchStatistics == null ? 0L : branchStatistics.getCodeSmells()); | |||
statusBuilder.setBugs(prStatistics == null ? 0L : prStatistics.getBugs()); | |||
statusBuilder.setVulnerabilities(prStatistics == null ? 0L : prStatistics.getVulnerabilities()); | |||
statusBuilder.setCodeSmells(prStatistics == null ? 0L : prStatistics.getCodeSmells()); | |||
builder.setStatus(statusBuilder); | |||
} | |||
} |
@@ -27,7 +27,6 @@ import java.util.Map; | |||
import java.util.Objects; | |||
import java.util.Optional; | |||
import java.util.Set; | |||
import java.util.function.Function; | |||
import javax.annotation.Nullable; | |||
import org.sonar.api.server.ws.Change; | |||
import org.sonar.api.server.ws.Request; | |||
@@ -37,12 +36,10 @@ import org.sonar.api.web.UserRole; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.BranchDto; | |||
import org.sonar.db.component.BranchType; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.measure.LiveMeasureDto; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.issue.index.BranchStatistics; | |||
import org.sonar.server.issue.index.IssueIndex; | |||
import org.sonar.server.user.UserSession; | |||
import org.sonar.server.ws.WsUtils; | |||
@@ -59,8 +56,8 @@ import static org.sonar.api.utils.DateUtils.formatDateTime; | |||
import static org.sonar.api.web.UserRole.USER; | |||
import static org.sonar.core.util.stream.MoreCollectors.toList; | |||
import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex; | |||
import static org.sonar.db.component.BranchType.BRANCH; | |||
import static org.sonar.db.component.BranchType.LONG; | |||
import static org.sonar.db.component.BranchType.SHORT; | |||
import static org.sonar.db.permission.OrganizationPermission.SCAN; | |||
import static org.sonar.server.branch.ws.BranchesWs.addProjectParam; | |||
import static org.sonar.server.branch.ws.ProjectBranchesParameters.ACTION_LIST; | |||
@@ -106,35 +103,32 @@ public class ListAction implements BranchWsAction { | |||
checkArgument(ALLOWED_QUALIFIERS.contains(project.qualifier()), "Invalid project"); | |||
Collection<BranchDto> branches = dbClient.branchDao().selectByComponent(dbSession, project).stream() | |||
.filter(b -> b.getBranchType() == SHORT || b.getBranchType() == LONG) | |||
.filter(b -> b.getBranchType() == LONG || b.getBranchType() == BRANCH) | |||
.collect(toList()); | |||
List<String> branchUuids = branches.stream().map(BranchDto::getUuid).collect(toList()); | |||
// TODO is this still used? | |||
Map<String, BranchDto> mergeBranchesByUuid = dbClient.branchDao() | |||
.selectByUuids(dbSession, branches.stream().map(BranchDto::getMergeBranchUuid).filter(Objects::nonNull).collect(toList())) | |||
.stream().collect(uniqueIndex(BranchDto::getUuid)); | |||
Map<String, LiveMeasureDto> qualityGateMeasuresByComponentUuids = dbClient.liveMeasureDao() | |||
.selectByComponentUuidsAndMetricKeys(dbSession, branchUuids, singletonList(ALERT_STATUS_KEY)).stream() | |||
.collect(uniqueIndex(LiveMeasureDto::getComponentUuid)); | |||
Map<String, BranchStatistics> branchStatisticsByBranchUuid = issueIndex.searchBranchStatistics(project.uuid(), branches.stream() | |||
.filter(b -> b.getBranchType().equals(SHORT)) | |||
.map(BranchDto::getUuid).collect(toList())).stream() | |||
.collect(uniqueIndex(BranchStatistics::getBranchUuid, Function.identity())); | |||
Map<String, String> analysisDateByBranchUuid = dbClient.snapshotDao() | |||
.selectLastAnalysesByRootComponentUuids(dbSession, branchUuids).stream() | |||
.collect(uniqueIndex(SnapshotDto::getComponentUuid, s -> formatDateTime(s.getCreatedAt()))); | |||
ProjectBranches.ListWsResponse.Builder protobufResponse = ProjectBranches.ListWsResponse.newBuilder(); | |||
branches.forEach(b -> addBranch(protobufResponse, b, mergeBranchesByUuid, qualityGateMeasuresByComponentUuids.get(b.getUuid()), branchStatisticsByBranchUuid.get(b.getUuid()), | |||
branches.forEach(b -> addBranch(protobufResponse, b, mergeBranchesByUuid, qualityGateMeasuresByComponentUuids.get(b.getUuid()), | |||
analysisDateByBranchUuid.get(b.getUuid()))); | |||
WsUtils.writeProtobuf(protobufResponse.build(), request, response); | |||
} | |||
} | |||
private static void addBranch(ProjectBranches.ListWsResponse.Builder response, BranchDto branch, Map<String, BranchDto> mergeBranchesByUuid, | |||
@Nullable LiveMeasureDto qualityGateMeasure, BranchStatistics branchStatistics, @Nullable String analysisDate) { | |||
@Nullable LiveMeasureDto qualityGateMeasure, @Nullable String analysisDate) { | |||
ProjectBranches.Branch.Builder builder = toBranchBuilder(branch, Optional.ofNullable(mergeBranchesByUuid.get(branch.getMergeBranchUuid()))); | |||
setBranchStatus(builder, branch, qualityGateMeasure, branchStatistics); | |||
setBranchStatus(builder, qualityGateMeasure); | |||
if (analysisDate != null) { | |||
builder.setAnalysisDate(analysisDate); | |||
} | |||
@@ -147,28 +141,14 @@ public class ListAction implements BranchWsAction { | |||
ofNullable(branchKey).ifPresent(builder::setName); | |||
builder.setIsMain(branch.isMain()); | |||
builder.setType(Common.BranchType.valueOf(branch.getBranchType().name())); | |||
if (branch.getBranchType() == SHORT) { | |||
if (mergeBranch.isPresent()) { | |||
String mergeBranchKey = mergeBranch.get().getKey(); | |||
builder.setMergeBranch(mergeBranchKey); | |||
} else { | |||
builder.setIsOrphan(true); | |||
} | |||
} | |||
return builder; | |||
} | |||
private static void setBranchStatus(ProjectBranches.Branch.Builder builder, BranchDto branch, @Nullable LiveMeasureDto qualityGateMeasure, | |||
@Nullable BranchStatistics branchStatistics) { | |||
private static void setBranchStatus(ProjectBranches.Branch.Builder builder, @Nullable LiveMeasureDto qualityGateMeasure) { | |||
ProjectBranches.Status.Builder statusBuilder = ProjectBranches.Status.newBuilder(); | |||
if (qualityGateMeasure != null) { | |||
ofNullable(qualityGateMeasure.getDataAsString()).ifPresent(statusBuilder::setQualityGateStatus); | |||
} | |||
if (branch.getBranchType() == BranchType.SHORT) { | |||
statusBuilder.setBugs(branchStatistics == null ? 0L : branchStatistics.getBugs()); | |||
statusBuilder.setVulnerabilities(branchStatistics == null ? 0L : branchStatistics.getVulnerabilities()); | |||
statusBuilder.setCodeSmells(branchStatistics == null ? 0L : branchStatistics.getCodeSmells()); | |||
} | |||
builder.setStatus(statusBuilder); | |||
} |
@@ -312,7 +312,7 @@ public class BulkChangeAction implements IssuesWsAction { | |||
} | |||
private static boolean hasNotificationSupport(@Nullable BranchDto branch) { | |||
return branch != null && branch.getBranchType() != BranchType.PULL_REQUEST && branch.getBranchType() != BranchType.SHORT; | |||
return branch != null && branch.getBranchType() != BranchType.PULL_REQUEST; | |||
} | |||
private static long oldestUpdateDate(Collection<DefaultIssue> issues) { | |||
@@ -360,7 +360,7 @@ public class BulkChangeAction implements IssuesWsAction { | |||
this.issues = getAuthorizedIssues(allIssues); | |||
this.componentsByUuid = getComponents(dbSession, | |||
issues.stream().map(DefaultIssue::componentUuid).collect(MoreCollectors.toSet())).stream() | |||
.collect(uniqueIndex(ComponentDto::uuid, identity())); | |||
.collect(uniqueIndex(ComponentDto::uuid, identity())); | |||
this.rulesByKey = dbClient.ruleDao().selectDefinitionByKeys(dbSession, | |||
issues.stream().map(DefaultIssue::ruleKey).collect(MoreCollectors.toSet())).stream() | |||
.collect(uniqueIndex(RuleDefinitionDto::getKey, identity())); |
@@ -49,7 +49,6 @@ import static com.google.common.base.Preconditions.checkState; | |||
import static java.util.Collections.singleton; | |||
import static java.util.Collections.singletonList; | |||
import static org.sonar.db.component.BranchType.PULL_REQUEST; | |||
import static org.sonar.db.component.BranchType.SHORT; | |||
public class IssueUpdater { | |||
@@ -96,10 +95,10 @@ public class IssueUpdater { | |||
if ( | |||
// since this method is called after an update of the issue, date should never be null | |||
issue.updateDate() == null | |||
// name of rule is displayed in notification, rule must therefor be present | |||
|| !rule.isPresent() | |||
// notification are not supported on PRs and short lived branches | |||
|| !hasNotificationSupport(branchDto)) { | |||
// name of rule is displayed in notification, rule must therefor be present | |||
|| !rule.isPresent() | |||
// notification are not supported on PRs and short lived branches | |||
|| !hasNotificationSupport(branchDto)) { | |||
return issueDto; | |||
} | |||
@@ -126,7 +125,7 @@ public class IssueUpdater { | |||
} | |||
private static boolean hasNotificationSupport(BranchDto branch) { | |||
return branch.getBranchType() != PULL_REQUEST && branch.getBranchType() != SHORT; | |||
return branch.getBranchType() != PULL_REQUEST; | |||
} | |||
private ComponentDto getComponent(DbSession dbSession, DefaultIssue issue, @Nullable String componentUuid) { |
@@ -147,7 +147,7 @@ public class LiveMeasureComputerImpl implements LiveMeasureComputer { | |||
} | |||
private static long getBeginningOfLeakPeriod(Optional<SnapshotDto> lastAnalysis, BranchDto branch) { | |||
if (isSLBorPR(branch)) { | |||
if (isPR(branch)) { | |||
return 0L; | |||
} else { | |||
Optional<Long> beginningOfLeakPeriod = lastAnalysis.map(SnapshotDto::getPeriodDate); | |||
@@ -155,12 +155,12 @@ public class LiveMeasureComputerImpl implements LiveMeasureComputer { | |||
} | |||
} | |||
private static boolean isSLBorPR(BranchDto branch) { | |||
return branch.getBranchType() == BranchType.SHORT || branch.getBranchType() == BranchType.PULL_REQUEST; | |||
private static boolean isPR(BranchDto branch) { | |||
return branch.getBranchType() == BranchType.PULL_REQUEST; | |||
} | |||
private static boolean shouldUseLeakFormulas(SnapshotDto lastAnalysis, BranchDto branch) { | |||
return lastAnalysis.getPeriodDate() != null || isSLBorPR(branch); | |||
return lastAnalysis.getPeriodDate() != null || isPR(branch); | |||
} | |||
@CheckForNull |
@@ -79,7 +79,7 @@ public class LiveQualityGateComputerImpl implements LiveQualityGateComputer { | |||
return new Condition(metricKey, operator, conditionDto.getErrorThreshold()); | |||
}); | |||
if (branch.getBranchType() == BranchType.PULL_REQUEST || branch.getBranchType() == BranchType.SHORT) { | |||
if (branch.getBranchType() == BranchType.PULL_REQUEST) { | |||
conditions = conditions.filter(Condition::isOnLeakPeriod); | |||
} | |||
@@ -40,7 +40,6 @@ import org.sonar.api.web.UserRole; | |||
import org.sonar.core.util.stream.MoreCollectors; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.BranchType; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.measure.LiveMeasureDto; | |||
@@ -139,22 +138,22 @@ public class ComponentAction implements MeasuresWsAction { | |||
checkPermissions(component); | |||
SnapshotDto analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, component.projectUuid()).orElse(null); | |||
boolean isSLBorPR = isSLBorPR(dbSession, component, branch, pullRequest); | |||
boolean isPR = isPR(pullRequest); | |||
Set<String> metricKeysToRequest = new HashSet<>(request.metricKeys); | |||
if (isSLBorPR) { | |||
SLBorPRMeasureFix.addReplacementMetricKeys(metricKeysToRequest); | |||
if (isPR) { | |||
PrMeasureFix.addReplacementMetricKeys(metricKeysToRequest); | |||
} | |||
List<MetricDto> metrics = searchMetrics(dbSession, metricKeysToRequest); | |||
List<LiveMeasureDto> measures = searchMeasures(dbSession, component, metrics); | |||
Map<MetricDto, LiveMeasureDto> measuresByMetric = getMeasuresByMetric(measures, metrics); | |||
if (isSLBorPR) { | |||
if (isPR) { | |||
Set<String> originalMetricKeys = new HashSet<>(request.metricKeys); | |||
SLBorPRMeasureFix.createReplacementMeasures(metrics, measuresByMetric, originalMetricKeys); | |||
SLBorPRMeasureFix.removeMetricsNotRequested(metrics, originalMetricKeys); | |||
PrMeasureFix.createReplacementMeasures(metrics, measuresByMetric, originalMetricKeys); | |||
PrMeasureFix.removeMetricsNotRequested(metrics, originalMetricKeys); | |||
} | |||
Optional<Measures.Period> period = snapshotToWsPeriods(analysis); | |||
@@ -216,11 +215,7 @@ public class ComponentAction implements MeasuresWsAction { | |||
} | |||
} | |||
private boolean isSLBorPR(DbSession dbSession, ComponentDto component, @Nullable String branch, @Nullable String pullRequest) { | |||
if (branch != null) { | |||
return dbClient.branchDao().selectByUuid(dbSession, component.projectUuid()) | |||
.map(b -> b.getBranchType() == BranchType.SHORT).orElse(false); | |||
} | |||
private boolean isPR(@Nullable String pullRequest) { | |||
return pullRequest != null; | |||
} | |||
@@ -57,7 +57,6 @@ import org.sonar.core.i18n.I18n; | |||
import org.sonar.core.util.stream.MoreCollectors; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.BranchType; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTreeQuery; | |||
import org.sonar.db.component.ComponentTreeQuery.Strategy; | |||
@@ -409,9 +408,9 @@ public class ComponentTreeAction implements MeasuresWsAction { | |||
Set<String> requestedMetricKeys = new HashSet<>(wsRequest.getMetricKeys()); | |||
Set<String> metricKeysToSearch = new HashSet<>(requestedMetricKeys); | |||
boolean isSLBorPR = isSLBorPR(dbSession, baseComponent, wsRequest.getBranch(), wsRequest.getPullRequest()); | |||
if (isSLBorPR) { | |||
SLBorPRMeasureFix.addReplacementMetricKeys(metricKeysToSearch); | |||
boolean isPR = isPR(wsRequest.getPullRequest()); | |||
if (isPR) { | |||
PrMeasureFix.addReplacementMetricKeys(metricKeysToSearch); | |||
} | |||
ComponentTreeQuery componentTreeQuery = toComponentTreeQuery(wsRequest, baseComponent); | |||
@@ -422,9 +421,9 @@ public class ComponentTreeAction implements MeasuresWsAction { | |||
components, | |||
metrics); | |||
if (isSLBorPR) { | |||
SLBorPRMeasureFix.removeMetricsNotRequested(metrics, requestedMetricKeys); | |||
SLBorPRMeasureFix.createReplacementMeasures(metrics, measuresByComponentUuidAndMetric, requestedMetricKeys); | |||
if (isPR) { | |||
PrMeasureFix.removeMetricsNotRequested(metrics, requestedMetricKeys); | |||
PrMeasureFix.createReplacementMeasures(metrics, measuresByComponentUuidAndMetric, requestedMetricKeys); | |||
} | |||
components = filterComponents(components, measuresByComponentUuidAndMetric, metrics, wsRequest); | |||
@@ -445,11 +444,7 @@ public class ComponentTreeAction implements MeasuresWsAction { | |||
} | |||
} | |||
private boolean isSLBorPR(DbSession dbSession, ComponentDto component, @Nullable String branch, @Nullable String pullRequest) { | |||
if (branch != null) { | |||
return dbClient.branchDao().selectByUuid(dbSession, component.projectUuid()) | |||
.map(b -> b.getBranchType() == BranchType.SHORT).orElse(false); | |||
} | |||
private boolean isPR(@Nullable String pullRequest) { | |||
return pullRequest != null; | |||
} | |||
@@ -65,7 +65,7 @@ import static org.sonar.api.measures.CoreMetrics.VULNERABILITIES_KEY; | |||
* See SONAR-11736 | |||
* This class should be removed in 8.0. | |||
*/ | |||
class SLBorPRMeasureFix { | |||
class PrMeasureFix { | |||
static final BiMap<String, String> METRICS; | |||
static { | |||
@@ -95,7 +95,7 @@ class SLBorPRMeasureFix { | |||
METRICS.put(NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, RELIABILITY_REMEDIATION_EFFORT_KEY); | |||
} | |||
private SLBorPRMeasureFix() { | |||
private PrMeasureFix() { | |||
// static only | |||
} | |||
@@ -98,7 +98,7 @@ public class SearchAction implements ProjectAnalysesWsAction { | |||
.setExampleValue(KeyExamples.KEY_PROJECT_EXAMPLE_001); | |||
action.createParam(PARAM_BRANCH) | |||
.setDescription("Key of a long lived branch") | |||
.setDescription("Key of a branch") | |||
.setSince("6.6") | |||
.setInternal(true) | |||
.setExampleValue(KEY_BRANCH_EXAMPLE_001); | |||
@@ -182,23 +182,10 @@ public class SearchAction implements ProjectAnalysesWsAction { | |||
private void addProject(SearchData.Builder data) { | |||
ComponentDto project = loadComponent(data.getDbSession(), data.getRequest()); | |||
checkBranchType(project.uuid(), data.getDbSession(), data.getRequest().getBranch()); | |||
checkArgument(Scopes.PROJECT.equals(project.scope()) && ALLOWED_QUALIFIERS.contains(project.qualifier()), "A project, portfolio or application is required"); | |||
data.setProject(project); | |||
} | |||
private void checkBranchType(String rootComponentUuid, DbSession dbSession, @Nullable String branchName) { | |||
if (branchName == null) { | |||
return; | |||
} | |||
Optional<BranchDto> branch = branchDao.selectByUuid(dbSession, rootComponentUuid); | |||
BranchDto branchDto = branch | |||
.orElseThrow(() -> new IllegalArgumentException(String.format("Branch '%s' not found", branchName))); | |||
if (branchDto.getBranchType() != BranchType.LONG) { | |||
throw new IllegalArgumentException(String.format("Branch '%s' is not of type LONG", branchName)); | |||
} | |||
} | |||
private ComponentDto loadComponent(DbSession dbSession, SearchRequest request) { | |||
String project = request.getProject(); | |||
String branch = request.getBranch(); |
@@ -122,9 +122,6 @@ public class SetBaselineAction implements ProjectAnalysesWsAction { | |||
BranchDto branchDto = dbClient.branchDao().selectByUuid(dbSession, project.uuid()) | |||
.orElseThrow(() -> new NotFoundException(format("Branch '%s' is not found", branchKey))); | |||
checkArgument(branchDto.getBranchType() == BranchType.LONG, | |||
"Not a long-living branch: '%s'", branchKey); | |||
return project; | |||
} | |||
@@ -28,13 +28,11 @@ import org.sonar.api.web.UserRole; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.BranchDto; | |||
import org.sonar.db.component.BranchType; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.user.UserSession; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static java.lang.String.format; | |||
import static org.apache.commons.lang.StringUtils.trimToNull; | |||
import static org.sonar.server.projectanalysis.ws.ProjectAnalysesWsParameters.PARAM_BRANCH; | |||
@@ -106,9 +104,6 @@ public class UnsetBaselineAction implements ProjectAnalysesWsAction { | |||
BranchDto branchDto = dbClient.branchDao().selectByUuid(dbSession, project.uuid()) | |||
.orElseThrow(() -> new NotFoundException(format("Branch '%s' is not found", branchKey))); | |||
checkArgument(branchDto.getBranchType() == BranchType.LONG, | |||
"Not a long-living branch: '%s'", branchKey); | |||
return project; | |||
} | |||
@@ -3,13 +3,9 @@ | |||
{ | |||
"name": "feature/foo", | |||
"isMain": false, | |||
"type": "SHORT", | |||
"mergeBranch": "master", | |||
"type": "LONG", | |||
"status": { | |||
"qualityGateStatus": "OK", | |||
"bugs": 1, | |||
"vulnerabilities": 0, | |||
"codeSmells": 0 | |||
"qualityGateStatus": "OK" | |||
}, | |||
"analysisDate": "2017-04-03T13:37:00+0100" | |||
}, |
@@ -65,7 +65,6 @@ import static org.sonar.api.measures.Metric.ValueType.RATING; | |||
import static org.sonar.api.measures.Metric.ValueType.WORK_DUR; | |||
import static org.sonar.api.web.UserRole.USER; | |||
import static org.sonar.db.component.BranchType.LONG; | |||
import static org.sonar.db.component.BranchType.SHORT; | |||
import static org.sonar.server.badge.ws.SvgGenerator.Color.DEFAULT; | |||
import static org.sonar.server.badge.ws.SvgGenerator.Color.QUALITY_GATE_ERROR; | |||
import static org.sonar.server.badge.ws.SvgGenerator.Color.QUALITY_GATE_OK; | |||
@@ -320,23 +319,6 @@ public class MeasureActionTest { | |||
checkError(response, "Project is invalid"); | |||
} | |||
@Test | |||
public void return_error_on_short_living_branch() throws ParseException { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto shortBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(SHORT)); | |||
UserDto user = db.users().insertUser(); | |||
userSession.logIn(user).addProjectPermission(USER, project); | |||
MetricDto metric = db.measures().insertMetric(m -> m.setKey(BUGS_KEY).setValueType(INT.name())); | |||
TestResponse response = ws.newRequest() | |||
.setParam("project", shortBranch.getKey()) | |||
.setParam("branch", shortBranch.getBranch()) | |||
.setParam("metric", metric.getKey()) | |||
.execute(); | |||
checkError(response, "Project is invalid"); | |||
} | |||
@Test | |||
public void return_error_on_private_project() throws ParseException { | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
@@ -472,6 +454,7 @@ public class MeasureActionTest { | |||
assertThat(newResponse.getInput()).isEmpty(); | |||
assertThat(newResponse.getStatus()).isEqualTo(304); | |||
} | |||
private MetricDto createQualityGateMetric() { | |||
return db.measures().insertMetric(m -> m.setKey(CoreMetrics.ALERT_STATUS_KEY).setValueType(LEVEL.name())); | |||
} |
@@ -51,7 +51,6 @@ import static org.sonar.api.measures.Metric.Level.OK; | |||
import static org.sonar.api.measures.Metric.ValueType.LEVEL; | |||
import static org.sonar.api.web.UserRole.USER; | |||
import static org.sonar.db.component.BranchType.LONG; | |||
import static org.sonar.db.component.BranchType.SHORT; | |||
public class QualityGateActionTest { | |||
@@ -190,20 +189,6 @@ public class QualityGateActionTest { | |||
checkError(response, "Project is invalid"); | |||
} | |||
@Test | |||
public void return_error_on_short_living_branch() throws ParseException { | |||
ComponentDto project = db.components().insertMainBranch(p -> p.setPrivate(false)); | |||
userSession.registerComponents(project); | |||
ComponentDto shortBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(SHORT)); | |||
TestResponse response = ws.newRequest() | |||
.setParam("project", shortBranch.getKey()) | |||
.setParam("branch", shortBranch.getBranch()) | |||
.execute(); | |||
checkError(response, "Project is invalid"); | |||
} | |||
@Test | |||
public void return_error_on_private_project() throws ParseException { | |||
ComponentDto project = db.components().insertPrivateProject(); |
@@ -19,7 +19,6 @@ | |||
*/ | |||
package org.sonar.server.branch.ws; | |||
import java.util.Optional; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
@@ -54,21 +53,16 @@ import static java.lang.String.format; | |||
import static java.util.Collections.emptySet; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.tuple; | |||
import static org.sonar.api.issue.Issue.RESOLUTION_FALSE_POSITIVE; | |||
import static org.sonar.api.issue.Issue.RESOLUTION_FIXED; | |||
import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY; | |||
import static org.sonar.api.resources.Qualifiers.PROJECT; | |||
import static org.sonar.api.rules.RuleType.BUG; | |||
import static org.sonar.api.rules.RuleType.CODE_SMELL; | |||
import static org.sonar.api.rules.RuleType.VULNERABILITY; | |||
import static org.sonar.api.utils.DateUtils.dateToLong; | |||
import static org.sonar.api.utils.DateUtils.parseDateTime; | |||
import static org.sonar.api.web.UserRole.USER; | |||
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION; | |||
import static org.sonar.db.component.BranchType.SHORT; | |||
import static org.sonar.db.component.BranchType.LONG; | |||
import static org.sonar.db.component.SnapshotTesting.newAnalysis; | |||
import static org.sonar.test.JsonAssert.assertJson; | |||
import static org.sonarqube.ws.ProjectBranches.Status; | |||
public class ListActionTest { | |||
@@ -112,14 +106,14 @@ public class ListActionTest { | |||
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(project.uuid())); | |||
ComponentDto branch = db.components() | |||
.insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(LONG)); | |||
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")); | |||
newAnalysis(branch).setLast(true).setCreatedAt(parseDateTime("2017-04-03T13:37:00+0100").getTime())); | |||
db.measures().insertLiveMeasure(branch, qualityGateStatus, m -> m.setData("OK")); | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
db.issues().insert(rule, shortLivingBranch, shortLivingBranch, i -> i.setType(BUG).setResolution(null)); | |||
db.issues().insert(rule, branch, branch, i -> i.setType(BUG).setResolution(null)); | |||
issueIndexer.indexOnStartup(emptySet()); | |||
@@ -141,14 +135,14 @@ public class ListActionTest { | |||
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(project.uuid())); | |||
ComponentDto branch = db.components() | |||
.insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(LONG)); | |||
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")); | |||
newAnalysis(branch).setLast(true).setCreatedAt(parseDateTime("2017-04-03T13:37:00+0100").getTime())); | |||
db.measures().insertLiveMeasure(branch, qualityGateStatus, m -> m.setData("OK")); | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
db.issues().insert(rule, shortLivingBranch, shortLivingBranch, i -> i.setType(BUG).setResolution(null)); | |||
db.issues().insert(rule, branch, branch, i -> i.setType(BUG).setResolution(null)); | |||
issueIndexer.indexOnStartup(emptySet()); | |||
userSession.logIn().addProjectPermission(SCAN_EXECUTION, project); | |||
@@ -223,65 +217,7 @@ public class ListActionTest { | |||
} | |||
@Test | |||
public void short_living_branches() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
userSession.logIn().addProjectPermission(USER, project); | |||
ComponentDto longLivingBranch = db.components().insertProjectBranch(project, | |||
b -> b.setKey("long").setBranchType(org.sonar.db.component.BranchType.LONG)); | |||
ComponentDto shortLivingBranch = db.components().insertProjectBranch(project, | |||
b -> b.setKey("short").setBranchType(SHORT).setMergeBranchUuid(longLivingBranch.uuid())); | |||
ComponentDto shortLivingBranchOnMaster = db.components().insertProjectBranch(project, | |||
b -> b.setKey("short_on_master").setBranchType(SHORT).setMergeBranchUuid(project.uuid())); | |||
ListWsResponse response = ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.executeProtobuf(ListWsResponse.class); | |||
assertThat(response.getBranchesList()) | |||
.extracting(Branch::getName, Branch::getType, Branch::getMergeBranch) | |||
.containsExactlyInAnyOrder( | |||
tuple("master", BranchType.LONG, ""), | |||
tuple(longLivingBranch.getBranch(), BranchType.LONG, ""), | |||
tuple(shortLivingBranch.getBranch(), BranchType.SHORT, longLivingBranch.getBranch()), | |||
tuple(shortLivingBranchOnMaster.getBranch(), BranchType.SHORT, "master")); | |||
} | |||
@Test | |||
public void mergeBranch_is_using_default_main_name_when_main_branch_has_no_name() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
userSession.logIn().addProjectPermission(USER, project); | |||
ComponentDto shortLivingBranch = db.components().insertProjectBranch(project, | |||
b -> b.setKey("short").setBranchType(SHORT).setMergeBranchUuid(project.uuid())); | |||
ProjectBranches.ShowWsResponse response = ws.newRequest() | |||
.setParam("project", shortLivingBranch.getKey()) | |||
.executeProtobuf(ProjectBranches.ShowWsResponse.class); | |||
assertThat(response.getBranch()) | |||
.extracting(Branch::getName, Branch::getType, Branch::getMergeBranch) | |||
.containsExactlyInAnyOrder(shortLivingBranch.getBranch(), BranchType.SHORT, "master"); | |||
} | |||
@Test | |||
public void short_living_branch_on_removed_branch() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
userSession.logIn().addProjectPermission(USER, project); | |||
ComponentDto shortLivingBranch = db.components().insertProjectBranch(project, | |||
b -> b.setKey("short").setBranchType(SHORT).setMergeBranchUuid("unknown")); | |||
ListWsResponse response = ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.executeProtobuf(ListWsResponse.class); | |||
assertThat(response.getBranchesList()) | |||
.extracting(Branch::getName, Branch::getType, Branch::hasMergeBranch, Branch::getIsOrphan) | |||
.containsExactlyInAnyOrder( | |||
tuple("master", BranchType.LONG, false, false), | |||
tuple(shortLivingBranch.getBranch(), BranchType.SHORT, false, true)); | |||
} | |||
@Test | |||
public void status_on_long_living_branch() { | |||
public void status_on_branch() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
userSession.logIn().addProjectPermission(USER, project); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.LONG)); | |||
@@ -296,79 +232,15 @@ public class ListActionTest { | |||
.containsExactlyInAnyOrder(tuple(false, ""), tuple(true, "OK")); | |||
} | |||
@Test | |||
public void status_on_short_living_branches() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
userSession.logIn().addProjectPermission(USER, project); | |||
ComponentDto longLivingBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.LONG)); | |||
ComponentDto shortLivingBranch = db.components().insertProjectBranch(project, | |||
b -> b.setKey("short").setBranchType(SHORT).setMergeBranchUuid(longLivingBranch.uuid())); | |||
db.measures().insertLiveMeasure(shortLivingBranch, qualityGateStatus, m -> m.setData("OK")); | |||
RuleDefinitionDto rule = db.rules().insert(); | |||
db.issues().insert(rule, shortLivingBranch, shortLivingBranch, i -> i.setType(BUG).setResolution(null)); | |||
db.issues().insert(rule, shortLivingBranch, shortLivingBranch, i -> i.setType(BUG).setResolution(RESOLUTION_FIXED)); | |||
db.issues().insert(rule, shortLivingBranch, shortLivingBranch, i -> i.setType(VULNERABILITY).setResolution(null)); | |||
db.issues().insert(rule, shortLivingBranch, shortLivingBranch, i -> i.setType(VULNERABILITY).setResolution(null)); | |||
db.issues().insert(rule, shortLivingBranch, shortLivingBranch, i -> i.setType(CODE_SMELL).setResolution(null)); | |||
db.issues().insert(rule, shortLivingBranch, shortLivingBranch, i -> i.setType(CODE_SMELL).setResolution(null)); | |||
db.issues().insert(rule, shortLivingBranch, shortLivingBranch, i -> i.setType(CODE_SMELL).setResolution(null)); | |||
db.issues().insert(rule, shortLivingBranch, shortLivingBranch, i -> i.setType(CODE_SMELL).setResolution(RESOLUTION_FALSE_POSITIVE)); | |||
issueIndexer.indexOnStartup(emptySet()); | |||
permissionIndexerTester.allowOnlyAnyone(project); | |||
ListWsResponse response = ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.executeProtobuf(ListWsResponse.class); | |||
assertThat(response.getBranchesList().stream().map(ProjectBranches.Branch::getStatus)) | |||
.extracting(Status::hasBugs, Status::getBugs, Status::hasVulnerabilities, Status::getVulnerabilities, Status::hasCodeSmells, Status::getCodeSmells) | |||
.containsExactlyInAnyOrder( | |||
tuple(false, 0L, false, 0L, false, 0L), | |||
tuple(false, 0L, false, 0L, false, 0L), | |||
tuple(true, 1L, true, 2L, true, 3L)); | |||
Optional<Branch> shortBranch = response.getBranchesList().stream().filter(b -> b.getName().equals("short")).findFirst(); | |||
assertThat(shortBranch).isPresent(); | |||
assertThat(shortBranch.get().getStatus().getQualityGateStatus()).isNotEmpty(); | |||
} | |||
@Test | |||
public void status_on_short_living_branch_with_no_issue() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
userSession.logIn().addProjectPermission(USER, project); | |||
ComponentDto longLivingBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.LONG)); | |||
db.components().insertProjectBranch(project, b -> b.setBranchType(SHORT).setMergeBranchUuid(longLivingBranch.uuid())); | |||
issueIndexer.indexOnStartup(emptySet()); | |||
permissionIndexerTester.allowOnlyAnyone(project); | |||
ListWsResponse response = ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.executeProtobuf(ListWsResponse.class); | |||
assertThat(response.getBranchesList().stream().filter(b -> b.getType().equals(BranchType.SHORT)).map(ProjectBranches.Branch::getStatus)) | |||
.extracting(Status::getBugs, Status::getVulnerabilities, Status::getCodeSmells) | |||
.containsExactlyInAnyOrder(tuple(0L, 0L, 0L)); | |||
} | |||
@Test | |||
public void response_contains_date_of_last_analysis() { | |||
Long lastAnalysisLongLivingBranch = dateToLong(parseDateTime("2017-04-01T00:00:00+0100")); | |||
Long previousAnalysisShortLivingBranch = dateToLong(parseDateTime("2017-04-02T00:00:00+0100")); | |||
Long lastAnalysisShortLivingBranch = dateToLong(parseDateTime("2017-04-03T00:00:00+0100")); | |||
Long lastAnalysisBranch = dateToLong(parseDateTime("2017-04-01T00:00:00+0100")); | |||
ComponentDto project = db.components().insertMainBranch(); | |||
userSession.logIn().addProjectPermission(USER, project); | |||
ComponentDto shortLivingBranch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(SHORT).setMergeBranchUuid(project.uuid())); | |||
ComponentDto longLivingBranch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.LONG)); | |||
ComponentDto shortLivingBranch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(SHORT).setMergeBranchUuid(longLivingBranch2.uuid())); | |||
db.getDbClient().snapshotDao().insert(db.getSession(), | |||
newAnalysis(longLivingBranch2).setCreatedAt(lastAnalysisLongLivingBranch)); | |||
db.getDbClient().snapshotDao().insert(db.getSession(), | |||
newAnalysis(shortLivingBranch2).setCreatedAt(previousAnalysisShortLivingBranch).setLast(false)); | |||
ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.LONG)); | |||
db.getDbClient().snapshotDao().insert(db.getSession(), | |||
newAnalysis(shortLivingBranch2).setCreatedAt(lastAnalysisShortLivingBranch)); | |||
newAnalysis(branch2).setCreatedAt(lastAnalysisBranch)); | |||
db.commit(); | |||
issueIndexer.indexOnStartup(emptySet()); | |||
permissionIndexerTester.allowOnlyAnyone(project); | |||
@@ -382,9 +254,7 @@ public class ListActionTest { | |||
b -> "".equals(b.getAnalysisDate()) ? null : dateToLong(parseDateTime(b.getAnalysisDate()))) | |||
.containsExactlyInAnyOrder( | |||
tuple(BranchType.LONG, false, null), | |||
tuple(BranchType.SHORT, false, null), | |||
tuple(BranchType.LONG, true, lastAnalysisLongLivingBranch), | |||
tuple(BranchType.SHORT, true, lastAnalysisShortLivingBranch)); | |||
tuple(BranchType.LONG, true, lastAnalysisBranch)); | |||
} | |||
@Test |
@@ -73,6 +73,7 @@ import static org.sonar.db.ce.CeQueueDto.Status.PENDING; | |||
import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_KEY; | |||
import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_TYPE_KEY; | |||
import static org.sonar.db.ce.CeTaskCharacteristicDto.PULL_REQUEST; | |||
import static org.sonar.db.component.BranchType.BRANCH; | |||
import static org.sonar.db.component.BranchType.LONG; | |||
import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_ID; | |||
import static org.sonar.server.ce.ws.CeWsParameters.PARAM_MAX_EXECUTED_AT; | |||
@@ -394,34 +395,34 @@ public class ActivityActionTest { | |||
} | |||
@Test | |||
public void long_living_branch_in_past_activity() { | |||
public void branch_in_past_activity() { | |||
logInAsSystemAdministrator(); | |||
ComponentDto project = db.components().insertMainBranch(); | |||
userSession.addProjectPermission(UserRole.USER, project); | |||
ComponentDto longLivingBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(LONG)); | |||
SnapshotDto analysis = db.components().insertSnapshot(longLivingBranch); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH)); | |||
SnapshotDto analysis = db.components().insertSnapshot(branch); | |||
CeActivityDto activity = insertActivity("T1", project, SUCCESS, analysis); | |||
insertCharacteristic(activity, BRANCH_KEY, longLivingBranch.getBranch()); | |||
insertCharacteristic(activity, BRANCH_TYPE_KEY, LONG.name()); | |||
insertCharacteristic(activity, BRANCH_KEY, branch.getBranch()); | |||
insertCharacteristic(activity, BRANCH_TYPE_KEY, BRANCH.name()); | |||
ActivityResponse response = ws.newRequest().executeProtobuf(ActivityResponse.class); | |||
assertThat(response.getTasksList()) | |||
.extracting(Task::getId, Ce.Task::getBranch, Ce.Task::getBranchType, Ce.Task::getStatus, Ce.Task::getComponentKey) | |||
.containsExactlyInAnyOrder( | |||
tuple("T1", longLivingBranch.getBranch(), Common.BranchType.LONG, Ce.TaskStatus.SUCCESS, longLivingBranch.getKey())); | |||
tuple("T1", branch.getBranch(), Common.BranchType.BRANCH, Ce.TaskStatus.SUCCESS, branch.getKey())); | |||
} | |||
@Test | |||
public void long_living_branch_in_queue_analysis() { | |||
public void branch_in_queue_analysis() { | |||
logInAsSystemAdministrator(); | |||
String branch = "ny_branch"; | |||
CeQueueDto queue1 = insertQueue("T1", null, IN_PROGRESS); | |||
insertCharacteristic(queue1, BRANCH_KEY, branch); | |||
insertCharacteristic(queue1, BRANCH_TYPE_KEY, LONG.name()); | |||
insertCharacteristic(queue1, BRANCH_TYPE_KEY, BRANCH.name()); | |||
CeQueueDto queue2 = insertQueue("T2", null, PENDING); | |||
insertCharacteristic(queue2, BRANCH_KEY, branch); | |||
insertCharacteristic(queue2, BRANCH_TYPE_KEY, LONG.name()); | |||
insertCharacteristic(queue2, BRANCH_TYPE_KEY, BRANCH.name()); | |||
ActivityResponse response = ws.newRequest() | |||
.setParam("status", "FAILED,IN_PROGRESS,PENDING") | |||
@@ -430,8 +431,8 @@ public class ActivityActionTest { | |||
assertThat(response.getTasksList()) | |||
.extracting(Task::getId, Ce.Task::getBranch, Ce.Task::getBranchType, Ce.Task::getStatus) | |||
.containsExactlyInAnyOrder( | |||
tuple("T1", branch, Common.BranchType.LONG, Ce.TaskStatus.IN_PROGRESS), | |||
tuple("T2", branch, Common.BranchType.LONG, Ce.TaskStatus.PENDING)); | |||
tuple("T1", branch, Common.BranchType.BRANCH, Ce.TaskStatus.IN_PROGRESS), | |||
tuple("T2", branch, Common.BranchType.BRANCH, Ce.TaskStatus.PENDING)); | |||
} | |||
@Test |
@@ -55,8 +55,7 @@ import static org.sonar.db.ce.CeQueueDto.Status.IN_PROGRESS; | |||
import static org.sonar.db.ce.CeQueueDto.Status.PENDING; | |||
import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_KEY; | |||
import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_TYPE_KEY; | |||
import static org.sonar.db.component.BranchType.LONG; | |||
import static org.sonar.db.component.BranchType.SHORT; | |||
import static org.sonar.db.component.BranchType.BRANCH; | |||
import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT; | |||
import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_ID; | |||
@@ -177,14 +176,14 @@ public class ComponentActionTest { | |||
} | |||
@Test | |||
public void long_living_branch_in_activity() { | |||
public void branch_in_activity() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
userSession.addProjectPermission(UserRole.USER, project); | |||
ComponentDto longLivingBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(LONG)); | |||
SnapshotDto analysis = db.components().insertSnapshot(longLivingBranch); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH)); | |||
SnapshotDto analysis = db.components().insertSnapshot(branch); | |||
CeActivityDto activity = insertActivity("T1", project, SUCCESS, analysis); | |||
insertCharacteristic(activity, BRANCH_KEY, longLivingBranch.getBranch()); | |||
insertCharacteristic(activity, BRANCH_TYPE_KEY, LONG.name()); | |||
insertCharacteristic(activity, BRANCH_KEY, branch.getBranch()); | |||
insertCharacteristic(activity, BRANCH_TYPE_KEY, BRANCH.name()); | |||
Ce.ComponentResponse response = ws.newRequest() | |||
.setParam(PARAM_COMPONENT, project.getKey()) | |||
@@ -193,30 +192,30 @@ public class ComponentActionTest { | |||
assertThat(response.getCurrent()) | |||
.extracting(Ce.Task::getId, Ce.Task::getBranch, Ce.Task::getBranchType, Ce.Task::getStatus, Ce.Task::getComponentKey, Ce.Task::getWarningCount, Ce.Task::getWarningsList) | |||
.containsOnly( | |||
"T1", longLivingBranch.getBranch(), Common.BranchType.LONG, Ce.TaskStatus.SUCCESS, project.getKey(), 0, emptyList()); | |||
"T1", branch.getBranch(), Common.BranchType.BRANCH, Ce.TaskStatus.SUCCESS, project.getKey(), 0, emptyList()); | |||
} | |||
@Test | |||
public void long_living_branch_in_queue_analysis() { | |||
public void branch_in_queue_analysis() { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
userSession.addProjectPermission(UserRole.USER, project); | |||
ComponentDto longLivingBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(LONG)); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH)); | |||
CeQueueDto queue1 = insertQueue("T1", project, IN_PROGRESS); | |||
insertCharacteristic(queue1, BRANCH_KEY, longLivingBranch.getBranch()); | |||
insertCharacteristic(queue1, BRANCH_TYPE_KEY, LONG.name()); | |||
insertCharacteristic(queue1, BRANCH_KEY, branch.getBranch()); | |||
insertCharacteristic(queue1, BRANCH_TYPE_KEY, BRANCH.name()); | |||
CeQueueDto queue2 = insertQueue("T2", project, PENDING); | |||
insertCharacteristic(queue2, BRANCH_KEY, longLivingBranch.getBranch()); | |||
insertCharacteristic(queue2, BRANCH_TYPE_KEY, LONG.name()); | |||
insertCharacteristic(queue2, BRANCH_KEY, branch.getBranch()); | |||
insertCharacteristic(queue2, BRANCH_TYPE_KEY, BRANCH.name()); | |||
Ce.ComponentResponse response = ws.newRequest() | |||
.setParam(PARAM_COMPONENT, longLivingBranch.getKey()) | |||
.setParam(PARAM_COMPONENT, branch.getKey()) | |||
.executeProtobuf(Ce.ComponentResponse.class); | |||
assertThat(response.getQueueList()) | |||
.extracting(Ce.Task::getId, Ce.Task::getBranch, Ce.Task::getBranchType, Ce.Task::getStatus, Ce.Task::getComponentKey, Ce.Task::getWarningCount, Ce.Task::getWarningsList) | |||
.containsOnly( | |||
tuple("T1", longLivingBranch.getBranch(), Common.BranchType.LONG, Ce.TaskStatus.IN_PROGRESS, project.getKey(), 0, emptyList()), | |||
tuple("T2", longLivingBranch.getBranch(), Common.BranchType.LONG, Ce.TaskStatus.PENDING, project.getKey(), 0, emptyList())); | |||
tuple("T1", branch.getBranch(), Common.BranchType.BRANCH, Ce.TaskStatus.IN_PROGRESS, project.getKey(), 0, emptyList()), | |||
tuple("T2", branch.getBranch(), Common.BranchType.BRANCH, Ce.TaskStatus.PENDING, project.getKey(), 0, emptyList())); | |||
} | |||
@Test | |||
@@ -224,25 +223,25 @@ public class ComponentActionTest { | |||
ComponentDto project = db.components().insertMainBranch(); | |||
userSession.addProjectPermission(UserRole.USER, project); | |||
insertQueue("Main", project, IN_PROGRESS); | |||
ComponentDto longLivingBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(LONG).setKey("long-branch")); | |||
CeQueueDto longLivingBranchQueue = insertQueue("Long", project, IN_PROGRESS); | |||
insertCharacteristic(longLivingBranchQueue, BRANCH_KEY, longLivingBranch.getBranch()); | |||
insertCharacteristic(longLivingBranchQueue, BRANCH_TYPE_KEY, LONG.name()); | |||
ComponentDto shortLivingBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(SHORT).setKey("short-branch")); | |||
CeQueueDto shortLivingBranchQueue = insertQueue("Short", project, PENDING); | |||
insertCharacteristic(shortLivingBranchQueue, BRANCH_KEY, shortLivingBranch.getBranch()); | |||
insertCharacteristic(shortLivingBranchQueue, BRANCH_TYPE_KEY, SHORT.name()); | |||
ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey("branch1")); | |||
CeQueueDto branchQueue1 = insertQueue("Branch1", project, IN_PROGRESS); | |||
insertCharacteristic(branchQueue1, BRANCH_KEY, branch1.getBranch()); | |||
insertCharacteristic(branchQueue1, BRANCH_TYPE_KEY, BRANCH.name()); | |||
ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey("branch2")); | |||
CeQueueDto branchQueue2 = insertQueue("Branch2", project, PENDING); | |||
insertCharacteristic(branchQueue2, BRANCH_KEY, branch2.getBranch()); | |||
insertCharacteristic(branchQueue2, BRANCH_TYPE_KEY, BRANCH.name()); | |||
Ce.ComponentResponse response = ws.newRequest() | |||
.setParam(PARAM_COMPONENT, longLivingBranch.getKey()) | |||
.setParam(PARAM_COMPONENT, branch1.getKey()) | |||
.executeProtobuf(Ce.ComponentResponse.class); | |||
assertThat(response.getQueueList()) | |||
.extracting(Ce.Task::getId, Ce.Task::getComponentKey, Ce.Task::getBranch, Ce.Task::getBranchType, Ce.Task::getWarningCount, Ce.Task::getWarningsList) | |||
.containsOnly( | |||
tuple("Main", project.getKey(), "", Common.BranchType.UNKNOWN_BRANCH_TYPE, 0, emptyList()), | |||
tuple("Long", longLivingBranch.getKey(), longLivingBranch.getBranch(), Common.BranchType.LONG, 0, emptyList()), | |||
tuple("Short", shortLivingBranch.getKey(), shortLivingBranch.getBranch(), Common.BranchType.SHORT, 0, emptyList())); | |||
tuple("Branch1", branch1.getKey(), branch1.getBranch(), Common.BranchType.BRANCH, 0, emptyList()), | |||
tuple("Branch2", branch2.getKey(), branch2.getBranch(), Common.BranchType.BRANCH, 0, emptyList())); | |||
} | |||
@Test | |||
@@ -250,7 +249,7 @@ public class ComponentActionTest { | |||
ComponentDto privateProject = db.components().insertPrivateProject(); | |||
userSession.addProjectPermission(UserRole.USER, privateProject); | |||
SnapshotDto analysis = db.components().insertSnapshot(privateProject); | |||
CeActivityDto activity = insertActivity("Short", privateProject, SUCCESS, analysis); | |||
CeActivityDto activity = insertActivity("Branch", privateProject, SUCCESS, analysis); | |||
int messageCount = 1 + new Random().nextInt(10); | |||
IntStream.range(0, messageCount).forEach(i -> db.getDbClient().ceTaskMessageDao().insert(db.getSession(), new CeTaskMessageDto() | |||
.setUuid("uuid_" + i) |
@@ -55,6 +55,7 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION; | |||
import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_KEY; | |||
import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_TYPE_KEY; | |||
import static org.sonar.db.component.BranchType.BRANCH; | |||
import static org.sonar.db.component.BranchType.LONG; | |||
import static org.sonar.db.permission.OrganizationPermission.SCAN; | |||
@@ -162,15 +163,15 @@ public class TaskActionTest { | |||
} | |||
@Test | |||
public void long_living_branch_in_past_activity() { | |||
public void branch_in_past_activity() { | |||
logInAsRoot(); | |||
ComponentDto project = db.components().insertMainBranch(); | |||
userSession.addProjectPermission(UserRole.USER, project); | |||
ComponentDto longLivingBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(LONG)); | |||
db.components().insertSnapshot(longLivingBranch); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH)); | |||
db.components().insertSnapshot(branch); | |||
CeActivityDto activity = createAndPersistArchivedTask(project); | |||
insertCharacteristic(activity, BRANCH_KEY, longLivingBranch.getBranch()); | |||
insertCharacteristic(activity, BRANCH_TYPE_KEY, LONG.name()); | |||
insertCharacteristic(activity, BRANCH_KEY, branch.getBranch()); | |||
insertCharacteristic(activity, BRANCH_TYPE_KEY, BRANCH.name()); | |||
Ce.TaskResponse taskResponse = ws.newRequest() | |||
.setParam("id", SOME_TASK_UUID) | |||
@@ -178,17 +179,17 @@ public class TaskActionTest { | |||
assertThat(taskResponse.getTask()) | |||
.extracting(Ce.Task::getId, Ce.Task::getBranch, Ce.Task::getBranchType, Ce.Task::getComponentKey) | |||
.containsExactlyInAnyOrder(SOME_TASK_UUID, longLivingBranch.getBranch(), Common.BranchType.LONG, longLivingBranch.getKey()); | |||
.containsExactlyInAnyOrder(SOME_TASK_UUID, branch.getBranch(), Common.BranchType.BRANCH, branch.getKey()); | |||
} | |||
@Test | |||
public void long_living_branch_in_queue_analysis() { | |||
public void branch_in_queue_analysis() { | |||
UserDto user = db.users().insertUser(); | |||
userSession.logIn(user).setRoot(); | |||
String branch = "my_branch"; | |||
CeQueueDto queueDto = createAndPersistQueueTask(null, user); | |||
insertCharacteristic(queueDto, BRANCH_KEY, branch); | |||
insertCharacteristic(queueDto, BRANCH_TYPE_KEY, LONG.name()); | |||
insertCharacteristic(queueDto, BRANCH_TYPE_KEY, BRANCH.name()); | |||
Ce.TaskResponse taskResponse = ws.newRequest() | |||
.setParam("id", SOME_TASK_UUID) | |||
@@ -196,7 +197,7 @@ public class TaskActionTest { | |||
assertThat(taskResponse.getTask()) | |||
.extracting(Ce.Task::getId, Ce.Task::getBranch, Ce.Task::getBranchType, Ce.Task::hasComponentKey) | |||
.containsExactlyInAnyOrder(SOME_TASK_UUID, branch, Common.BranchType.LONG, false); | |||
.containsExactlyInAnyOrder(SOME_TASK_UUID, branch, Common.BranchType.BRANCH, false); | |||
} | |||
@Test |
@@ -398,11 +398,6 @@ public class BulkChangeActionTest { | |||
verifyPostProcessorCalled(fileOnBranch); | |||
} | |||
@Test | |||
public void send_no_notification_on_short_branch() { | |||
verifySendNoNotification(BranchType.SHORT); | |||
} | |||
@Test | |||
public void send_no_notification_on_PR() { | |||
verifySendNoNotification(BranchType.PULL_REQUEST); |
@@ -93,7 +93,8 @@ public class IssueUpdaterTest { | |||
private TestIssueChangePostProcessor issueChangePostProcessor = new TestIssueChangePostProcessor(); | |||
private IssuesChangesNotificationSerializer issuesChangesSerializer = new IssuesChangesNotificationSerializer(); | |||
private IssueUpdater underTest = new IssueUpdater(dbClient, | |||
new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient, defaultOrganizationProvider), issueIndexer), notificationManager, issueChangePostProcessor, issuesChangesSerializer); | |||
new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient, defaultOrganizationProvider), issueIndexer), notificationManager, issueChangePostProcessor, | |||
issuesChangesSerializer); | |||
@Test | |||
public void update_issue() { | |||
@@ -201,23 +202,6 @@ public class IssueUpdaterTest { | |||
assertThat(builder.getChange()).isEqualTo(new UserChange(issue.updateDate().getTime(), userOf(changeAuthor))); | |||
} | |||
@Test | |||
public void verify_no_notification_on_short_branch() { | |||
RuleDto rule = db.rules().insertRule(); | |||
ComponentDto project = db.components().insertMainBranch(); | |||
ComponentDto branch = db.components().insertProjectBranch(project, t -> t.setBranchType(BranchType.SHORT)); | |||
ComponentDto file = db.components().insertComponent(newFileDto(branch)); | |||
RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; | |||
DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), branch, file) | |||
.setType(randomTypeExceptHotspot)).setSeverity(MAJOR).toDefaultIssue(); | |||
IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid"); | |||
issueFieldsSetter.setSeverity(issue, BLOCKER, context); | |||
underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, false); | |||
verifyZeroInteractions(notificationManager); | |||
} | |||
@Test | |||
public void verify_no_notification_on_pr() { | |||
RuleDto rule = db.rules().insertRule(); |
@@ -65,8 +65,8 @@ import static org.sonar.api.utils.DateUtils.parseDateTime; | |||
import static org.sonar.api.web.UserRole.USER; | |||
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; | |||
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02; | |||
import static org.sonar.db.component.BranchType.LONG; | |||
import static org.sonar.db.component.BranchType.PULL_REQUEST; | |||
import static org.sonar.db.component.BranchType.SHORT; | |||
import static org.sonar.db.component.ComponentTesting.newDirectory; | |||
import static org.sonar.db.component.ComponentTesting.newFileDto; | |||
import static org.sonar.db.component.ComponentTesting.newModuleDto; | |||
@@ -168,12 +168,12 @@ public class SearchActionComponentsTest { | |||
assertThat(ws.newRequest() | |||
.setParam(PARAM_COMPONENT_KEYS, module1.getKey()) | |||
.executeProtobuf(SearchWsResponse.class).getIssuesList()).extracting(Issue::getKey) | |||
.containsExactlyInAnyOrder(issue1.getKey()); | |||
.containsExactlyInAnyOrder(issue1.getKey()); | |||
assertThat(ws.newRequest() | |||
.setParam(PARAM_MODULE_UUIDS, module1.uuid()) | |||
.executeProtobuf(SearchWsResponse.class).getIssuesList()).extracting(Issue::getKey) | |||
.containsExactlyInAnyOrder(issue1.getKey()); | |||
.containsExactlyInAnyOrder(issue1.getKey()); | |||
} | |||
@Test | |||
@@ -481,11 +481,11 @@ public class SearchActionComponentsTest { | |||
.setParam(PARAM_COMPONENT_KEYS, applicationBranch1.getKey()) | |||
.setParam(PARAM_BRANCH, applicationBranch1.getBranch()) | |||
.executeProtobuf(SearchWsResponse.class).getIssuesList()) | |||
.extracting(Issue::getKey, Issue::getComponent, Issue::getProject, Issue::getBranch, Issue::hasBranch) | |||
.containsExactlyInAnyOrder( | |||
tuple(issueOnProject1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getBranch(), true), | |||
tuple(issueOnFileOnProject1Branch1.getKey(), fileOnProject1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getBranch(), true), | |||
tuple(issueOnProject2.getKey(), project2.getKey(), project2.getKey(), "", false)); | |||
.extracting(Issue::getKey, Issue::getComponent, Issue::getProject, Issue::getBranch, Issue::hasBranch) | |||
.containsExactlyInAnyOrder( | |||
tuple(issueOnProject1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getBranch(), true), | |||
tuple(issueOnFileOnProject1Branch1.getKey(), fileOnProject1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getBranch(), true), | |||
tuple(issueOnProject2.getKey(), project2.getKey(), project2.getKey(), "", false)); | |||
// Issues on project1Branch1 | |||
assertThat(ws.newRequest() | |||
@@ -493,10 +493,10 @@ public class SearchActionComponentsTest { | |||
.setParam(PARAM_PROJECTS, project1.getKey()) | |||
.setParam(PARAM_BRANCH, applicationBranch1.getBranch()) | |||
.executeProtobuf(SearchWsResponse.class).getIssuesList()) | |||
.extracting(Issue::getKey, Issue::getComponent, Issue::getBranch) | |||
.containsExactlyInAnyOrder( | |||
tuple(issueOnProject1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getBranch()), | |||
tuple(issueOnFileOnProject1Branch1.getKey(), fileOnProject1Branch1.getKey(), project1Branch1.getBranch())); | |||
.extracting(Issue::getKey, Issue::getComponent, Issue::getBranch) | |||
.containsExactlyInAnyOrder( | |||
tuple(issueOnProject1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getBranch()), | |||
tuple(issueOnFileOnProject1Branch1.getKey(), fileOnProject1Branch1.getKey(), project1Branch1.getBranch())); | |||
} | |||
@Test | |||
@@ -656,7 +656,7 @@ public class SearchActionComponentsTest { | |||
ComponentDto file = db.components().insertComponent(newFileDto(project)); | |||
IssueDto issue = db.issues().insertIssue(newIssue(rule, project, file)); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(SHORT)); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(LONG)); | |||
ComponentDto branchFile = db.components().insertComponent(newFileDto(branch)); | |||
IssueDto branchIssue = db.issues().insertIssue(newIssue(rule, branch, branchFile)); | |||
allowAnyoneOnProjects(project); | |||
@@ -667,24 +667,24 @@ public class SearchActionComponentsTest { | |||
.setParam(PARAM_COMPONENT_KEYS, project.getKey()) | |||
.setParam(PARAM_BRANCH, branch.getBranch()) | |||
.executeProtobuf(SearchWsResponse.class).getIssuesList()) | |||
.extracting(Issue::getKey, Issue::getComponent, Issue::getBranch) | |||
.containsExactlyInAnyOrder(tuple(branchIssue.getKey(), branchFile.getKey(), branchFile.getBranch())); | |||
.extracting(Issue::getKey, Issue::getComponent, Issue::getBranch) | |||
.containsExactlyInAnyOrder(tuple(branchIssue.getKey(), branchFile.getKey(), branchFile.getBranch())); | |||
// On project key + branch | |||
assertThat(ws.newRequest() | |||
.setParam(PARAM_PROJECT_KEYS, project.getKey()) | |||
.setParam(PARAM_BRANCH, branch.getBranch()) | |||
.executeProtobuf(SearchWsResponse.class).getIssuesList()) | |||
.extracting(Issue::getKey, Issue::getComponent, Issue::getBranch) | |||
.containsExactlyInAnyOrder(tuple(branchIssue.getKey(), branchFile.getKey(), branchFile.getBranch())); | |||
.extracting(Issue::getKey, Issue::getComponent, Issue::getBranch) | |||
.containsExactlyInAnyOrder(tuple(branchIssue.getKey(), branchFile.getKey(), branchFile.getBranch())); | |||
// On file key + branch | |||
assertThat(ws.newRequest() | |||
.setParam(PARAM_COMPONENT_KEYS, branchFile.getKey()) | |||
.setParam(PARAM_BRANCH, branch.getBranch()) | |||
.executeProtobuf(SearchWsResponse.class).getIssuesList()) | |||
.extracting(Issue::getKey, Issue::getComponent, Issue::getBranch) | |||
.containsExactlyInAnyOrder(tuple(branchIssue.getKey(), branchFile.getKey(), branchFile.getBranch())); | |||
.extracting(Issue::getKey, Issue::getComponent, Issue::getBranch) | |||
.containsExactlyInAnyOrder(tuple(branchIssue.getKey(), branchFile.getKey(), branchFile.getBranch())); | |||
} | |||
@Test | |||
@@ -693,7 +693,7 @@ public class SearchActionComponentsTest { | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); | |||
IssueDto projectIssue = db.issues().insertIssue(newIssue(rule, project, projectFile)); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(SHORT)); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(LONG)); | |||
ComponentDto branchFile = db.components().insertComponent(newFileDto(branch)); | |||
IssueDto branchIssue = db.issues().insertIssue(newIssue(rule, branch, branchFile)); | |||
allowAnyoneOnProjects(project); |
@@ -66,32 +66,12 @@ public class LiveQualityGateComputerImplTest { | |||
private TestQualityGateEvaluator qualityGateEvaluator = new TestQualityGateEvaluator(); | |||
private LiveQualityGateComputerImpl underTest = new LiveQualityGateComputerImpl(db.getDbClient(), new QualityGateFinder(db.getDbClient()), qualityGateEvaluator); | |||
@Test | |||
public void loadQualityGate_returns_hardcoded_gate_for_short_living_branches() { | |||
OrganizationDto organization = db.organizations().insert(); | |||
ComponentDto project = db.components().insertPublicProject(organization); | |||
BranchDto branch = newBranchDto(project).setBranchType(BranchType.SHORT); | |||
db.components().insertProjectBranch(project, branch); | |||
MetricDto metric1 = db.measures().insertMetric(m -> m.setKey("new_metric")); | |||
MetricDto metric2 = db.measures().insertMetric(m -> m.setKey("metric")); | |||
QGateWithOrgDto gate = db.qualityGates().insertQualityGate(organization); | |||
db.qualityGates().setDefaultQualityGate(organization, gate); | |||
db.qualityGates().addCondition(gate, metric1); | |||
db.qualityGates().addCondition(gate, metric2); | |||
QualityGate result = underTest.loadQualityGate(db.getSession(), organization, project, branch); | |||
assertThat(result.getConditions()).extracting(Condition::getMetricKey).containsExactly("new_metric"); | |||
} | |||
@Test | |||
public void loadQualityGate_returns_hardcoded_gate_for_pull_requests() { | |||
OrganizationDto organization = db.organizations().insert(); | |||
ComponentDto project = db.components().insertPublicProject(organization); | |||
BranchDto branch = newBranchDto(project).setBranchType(BranchType.SHORT); | |||
BranchDto branch = newBranchDto(project).setBranchType(BranchType.PULL_REQUEST); | |||
db.components().insertProjectBranch(project, branch); | |||
MetricDto metric1 = db.measures().insertMetric(m -> m.setKey("new_metric")); | |||
MetricDto metric2 = db.measures().insertMetric(m -> m.setKey("metric")); |
@@ -21,7 +21,6 @@ package org.sonar.server.measure.ws; | |||
import com.google.common.base.Joiner; | |||
import java.util.List; | |||
import java.util.function.Function; | |||
import java.util.stream.IntStream; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
@@ -72,7 +71,6 @@ import static org.sonar.api.server.ws.WebService.Param.SORT; | |||
import static org.sonar.api.utils.DateUtils.parseDateTime; | |||
import static org.sonar.api.web.UserRole.USER; | |||
import static org.sonar.db.component.BranchType.PULL_REQUEST; | |||
import static org.sonar.db.component.BranchType.SHORT; | |||
import static org.sonar.db.component.ComponentTesting.newDirectory; | |||
import static org.sonar.db.component.ComponentTesting.newFileDto; | |||
import static org.sonar.db.component.ComponentTesting.newProjectCopy; | |||
@@ -605,62 +603,23 @@ public class ComponentTreeActionTest { | |||
} | |||
@Test | |||
public void new_issue_count_measures_are_transformed_in_slb() { | |||
public void new_issue_count_measures_are_not_transformed_if_they_dont_exist_in_pr() { | |||
OrganizationDto organization = db.organizations().insert(); | |||
ComponentDto project = db.components().insertPrivateProject(organization); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("slb").setBranchType(SHORT)); | |||
SnapshotDto analysis = db.components().insertSnapshot(branch); | |||
ComponentDto file = db.components().insertComponent(newFileDto(branch)); | |||
ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setKey("pr").setBranchType(PULL_REQUEST)); | |||
SnapshotDto analysis = db.components().insertSnapshot(pr); | |||
ComponentDto file = db.components().insertComponent(newFileDto(pr)); | |||
MetricDto bug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.BUGS_KEY)); | |||
MetricDto newBug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.NEW_BUGS_KEY)); | |||
LiveMeasureDto measure = db.measures().insertLiveMeasure(file, bug, m -> m.setValue(12.0d).setVariation(null)); | |||
ComponentTreeWsResponse response = ws.newRequest() | |||
.setParam(PARAM_COMPONENT, file.getKey()) | |||
.setParam(PARAM_BRANCH, "slb") | |||
.setParam(PARAM_PULL_REQUEST, "pr") | |||
.setParam(PARAM_METRIC_KEYS, newBug.getKey() + "," + bug.getKey()) | |||
.executeProtobuf(ComponentTreeWsResponse.class); | |||
Function<Measure, Double> extractVariation = m -> { | |||
Double periodValue = null; | |||
if (m.getPeriods().getPeriodsValueCount() > 0) { | |||
periodValue = parseDouble(m.getPeriods().getPeriodsValue(0).getValue()); | |||
} | |||
if (m.hasPeriod()) { | |||
assertThat(parseDouble(m.getPeriod().getValue())).isEqualTo(periodValue); | |||
} | |||
return periodValue; | |||
}; | |||
assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getBranch) | |||
.containsExactlyInAnyOrder(file.getKey(), "slb"); | |||
assertThat(response.getBaseComponent().getMeasuresList()) | |||
.extracting(Measure::getMetric, extractVariation, m -> m.getValue().isEmpty() ? null : parseDouble(m.getValue())) | |||
.containsExactlyInAnyOrder( | |||
tuple(newBug.getKey(), measure.getValue(), null), | |||
tuple(bug.getKey(), null, measure.getValue())); | |||
} | |||
@Test | |||
public void new_issue_count_measures_are_not_transformed_if_they_dont_exist_in_slb() { | |||
OrganizationDto organization = db.organizations().insert(); | |||
ComponentDto project = db.components().insertPrivateProject(organization); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("slb").setBranchType(SHORT)); | |||
SnapshotDto analysis = db.components().insertSnapshot(branch); | |||
ComponentDto file = db.components().insertComponent(newFileDto(branch)); | |||
MetricDto bug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.BUGS_KEY)); | |||
MetricDto newBug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.NEW_BUGS_KEY)); | |||
ComponentTreeWsResponse response = ws.newRequest() | |||
.setParam(PARAM_COMPONENT, file.getKey()) | |||
.setParam(PARAM_BRANCH, "slb") | |||
.setParam(PARAM_METRIC_KEYS, newBug.getKey() + "," + bug.getKey()) | |||
.executeProtobuf(ComponentTreeWsResponse.class); | |||
assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getBranch) | |||
.containsExactlyInAnyOrder(file.getKey(), "slb"); | |||
assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getPullRequest) | |||
.containsExactlyInAnyOrder(file.getKey(), "pr"); | |||
assertThat(response.getBaseComponent().getMeasuresList()) | |||
.isEmpty(); | |||
} |
@@ -38,12 +38,12 @@ import static org.sonar.api.measures.CoreMetrics.MINOR_VIOLATIONS_KEY; | |||
import static org.sonar.api.measures.CoreMetrics.NEW_BUGS_KEY; | |||
import static org.sonar.api.measures.CoreMetrics.NEW_MINOR_VIOLATIONS_KEY; | |||
public class SLBorPRMeasureFixTest { | |||
public class prMeasureFixTest { | |||
@Test | |||
public void should_add_replacement_metrics() { | |||
List<String> metricList = new ArrayList<>(Arrays.asList(NEW_BUGS_KEY, NEW_MINOR_VIOLATIONS_KEY)); | |||
SLBorPRMeasureFix.addReplacementMetricKeys(metricList); | |||
PrMeasureFix.addReplacementMetricKeys(metricList); | |||
assertThat(metricList).contains(BUGS_KEY, NEW_BUGS_KEY, MINOR_VIOLATIONS_KEY, NEW_MINOR_VIOLATIONS_KEY); | |||
} | |||
@@ -57,7 +57,7 @@ public class SLBorPRMeasureFixTest { | |||
List<MetricDto> metricList = new ArrayList<>(Arrays.asList(dto1, dto2, dto3, dto4)); | |||
SLBorPRMeasureFix.removeMetricsNotRequested(metricList, originalMetricList); | |||
PrMeasureFix.removeMetricsNotRequested(metricList, originalMetricList); | |||
assertThat(metricList).containsOnly(dto2, dto3, dto4); | |||
} | |||
@@ -83,7 +83,7 @@ public class SLBorPRMeasureFixTest { | |||
measureByMetric.put(violationsMetric, violations); | |||
measureByMetric.put(newViolationsMetric, newViolations); | |||
SLBorPRMeasureFix.createReplacementMeasures(metricList, measureByMetric, requestedKeys); | |||
PrMeasureFix.createReplacementMeasures(metricList, measureByMetric, requestedKeys); | |||
assertThat(measureByMetric.entrySet()).extracting(e -> e.getKey().getKey(), e -> e.getValue().getValue(), e -> e.getValue().getVariation()) | |||
.containsOnly(tuple(NEW_BUGS_KEY, null, 10.0), | |||
tuple(MINOR_VIOLATIONS_KEY, 20.0, null), |
@@ -107,7 +107,7 @@ public class ListActionTest { | |||
ComponentDto project = componentDb.insertMainBranch(); | |||
createBranches(project, 5, BranchType.LONG); | |||
createBranches(project, 3, BranchType.SHORT); | |||
createBranches(project, 3, BranchType.PULL_REQUEST); | |||
logInAsProjectAdministrator(project); | |||
@@ -249,21 +249,6 @@ public class SetActionTest { | |||
.execute(); | |||
} | |||
@Test | |||
public void throw_IAE_if_branch_is_a_SLB() { | |||
ComponentDto project = componentDb.insertMainBranch(); | |||
ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch").setBranchType(BranchType.SHORT)); | |||
logInAsProjectAdministrator(project); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Not a long-living branch: 'branch'"); | |||
ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.setParam("type", "previous_version") | |||
.setParam("branch", "branch") | |||
.execute(); | |||
} | |||
// permission | |||
@Test | |||
public void throw_NFE_if_no_project_permission() { |
@@ -29,7 +29,6 @@ import org.sonar.core.util.UuidFactoryFast; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.BranchType; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodDao; | |||
@@ -111,20 +110,6 @@ public class ShowActionTest { | |||
.execute(); | |||
} | |||
@Test | |||
public void throw_IAE_if_branch_is_a_SLB() { | |||
ComponentDto project = componentDb.insertMainBranch(); | |||
ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch").setBranchType(BranchType.SHORT)); | |||
logInAsProjectAdministrator(project); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Not a long-living branch: 'branch'"); | |||
ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.setParam("branch", "branch") | |||
.execute(); | |||
} | |||
@Test | |||
public void throw_FE_if_no_project_permission() { | |||
ComponentDto project = componentDb.insertMainBranch(); |
@@ -19,6 +19,8 @@ | |||
*/ | |||
package org.sonar.server.newcodeperiod.ws; | |||
import java.util.Optional; | |||
import javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
@@ -31,7 +33,6 @@ import org.sonar.core.util.UuidFactoryFast; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.BranchType; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodDao; | |||
@@ -43,9 +44,6 @@ import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import org.sonar.server.ws.WsActionTester; | |||
import javax.annotation.Nullable; | |||
import java.util.Optional; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.entry; | |||
import static org.mockito.Mockito.mock; | |||
@@ -119,21 +117,6 @@ public class UnsetActionTest { | |||
.execute(); | |||
} | |||
@Test | |||
public void throw_IAE_if_branch_is_a_SLB() { | |||
ComponentDto project = componentDb.insertMainBranch(); | |||
ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch").setBranchType(BranchType.SHORT)); | |||
logInAsProjectAdministrator(project); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Not a long-living branch: 'branch'"); | |||
ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.setParam("type", "previous_version") | |||
.setParam("branch", "branch") | |||
.execute(); | |||
} | |||
// permission | |||
@Test | |||
public void throw_NFE_if_no_project_permission() { |
@@ -43,7 +43,6 @@ import org.sonar.db.DbClient; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.BranchDao; | |||
import org.sonar.db.component.BranchDto; | |||
import org.sonar.db.component.BranchType; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.component.SnapshotDto; | |||
@@ -607,24 +606,6 @@ public class SearchActionTest { | |||
assertThat(result.get(0).getEventsList()).extracting(Event::getKey).containsExactlyInAnyOrder(event.getUuid()); | |||
} | |||
@Test | |||
public void fail_if_branch_is_short_lived() { | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
userSession.addProjectPermission(UserRole.USER, project); | |||
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch").setBranchType(BranchType.SHORT)); | |||
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(branch)); | |||
EventDto event = db.events().insertEvent(newEvent(analysis).setCategory(QUALITY_GATE.getLabel())); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Branch 'my_branch' is not of type LONG"); | |||
call(SearchRequest.builder() | |||
.setProject(project.getKey()) | |||
.setBranch("my_branch") | |||
.build()) | |||
.getAnalysesList(); | |||
} | |||
@Test | |||
public void empty_response() { | |||
ComponentDto project = db.components().insertPrivateProject(); |
@@ -97,7 +97,7 @@ public class SetBaselineActionTest { | |||
@DataProvider | |||
public static Object[][] nullOrEmpty() { | |||
return new Object[][]{ | |||
return new Object[][] { | |||
{null}, | |||
{""}, | |||
{" "}, | |||
@@ -150,7 +150,7 @@ public class SetBaselineActionTest { | |||
.put(PARAM_BRANCH, "branch key") | |||
.put(PARAM_ANALYSIS, "analysis uuid"); | |||
return new Object[][]{ | |||
return new Object[][] { | |||
{builder.put(PARAM_PROJECT, null).map, "The 'project' parameter is missing"}, | |||
{builder.put(PARAM_PROJECT, "").map, "The 'project' parameter is missing"}, | |||
{builder.put(PARAM_ANALYSIS, null).map, "The 'analysis' parameter is missing"}, | |||
@@ -184,7 +184,7 @@ public class SetBaselineActionTest { | |||
public static Object[][] nonexistentParamsAndFailureMessage() { | |||
MapBuilder builder = new MapBuilder(); | |||
return new Object[][]{ | |||
return new Object[][] { | |||
{builder.put(PARAM_PROJECT, "nonexistent").map, "Component 'nonexistent' on branch .* not found"}, | |||
{builder.put(PARAM_BRANCH, "nonexistent").map, "Component .* on branch 'nonexistent' not found"}, | |||
{builder.put(PARAM_ANALYSIS, "nonexistent").map, "Analysis 'nonexistent' is not found"}, | |||
@@ -250,21 +250,6 @@ public class SetBaselineActionTest { | |||
call(project.getKey(), branch.getKey(), otherAnalysis.getUuid()); | |||
} | |||
@Test | |||
public void fail_when_branch_is_not_long() { | |||
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert()); | |||
BranchDto branch = ComponentTesting.newBranchDto(project.projectUuid(), BranchType.SHORT); | |||
db.components().insertProjectBranch(project, branch); | |||
ComponentDto branchComponentDto = ComponentTesting.newProjectBranch(project, branch); | |||
SnapshotDto analysis = db.components().insertSnapshot(branchComponentDto); | |||
logInAsProjectAdministrator(project); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage(String.format("Not a long-living branch: '%s'", branch.getKey())); | |||
call(project.getKey(), branch.getKey(), analysis.getUuid()); | |||
} | |||
@Test | |||
public void ws_parameters() { | |||
WebService.Action definition = ws.getDef(); |
@@ -226,19 +226,6 @@ public class UnsetBaselineActionTest { | |||
call(project.getKey(), otherBranch.getKey()); | |||
} | |||
@Test | |||
public void fail_with_IAE_when_branch_is_short() { | |||
ComponentDto project = newPrivateProjectDto(db.organizations().insert()); | |||
BranchDto branch = newBranchDto(project.projectUuid(), BranchType.SHORT); | |||
db.components().insertProjectBranch(project, branch); | |||
logInAsProjectAdministrator(project); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage(String.format("Not a long-living branch: '%s'", branch.getKey())); | |||
call(project.getKey(), branch.getKey()); | |||
} | |||
@Test | |||
public void fail_with_NotFoundException_when_branch_is_pull_request() { | |||
ComponentDto project = newPrivateProjectDto(db.organizations().insert()); |
@@ -27,7 +27,7 @@ import java.util.Optional; | |||
public interface Branch { | |||
enum Type { | |||
LONG, SHORT, PULL_REQUEST | |||
LONG, SHORT, BRANCH, PULL_REQUEST | |||
} | |||
boolean isMain(); |
@@ -40,20 +40,15 @@ message Branch { | |||
optional string name = 1; | |||
optional bool isMain = 2; | |||
optional sonarqube.ws.commons.BranchType type = 3; | |||
// Merge branch is only present for short living branch | |||
optional string mergeBranch = 4; | |||
reserved 4; | |||
optional Status status = 5; | |||
optional bool isOrphan = 6; | |||
optional string analysisDate = 7; | |||
} | |||
message Status { | |||
// Quality gate status is only present for long living branch | |||
optional string qualityGateStatus = 1; | |||
// Merge bugs, vulnerabilities and codeSmell are only present for short living branch | |||
optional int64 bugs = 2; | |||
optional int64 vulnerabilities = 3; | |||
optional int64 codeSmells = 4; | |||
reserved 2, 3, 4; | |||
} | |||