add controller
parent
d9eab69b68
commit
685eb9584d
@ -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()));
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue