diff --git a/pom.xml b/pom.xml
index a2d25425..5f21e018 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@
org.springframework.boot
spring-boot-starter-parent
- 3.2.1
+ 3.2.2
@@ -82,7 +82,7 @@
commons-codec
commons-codec
- 1.15
+ 1.16.0
com.google.code.findbugs
@@ -159,7 +159,7 @@
org.apache.maven.plugins
maven-compiler-plugin
- 3.12.1
+ 3.10.0
17
true
@@ -167,6 +167,9 @@
-Xlint:all,-serial,-processing
+
+ **/package-info.java
+
diff --git a/src/main/java/com/lpvs/entity/LPVSDetectedLicense.java b/src/main/java/com/lpvs/entity/LPVSDetectedLicense.java
index 3b684ca8..e417d96d 100644
--- a/src/main/java/com/lpvs/entity/LPVSDetectedLicense.java
+++ b/src/main/java/com/lpvs/entity/LPVSDetectedLicense.java
@@ -17,7 +17,7 @@
* This class is mapped to the "detected_license" table in the "lpvs" schema.
*/
@Entity
-@Table(name = "detected_license", schema = "lpvs")
+@Table(name = "detected_license", schema = "${lpvs.schema:lpvs}")
@Getter
@Setter
public class LPVSDetectedLicense implements Serializable {
diff --git a/src/main/java/com/lpvs/entity/LPVSLicense.java b/src/main/java/com/lpvs/entity/LPVSLicense.java
index 1cf68f89..6aea6a05 100644
--- a/src/main/java/com/lpvs/entity/LPVSLicense.java
+++ b/src/main/java/com/lpvs/entity/LPVSLicense.java
@@ -21,7 +21,7 @@
@Entity
@Table(
name = "licenses",
- schema = "lpvs",
+ schema = "${lpvs.schema:lpvs}",
indexes = {@Index(name = "spdx_id", columnList = "license_spdx", unique = true)})
@Getter
@Setter
diff --git a/src/main/java/com/lpvs/entity/LPVSLicenseConflict.java b/src/main/java/com/lpvs/entity/LPVSLicenseConflict.java
index c07c8048..2e4561e8 100644
--- a/src/main/java/com/lpvs/entity/LPVSLicenseConflict.java
+++ b/src/main/java/com/lpvs/entity/LPVSLicenseConflict.java
@@ -18,7 +18,7 @@
* This class is mapped to the "license_conflicts" table in the "lpvs" schema.
*/
@Entity
-@Table(name = "license_conflicts", schema = "lpvs")
+@Table(name = "license_conflicts", schema = "${lpvs.schema:lpvs}")
@Getter
@Setter
@NoArgsConstructor
diff --git a/src/main/java/com/lpvs/entity/LPVSPullRequest.java b/src/main/java/com/lpvs/entity/LPVSPullRequest.java
index 54249512..a874ca1b 100644
--- a/src/main/java/com/lpvs/entity/LPVSPullRequest.java
+++ b/src/main/java/com/lpvs/entity/LPVSPullRequest.java
@@ -21,7 +21,7 @@
* This class is mapped to the "pull_requests" table in the "lpvs" schema.
*/
@Entity
-@Table(name = "pull_requests", schema = "lpvs")
+@Table(name = "pull_requests", schema = "${lpvs.schema:lpvs}")
@Getter
@Setter
@AllArgsConstructor
diff --git a/src/main/java/com/lpvs/entity/LPVSQueue.java b/src/main/java/com/lpvs/entity/LPVSQueue.java
index d86e33c7..83c89d96 100644
--- a/src/main/java/com/lpvs/entity/LPVSQueue.java
+++ b/src/main/java/com/lpvs/entity/LPVSQueue.java
@@ -20,7 +20,7 @@
* This class is mapped to the "queue" table in the "lpvs" schema.
*/
@Entity
-@Table(name = "queue", schema = "lpvs")
+@Table(name = "queue", schema = "${lpvs.schema:lpvs}")
@Getter
@Setter
public class LPVSQueue implements Serializable {
diff --git a/src/main/java/com/lpvs/entity/auth/LPVSMember.java b/src/main/java/com/lpvs/entity/auth/LPVSMember.java
index 5b47f365..37502783 100644
--- a/src/main/java/com/lpvs/entity/auth/LPVSMember.java
+++ b/src/main/java/com/lpvs/entity/auth/LPVSMember.java
@@ -22,7 +22,7 @@
@Entity
@Table(
name = "member",
- schema = "lpvs",
+ schema = "${lpvs.schema:lpvs}",
indexes = {@Index(name = "unq_member", columnList = "email, provider", unique = true)})
public class LPVSMember {
diff --git a/src/main/java/com/lpvs/entity/enums/LPVSPullRequestAction.java b/src/main/java/com/lpvs/entity/enums/LPVSPullRequestAction.java
index d73bbe43..554d4a8e 100644
--- a/src/main/java/com/lpvs/entity/enums/LPVSPullRequestAction.java
+++ b/src/main/java/com/lpvs/entity/enums/LPVSPullRequestAction.java
@@ -40,7 +40,12 @@ public enum LPVSPullRequestAction {
/**
* Represents the action of triggering a manual single scan of a pull request.
*/
- SINGLE_SCAN("single-scan");
+ SINGLE_SCAN("single-scan"),
+
+ /**
+ * Represents the action of triggering a scan of a pull request by automation bot.
+ */
+ BOT_SCAN("bot-scan");
/**
* The string representation of the pull request action.
@@ -84,6 +89,8 @@ public static LPVSPullRequestAction convertFrom(String action) {
return RESCAN;
} else if (action.equals(SINGLE_SCAN.getPullRequestAction())) {
return SINGLE_SCAN;
+ } else if (action.equals(BOT_SCAN.getPullRequestAction())) {
+ return BOT_SCAN;
} else {
return null;
}
diff --git a/src/main/java/com/lpvs/service/LPVSGitHubService.java b/src/main/java/com/lpvs/service/LPVSGitHubService.java
index 10e3832c..bb7b929f 100644
--- a/src/main/java/com/lpvs/service/LPVSGitHubService.java
+++ b/src/main/java/com/lpvs/service/LPVSGitHubService.java
@@ -333,9 +333,10 @@ public void commentResults(
}
commitCommentBuilder.append("");
if (null != webhookConfig.getHubLink()) {
- commitCommentBuilder.append("(");
+ commitCommentBuilder.append(
+ "\n\n###### Check the validation details at the link(");
commitCommentBuilder.append(webhookConfig.getHubLink());
- commitCommentBuilder.append(")");
+ commitCommentBuilder.append(")
");
}
commitComment += commitCommentBuilder.toString();
}
@@ -345,8 +346,7 @@ public void commentResults(
pullRequestRepository.save(lpvsPullRequest);
pullRequest.comment(
"**\\[License Pre-Validation Service\\]** Potential license problem(s) detected \n\n"
- + commitComment
- + "
");
+ + commitComment);
repository.createCommitStatus(
webhookConfig.getHeadCommitSHA(),
GHCommitState.FAILURE,
@@ -358,8 +358,7 @@ public void commentResults(
pullRequestRepository.save(lpvsPullRequest);
pullRequest.comment(
"**\\[License Pre-Validation Service\\]** No license issue detected \n\n"
- + commitComment
- + "");
+ + commitComment);
repository.createCommitStatus(
webhookConfig.getHeadCommitSHA(),
GHCommitState.SUCCESS,
diff --git a/src/main/java/com/lpvs/util/LPVSFileUtil.java b/src/main/java/com/lpvs/util/LPVSFileUtil.java
index 7fe1643c..852c2eb1 100644
--- a/src/main/java/com/lpvs/util/LPVSFileUtil.java
+++ b/src/main/java/com/lpvs/util/LPVSFileUtil.java
@@ -39,6 +39,10 @@ public class LPVSFileUtil {
*/
public static void saveFile(String fileName, String directoryPath, List patchedLines) {
try {
+ if (patchedLines == null || patchedLines.size() == 0) {
+ log.error("Empty patch for file " + fileName);
+ return;
+ }
int cnt = 1;
StringBuilder prettyPatch = new StringBuilder();
for (String patchedLine : patchedLines) {
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index f0e8cd62..d5fb8188 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -28,6 +28,9 @@ lpvs.cores=8
lpvs.attempts=4
# DB Configuration
+# The name of DB schema
+lpvs.schema=lpvs
+
spring.jpa.open-in-view=true
spring.jpa.properties.hibernate.connection.CharSet=utf8
spring.jpa.properties.hibernate.connection.characterEncoding=utf8
diff --git a/src/test/java/com/lpvs/entity/enums/LPVSPullRequestActionTest.java b/src/test/java/com/lpvs/entity/enums/LPVSPullRequestActionTest.java
index d2973d73..77049178 100644
--- a/src/test/java/com/lpvs/entity/enums/LPVSPullRequestActionTest.java
+++ b/src/test/java/com/lpvs/entity/enums/LPVSPullRequestActionTest.java
@@ -23,6 +23,7 @@ public void testConvertFrom() {
assertEquals(
LPVSPullRequestAction.convertFrom("single-scan"),
LPVSPullRequestAction.SINGLE_SCAN);
+ assertEquals(LPVSPullRequestAction.convertFrom("bot-scan"), LPVSPullRequestAction.BOT_SCAN);
assertNotEquals(
LPVSPullRequestAction.convertFrom("random_name"), LPVSPullRequestAction.OPEN);
@@ -37,6 +38,8 @@ public void testConvertFrom() {
assertNotEquals(
LPVSPullRequestAction.convertFrom("random_name"),
LPVSPullRequestAction.SINGLE_SCAN);
+ assertNotEquals(
+ LPVSPullRequestAction.convertFrom("random_name"), LPVSPullRequestAction.BOT_SCAN);
assertNull(LPVSPullRequestAction.convertFrom("random_name"));
}
@@ -49,5 +52,6 @@ public void testGetPullRequestAction() {
assertEquals(LPVSPullRequestAction.UPDATE.getPullRequestAction(), "synchronize");
assertEquals(LPVSPullRequestAction.RESCAN.getPullRequestAction(), "rescan");
assertEquals(LPVSPullRequestAction.SINGLE_SCAN.getPullRequestAction(), "single-scan");
+ assertEquals(LPVSPullRequestAction.BOT_SCAN.getPullRequestAction(), "bot-scan");
}
}
diff --git a/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java b/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java
index 6c1de107..f2b49396 100644
--- a/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java
+++ b/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java
@@ -2180,7 +2180,8 @@ class TestCommentResults__ProhibitedPresentConflictsPresent {
+ " * found in the LICENSE file.\n"
+ " */\n\n\n\n\n"
+ "**Detected license conflicts:**\n\n\n"
- + "()";
+ + ""
+ + "\n\n###### Check the validation details at the link()
";
@BeforeEach
void setUp() {
@@ -2508,7 +2509,8 @@ class TestCommentResults__EmptyPresentConflictsPresent {
+ " * found in the LICENSE file.\n"
+ " */\n\n\n\n\n"
+ "**Detected license conflicts:**\n\n\n"
- + "()";
+ + ""
+ + "\n\n###### Check the validation details at the link()
";
@BeforeEach
void setUp() {
@@ -2661,7 +2663,7 @@ public void testCommentResults__EmptyPresentConflictsPresentLicensePresent()
+ LPVSWebhookUtil.getRepositoryName(webhookConfig));
} catch (IOException e) {
log.error(
- "TestCommentResults__EmptyPresentConflictsPresent.testCommentResults__EmptyPresentConflictsPresent() error "
+ "TestCommentResults__EmptyPresentConflictsPresent.testCommentResults__EmptyPresentConflictsPresentLicensePresent() error "
+ e);
fail();
}
@@ -2679,7 +2681,7 @@ public void testCommentResults__EmptyPresentConflictsPresentLicensePresent()
"[License Pre-Validation Service]");
} catch (IOException e) {
log.error(
- "TestCommentResults__EmptyPresentConflictsPresent.testCommentResults__EmptyPresentConflictsPresent() error "
+ "TestCommentResults__EmptyPresentConflictsPresent.testCommentResults__EmptyPresentConflictsPresentLicensePresent() error "
+ e);
fail();
}
@@ -2721,7 +2723,7 @@ public void testCommentResults__EmptyPresentConflictsPresentLicensePresentAlt()
+ LPVSWebhookUtil.getRepositoryName(webhookConfig));
} catch (IOException e) {
log.error(
- "TestCommentResults__EmptyPresentConflictsPresent.testCommentResults__EmptyPresentConflictsPresent() error "
+ "TestCommentResults__EmptyPresentConflictsPresent.testCommentResults__EmptyPresentConflictsPresentLicensePresentAlt() error "
+ e);
fail();
}
@@ -2739,7 +2741,7 @@ public void testCommentResults__EmptyPresentConflictsPresentLicensePresentAlt()
"[License Pre-Validation Service]");
} catch (IOException e) {
log.error(
- "TestCommentResults__EmptyPresentConflictsPresent.testCommentResults__EmptyPresentConflictsPresent() error "
+ "TestCommentResults__EmptyPresentConflictsPresent.testCommentResults__EmptyPresentConflictsPresentLicensePresentAlt() error "
+ e);
fail();
}
@@ -2835,7 +2837,8 @@ class TestCommentResults__UnreviewedPresentConflictsPresent {
+ " * found in the LICENSE file.\n"
+ " */\n\n\n\n\n"
+ "**Detected license conflicts:**\n\n\n"
- + "()";
+ + ""
+ + "\n\n###### Check the validation details at the link()
";
@BeforeEach
void setUp() {
@@ -2931,7 +2934,7 @@ public void testCommentResults__RestrictedPresentConflictsPresent() throws IOExc
+ LPVSWebhookUtil.getRepositoryName(webhookConfig));
} catch (IOException e) {
log.error(
- "TestCommentResults__UnreviewedPresentConflictsPresent.testCommentResults__UnreviewedPresentConflictsPresent() error "
+ "TestCommentResults__UnreviewedPresentConflictsPresent.testCommentResults__RestrictedPresentConflictsPresent() error "
+ e);
fail();
}
@@ -2949,7 +2952,7 @@ public void testCommentResults__RestrictedPresentConflictsPresent() throws IOExc
"[License Pre-Validation Service]");
} catch (IOException e) {
log.error(
- "TestCommentResults__UnreviewedPresentConflictsPresent.testCommentResults__UnreviewedPresentConflictsPresent() error "
+ "TestCommentResults__UnreviewedPresentConflictsPresent.testCommentResults__RestrictedPresentConflictsPresent() error "
+ e);
fail();
}
@@ -2990,7 +2993,7 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresent(
+ LPVSWebhookUtil.getRepositoryName(webhookConfig));
} catch (IOException e) {
log.error(
- "TestCommentResults__UnreviewedPresentConflictsPresent.testCommentResults__UnreviewedPresentConflictsPresent() error "
+ "TestCommentResults__UnreviewedPresentConflictsPresent.testCommentResults__RestrictedPresentConflictsPresentLicensePresent() error "
+ e);
fail();
}
@@ -3008,7 +3011,7 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresent(
"[License Pre-Validation Service]");
} catch (IOException e) {
log.error(
- "TestCommentResults__UnreviewedPresentConflictsPresent.testCommentResults__UnreviewedPresentConflictsPresent() error "
+ "TestCommentResults__UnreviewedPresentConflictsPresent.testCommentResults__RestrictedPresentConflictsPresentLicensePresent() error "
+ e);
fail();
}
@@ -3050,7 +3053,7 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresentA
+ LPVSWebhookUtil.getRepositoryName(webhookConfig));
} catch (IOException e) {
log.error(
- "TestCommentResults__UnreviewedPresentConflictsPresent.testCommentResults__UnreviewedPresentConflictsPresent() error "
+ "TestCommentResults__UnreviewedPresentConflictsPresent.testCommentResults__RestrictedPresentConflictsPresentLicensePresentAlt() error "
+ e);
fail();
}
@@ -3068,7 +3071,7 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresentA
"[License Pre-Validation Service]");
} catch (IOException e) {
log.error(
- "TestCommentResults__UnreviewedPresentConflictsPresent.testCommentResults__UnreviewedPresentConflictsPresent() error "
+ "TestCommentResults__UnreviewedPresentConflictsPresent.testCommentResults__RestrictedPresentConflictsPresentLicensePresentAlt() error "
+ e);
fail();
}
@@ -3164,7 +3167,8 @@ class TestCommentResults__RestrictedPresentConflictsPresent {
+ " * found in the LICENSE file.\n"
+ " */\n\n\n\n\n"
+ "**Detected license conflicts:**\n\n\n"
- + "()";
+ + ""
+ + "\n\n###### Check the validation details at the link()
";
@BeforeEach
void setUp() {
@@ -3319,7 +3323,7 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresent(
+ LPVSWebhookUtil.getRepositoryName(webhookConfig));
} catch (IOException e) {
log.error(
- "TestCommentResults__RestrictedPresentConflictsPresent.testCommentResults__RestrictedPresentConflictsPresent() error "
+ "TestCommentResults__RestrictedPresentConflictsPresent.testCommentResults__RestrictedPresentConflictsPresentLicensePresent() error "
+ e);
fail();
}
@@ -3337,7 +3341,7 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresent(
"[License Pre-Validation Service]");
} catch (IOException e) {
log.error(
- "TestCommentResults__RestrictedPresentConflictsPresent.testCommentResults__RestrictedPresentConflictsPresent() error "
+ "TestCommentResults__RestrictedPresentConflictsPresent.testCommentResults__RestrictedPresentConflictsPresentLicensePresent() error "
+ e);
fail();
}
@@ -3379,7 +3383,7 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresentA
+ LPVSWebhookUtil.getRepositoryName(webhookConfig));
} catch (IOException e) {
log.error(
- "TestCommentResults__RestrictedPresentConflictsPresent.testCommentResults__RestrictedPresentConflictsPresent() error "
+ "TestCommentResults__RestrictedPresentConflictsPresent.testCommentResults__RestrictedPresentConflictsPresentLicensePresentAlt() error "
+ e);
fail();
}
@@ -3397,7 +3401,7 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresentA
"[License Pre-Validation Service]");
} catch (IOException e) {
log.error(
- "TestCommentResults__RestrictedPresentConflictsPresent.testCommentResults__RestrictedPresentConflictsPresent() error "
+ "TestCommentResults__RestrictedPresentConflictsPresent.testCommentResults__RestrictedPresentConflictsPresentLicensePresentAlt() error "
+ e);
fail();
}
@@ -3476,8 +3480,7 @@ class TestCommentResults__ProhibitedAbsentConflictsAbsent {
+ " *\n"
+ " * 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"
- + "";
+ + " */\n\n\n\n\n";
@BeforeEach
void setUp() {
diff --git a/src/test/java/com/lpvs/util/LPVSFileUtilTest.java b/src/test/java/com/lpvs/util/LPVSFileUtilTest.java
index e81cabaa..72f4dd76 100644
--- a/src/test/java/com/lpvs/util/LPVSFileUtilTest.java
+++ b/src/test/java/com/lpvs/util/LPVSFileUtilTest.java
@@ -13,7 +13,12 @@
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.springframework.test.util.ReflectionTestUtils;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.ArrayList;
+import java.util.List;
+
import static org.mockito.Mockito.*;
public class LPVSFileUtilTest {
@@ -227,4 +232,19 @@ public void testGetScanResultsDirectoryPath() {
assert (result.equals(expectedPath));
}
}
+
+ @Test
+ public void testSaveFileWithEmptyPatchedLines() {
+ String fileName = "testFile.txt";
+ String directoryPath = "testDirectory";
+ List patchedLines = new ArrayList<>();
+
+ LPVSFileUtil.saveFile(fileName, directoryPath, patchedLines);
+ Boolean result1 = Files.exists(Paths.get(directoryPath, fileName));
+ assert (result1.equals(false));
+
+ LPVSFileUtil.saveFile(fileName, directoryPath, null);
+ Boolean result2 = Files.exists(Paths.get(directoryPath, fileName));
+ assert (result2.equals(false));
+ }
}