diff --git a/src/main/java/com/lpvs/controller/GitHubController.java b/src/main/java/com/lpvs/controller/GitHubController.java index 99c4369c..f3a735e7 100644 --- a/src/main/java/com/lpvs/controller/GitHubController.java +++ b/src/main/java/com/lpvs/controller/GitHubController.java @@ -224,8 +224,7 @@ public ResponseEntity gitHubWebhooks( public ResponseEntity gitHubSingleScan( @PathVariable("gitHubOrg") @NotEmpty @Valid String gitHubOrg, @PathVariable("gitHubRepo") @NotEmpty @Valid String gitHubRepo, - @PathVariable("prNumber") @Min(1) @Valid Integer prNumber) - throws InterruptedException, IOException { + @PathVariable("prNumber") @Min(1) @Valid Integer prNumber) { log.debug("New GitHub single scan request received"); if (GITHUB_SECRET.trim().isEmpty()) { diff --git a/src/main/java/com/lpvs/entity/enums/LPVSPullRequestAction.java b/src/main/java/com/lpvs/entity/enums/LPVSPullRequestAction.java index 04857e82..d0d84686 100644 --- a/src/main/java/com/lpvs/entity/enums/LPVSPullRequestAction.java +++ b/src/main/java/com/lpvs/entity/enums/LPVSPullRequestAction.java @@ -45,7 +45,12 @@ public enum LPVSPullRequestAction { /** * Represents the action of triggering a scan of a pull request by automation bot. */ - BOT_SCAN("bot-scan"); + BOT_SCAN("bot-scan"), + + /** + * Represents the action of triggering a scan of a repository branch. + */ + REPO_SCAN("repo-scan"); /** * The string representation of the pull request action. @@ -91,6 +96,8 @@ public static LPVSPullRequestAction convertFrom(String action) { return SINGLE_SCAN; } else if (action.equals(BOT_SCAN.getPullRequestAction())) { return BOT_SCAN; + } else if (action.equals(REPO_SCAN.getPullRequestAction())) { + return REPO_SCAN; } else { return null; } diff --git a/src/main/java/com/lpvs/service/LPVSGitHubConnectionService.java b/src/main/java/com/lpvs/service/LPVSGitHubConnectionService.java index 7ac91aec..99b08342 100644 --- a/src/main/java/com/lpvs/service/LPVSGitHubConnectionService.java +++ b/src/main/java/com/lpvs/service/LPVSGitHubConnectionService.java @@ -149,6 +149,23 @@ public GitHub connectToGitHubApi() throws IOException { return gH; } + /** + * Connects to the GitHub API based on the configured authentication token and API URL with custom token. + * + * @param token GitHub custom authentication token. + * @return GitHub instance for interacting with the GitHub API. + * @throws IOException if an error occurs during the GitHub connection. + */ + public GitHub connectToEnterpriseApiWithCustomToken(String token) throws IOException { + GitHub gH; + if (StringUtils.isBlank(token)) { + gH = connectToGitHubApi(); + } else { + gH = GitHub.connectToEnterpriseWithOAuth(GITHUB_API_URL, GITHUB_LOGIN, token); + } + return gH; + } + /** * Sets the GitHub authentication token from the environment variable if available. */ diff --git a/src/test/java/com/lpvs/entity/enums/LPVSPullRequestActionTest.java b/src/test/java/com/lpvs/entity/enums/LPVSPullRequestActionTest.java index 379933e5..3b76f178 100644 --- a/src/test/java/com/lpvs/entity/enums/LPVSPullRequestActionTest.java +++ b/src/test/java/com/lpvs/entity/enums/LPVSPullRequestActionTest.java @@ -24,6 +24,8 @@ public void testConvertFrom() { LPVSPullRequestAction.convertFrom("single-scan"), LPVSPullRequestAction.SINGLE_SCAN); assertEquals(LPVSPullRequestAction.convertFrom("bot-scan"), LPVSPullRequestAction.BOT_SCAN); + assertEquals( + LPVSPullRequestAction.convertFrom("repo-scan"), LPVSPullRequestAction.REPO_SCAN); assertNotEquals( LPVSPullRequestAction.convertFrom("random_name"), LPVSPullRequestAction.OPEN); @@ -40,6 +42,8 @@ public void testConvertFrom() { LPVSPullRequestAction.SINGLE_SCAN); assertNotEquals( LPVSPullRequestAction.convertFrom("random_name"), LPVSPullRequestAction.BOT_SCAN); + assertNotEquals( + LPVSPullRequestAction.convertFrom("random_name"), LPVSPullRequestAction.REPO_SCAN); assertNull(LPVSPullRequestAction.convertFrom("random_name")); } @@ -53,5 +57,6 @@ public void testGetPullRequestAction() { assertEquals(LPVSPullRequestAction.RESCAN.getPullRequestAction(), "rescan"); assertEquals(LPVSPullRequestAction.SINGLE_SCAN.getPullRequestAction(), "single-scan"); assertEquals(LPVSPullRequestAction.BOT_SCAN.getPullRequestAction(), "bot-scan"); + assertEquals(LPVSPullRequestAction.REPO_SCAN.getPullRequestAction(), "repo-scan"); } }