From 199e9a7eb1115d5d21090c48bb4da86ef44b4339 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 19 Feb 2021 16:00:09 +0400 Subject: [PATCH] add class Commit --- src/main/java/ru/ulstu/extractor/Commit.java | 25 +++++++++++++++++++ .../ulstu/extractor/GitRepositoryService.java | 20 +++++++++++++++ .../ru/ulstu/extractor/RepoController.java | 7 ++++++ 3 files changed, 52 insertions(+) create mode 100644 src/main/java/ru/ulstu/extractor/Commit.java diff --git a/src/main/java/ru/ulstu/extractor/Commit.java b/src/main/java/ru/ulstu/extractor/Commit.java new file mode 100644 index 0000000..328a5e8 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/Commit.java @@ -0,0 +1,25 @@ +package ru.ulstu.extractor; + +import java.util.Date; + +public class Commit { + private String message; + private Date date; + private String author; + + public Commit(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public Date getDate() { + return date; + } + + public String getAuthor() { + return author; + } +} diff --git a/src/main/java/ru/ulstu/extractor/GitRepositoryService.java b/src/main/java/ru/ulstu/extractor/GitRepositoryService.java index 0fffc3d..1d02866 100644 --- a/src/main/java/ru/ulstu/extractor/GitRepositoryService.java +++ b/src/main/java/ru/ulstu/extractor/GitRepositoryService.java @@ -11,6 +11,8 @@ import org.springframework.stereotype.Service; import java.io.File; import java.io.IOException; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; import static org.apache.logging.log4j.util.Strings.isBlank; @@ -54,4 +56,22 @@ public class GitRepositoryService { private boolean projectDirExists(File file) { return file.exists(); } + + public List getCommits(String url) throws GitAPIException, IOException { + cloneOrUpdateRepo(url); + Repository localRepo = new FileRepository(getProjectGitDirectory(url)); + Git git = new Git(localRepo); + git.pull().call(); + List commits = new ArrayList<>(); + //TODO: сделать преобразование в коллекцию "наших объектов" + git.log().call().forEach(commits::add); + + List list = new ArrayList<>(); + for (RevCommit commit : commits) { + Commit fullMessage = new Commit(commit.getFullMessage()); + list.add(fullMessage); + } + + return list; + } } diff --git a/src/main/java/ru/ulstu/extractor/RepoController.java b/src/main/java/ru/ulstu/extractor/RepoController.java index 3d3b2de..e1aa4fc 100644 --- a/src/main/java/ru/ulstu/extractor/RepoController.java +++ b/src/main/java/ru/ulstu/extractor/RepoController.java @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.io.IOException; +import java.util.List; import static ru.ulstu.extractor.RepoController.URL; @@ -24,4 +25,10 @@ public class RepoController { public void cloneRepository(@RequestParam("url") String url) throws GitAPIException, IOException { gitRepositoryService.cloneOrUpdateRepo(url); } + + @GetMapping("commits") + public List getCommits(@RequestParam("url") String url) throws GitAPIException, IOException { + return gitRepositoryService.getCommits(url); + } + }