fix indexing UI

merge-requests/14/merge
Anton Romanov 3 years ago
parent dc99cd6ab2
commit 8365cf825a

@ -25,6 +25,9 @@ import ru.ulstu.extractor.model.LineChange;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.time.Instant;
import java.util.ArrayList;
@ -141,10 +144,22 @@ public class GitRepositoryService {
}
private File getProjectDirectoryFile(String url) {
validateUrl(url);
return Path.of(getProjectDirectory(url))
.toFile();
}
private void validateUrl(String url) {
if (url == null || url.isEmpty()) {
throw new RuntimeException("Repository url must not empty");
}
try {
new URL(url).toURI();
} catch (MalformedURLException | URISyntaxException e) {
throw new RuntimeException("Repository url not valid");
}
}
private boolean projectDirExists(File file) {
return file.exists();
}

@ -48,15 +48,16 @@ public class IndexService {
public void index(@NotNull String repositoryUrl, @NotNull String branchName) throws GitAPIException, IOException {
Repository repository = repositoryRepository.findByUrl(repositoryUrl);
if (repository == null) {
repositoryRepository.save(new Repository(repositoryUrl));
repository = repositoryRepository.save(new Repository(repositoryUrl));
}
Branch branch = branchRepository.findByRepositoryAndName(repository, branchName);
if (branch == null) {
branch = branchRepository.save(new Branch(repository, branchName));
}
List<Commit> commits = gitRepositoryService.getCommits(repositoryUrl, branchName);
commitRepository.deleteAll(branch.getCommits());
List<Commit> commitsToRemove = branch.getCommits();
branch.getCommits().clear();
commitRepository.deleteAll(commitsToRemove);
branch.setCommits(commits);
branchRepository.save(branch);
}

@ -11,11 +11,12 @@
<form action="#" th:action="${@route.INDEXING_NEW_REPOSITORY}" th:object="${repoForm}" method="post">
<button class="btn btn-outline-dark dropdown-toggle" type="button" data-toggle="collapse"
data-target="#collapseOne" aria-expanded="false" aria-controls="collapseExample"
th:if="${repoForm.repo != null}"
th:text="${repoForm.repo == null ? 'Репозиторий' : repoForm.repo}">
th:if="${repoForm.repo != '' && repoForm.repo != null && (error == '' || error == null)}"
th:text="${repoForm.repo == '' || repoForm.repo == null ? 'Репозиторий' : repoForm.repo}">
Button with data-target
</button>
<div id="collapseOne" th:class="${repoForm.repo == null ? 'collapse show' : 'collapse'}"
<div id="collapseOne"
th:class="${repoForm.repo == '' || repoForm.repo == null || (error != '' && error != null) ? 'collapse show' : 'collapse'}"
aria-labelledby="headingOne">
<div class="card-body">
<div class="form-group">
@ -34,7 +35,8 @@
</div>
</div>
</div>
<div id="collapseTwo" class="collapse show" aria-labelledby="headingOne" th:if="${repoForm.repo != null}">
<div id="collapseTwo" class="collapse show" aria-labelledby="headingOne"
th:if="${repoForm.repo != '' && repoForm.repo != null && (error == '' || error == null) }">
<div class="card-body">
<div class="form-group">
<label for="select-branch">Ветки:</label>

Loading…
Cancel
Save