Skip to content

Commit

Permalink
refactor: Use LPVSFileUtil API for getReader (#535)
Browse files Browse the repository at this point in the history
* test: Use assertEquals to accurately verify the return value

Signed-off-by: Taewan Kim <[email protected]>

* refactor: Use LPVSFileUtil API for getReader

Signed-off-by: Taewan Kim <[email protected]>

* fix: Fix lint errors

Signed-off-by: Taewan Kim <[email protected]>

---------

Signed-off-by: Taewan Kim <[email protected]>
  • Loading branch information
tiokim authored Jun 4, 2024
1 parent 4e31ac1 commit e989b32
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.lpvs.repository.LPVSLicenseRepository;
import com.lpvs.service.LPVSLicenseService;
import com.lpvs.service.scan.LPVSScanService;
import com.lpvs.util.LPVSFileUtil;
import com.lpvs.util.LPVSPayloadUtil;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Expand Down Expand Up @@ -244,24 +245,8 @@ private ScanossJsonStructure getScanossJsonStructure(String content, LPVSFile fi
* @throws IOException If an error occurs while creating the BufferedReader object.
*/
private static Reader getReader(LPVSQueue webhookConfig) throws IOException {
String fileName = null;
if (webhookConfig.getHeadCommitSHA() == null
|| webhookConfig.getHeadCommitSHA().isBlank()) {
fileName = LPVSPayloadUtil.getPullRequestId(webhookConfig);
} else {
fileName = webhookConfig.getHeadCommitSHA();
}

return Files.newBufferedReader(
Paths.get(
System.getProperty("user.home")
+ File.separator
+ "Results"
+ File.separator
+ LPVSPayloadUtil.getRepositoryName(webhookConfig)
+ File.separator
+ fileName
+ ".json"));
Paths.get(LPVSFileUtil.getScanResultsJsonFilePath(webhookConfig)));
}

/**
Expand Down
30 changes: 13 additions & 17 deletions src/main/java/com/lpvs/util/LPVSFileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,22 @@ public static String getLocalDirectoryPath(LPVSQueue webhookConfig) {
* @return The file path for storing scan results in JSON format.
*/
public static String getScanResultsJsonFilePath(LPVSQueue webhookConfig) {
String fileName = null;
if (webhookConfig.getHeadCommitSHA() == null
|| webhookConfig.getHeadCommitSHA().equals("")) {
return System.getProperty("user.home")
+ File.separator
+ "Results"
+ File.separator
+ LPVSPayloadUtil.getRepositoryName(webhookConfig)
+ File.separator
+ LPVSPayloadUtil.getPullRequestId(webhookConfig)
+ ".json";
|| webhookConfig.getHeadCommitSHA().isBlank()) {
fileName = LPVSPayloadUtil.getPullRequestId(webhookConfig);
} else {
return System.getProperty("user.home")
+ File.separator
+ "Results"
+ File.separator
+ LPVSPayloadUtil.getRepositoryName(webhookConfig)
+ File.separator
+ webhookConfig.getHeadCommitSHA()
+ ".json";
fileName = webhookConfig.getHeadCommitSHA();
}

return System.getProperty("user.home")
+ File.separator
+ "Results"
+ File.separator
+ LPVSPayloadUtil.getRepositoryName(webhookConfig)
+ File.separator
+ fileName
+ ".json";
}

/**
Expand Down
Loading

0 comments on commit e989b32

Please sign in to comment.