mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-08 05:10:20 +01:00
Merge with 2.0.0-m3
This commit is contained in:
@@ -8,56 +8,48 @@ import sonia.scm.repository.Person;
|
||||
import sonia.scm.repository.client.api.ClientCommand;
|
||||
import sonia.scm.repository.client.api.RepositoryClient;
|
||||
import sonia.scm.repository.client.api.RepositoryClientFactory;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static sonia.scm.it.RestUtil.ADMIN_PASSWORD;
|
||||
import static sonia.scm.it.RestUtil.ADMIN_USERNAME;
|
||||
import static sonia.scm.it.RestUtil.given;
|
||||
import java.util.UUID;
|
||||
|
||||
public class RepositoryUtil {
|
||||
|
||||
private static final RepositoryClientFactory REPOSITORY_CLIENT_FACTORY = new RepositoryClientFactory();
|
||||
|
||||
private final RepositoryClient repositoryClient;
|
||||
private final File folder;
|
||||
|
||||
RepositoryUtil(String repositoryType, File folder) throws IOException {
|
||||
this.repositoryClient = createRepositoryClient(repositoryType, folder);
|
||||
this.folder = folder;
|
||||
static RepositoryClient createRepositoryClient(String repositoryType, File folder) throws IOException {
|
||||
return createRepositoryClient(repositoryType, folder, "scmadmin", "scmadmin");
|
||||
}
|
||||
|
||||
static RepositoryClient createRepositoryClient(String repositoryType, File folder) throws IOException {
|
||||
String httpProtocolUrl = given(VndMediaType.REPOSITORY)
|
||||
|
||||
.when()
|
||||
.get(TestData.getDefaultRepositoryUrl(repositoryType))
|
||||
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK)
|
||||
static RepositoryClient createRepositoryClient(String repositoryType, File folder, String username, String password) throws IOException {
|
||||
String httpProtocolUrl = TestData.callRepository(username, password, repositoryType, HttpStatus.SC_OK)
|
||||
.extract()
|
||||
.path("_links.httpProtocol.href");
|
||||
|
||||
|
||||
return REPOSITORY_CLIENT_FACTORY.create(repositoryType, httpProtocolUrl, ADMIN_USERNAME, ADMIN_PASSWORD, folder);
|
||||
return REPOSITORY_CLIENT_FACTORY.create(repositoryType, httpProtocolUrl, username, password, folder);
|
||||
}
|
||||
|
||||
void createAndCommitFile(String fileName, String content) throws IOException {
|
||||
File file = new File(folder, fileName);
|
||||
static String addAndCommitRandomFile(RepositoryClient client, String username) throws IOException {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String name = "file-" + uuid + ".uuid";
|
||||
createAndCommitFile(client, username, name, uuid);
|
||||
return name;
|
||||
}
|
||||
|
||||
static void createAndCommitFile(RepositoryClient repositoryClient, String username, String fileName, String content) throws IOException {
|
||||
File file = new File(repositoryClient.getWorkingCopy(), fileName);
|
||||
Files.write(content, file, Charsets.UTF_8);
|
||||
addWithParentDirectories(file);
|
||||
commit("added " + fileName);
|
||||
addWithParentDirectories(repositoryClient, file);
|
||||
commit(repositoryClient, username, "added " + fileName);
|
||||
}
|
||||
|
||||
private String addWithParentDirectories(File file) throws IOException {
|
||||
private static String addWithParentDirectories(RepositoryClient repositoryClient, File file) throws IOException {
|
||||
File parent = file.getParentFile();
|
||||
String thisName = file.getName();
|
||||
String path;
|
||||
if (!folder.equals(parent)) {
|
||||
addWithParentDirectories(parent);
|
||||
path = addWithParentDirectories(parent) + File.separator + thisName;
|
||||
if (!repositoryClient.getWorkingCopy().equals(parent)) {
|
||||
addWithParentDirectories(repositoryClient, parent);
|
||||
path = addWithParentDirectories(repositoryClient, parent) + File.separator + thisName;
|
||||
} else {
|
||||
path = thisName;
|
||||
}
|
||||
@@ -65,10 +57,8 @@ public class RepositoryUtil {
|
||||
return path;
|
||||
}
|
||||
|
||||
Changeset commit(String message) throws IOException {
|
||||
Changeset changeset = repositoryClient.getCommitCommand().commit(
|
||||
new Person("scmadmin", "scmadmin@scm-manager.org"), message
|
||||
);
|
||||
static Changeset commit(RepositoryClient repositoryClient, String username, String message) throws IOException {
|
||||
Changeset changeset = repositoryClient.getCommitCommand().commit(new Person(username, username + "@scm-manager.org"), message);
|
||||
if (repositoryClient.isCommandSupported(ClientCommand.PUSH)) {
|
||||
repositoryClient.getPushCommand().push();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user