Skip to content

Commit ac92f41

Browse files
authored
Merge pull request #162 from rostilos/1.5.5-rc
1.5.5 rc
2 parents d39b040 + e7db99d commit ac92f41

3 files changed

Lines changed: 63 additions & 7 deletions

File tree

java-ecosystem/libs/core/src/main/java/org/rostilos/codecrow/core/persistence/repository/codeanalysis/CodeAnalysisIssueRepository.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,42 @@ List<CodeAnalysisIssue> findByProjectIdAndPrNumberAndFilePath(
107107
@Param("prNumber") Long prNumber,
108108
@Param("filePath") String filePath);
109109

110+
/**
111+
* Find issues for the <b>latest PR version only</b>.
112+
* Scopes to the analysis with MAX(prVersion) for this PR number.
113+
* Used by the PR source code viewer (file tree counts).
114+
*/
115+
@Query("SELECT cai FROM CodeAnalysisIssue cai " +
116+
"WHERE cai.analysis.project.id = :projectId " +
117+
"AND cai.analysis.prNumber = :prNumber " +
118+
"AND cai.analysis.prVersion = (" +
119+
" SELECT MAX(a.prVersion) FROM CodeAnalysis a " +
120+
" WHERE a.project.id = :projectId AND a.prNumber = :prNumber" +
121+
") " +
122+
"ORDER BY cai.filePath ASC, cai.lineNumber ASC")
123+
List<CodeAnalysisIssue> findByProjectIdAndPrNumberLatestVersion(
124+
@Param("projectId") Long projectId,
125+
@Param("prNumber") Long prNumber);
126+
127+
/**
128+
* Find issues for a specific file in the <b>latest PR version only</b>.
129+
* Scopes to the analysis with MAX(prVersion) for this PR number.
130+
* Used by the PR source code viewer (inline issue annotations).
131+
*/
132+
@Query("SELECT cai FROM CodeAnalysisIssue cai " +
133+
"WHERE cai.analysis.project.id = :projectId " +
134+
"AND cai.analysis.prNumber = :prNumber " +
135+
"AND cai.filePath = :filePath " +
136+
"AND cai.analysis.prVersion = (" +
137+
" SELECT MAX(a.prVersion) FROM CodeAnalysis a " +
138+
" WHERE a.project.id = :projectId AND a.prNumber = :prNumber" +
139+
") " +
140+
"ORDER BY cai.lineNumber ASC")
141+
List<CodeAnalysisIssue> findByProjectIdAndPrNumberAndFilePathLatestVersion(
142+
@Param("projectId") Long projectId,
143+
@Param("prNumber") Long prNumber,
144+
@Param("filePath") String filePath);
145+
110146
// ── Aggregate queries (for analytics — avoid loading full entity graphs) ──
111147

112148
@Query("SELECT COUNT(cai) FROM CodeAnalysisIssue cai " +

java-ecosystem/libs/core/src/main/java/org/rostilos/codecrow/core/service/CodeAnalysisService.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,22 @@ public List<CodeAnalysisIssue> findIssuesByPrNumberAndFilePath(Long projectId, L
930930
issueRepository.findByProjectIdAndPrNumberAndFilePath(projectId, prNumber, filePath));
931931
}
932932

933+
/**
934+
* Find all issues for the <b>latest PR version only</b>.
935+
* No cross-iteration deduplication needed — single iteration scope.
936+
*/
937+
public List<CodeAnalysisIssue> findIssuesByPrNumberLatestVersion(Long projectId, Long prNumber) {
938+
return issueRepository.findByProjectIdAndPrNumberLatestVersion(projectId, prNumber);
939+
}
940+
941+
/**
942+
* Find issues for a specific file in the <b>latest PR version only</b>.
943+
* No cross-iteration deduplication needed — single iteration scope.
944+
*/
945+
public List<CodeAnalysisIssue> findIssuesByPrNumberAndFilePathLatestVersion(Long projectId, Long prNumber, String filePath) {
946+
return issueRepository.findByProjectIdAndPrNumberAndFilePathLatestVersion(projectId, prNumber, filePath);
947+
}
948+
933949
/**
934950
* Deduplicate issues that span multiple analyses on the same branch.
935951
* When the same logical issue is tracked across analyses (via trackedFromIssueId),

java-ecosystem/services/web-server/src/main/java/org/rostilos/codecrow/webserver/analysis/service/FileViewService.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ public Optional<AnalysisFilesResponse> listPrFiles(Long projectId, Long prNumber
362362
return Optional.empty();
363363
}
364364

365-
// Aggregate issues across all analyses for this PR number
366-
List<CodeAnalysisIssue> issues = codeAnalysisService.findIssuesByPrNumber(projectId, prNumber);
365+
// Only show issues from the latest PR version (not accumulated across all iterations)
366+
List<CodeAnalysisIssue> issues = codeAnalysisService.findIssuesByPrNumberLatestVersion(projectId, prNumber);
367367
Map<String, List<CodeAnalysisIssue>> issuesByFile = issues.stream()
368368
.filter(i -> i.getFilePath() != null)
369369
.filter(FileViewService::hasTitle)
@@ -416,10 +416,11 @@ public Optional<FileViewResponse> getPrFileView(Long projectId, Long prNumber, S
416416
int lineCount = countLines(content);
417417
LineHashSequence lineHashes = LineHashSequence.from(content);
418418

419-
// Aggregate issues across all analyses for this PR number
420-
List<CodeAnalysisIssue> fileIssues = codeAnalysisService.findIssuesByPrNumberAndFilePath(projectId, prNumber, filePath);
419+
// Only show issues from the latest PR version (not accumulated across all iterations)
420+
List<CodeAnalysisIssue> fileIssues = codeAnalysisService.findIssuesByPrNumberAndFilePathLatestVersion(projectId, prNumber, filePath);
421421
List<FileViewResponse.InlineIssue> inlineIssues = fileIssues.stream()
422422
.filter(FileViewService::hasTitle)
423+
.filter(i -> !i.isResolved())
423424
.map(i -> new FileViewResponse.InlineIssue(
424425
i.getId(),
425426
correctLineNumber(i, lineHashes),
@@ -476,11 +477,12 @@ public Optional<FileSnippetResponse> getPrFileSnippet(
476477
snippetLines.add(new FileSnippetResponse.SnippetLine(i, lineContent));
477478
}
478479

479-
// Get issues for this PR and file, filtered to the snippet range
480-
List<CodeAnalysisIssue> allIssues = codeAnalysisService.findIssuesByPrNumberAndFilePath(projectId, prNumber, filePath);
480+
// Only show issues from the latest PR version, filtered to the snippet range
481+
List<CodeAnalysisIssue> allIssues = codeAnalysisService.findIssuesByPrNumberAndFilePathLatestVersion(projectId, prNumber, filePath);
481482
int finalStartLine = startLine;
482483
int finalEndLine = endLine;
483484
List<FileViewResponse.InlineIssue> inlineIssues = allIssues.stream()
485+
.filter(i -> !i.isResolved())
484486
.filter(i -> {
485487
int ln = i.getLineNumber() != null ? i.getLineNumber() : 0;
486488
return ln >= finalStartLine && ln <= finalEndLine;
@@ -541,10 +543,12 @@ public Optional<FileSnippetResponse> getPrFileSnippetByRange(
541543
snippetLines.add(new FileSnippetResponse.SnippetLine(i, lineContent));
542544
}
543545

544-
List<CodeAnalysisIssue> allIssues = codeAnalysisService.findIssuesByPrNumberAndFilePath(projectId, prNumber, filePath);
546+
// Only show issues from the latest PR version, filtered to the line range
547+
List<CodeAnalysisIssue> allIssues = codeAnalysisService.findIssuesByPrNumberAndFilePathLatestVersion(projectId, prNumber, filePath);
545548
int finalStart = startLine;
546549
int finalEnd = endLine;
547550
List<FileViewResponse.InlineIssue> inlineIssues = allIssues.stream()
551+
.filter(i -> !i.isResolved())
548552
.filter(i -> {
549553
int ln = i.getLineNumber() != null ? i.getLineNumber() : 0;
550554
return ln >= finalStart && ln <= finalEnd;

0 commit comments

Comments
 (0)