diff --git a/README.md b/README.md index ad92cf21..d9982be2 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ LPVS will start scanning automatically, then provide comments about the licenses Or alternatively build and run the Docker container with LPVS: ```bash docker build -t lpvs . - docker run -p 7896:7896 --name lpvs lpvs:latest + docker run -p 7896:7896 --name lpvs -e LPVS_GITHUB_TOKEN=<`github.token`> lpvs:latest ``` For additional information about using Docker and tips, please check file [Docker_Usage](.github/Docker_Usage.md). diff --git a/src/main/java/com/lpvs/service/GitHubService.java b/src/main/java/com/lpvs/service/GitHubService.java index f68703e8..dd49fa64 100644 --- a/src/main/java/com/lpvs/service/GitHubService.java +++ b/src/main/java/com/lpvs/service/GitHubService.java @@ -45,6 +45,7 @@ public String getPullRequestFiles (WebhookConfig webhookConfig) { webhookConfig.getRepositoryName() + "/pulls/" + webhookConfig.getPullRequestId()); } try { + if (GITHUB_AUTH_TOKEN.isEmpty()) setGithubTokenFromEnv(); if (GITHUB_API_URL.isEmpty()) gitHub = GitHub.connect(GITHUB_LOGIN, GITHUB_AUTH_TOKEN); else gitHub = GitHub.connectToEnterpriseWithOAuth(GITHUB_API_URL, GITHUB_LOGIN, GITHUB_AUTH_TOKEN); GHRepository repository = gitHub.getRepository(webhookConfig.getRepositoryOrganization()+"/" @@ -82,6 +83,7 @@ private GHPullRequest getPullRequest(WebhookConfig webhookConfig, GHRepository r public void setPendingCheck(WebhookConfig webhookConfig) { try { + if (GITHUB_AUTH_TOKEN.isEmpty()) setGithubTokenFromEnv(); if (GITHUB_API_URL.isEmpty()) gitHub = GitHub.connect(GITHUB_LOGIN, GITHUB_AUTH_TOKEN); else gitHub = GitHub.connectToEnterpriseWithOAuth(GITHUB_API_URL, GITHUB_LOGIN, GITHUB_AUTH_TOKEN); GHRepository repository = gitHub.getRepository(webhookConfig.getRepositoryOrganization() + "/" @@ -95,6 +97,7 @@ public void setPendingCheck(WebhookConfig webhookConfig) { public void setErrorCheck(WebhookConfig webhookConfig) { try { + if (GITHUB_AUTH_TOKEN.isEmpty()) setGithubTokenFromEnv(); if (GITHUB_API_URL.isEmpty()) gitHub = GitHub.connect(GITHUB_LOGIN, GITHUB_AUTH_TOKEN); else gitHub = GitHub.connectToEnterpriseWithOAuth(GITHUB_API_URL, GITHUB_LOGIN, GITHUB_AUTH_TOKEN); GHRepository repository = gitHub.getRepository(webhookConfig.getRepositoryOrganization() + "/" @@ -173,6 +176,7 @@ public String getRepositoryLicense(WebhookConfig webhookConfig) { try { String repositoryName = webhookConfig.getRepositoryName(); String repositoryOrganization = webhookConfig.getRepositoryOrganization(); + if (GITHUB_AUTH_TOKEN.isEmpty()) setGithubTokenFromEnv(); if (GITHUB_API_URL.isEmpty()) gitHub = GitHub.connect(GITHUB_LOGIN, GITHUB_AUTH_TOKEN); else gitHub = GitHub.connectToEnterpriseWithOAuth(GITHUB_API_URL, GITHUB_LOGIN, GITHUB_AUTH_TOKEN); GHRepository repository = gitHub.getRepository(repositoryOrganization + "/" + repositoryName); @@ -203,4 +207,8 @@ public String getMatchedLinesAsLink(WebhookConfig webhookConfig, LPVSFile file) return matchedLines; } + public void setGithubTokenFromEnv() { + if (System.getenv("LPVS_GITHUB_TOKEN") != null) GITHUB_AUTH_TOKEN = System.getenv("LPVS_GITHUB_TOKEN"); + } + }