Merge branch '6-work-branches' into 'master'
Resolve "Работа с ветками" Closes #6 See merge request romanov73/git-extractor!6
This commit is contained in:
commit
4af08bc9b8
@ -64,7 +64,6 @@ dependencies {
|
||||
compile group: 'org.webjars', name: 'bootstrap-select', version: '1.13.8'
|
||||
compile group: 'org.webjars', name: 'font-awesome', version: '4.7.0'
|
||||
|
||||
|
||||
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
|
||||
}
|
||||
|
||||
|
14
src/main/java/ru/ulstu/extractor/model/Branch.java
Normal file
14
src/main/java/ru/ulstu/extractor/model/Branch.java
Normal file
@ -0,0 +1,14 @@
|
||||
package ru.ulstu.extractor.model;
|
||||
|
||||
public class Branch {
|
||||
private String name;
|
||||
|
||||
public Branch(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
@ -5,11 +5,16 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import ru.ulstu.extractor.model.Branch;
|
||||
import ru.ulstu.extractor.mvc.model.FilterForm;
|
||||
import ru.ulstu.extractor.mvc.model.RepoForm;
|
||||
import ru.ulstu.extractor.service.FilteringService;
|
||||
import ru.ulstu.extractor.service.GitRepositoryService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
public class GitExtractorController {
|
||||
private final FilteringService filteringService;
|
||||
@ -33,29 +38,35 @@ public class GitExtractorController {
|
||||
return "filtering";
|
||||
}
|
||||
|
||||
@PostMapping("/sendRepo")
|
||||
public String sendRepo(@ModelAttribute RepoForm repoForm, Model model) {
|
||||
if (repoForm.getRepo() == null || repoForm.getRepo().isEmpty()) {
|
||||
model.addAttribute("error", "'Git' не должно быть пустым");
|
||||
return "newRepo";
|
||||
}
|
||||
model.addAttribute("filterForm", new FilterForm(repoForm.getRepo()));
|
||||
try {
|
||||
gitRepositoryService.cloneOrUpdateRepo(repoForm.getRepo());
|
||||
} catch (Exception ex) {
|
||||
model.addAttribute("error", ex.getMessage());
|
||||
return "newRepo";
|
||||
}
|
||||
return "filtering";
|
||||
}
|
||||
|
||||
@PostMapping("/sendFilter")
|
||||
public String sendFilter(@ModelAttribute FilterForm filterForm, Model model) {
|
||||
if (filterForm.getFilter() == null || filterForm.getFilter().isEmpty()) {
|
||||
model.addAttribute("error", "'Строка' не должно быть пустым");
|
||||
return "filtering";
|
||||
}
|
||||
model.addAttribute("commits", filteringService.getCommits(filterForm.getFilter(), filterForm.getFilter()));
|
||||
return "resultRepo";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/newRepo", method = RequestMethod.POST, params = "send")
|
||||
public String getBranch(@ModelAttribute RepoForm repoForm, Model model) {
|
||||
try {
|
||||
gitRepositoryService.cloneOrUpdateRepo(repoForm.getRepo());
|
||||
List<Branch> list = gitRepositoryService.getBranches(repoForm.getRepo());
|
||||
model.addAttribute("branches", list);
|
||||
return "newRepo";
|
||||
} catch (Exception ex) {
|
||||
model.addAttribute("error", ex.getMessage());
|
||||
return "newRepo";
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/newRepo", method = RequestMethod.POST, params = "next")
|
||||
public String setBranch(@ModelAttribute RepoForm repoForm, Model model) {
|
||||
model.addAttribute("filterForm", new FilterForm(repoForm.getRepo()));
|
||||
if (repoForm.getBranch() == null) {
|
||||
return "newRepo";
|
||||
} else {
|
||||
return "filtering";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package ru.ulstu.extractor.mvc.model;
|
||||
public class RepoForm {
|
||||
private String repo;
|
||||
|
||||
private String branch;
|
||||
|
||||
public String getRepo() {
|
||||
return repo;
|
||||
}
|
||||
@ -11,6 +13,14 @@ public class RepoForm {
|
||||
this.repo = repo;
|
||||
}
|
||||
|
||||
public String getBranch() {
|
||||
return branch;
|
||||
}
|
||||
|
||||
public void setBranch(String branch) {
|
||||
this.branch = branch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RepoForm{" +
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ru.ulstu.extractor.service;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.ListBranchCommand;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.diff.DiffFormatter;
|
||||
import org.eclipse.jgit.internal.storage.file.FileRepository;
|
||||
@ -8,6 +9,7 @@ import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.extractor.model.Branch;
|
||||
import ru.ulstu.extractor.model.Changes;
|
||||
import ru.ulstu.extractor.model.Commit;
|
||||
import ru.ulstu.extractor.model.FileChange;
|
||||
@ -22,6 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.logging.log4j.util.Strings.isBlank;
|
||||
|
||||
@ -188,4 +191,15 @@ public class GitRepositoryService {
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public List<Branch> getBranches(String url) throws GitAPIException, IOException {
|
||||
cloneOrUpdateRepo(url);
|
||||
Repository localRepo = new FileRepository(getProjectGitDirectory(url));
|
||||
Git git = new Git(localRepo);
|
||||
return git.branchList().setListMode(ListBranchCommand.ListMode.REMOTE)
|
||||
.call()
|
||||
.stream()
|
||||
.map(r -> new Branch(r.getName()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
<title th:text="#{messages.app-name}">app-name</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<script type="text/javascript" src="/webjars/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="/webjars/bootstrap/4.6.0/js/bootstrap.min.js"></script>
|
||||
<script type="text/javascript" src="/webjars/bootstrap/4.6.0/js/bootstrap.bundle.min.js"></script>
|
||||
<script type="text/javascript" src="/webjars/bootstrap-select/1.13.8/js/bootstrap-select.min.js"></script>
|
||||
<link rel="stylesheet" href="/webjars/bootstrap/4.6.0/css/bootstrap.min.css"/>
|
||||
<link rel="stylesheet" href="/webjars/bootstrap-select/1.13.8/css/bootstrap-select.min.css"/>
|
||||
|
@ -30,19 +30,18 @@
|
||||
<input type="hidden" th:field="*{url}">
|
||||
</p>
|
||||
<p style="color:red" th:text="${error}"></p>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Author</th>
|
||||
<th>Date</th>
|
||||
<th>Commit</th>
|
||||
</tr>
|
||||
<tr th:each="commit : ${commits}">
|
||||
<td th:text="${commit.author}">Onions</td>
|
||||
<td th:text="${commit.date}">2.41</td>
|
||||
<td th:text="${commit.message}">yes</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- <table>-->
|
||||
<!-- <tr>-->
|
||||
<!-- <th>Author</th>-->
|
||||
<!-- <th>Date</th>-->
|
||||
<!-- <th>Commit</th>-->
|
||||
<!-- </tr>-->
|
||||
<!-- <tr th:each="commit : ${commits}">-->
|
||||
<!-- <td th:text="${commit.author}">Onions</td>-->
|
||||
<!-- <td th:text="${commit.date}">2.41</td>-->
|
||||
<!-- <td th:text="${commit.message}">yes</td>-->
|
||||
<!-- </tr>-->
|
||||
<!-- </table>-->
|
||||
<p>
|
||||
<input type="submit" value="Отправить"/>
|
||||
</p>
|
||||
|
@ -8,15 +8,29 @@
|
||||
</head>
|
||||
<div class="container" layout:fragment="content">
|
||||
<body>
|
||||
<form action="#" th:action="@{/sendRepo}" th:object="${repoForm}" method="post">
|
||||
<form action="#" th:action="@{/newRepo}" th:object="${repoForm}" method="post">
|
||||
<p style="color:red" th:text="${error}"></p>
|
||||
<p><b>Ваш git репозиторий:</b><br>
|
||||
<input type="text" size="40" th:field="*{repo}">
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" value="Отправить"/>
|
||||
<input type="submit" name="send" value="Отправить"/>
|
||||
</p>
|
||||
<p>Ветки:<br>
|
||||
<select id="select-branch" class="selectpicker" data-live-search="true" th:field="*{branch}">
|
||||
<option th:each="branch : ${branches}"
|
||||
th:value="${branch.name}"
|
||||
th:utext="${branch.name}"/>
|
||||
</option>
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" name="next" value="Продолжить"/>
|
||||
</p>
|
||||
</form>
|
||||
</body>
|
||||
</div>
|
||||
<script>
|
||||
$('#select-branch').selectpicker('refresh');
|
||||
</script>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user