Skip to content

Commit

Permalink
fix: read token from env variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
hemanik committed Apr 16, 2018
1 parent f4c9e9b commit 216b60e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 187 deletions.
32 changes: 1 addition & 31 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,7 @@
language: java

jdk:
- oraclejdk8

sudo: required

addons:
apt:
sources:
- git-core
packages:
- git
- jq

cache:
directories:
- $HOME/.m2
- $HOME/cache/

branches:
except:
- /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/

before_install:
- chmod +x ./_scripts/prepare_build.sh

install:
- TRAVIS_WORK_DIR="${PWD}/.."
- ./_scripts/prepare_build.sh --working-dir=${TRAVIS_WORK_DIR}

script:
- mvn clean install -Darquillian.blog.url=http://arquillian.org/ -Dbrowser=chromeHeadless -Darq.extension.webdriver.chromeDriverVersion=2.33

notifications:
email:
recipients:
secure: ZYuQRQkZAzs3VDBD15tbIAlA+HJn0btzoRCSAVdF81fzgyFG6e8ba5HapLot9KRdFh4BYrvBD6kAbvzxewNEDAm9HVP/JugOx9KR1TsMUKOYoNl81UzhnlgJWakutiQJd5yAreWrlWUEtlj3BWOzUQVMiskMi0gOSUxue1h2Lx8=
5 changes: 0 additions & 5 deletions _scripts/colors

This file was deleted.

82 changes: 0 additions & 82 deletions _scripts/parse_arguments.sh

This file was deleted.

68 changes: 0 additions & 68 deletions _scripts/prepare_build.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import com.google.gson.JsonElement;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import org.apache.http.client.utils.URIBuilder;
import org.jboss.arquillian.drone.webdriver.utils.HttpClient;
import org.jboss.arquillian.drone.webdriver.utils.Validate;
Expand All @@ -16,10 +18,12 @@

public class GitHubProjectVersionExtractor {

private static final Logger logger = Logger.getLogger(GitHubProjectVersionExtractor.class.getName());
private static final String OAUTH_AUTHORIZATION_HEADER_VALUE_PREFIX = "Bearer ";

private String TAGS_URL = "/tags";
private String TAG_NAME = "name";
private String DEFAULT_TOKEN = "";
private String project;

public GitHubProjectVersionExtractor(String project) {
Expand Down Expand Up @@ -50,10 +54,25 @@ private HttpClient.Response sentGetRequestWithPagination(String url, int pageNum

private Map<String, String> getAuthorizationHeader() throws IOException {
Map<String, String> headers = new HashMap<>();
String token = new String(Files.readAllBytes(Paths.get(".github-auth"))).trim();
String token = getGithubAuthToken();
if (Validate.nonEmpty(token)) {
headers.put(AUTHORIZATION_HEADER_KEY, OAUTH_AUTHORIZATION_HEADER_VALUE_PREFIX + token);
} else {
logger.warning("Missing GitHub authentication configuration. Making an unauthenticated request to the GitHub API.");
}
return headers;
}

private String getGithubAuthToken() throws IOException {
final String githubToken = System.getenv("GITHUB_AUTH");
final Path path = Paths.get(".github-auth");

if (githubToken != null) {
return githubToken;
} else if (Files.exists(path)) {
return new String(Files.readAllBytes(path)).trim();
}
return DEFAULT_TOKEN;
}
}

0 comments on commit 216b60e

Please sign in to comment.