Skip to content

Commit

Permalink
Added private repository support (personal access token)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitris committed Apr 14, 2022
1 parent b727b7a commit 4669c9f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 8 deletions.
Binary file modified jars/interest.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<properties>
<java.version>11</java.version>
<testcontainers.version>1.16.3</testcontainers.version>
<hibernate-types.version>2.14.0</hibernate-types.version>
<hibernate-types.version>2.15.1</hibernate-types.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Objects;

import gr.zisis.interestapi.controller.response.entity.*;
import gr.zisis.interestapi.domain.AnalysisInfo;
import gr.zisis.interestapi.domain.ProjectDomain;
import gr.zisis.interestapi.service.ProjectsService;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -103,9 +104,9 @@ Collection<AnalyzedCommit> getAnalyzedCommitIds(@RequestParam(required = true) S

@CrossOrigin(origins = "*")
@PostMapping(path = "/startInterestAnalysis", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<Project> startInterestAnalysis(@RequestBody(required = true) ProjectDomain project) throws IOException {
ResponseEntity<Project> startInterestAnalysis(@RequestBody(required = true) AnalysisInfo info) throws IOException {
try {
return new ResponseEntity<>(projectsService.save(project.getUrl()), HttpStatus.CREATED);
return new ResponseEntity<>(projectsService.save(info.getUrl(), info.getToken()), HttpStatus.CREATED);
} catch (IOException | InterruptedException e) {
throw new ServerException("IOException");
}
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/gr/zisis/interestapi/domain/AnalysisInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package gr.zisis.interestapi.domain;

import java.util.Objects;

/*
*
* * Copyright (C) 2021 UoM - University of Macedonia
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License 2.0 which is available at
* * https://www.eclipse.org/legal/epl-2.0/
* *
* * SPDX-License-Identifier: EPL-2.0
*
*/

public class AnalysisInfo {

private String url;
private String token;

public AnalysisInfo() { }

public AnalysisInfo(String url, String token) {
this.url = url;
this.token = token;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getToken() {
return token;
}

public void setToken(String token) {
this.token = token;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AnalysisInfo that = (AnalysisInfo) o;
return Objects.equals(url, that.url) && Objects.equals(token, that.token);
}

@Override
public int hashCode() {
return Objects.hash(url, token);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
*/

public interface ProjectsService {
Project save(String url) throws IOException, InterruptedException;
Project save(String url, String VCSAccessToken) throws IOException, InterruptedException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.util.FileSystemUtils;
import org.springframework.web.server.ResponseStatusException;

import java.io.File;
import java.io.IOException;
import java.util.Objects;

/*
*
Expand Down Expand Up @@ -42,13 +45,19 @@ public class ProjectsServiceBean implements ProjectsService {
private String databasePass;

@Override
public Project save(String url) throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder("java", "-jar", "interest.jar", url, databaseDriver, databaseUrl, databaseUser, databasePass);
public Project save(String url, String VCSAccessToken) throws IOException, InterruptedException {
ProcessBuilder pb;
String owner = getRepositoryOwner(url);
String repoName = getRepositoryName(url);
String clonePath = "/tmp/"+ owner + "_" + repoName + "_" + System.currentTimeMillis() / 1000;
if (Objects.isNull(VCSAccessToken))
pb = new ProcessBuilder("java", "-jar", "interest.jar", url, clonePath, databaseDriver, databaseUrl, databaseUser, databasePass);
else
pb = new ProcessBuilder("java", "-jar", "interest.jar", url, clonePath, databaseDriver, databaseUrl, databaseUser, databasePass, VCSAccessToken);
Process process = pb.start();
process.waitFor();
FileSystemUtils.deleteRecursively(new File(clonePath));
if (process.exitValue() == 0) {
String owner = getRepositoryOwner(url);
String repoName = getRepositoryName(url);
return projectsRepository.findProject(owner, repoName);
} else if (process.exitValue() == -1) {
throw new ResponseStatusException(
Expand Down

0 comments on commit 4669c9f

Please sign in to comment.