diff --git a/build.gradle b/build.gradle index 941f505..227b6d5 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } diff --git a/src/main/java/ru/ulstu/extractor/GitRepositoryService.java b/src/main/java/ru/ulstu/extractor/GitRepositoryService.java new file mode 100644 index 0000000..e6cf44e --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/GitRepositoryService.java @@ -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 commits = git.log().call(); + commits.forEach(c -> System.out.println(c.getFullMessage())); + } +} diff --git a/src/main/java/ru/ulstu/extractor/RepoController.java b/src/main/java/ru/ulstu/extractor/RepoController.java new file mode 100644 index 0000000..42c9600 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/RepoController.java @@ -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); + } +}