From 57ff5ecf294cc32417f099fa82dde3bee1f87b8a Mon Sep 17 00:00:00 2001
From: Mykola Rudyk
Date: Tue, 12 Sep 2023 22:05:06 +0300
Subject: [PATCH] fix: fix missing comment on pull request
---
src/main/java/com/lpvs/service/LPVSGitHubService.java | 9 +++++++--
src/main/java/com/lpvs/service/LPVSQueueService.java | 2 +-
.../scanner/scanoss/LPVSScanossDetectService.java | 1 +
.../java/com/lpvs/service/LPVSGitHubServiceTest.java | 2 +-
4 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/lpvs/service/LPVSGitHubService.java b/src/main/java/com/lpvs/service/LPVSGitHubService.java
index 4848c68b..5e431f6a 100644
--- a/src/main/java/com/lpvs/service/LPVSGitHubService.java
+++ b/src/main/java/com/lpvs/service/LPVSGitHubService.java
@@ -252,6 +252,11 @@ public void commentResults(LPVSQueue webhookConfig, List scanResults,
lpvsDetectedLicenseRepository.saveAndFlush(detectedIssue);
}
commitCommentBuilder.append("");
+ if (null != webhookConfig.getHubLink()) {
+ commitCommentBuilder.append("(");
+ commitCommentBuilder.append(webhookConfig.getHubLink());
+ commitCommentBuilder.append(")");
+ }
commitComment += commitCommentBuilder.toString();
}
@@ -259,14 +264,14 @@ public void commentResults(LPVSQueue webhookConfig, List scanResults,
lpvsPullRequest.setStatus(LPVSPullRequestStatus.ISSUES_DETECTED.toString());
pullRequestRepository.save(lpvsPullRequest);
pullRequest.comment("**\\[License Pre-Validation Service\\]** Potential license problem(s) detected \n\n" +
- commitComment + "(" + webhookConfig.getHubLink() + ")
");
+ commitComment + "");
repository.createCommitStatus(webhookConfig.getHeadCommitSHA(), GHCommitState.FAILURE, null,
"Potential license problem(s) detected", "[License Pre-Validation Service]");
} else {
lpvsPullRequest.setStatus(LPVSPullRequestStatus.COMPLETED.toString());
pullRequestRepository.save(lpvsPullRequest);
pullRequest.comment("**\\[License Pre-Validation Service\\]** No license issue detected \n\n" +
- commitComment + "(" + webhookConfig.getHubLink() + ")");
+ commitComment + "");
repository.createCommitStatus(webhookConfig.getHeadCommitSHA(), GHCommitState.SUCCESS, null,
"No license issue detected", "[License Pre-Validation Service]");
}
diff --git a/src/main/java/com/lpvs/service/LPVSQueueService.java b/src/main/java/com/lpvs/service/LPVSQueueService.java
index b1df41bd..851cdacf 100644
--- a/src/main/java/com/lpvs/service/LPVSQueueService.java
+++ b/src/main/java/com/lpvs/service/LPVSQueueService.java
@@ -172,10 +172,10 @@ public void processWebHook(LPVSQueue webhookConfig) throws IOException {
}
delete(webhookConfig);
} catch (Exception | Error e) {
- pullRequest.setStatus(LPVSPullRequestStatus.INTERNAL_ERROR.toString());
pullRequest = lpvsPullRequestRepository.saveAndFlush(pullRequest);
log.error("Can't authorize commentResults() " + e);
e.printStackTrace();
+ pullRequest.setStatus(LPVSPullRequestStatus.INTERNAL_ERROR.toString());
delete(webhookConfig);
}
}
diff --git a/src/main/java/com/lpvs/service/scanner/scanoss/LPVSScanossDetectService.java b/src/main/java/com/lpvs/service/scanner/scanoss/LPVSScanossDetectService.java
index f63f9994..e574cbc7 100644
--- a/src/main/java/com/lpvs/service/scanner/scanoss/LPVSScanossDetectService.java
+++ b/src/main/java/com/lpvs/service/scanner/scanoss/LPVSScanossDetectService.java
@@ -132,6 +132,7 @@ public List checkLicenses(LPVSQueue webhookConfig) {
.replaceAll("],", "\"],")
.replaceAll("\"\\{\"","{\"")
.replaceAll("\"}\"]", "\"}]")
+ .replaceAll("\\[\"\"\\]", "[]")
.replaceAll("incompatible_with\" : (\".*?\"), \"name", "incompatible_with\" : \\[$1\\], \"name")
;
content = content.substring(1, content.length() - 1);
diff --git a/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java b/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java
index a9bef5ff..a21e0e09 100644
--- a/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java
+++ b/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java
@@ -1646,7 +1646,7 @@ class TestCommentResults__ProhibitedAbsentConflictsAbsent {
" * Use of this source code is governed by a MIT license that can be\n" +
" * found in the LICENSE file.\n" +
" */\n\n\n\n\n" +
- "(null)";
+ "";
@BeforeEach
void setUp() {