Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce OauthToken parameter to HTTP endpoint #793

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading