Skip to content

Commit

Permalink
defect #832120: Jenkins plugin - scm lines enrichment is failing if o…
Browse files Browse the repository at this point in the history
…ne of the changes in the commit is file deletion
  • Loading branch information
emanueli committed Apr 30, 2019
1 parent 270231e commit d5fa69f
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ private SCMData enrichLinesOnSCMData(SCMData scmData, AbstractBuild build) {
if (workspace != null) {
File repoDir = new File(getRemoteString(build) + File.separator + ".git");
scmData = workspace.act(new LineEnricherCallable(repoDir, scmData));
logger.info("Line enricher: process took: " + ((System.currentTimeMillis() - startTime) / 1000) + " seconds");
}
else {
logger.warn("Line enricher: workspace is null");
}
} catch (Exception e1) {
logger.error("Line enricher: FAILED. could not enrich lines on SCM Data " + e1);
logger.error("Line enricher: FAILED. could not enrich lines on SCM Data ", e1);
}
logger.info("Line enricher: process took: " + ((System.currentTimeMillis() - startTime) / 1000) + " seconds");
return scmData;
}

Expand Down Expand Up @@ -349,7 +352,7 @@ public SCMData invoke(File rootDir, VirtualChannel channel) throws IOException {
df.setDetectRenames(true);

//add blame data to scm data
Set<String> committedFiles = getCommittedFiles(scmData);
Set<String> committedFiles = getAddedOrEditedFiles(scmData);
List<SCMFileBlame> fileBlameList = getBlameData(repo, committedFiles);
scmData.setFileBlameList(fileBlameList);

Expand Down Expand Up @@ -396,10 +399,10 @@ public SCMData invoke(File rootDir, VirtualChannel channel) throws IOException {
}
}

private static Set<String> getCommittedFiles(SCMData scmData) {
private static Set<String> getAddedOrEditedFiles(SCMData scmData) {
Set<String> filesCommittedInPPR = new HashSet<>();
for (SCMCommit curCommit : scmData.getCommits()) {
curCommit.getChanges().forEach(change -> filesCommittedInPPR.add(change.getFile()));
curCommit.getChanges().stream().filter(change -> !change.getType().equals("delete")).forEach(change -> filesCommittedInPPR.add(change.getFile()));
}
return filesCommittedInPPR;
}
Expand Down

0 comments on commit d5fa69f

Please sign in to comment.