add class Commit
This commit is contained in:
parent
ac2e20da0e
commit
199e9a7eb1
25
src/main/java/ru/ulstu/extractor/Commit.java
Normal file
25
src/main/java/ru/ulstu/extractor/Commit.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -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<Commit> getCommits(String url) throws GitAPIException, IOException {
|
||||
cloneOrUpdateRepo(url);
|
||||
Repository localRepo = new FileRepository(getProjectGitDirectory(url));
|
||||
Git git = new Git(localRepo);
|
||||
git.pull().call();
|
||||
List<RevCommit> commits = new ArrayList<>();
|
||||
//TODO: сделать преобразование в коллекцию "наших объектов"
|
||||
git.log().call().forEach(commits::add);
|
||||
|
||||
List<Commit> list = new ArrayList<>();
|
||||
for (RevCommit commit : commits) {
|
||||
Commit fullMessage = new Commit(commit.getFullMessage());
|
||||
list.add(fullMessage);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -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<Commit> getCommits(@RequestParam("url") String url) throws GitAPIException, IOException {
|
||||
return gitRepositoryService.getCommits(url);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user