add controller

This commit is contained in:
Anton Romanov 2021-02-17 16:41:22 +04:00
parent d9eab69b68
commit 685eb9584d
3 changed files with 49 additions and 0 deletions

View File

@ -54,6 +54,8 @@ dependencies {
compile group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'
compile group: 'com.ibm.icu', name: 'icu4j', version: '63.1'
compile group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '5.9.0.202009080501-r'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
}

View File

@ -0,0 +1,22 @@
package ru.ulstu.extractor;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.revwalk.RevCommit;
import org.springframework.stereotype.Service;
import java.nio.file.Path;
@Service
public class GitRepositoryService {
private final static String LOCAL_PATH = "c:\\temp\\1";
public void clone(String url) throws GitAPIException {
Git git = Git.cloneRepository()
.setURI(url)
.setDirectory(Path.of(LOCAL_PATH).toFile())
.call();
Iterable<RevCommit> commits = git.log().call();
commits.forEach(c -> System.out.println(c.getFullMessage()));
}
}

View File

@ -0,0 +1,25 @@
package ru.ulstu.extractor;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import static ru.ulstu.extractor.RepoController.URL;
@RestController
@RequestMapping(URL)
public class RepoController {
public static final String URL = "/";
private final GitRepositoryService gitRepositoryService;
public RepoController(GitRepositoryService gitRepositoryService) {
this.gitRepositoryService = gitRepositoryService;
}
@GetMapping("clone")
public void cloneRepository(@RequestParam("url") String url) throws GitAPIException {
gitRepositoryService.clone(url);
}
}