From 8469672072aee1427461a91dffeba3c20e4227cc Mon Sep 17 00:00:00 2001 From: hemanik Date: Fri, 6 Apr 2018 12:06:11 +0530 Subject: [PATCH 1/4] fix: adds GitHub authentication to avoid rate limiting failures. --- .../GitHubProjectVersionExtractor.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java b/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java index 4013cd02465..7e6c0a8b902 100644 --- a/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java +++ b/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java @@ -3,11 +3,21 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; import org.apache.http.client.utils.URIBuilder; import org.jboss.arquillian.drone.webdriver.utils.HttpClient; +import org.jboss.arquillian.drone.webdriver.utils.Validate; + +import static org.jboss.arquillian.drone.webdriver.binary.downloading.source.GitHubSource.AUTHORIZATION_HEADER_KEY; public class GitHubProjectVersionExtractor { + private static final String OAUTH_AUTHORIZATION_HEADER_VALUE_PREFIX = "Bearer "; + private String TAGS_URL = "/tags"; private String TAG_NAME = "name"; private String project; @@ -18,7 +28,7 @@ public GitHubProjectVersionExtractor(String project) { public String getLatestReleaseFromGitHub() { try { - final HttpClient.Response response = sentGetRequestWithPagination(project + TAGS_URL, 1); + final HttpClient.Response response = sentGetRequestWithPagination(project + TAGS_URL, 1, getAuthorizationHeader()); JsonArray releaseTags = new Gson().fromJson(response.getPayload(), JsonElement.class).getAsJsonArray(); if (releaseTags.size() == 0) { return null; @@ -29,11 +39,21 @@ public String getLatestReleaseFromGitHub() { } } - private HttpClient.Response sentGetRequestWithPagination(String url, int pageNumber) throws Exception { + private HttpClient.Response sentGetRequestWithPagination(String url, int pageNumber, Map headers) + throws Exception { final URIBuilder uriBuilder = new URIBuilder(url); if (pageNumber != 1) { uriBuilder.setParameter("page", String.valueOf(pageNumber)); } - return new HttpClient().get(uriBuilder.build().toString()); + return new HttpClient().get(uriBuilder.build().toString(), headers); + } + + private Map getAuthorizationHeader() throws IOException { + Map headers = new HashMap<>(); + String token = new String(Files.readAllBytes(Paths.get(".github-auth"))).trim(); + if (Validate.nonEmpty(token)) { + headers.put(AUTHORIZATION_HEADER_KEY, OAUTH_AUTHORIZATION_HEADER_VALUE_PREFIX + token); + } + return headers; } } From f4c9e9b63aad2bd46ef49c443801704b02df3af2 Mon Sep 17 00:00:00 2001 From: hemanik Date: Fri, 6 Apr 2018 16:37:25 +0530 Subject: [PATCH 2/4] fix: updates travis.yml. --- .travis.yml | 32 ++++++++++++++- _scripts/colors | 5 +++ _scripts/parse_arguments.sh | 82 +++++++++++++++++++++++++++++++++++++ _scripts/prepare_build.sh | 68 ++++++++++++++++++++++++++++++ 4 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 _scripts/colors create mode 100755 _scripts/parse_arguments.sh create mode 100644 _scripts/prepare_build.sh diff --git a/.travis.yml b/.travis.yml index 43f7c7f8562..af087aa6155 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,37 @@ 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= diff --git a/_scripts/colors b/_scripts/colors new file mode 100644 index 00000000000..51c4feb57ef --- /dev/null +++ b/_scripts/colors @@ -0,0 +1,5 @@ +export LIGHT_GREEN='\033[1;32m' +export GREEN='\033[0;32m' +export YELLOW='\033[0;33m' +export CLEAR='\033[0m' +export RED='\033[31m' diff --git a/_scripts/parse_arguments.sh b/_scripts/parse_arguments.sh new file mode 100755 index 00000000000..e6f0aeca657 --- /dev/null +++ b/_scripts/parse_arguments.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +######################### parse input parameters ######################### + +for i in "$@" +do +case $i in + -wd=*|--working-dir=*) + export WORKING_DIR="${i#*=}" + shift + ;; + -ga=*|--github-auth=*) + export GITHUB_AUTH="${i#*=}" + shift + ;; + -c=*|--clean=*) + export CLEAN="${i#*=}" + shift + ;; + -c|--clean) + CLEAN="true" + shift + ;; + -itf=*|--ignore-test-failure=*) + export IGNORE_TEST_FAILURE="${i#*=}" + shift + ;; + -itf|--ignore-test-failure) + export IGNORE_TEST_FAILURE="true" + shift + ;; + -bc=*|--browser-command=*) + export BROWSER_COMMAND="${i#*=}" + shift + ;; + -bt=*|--browser-test=*) + export BROWSER_TEST="${i#*=}" + shift + ;; + -cv=*|--chrome-driver-version=*) + export CHROME_DRIVER_VERSION="${i#*=}" + shift + ;; + -gp=*|--github-project=*) + export GIT_PROJECT="${i#*=}" + shift + ;; + -h|--help) + echo -e "Usage: you can use scripts publish.sh and prepare_build_prod_and_run.sh with following parameters" + echo -e "" + echo -e " -wd= \t\t \t Path to working directory - where all necessary directories and files will be stored." + echo -e " --working-dir= \t \t Default value is -/tmp/arquillian-blog" + echo -e "" + echo -e " -ga= \t\t \t Your GitHub authentication token" + echo -e " --github-auth= \t If not set, content of the file .../project-directory/.github-auth is taken" + echo -e "" + echo -e " -c [-c=] \t \t If the content of the working directory should be removed." + echo -e " --clean \t \t \t Default value is false" + echo -e "" + echo -e " -itf [-itf=] \t If a potential failure of test execution should be ignored" + echo -e " --ignore-test-failure \t Default value is false" + echo -e "" + echo -e " -bc= \t\t Command that should be used for opening a browser" + echo -e " --browser-command= \t Default value is 'firefox'" + echo -e "" + echo -e " -bt= \t\t Browser to be used for executing UI tests" + echo -e " --browser-test= \t Default value is 'chromeHeadless'" + echo -e "" + echo -e " -gp= \t\t \t Url to GitHub project to be cloned and used for generating web pages" + echo -e " --github-project= \t Default value is: `git remote get-url origin`" + exit + ;; + *) + ;; +esac +done + + +export CURRENT_DIR=`pwd` +export IGNORE_TEST_FAILURE=${IGNORE_TEST_FAILURE:-"false"} +export BROWSER_TEST=${BROWSER_TEST:-"chromeHeadless"} +export BROWSER_COMMAND=${BROWSER_COMMAND:-"firefox"} diff --git a/_scripts/prepare_build.sh b/_scripts/prepare_build.sh new file mode 100644 index 00000000000..93121f76427 --- /dev/null +++ b/_scripts/prepare_build.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +######################### Parse arguments ######################### + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +. ${SCRIPT_DIR}/parse_arguments.sh +. ${SCRIPT_DIR}/colors + +######################### set variables & clone & create dirs ######################### + +### set & clean working directory - the set one or default one: /tmp/arquillian-blog +WORKING_DIR=`readlink -f ${WORKING_DIR:-/tmp/arquillian-blog}` +echo -e "${LIGHT_GREEN}-> Working directory is: ${WORKING_DIR} ${CLEAR}" +if [ ! -d ${WORKING_DIR} ]; then + echo -e "${LIGHT_GREEN}-> Creating the working directory ${CLEAR}" + mkdir ${WORKING_DIR} + +elif [[ "$CLEAN" = "true" || "$CLEAN" = "yes" ]] ; then + echo -e "${LIGHT_GREEN}-> cleaning working directory ${CLEAR}" + rm -rf ${WORKING_DIR}/* +fi + + +### for non-travis environment, the project is cloned +if [[ ${TRAVIS} != "true" ]]; then + if [[ -z "${GIT_PROJECT}" ]]; then + GIT_PROJECT=`git remote get-url origin` + fi + ARQUILLIAN_PROJECT_DIR="${WORKING_DIR}/${PWD##*/}" + + if [ ! -d "${ARQUILLIAN_PROJECT_DIR}" ]; then + CURRENT_BRANCH=`git branch | grep \* | cut -d ' ' -f2` + LS_REMOTE_BRANCH=`git ls-remote --heads ${GIT_PROJECT} ${CURRENT_BRANCH}` + + if [ -z "${LS_REMOTE_BRANCH}" ]; then + BRANCH_TO_CLONE="${CURRENT_BRANCH}" + else + BRANCH_TO_CLONE="develop" + fi + + echo -e "${LIGHT_GREEN}-> Cloning branch ${BRANCH_TO_CLONE} from project ${GIT_PROJECT} into ${ARQUILLIAN_PROJECT_DIR} ${CLEAR}" + git clone -b ${BRANCH_TO_CLONE} ${GIT_PROJECT} ${ARQUILLIAN_PROJECT_DIR} + + else + echo -e "${LIGHT_GREEN}-> The project ${ARQUILLIAN_PROJECT_DIR##*/} will not be cloned because it exist on location: ${ARQUILLIAN_PROJECT_DIR} ${CLEAR}" + fi + +### for travis it is expected that I'm located in the project dir to be processed +else + ARQUILLIAN_PROJECT_DIR="${PWD}" + echo -e "${LIGHT_GREEN}-> Travis environment - using project ${ARQUILLIAN_PROJECT_DIR} ${CLEAR}" +fi + +ARQUILLIAN_PROJECT_DIR_NAME=${ARQUILLIAN_PROJECT_DIR##*/} + +### sets .github-auth file (if not available already) +if [[ -z "${GITHUB_AUTH}" ]]; then + if [[ -f ${SCRIPT_DIR}/../.github-auth ]]; then + GITHUB_AUTH=`cat ${SCRIPT_DIR}/../.github-auth` + else + ### sets token with read permissions - no scopes + GITHUB_AUTH="c23fbf83c47dd31b546d392b2ba054c356620b3c" + fi +fi + +echo -e "${LIGHT_GREEN}-> Setting .github-auth file ${CLEAR}" +echo ${GITHUB_AUTH} > ${ARQUILLIAN_PROJECT_DIR}/.github-auth + From 81640e20d3642386cf7164661825976208307c04 Mon Sep 17 00:00:00 2001 From: hemanik Date: Mon, 16 Apr 2018 18:07:46 +0530 Subject: [PATCH 3/4] fix: read token from env variable. --- .travis.yml | 32 +------- _scripts/colors | 5 -- _scripts/parse_arguments.sh | 82 ------------------- _scripts/prepare_build.sh | 68 --------------- .../GitHubProjectVersionExtractor.java | 21 ++++- 5 files changed, 21 insertions(+), 187 deletions(-) delete mode 100644 _scripts/colors delete mode 100755 _scripts/parse_arguments.sh delete mode 100644 _scripts/prepare_build.sh diff --git a/.travis.yml b/.travis.yml index af087aa6155..43f7c7f8562 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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= diff --git a/_scripts/colors b/_scripts/colors deleted file mode 100644 index 51c4feb57ef..00000000000 --- a/_scripts/colors +++ /dev/null @@ -1,5 +0,0 @@ -export LIGHT_GREEN='\033[1;32m' -export GREEN='\033[0;32m' -export YELLOW='\033[0;33m' -export CLEAR='\033[0m' -export RED='\033[31m' diff --git a/_scripts/parse_arguments.sh b/_scripts/parse_arguments.sh deleted file mode 100755 index e6f0aeca657..00000000000 --- a/_scripts/parse_arguments.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash - -######################### parse input parameters ######################### - -for i in "$@" -do -case $i in - -wd=*|--working-dir=*) - export WORKING_DIR="${i#*=}" - shift - ;; - -ga=*|--github-auth=*) - export GITHUB_AUTH="${i#*=}" - shift - ;; - -c=*|--clean=*) - export CLEAN="${i#*=}" - shift - ;; - -c|--clean) - CLEAN="true" - shift - ;; - -itf=*|--ignore-test-failure=*) - export IGNORE_TEST_FAILURE="${i#*=}" - shift - ;; - -itf|--ignore-test-failure) - export IGNORE_TEST_FAILURE="true" - shift - ;; - -bc=*|--browser-command=*) - export BROWSER_COMMAND="${i#*=}" - shift - ;; - -bt=*|--browser-test=*) - export BROWSER_TEST="${i#*=}" - shift - ;; - -cv=*|--chrome-driver-version=*) - export CHROME_DRIVER_VERSION="${i#*=}" - shift - ;; - -gp=*|--github-project=*) - export GIT_PROJECT="${i#*=}" - shift - ;; - -h|--help) - echo -e "Usage: you can use scripts publish.sh and prepare_build_prod_and_run.sh with following parameters" - echo -e "" - echo -e " -wd= \t\t \t Path to working directory - where all necessary directories and files will be stored." - echo -e " --working-dir= \t \t Default value is -/tmp/arquillian-blog" - echo -e "" - echo -e " -ga= \t\t \t Your GitHub authentication token" - echo -e " --github-auth= \t If not set, content of the file .../project-directory/.github-auth is taken" - echo -e "" - echo -e " -c [-c=] \t \t If the content of the working directory should be removed." - echo -e " --clean \t \t \t Default value is false" - echo -e "" - echo -e " -itf [-itf=] \t If a potential failure of test execution should be ignored" - echo -e " --ignore-test-failure \t Default value is false" - echo -e "" - echo -e " -bc= \t\t Command that should be used for opening a browser" - echo -e " --browser-command= \t Default value is 'firefox'" - echo -e "" - echo -e " -bt= \t\t Browser to be used for executing UI tests" - echo -e " --browser-test= \t Default value is 'chromeHeadless'" - echo -e "" - echo -e " -gp= \t\t \t Url to GitHub project to be cloned and used for generating web pages" - echo -e " --github-project= \t Default value is: `git remote get-url origin`" - exit - ;; - *) - ;; -esac -done - - -export CURRENT_DIR=`pwd` -export IGNORE_TEST_FAILURE=${IGNORE_TEST_FAILURE:-"false"} -export BROWSER_TEST=${BROWSER_TEST:-"chromeHeadless"} -export BROWSER_COMMAND=${BROWSER_COMMAND:-"firefox"} diff --git a/_scripts/prepare_build.sh b/_scripts/prepare_build.sh deleted file mode 100644 index 93121f76427..00000000000 --- a/_scripts/prepare_build.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env bash - -######################### Parse arguments ######################### - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -. ${SCRIPT_DIR}/parse_arguments.sh -. ${SCRIPT_DIR}/colors - -######################### set variables & clone & create dirs ######################### - -### set & clean working directory - the set one or default one: /tmp/arquillian-blog -WORKING_DIR=`readlink -f ${WORKING_DIR:-/tmp/arquillian-blog}` -echo -e "${LIGHT_GREEN}-> Working directory is: ${WORKING_DIR} ${CLEAR}" -if [ ! -d ${WORKING_DIR} ]; then - echo -e "${LIGHT_GREEN}-> Creating the working directory ${CLEAR}" - mkdir ${WORKING_DIR} - -elif [[ "$CLEAN" = "true" || "$CLEAN" = "yes" ]] ; then - echo -e "${LIGHT_GREEN}-> cleaning working directory ${CLEAR}" - rm -rf ${WORKING_DIR}/* -fi - - -### for non-travis environment, the project is cloned -if [[ ${TRAVIS} != "true" ]]; then - if [[ -z "${GIT_PROJECT}" ]]; then - GIT_PROJECT=`git remote get-url origin` - fi - ARQUILLIAN_PROJECT_DIR="${WORKING_DIR}/${PWD##*/}" - - if [ ! -d "${ARQUILLIAN_PROJECT_DIR}" ]; then - CURRENT_BRANCH=`git branch | grep \* | cut -d ' ' -f2` - LS_REMOTE_BRANCH=`git ls-remote --heads ${GIT_PROJECT} ${CURRENT_BRANCH}` - - if [ -z "${LS_REMOTE_BRANCH}" ]; then - BRANCH_TO_CLONE="${CURRENT_BRANCH}" - else - BRANCH_TO_CLONE="develop" - fi - - echo -e "${LIGHT_GREEN}-> Cloning branch ${BRANCH_TO_CLONE} from project ${GIT_PROJECT} into ${ARQUILLIAN_PROJECT_DIR} ${CLEAR}" - git clone -b ${BRANCH_TO_CLONE} ${GIT_PROJECT} ${ARQUILLIAN_PROJECT_DIR} - - else - echo -e "${LIGHT_GREEN}-> The project ${ARQUILLIAN_PROJECT_DIR##*/} will not be cloned because it exist on location: ${ARQUILLIAN_PROJECT_DIR} ${CLEAR}" - fi - -### for travis it is expected that I'm located in the project dir to be processed -else - ARQUILLIAN_PROJECT_DIR="${PWD}" - echo -e "${LIGHT_GREEN}-> Travis environment - using project ${ARQUILLIAN_PROJECT_DIR} ${CLEAR}" -fi - -ARQUILLIAN_PROJECT_DIR_NAME=${ARQUILLIAN_PROJECT_DIR##*/} - -### sets .github-auth file (if not available already) -if [[ -z "${GITHUB_AUTH}" ]]; then - if [[ -f ${SCRIPT_DIR}/../.github-auth ]]; then - GITHUB_AUTH=`cat ${SCRIPT_DIR}/../.github-auth` - else - ### sets token with read permissions - no scopes - GITHUB_AUTH="c23fbf83c47dd31b546d392b2ba054c356620b3c" - fi -fi - -echo -e "${LIGHT_GREEN}-> Setting .github-auth file ${CLEAR}" -echo ${GITHUB_AUTH} > ${ARQUILLIAN_PROJECT_DIR}/.github-auth - diff --git a/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java b/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java index 7e6c0a8b902..a1781e5bf20 100644 --- a/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java +++ b/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java @@ -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; @@ -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) { @@ -50,10 +54,25 @@ private HttpClient.Response sentGetRequestWithPagination(String url, int pageNum private Map getAuthorizationHeader() throws IOException { Map 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; + } } + From 71669767ca8d943c445b1cd166893c705be15a62 Mon Sep 17 00:00:00 2001 From: hemanik Date: Mon, 16 Apr 2018 18:49:44 +0530 Subject: [PATCH 4/4] fix: undo reading token from variable. --- .../utilities/GitHubProjectVersionExtractor.java | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java b/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java index a1781e5bf20..65a7f8c8db8 100644 --- a/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java +++ b/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java @@ -5,7 +5,6 @@ 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; @@ -23,7 +22,6 @@ public class GitHubProjectVersionExtractor { private String TAGS_URL = "/tags"; private String TAG_NAME = "name"; - private String DEFAULT_TOKEN = ""; private String project; public GitHubProjectVersionExtractor(String project) { @@ -54,7 +52,7 @@ private HttpClient.Response sentGetRequestWithPagination(String url, int pageNum private Map getAuthorizationHeader() throws IOException { Map headers = new HashMap<>(); - String token = getGithubAuthToken(); + String token = new String(Files.readAllBytes(Paths.get(".github-auth"))).trim(); if (Validate.nonEmpty(token)) { headers.put(AUTHORIZATION_HEADER_KEY, OAUTH_AUTHORIZATION_HEADER_VALUE_PREFIX + token); } else { @@ -62,17 +60,5 @@ private Map getAuthorizationHeader() throws IOException { } 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; - } }