Skip to content

Commit

Permalink
Fix an error using pipeline and jTravis, as jTravis was only conceive…
Browse files Browse the repository at this point in the history
…d to use env variable for github token. Now it has an helper to specify where to find github tokens.
  • Loading branch information
surli committed Jun 27, 2017
1 parent ab4fd55 commit 9ce1fc6
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ private void checkResponse(Response response) throws IOException {

protected GitHub getGithub() throws IOException {
if (this.github == null) {
if (System.getenv("GITHUB_OAUTH") != null && System.getenv("GITHUB_LOGIN") != null) {
this.getLogger().debug("Get GH login: "+System.getenv("GITHUB_LOGIN")+ "; OAuth (10 first characters): "+System.getenv("GITHUB_OAUTH").substring(0,10));
this.github = GitHubBuilder.fromEnvironment().build();
if (GithubTokenHelper.getInstance().isAvailable()) {
this.getLogger().debug("Get GH login: "+GithubTokenHelper.getInstance().getGithubLogin()+ "; OAuth (10 first characters): "+GithubTokenHelper.getInstance().getGithubOauth().substring(0,10));
this.github = GitHubBuilder.fromCredentials().withOAuthToken(GithubTokenHelper.getInstance().getGithubOauth(), GithubTokenHelper.getInstance().getGithubLogin()).build();
} else {
this.github = GitHub.connectAnonymously();
this.getLogger().warn("No github information has been given to connect (set GITHUB_OAUTH and GITHUB_LOGIN), you will have a very low ratelimit for github requests.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package fr.inria.spirals.jtravis.helpers;

/**
* Created by urli on 27/06/2017.
*/
public class GithubTokenHelper {
private static GithubTokenHelper instance;

private String githubLogin;
private String githubOauth;

private GithubTokenHelper() {}

public static GithubTokenHelper getInstance() {
if (instance == null) {
instance = new GithubTokenHelper();
}
return instance;
}

public String getGithubLogin() {
return (isAvailable()) ? githubLogin : null;
}

public void setGithubLogin(String githubLogin) {
this.githubLogin = githubLogin;
}

public String getGithubOauth() {
return (isAvailable()) ? githubOauth : null;
}

public void setGithubOauth(String githubOauth) {
this.githubOauth = githubOauth;
}

public boolean isAvailable() {
if (this.githubLogin != null && this.githubOauth != null) {
return true;
}

if (System.getenv("GITHUB_OAUTH") != null && System.getenv("GITHUB_LOGIN") != null) {
this.setGithubLogin(System.getenv("GITHUB_LOGIN"));
this.setGithubOauth(System.getenv("GITHUB_OAUTH"));
return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,30 @@ public void testGetBuildsFromRepositoryInTimeInterval() {
assertEquals(215, Integer.parseInt(builds.get(builds.size()-1).getNumber()));
}

@Test
public void testGetBuildsFromRepositoryInTimeIntervalAlsoTakePR() {
Repository repo = new Repository();
repo.setSlug("INRIA/spoon");

Date initialDate = TestUtils.getDate(2017, 06, 26, 20, 00, 00);

Date finalDate = TestUtils.getDate(2017, 06, 26, 21, 00, 00);
List<Build> builds = BuildHelper.getBuildsFromRepositoryInTimeInterval(repo, initialDate, finalDate);

assertTrue(builds != null);

if (builds.size() > 1) {
Collections.sort(builds);
}

assertEquals(3, builds.size());
assertEquals(3424, Integer.parseInt(builds.get(0).getNumber()));
for (Build build : builds) {
assertTrue(build.isPullRequest());
}


assertEquals(1428, builds.get(0).getPullRequestNumber());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import fr.inria.spirals.jtravis.entities.Build;
import fr.inria.spirals.jtravis.entities.BuildStatus;
import fr.inria.spirals.jtravis.helpers.BuildHelper;
import fr.inria.spirals.jtravis.helpers.GithubTokenHelper;
import fr.inria.spirals.repairnator.BuildToBeInspected;
import fr.inria.spirals.repairnator.serializer.MetricsSerializer;
import fr.inria.spirals.repairnator.states.LauncherMode;
Expand Down Expand Up @@ -98,6 +99,9 @@ private void initConfig() {

this.config.setGithubLogin(this.arguments.getString("ghLogin"));
this.config.setGithubToken(this.arguments.getString("ghOauth"));

GithubTokenHelper.getInstance().setGithubOauth(this.config.getGithubToken());
GithubTokenHelper.getInstance().setGithubLogin(this.config.getGithubLogin());
}

private void initializeSerializerEngines() {
Expand Down

0 comments on commit 9ce1fc6

Please sign in to comment.