private final AnalysisMetadataHolder analysisMetadataHolder;
private final ScmInfoRepository scmInfoRepository;
private final PeriodHolder periodHolder;
- private final Map<Component, Optional<Set<Integer>>> changedLinesCache = new HashMap<>();
+ private final Map<Component, Optional<Set<Integer>>> reportChangedLinesCache = new HashMap<>();
public NewLinesRepository(BatchReportReader reportReader, AnalysisMetadataHolder analysisMetadataHolder, PeriodHolder periodHolder, ScmInfoRepository scmInfoRepository) {
this.reportReader = reportReader;
}
public boolean newLinesAvailable() {
- return periodHolder.hasPeriod();
+ return isPullRequestOrShortLivedBranch() || periodHolder.hasPeriod();
}
public Optional<Set<Integer>> getNewLines(Component component) {
- return changedLinesCache.computeIfAbsent(component, this::computeNewLines);
- }
-
- private Optional<Set<Integer>> computeNewLines(Component component) {
Optional<Set<Integer>> reportChangedLines = getChangedLinesFromReport(component);
if (reportChangedLines.isPresent()) {
return reportChangedLines;
}
private Optional<Set<Integer>> getChangedLinesFromReport(Component component) {
- if (analysisMetadataHolder.isPullRequest() || analysisMetadataHolder.isShortLivingBranch()) {
- return reportReader.readComponentChangedLines(component.getReportAttributes().getRef())
- .map(c -> new HashSet<>(c.getLineList()));
+ if (isPullRequestOrShortLivedBranch()) {
+ return reportChangedLinesCache.computeIfAbsent(component, this::readFromReport);
}
return Optional.empty();
}
+
+ private boolean isPullRequestOrShortLivedBranch() {
+ return analysisMetadataHolder.isPullRequest() || analysisMetadataHolder.isShortLivingBranch();
+ }
+
+ private Optional<Set<Integer>> readFromReport(Component component) {
+ return reportReader.readComponentChangedLines(component.getReportAttributes().getRef())
+ .map(c -> new HashSet<>(c.getLineList()));
+ }
}
@Test
public void load_new_lines_from_report_if_available_and_pullrequest() {
- periodHolder.setPeriod(new Period("", null, Long.MAX_VALUE, ""));
setPullRequest();
createChangedLinesInReport(1, 2, 5);
}
@Test
- public void return_empty_if_no_period() {
+ public void return_empty_if_no_period_and_not_pullrequest() {
periodHolder.setPeriod(null);
// even though we have lines in the report and scm data, nothing should be returned since we have no period