Skip to content

Commit

Permalink
Introduce OauthToken parameter to HTTP endpoint to allow the Chrome e…
Browse files Browse the repository at this point in the history
…xtension to inspect private repos
  • Loading branch information
victorgveloso authored and tsantalis committed Nov 2, 2024
1 parent da713f2 commit 7df2305
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ public void handle(HttpExchange exchange) throws IOException {

String gitURL = queryToMap.get("gitURL");
String commitId = queryToMap.get("commitId");
String oAuthToken = queryToMap.getOrDefault("token", "");
int timeout = Integer.parseInt(queryToMap.get("timeout"));
List<Refactoring> detectedRefactorings = new ArrayList<Refactoring>();

GitHistoryRefactoringMiner miner = new GitHistoryRefactoringMinerImpl();
if (!oAuthToken.isEmpty()) {
miner.connectToGitHub(oAuthToken);
}
miner.detectAtCommit(gitURL, commitId, new RefactoringHandler() {
@Override
public void handle(String commitId, List<Refactoring> refactorings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,14 @@ public void handle(HttpExchange exchange) throws IOException {

String gitURL = queryToMap.get("gitURL");
String commitId = queryToMap.get("commitId");
String oAuthToken = queryToMap.getOrDefault("token", "");
int timeout = Integer.parseInt(queryToMap.get("timeout"));
List<Refactoring> detectedRefactorings = new ArrayList<Refactoring>();

GitHistoryRefactoringMiner miner = new GitHistoryRefactoringMinerImpl();
if (!oAuthToken.isEmpty()) {
miner.connectToGitHub(oAuthToken);
}
miner.detectAtCommit(gitURL, commitId, new RefactoringHandler() {
@Override
public void handle(String commitId, List<Refactoring> refactorings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Map;

import org.eclipse.jgit.lib.Repository;
import org.kohsuke.github.GitHub;
import org.refactoringminer.astDiff.models.ProjectASTDiff;

/**
Expand All @@ -13,6 +14,8 @@
*/
public interface GitHistoryRefactoringMiner {

GitHub connectToGitHub(String oAuthToken);

/**
* Iterate over each commit of a git repository and detect all refactorings performed in the
* entire repository history. Merge commits are ignored to avoid detecting the same refactoring
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,23 @@ else if (commitFile.getStatus().equals("renamed")) {
}
}

@Override
public GitHub connectToGitHub(String oAuthToken) {
if(gitHub == null) {
try {
gitHub = GitHub.connectUsingOAuth(oAuthToken);
if(gitHub.isCredentialValid()) {
logger.info("Connected to GitHub with OAuth token");
} else {
connectToGitHub();
}
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
return gitHub;
}

private GitHub connectToGitHub() {
if(gitHub == null) {
try {
Expand Down

0 comments on commit 7df2305

Please sign in to comment.