-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enable starting scans with pull request argument (#300)
* Enabled starting scans with pull request argument Signed-off-by: Vasyl Kerimov <[email protected]> * Removed debug logs Signed-off-by: Vasyl Kerimov <[email protected]> * Formatting fixed Signed-off-by: Vasyl Kerimov <[email protected]> * Refactoring: moved GitHub connection establishment into separate service Signed-off-by: Vasyl Kerimov <[email protected]> * Formatting style fix Signed-off-by: Vasyl Kerimov <[email protected]> * Made a static method static Signed-off-by: Vasyl Kerimov <[email protected]> * doc: update readme, add signe scan description Signed-off-by: Mykola Rudyk <[email protected]> * fix: initialization procedure Signed-off-by: Mykola Rudyk <[email protected]> * Change format of github.pull.request Signed-off-by: Vasyl Kerimov <[email protected]> * README.md update Signed-off-by: Vasyl Kerimov <[email protected]> * fix: output results Signed-off-by: Mykola Rudyk <[email protected]> * Fix code style Signed-off-by: Vasyl Kerimov <[email protected]> * Fix code style more Signed-off-by: Vasyl Kerimov <[email protected]> * All necessary licenses added to the dump Signed-off-by: Vasyl Kerimov <[email protected]> * H2 properties added Signed-off-by: Vasyl Kerimov <[email protected]> * Removed repeat properties in singlescan profile properties file Signed-off-by: Vasyl Kerimov <[email protected]> * Updated README.md Signed-off-by: Vasyl Kerimov <[email protected]> * Reverted unnecessary change Signed-off-by: Vasyl Kerimov <[email protected]> * Formatting mistakes fixed Signed-off-by: Vasyl Kerimov <[email protected]> * Added license to a new file Signed-off-by: Vasyl Kerimov <[email protected]> * fix: small remarks Signed-off-by: Mykola Rudyk <[email protected]> * test: update unit tests for newly added features Signed-off-by: Mykola Rudyk <[email protected]> * Fixed README.md Signed-off-by: Vasyl Kerimov <[email protected]> * Fixed code style Signed-off-by: Vasyl Kerimov <[email protected]> * user column name reinstated Signed-off-by: Vasyl Kerimov <[email protected]> * Response to Oleg Kopysov's request Signed-off-by: Vasyl Kerimov <[email protected]> * test: update tests Signed-off-by: Mykola Rudyk <[email protected]> * Unnecessary imports deleted Signed-off-by: Vasyl Kerimov <[email protected]> * test: update tests Signed-off-by: Mykola Rudyk <[email protected]> * fix: fix style analyser warning Signed-off-by: Mykola Rudyk <[email protected]> * Fix to README.md Signed-off-by: Vasyl Kerimov <[email protected]> * fix: fix printing via internal loggin, add user input check Signed-off-by: Mykola Rudyk <[email protected]> * test: update unit tests to increase coverage Signed-off-by: Mykola Rudyk <[email protected]> * README.md instruction numbering fixed Signed-off-by: Vasyl Kerimov <[email protected]> * Removed credential from properties file Signed-off-by: Vasyl Kerimov <[email protected]> * Added htmlEscape, as per request Signed-off-by: Vasyl Kerimov <[email protected]> * Added ident Signed-off-by: Vasyl Kerimov <[email protected]> --------- Signed-off-by: Vasyl Kerimov <[email protected]> Signed-off-by: Mykola Rudyk <[email protected]> Co-authored-by: Mykola Rudyk <[email protected]> Co-authored-by: Oleg Kopysov <[email protected]>
- Loading branch information
1 parent
1776696
commit 54f4d9b
Showing
15 changed files
with
592 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/main/java/com/lpvs/service/LPVSGitHubConnectionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* Copyright (c) 2023, Samsung Electronics Co., Ltd. All rights reserved. | ||
* | ||
* Use of this source code is governed by a MIT license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
package com.lpvs.service; | ||
|
||
import com.lpvs.util.LPVSExitHandler; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.kohsuke.github.GitHub; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
@Service | ||
@Slf4j | ||
public class LPVSGitHubConnectionService { | ||
|
||
private String GITHUB_LOGIN; | ||
private String GITHUB_AUTH_TOKEN; | ||
private String GITHUB_API_URL; | ||
|
||
private static final String GITHUB_LOGIN_PROP_NAME = "github.login"; | ||
private static final String GITHUB_AUTH_TOKEN_PROP_NAME = "github.token"; | ||
private static final String GITHUB_API_URL_PROP_NAME = "github.api.url"; | ||
|
||
private static final String GITHUB_LOGIN_ENV_VAR_NAME = "LPVS_GITHUB_LOGIN"; | ||
private static final String GITHUB_AUTH_TOKEN_ENV_VAR_NAME = "LPVS_GITHUB_TOKEN"; | ||
private static final String GITHUB_API_URL_ENV_VAR_NAME = "LPVS_GITHUB_API_URL"; | ||
|
||
private LPVSExitHandler exitHandler; | ||
|
||
@Autowired | ||
public LPVSGitHubConnectionService( | ||
@Value("${" + GITHUB_LOGIN_PROP_NAME + "}") String GITHUB_LOGIN, | ||
@Value("${" + GITHUB_AUTH_TOKEN_PROP_NAME + "}") String GITHUB_AUTH_TOKEN, | ||
@Value("${" + GITHUB_API_URL_PROP_NAME + "}") String GITHUB_API_URL, | ||
LPVSExitHandler exitHandler) { | ||
this.GITHUB_LOGIN = | ||
Optional.ofNullable(GITHUB_LOGIN) | ||
.filter(s -> !s.isEmpty()) | ||
.orElse( | ||
Optional.ofNullable(System.getenv(GITHUB_LOGIN_ENV_VAR_NAME)) | ||
.orElse("")); | ||
this.GITHUB_AUTH_TOKEN = | ||
Optional.ofNullable(GITHUB_AUTH_TOKEN) | ||
.filter(s -> !s.isEmpty()) | ||
.orElse( | ||
Optional.ofNullable(System.getenv(GITHUB_AUTH_TOKEN_ENV_VAR_NAME)) | ||
.orElse("")); | ||
this.GITHUB_API_URL = | ||
Optional.ofNullable(GITHUB_API_URL) | ||
.filter(s -> !s.isEmpty()) | ||
.orElse( | ||
Optional.ofNullable(System.getenv(GITHUB_API_URL_ENV_VAR_NAME)) | ||
.orElse("")); | ||
this.exitHandler = exitHandler; | ||
} | ||
|
||
@PostConstruct | ||
private void checks() { | ||
if (this.GITHUB_AUTH_TOKEN.isEmpty()) { | ||
log.error( | ||
GITHUB_AUTH_TOKEN_ENV_VAR_NAME | ||
+ "(" | ||
+ GITHUB_AUTH_TOKEN_PROP_NAME | ||
+ ") is not set."); | ||
exitHandler.exit(-1); | ||
} | ||
} | ||
|
||
public GitHub connectToGitHubApi() throws IOException { | ||
GitHub gH; | ||
if (GITHUB_AUTH_TOKEN.isEmpty()) setGithubTokenFromEnv(); | ||
if (GITHUB_API_URL.isEmpty()) gH = GitHub.connect(GITHUB_LOGIN, GITHUB_AUTH_TOKEN); | ||
else | ||
gH = | ||
GitHub.connectToEnterpriseWithOAuth( | ||
GITHUB_API_URL, GITHUB_LOGIN, GITHUB_AUTH_TOKEN); | ||
return gH; | ||
} | ||
|
||
public void setGithubTokenFromEnv() { | ||
if (System.getenv("LPVS_GITHUB_TOKEN") != null) | ||
GITHUB_AUTH_TOKEN = System.getenv("LPVS_GITHUB_TOKEN"); | ||
} | ||
} |
Oops, something went wrong.