use of io.hops.hopsworks.persistence.entity.git.GitRepository in project hopsworks by logicalclocks.
the class GitController method fileCheckout.
public GitOpExecution fileCheckout(Project project, Users hopsworksUser, Integer repositoryId, List<String> filePaths) throws GitOpException, HopsSecurityException {
if (filePaths.isEmpty()) {
throw new IllegalArgumentException("File paths are empty.");
}
GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
String repositoryFullPath = inodeController.getPath(repository.getInode());
GitCommandConfiguration fileCheckoutConfiguration = new GitCommandConfigurationBuilder().setCommandType(GitCommandType.FILE_CHECKOUT).setPath(repositoryFullPath).setFiles(filePaths).build();
return executionController.createExecution(fileCheckoutConfiguration, project, hopsworksUser, repository);
}
use of io.hops.hopsworks.persistence.entity.git.GitRepository in project hopsworks by logicalclocks.
the class GitController method addOrDeleteRemote.
public GitOpExecution addOrDeleteRemote(GitRemotesAction action, Project project, Users hopsworksUser, Integer repositoryId, String remoteName, String remoteUrl) throws GitOpException, IllegalArgumentException, HopsSecurityException {
if (Strings.isNullOrEmpty(remoteName)) {
throw new IllegalArgumentException(RESTCodes.GitOpErrorCode.INVALID_REMOTE_NAME.getMessage());
}
GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
String repositoryFullPath = inodeController.getPath(repository.getInode());
GitCommandConfigurationBuilder builder = new GitCommandConfigurationBuilder().setPath(repositoryFullPath).setRemoteName(remoteName);
switch(action) {
case ADD:
if (Strings.isNullOrEmpty(remoteUrl)) {
throw new IllegalArgumentException(RESTCodes.GitOpErrorCode.INVALID_REMOTE_URL_PROVIDED.getMessage());
}
builder.setCommandType(GitCommandType.ADD_REMOTE);
builder.setRemoteUrl(remoteUrl);
return executionController.createExecution(builder.build(), project, hopsworksUser, repository);
case DELETE:
builder.setCommandType(GitCommandType.DELETE_REMOTE);
return executionController.createExecution(builder.build(), project, hopsworksUser, repository);
default:
throw new IllegalArgumentException(RESTCodes.GitOpErrorCode.INVALID_REMOTES_ACTION.getMessage());
}
}
use of io.hops.hopsworks.persistence.entity.git.GitRepository in project hopsworks by logicalclocks.
the class GitController method pull.
public GitOpExecution pull(PullCommandConfiguration configDTO, Project project, Users hopsworksUser, Integer repositoryId) throws GitOpException, HopsSecurityException, IllegalArgumentException {
commandConfigurationValidator.verifyRemoteNameAndBranch(configDTO.getRemoteName(), configDTO.getBranchName());
GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
String repositoryFullPath = inodeController.getPath(repository.getInode());
GitCommandConfiguration pullCommandConfiguration = new GitCommandConfigurationBuilder().setCommandType(GitCommandType.PULL).setRemoteName(configDTO.getRemoteName()).setForce(configDTO.isForce()).setBranchName(configDTO.getBranchName()).setPath(repositoryFullPath).build();
return executionController.createExecution(pullCommandConfiguration, project, hopsworksUser, repository);
}
use of io.hops.hopsworks.persistence.entity.git.GitRepository in project hopsworks by logicalclocks.
the class GitController method executeBranchAction.
public GitOpExecution executeBranchAction(GitBranchAction action, Project project, Users hopsworksUser, Integer repositoryId, String branchName, String commit) throws GitOpException, HopsSecurityException, IllegalArgumentException {
GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
String repositoryFullPath = inodeController.getPath(repository.getInode());
GitCommandConfigurationBuilder builder = new GitCommandConfigurationBuilder();
builder.setBranchName(branchName);
builder.setPath(repositoryFullPath);
switch(action) {
case CREATE:
case CREATE_CHECKOUT:
if (Strings.isNullOrEmpty(branchName)) {
throw new GitOpException(RESTCodes.GitOpErrorCode.INVALID_BRANCH_NAME, Level.WARNING, "Branch name is empty" + ".");
}
builder.setCommandType(GitCommandType.CREATE_BRANCH);
builder.setCheckout(action == GitBranchAction.CREATE_CHECKOUT);
return executionController.createExecution(builder.build(), project, hopsworksUser, repository);
case DELETE:
if (Strings.isNullOrEmpty(branchName)) {
throw new GitOpException(RESTCodes.GitOpErrorCode.INVALID_BRANCH_NAME, Level.WARNING, "Branch name is empty" + ".");
}
builder.setCommandType(GitCommandType.DELETE_BRANCH);
builder.setDeleteOnRemote(false);
return executionController.createExecution(builder.build(), project, hopsworksUser, repository);
case CHECKOUT:
case CHECKOUT_FORCE:
if (Strings.isNullOrEmpty(branchName) && Strings.isNullOrEmpty(commit)) {
throw new GitOpException(RESTCodes.GitOpErrorCode.INVALID_BRANCH_AND_COMMIT_CHECKOUT_COMBINATION, Level.WARNING, "Please provide either branch or commit to checkout.");
} else if (!Strings.isNullOrEmpty(branchName) && !Strings.isNullOrEmpty(commit)) {
throw new GitOpException(RESTCodes.GitOpErrorCode.INVALID_BRANCH_AND_COMMIT_CHECKOUT_COMBINATION, Level.WARNING, "Checkout requires a commit or branch but not both.");
}
builder.setCommandType(GitCommandType.CHECKOUT);
builder.setCommit(commit);
builder.setForce(action == GitBranchAction.CHECKOUT_FORCE);
return executionController.createExecution(builder.build(), project, hopsworksUser, repository);
default:
throw new IllegalArgumentException(RESTCodes.GitOpErrorCode.INVALID_BRANCH_ACTION.getMessage());
}
}
use of io.hops.hopsworks.persistence.entity.git.GitRepository in project hopsworks by logicalclocks.
the class GitController method status.
public GitOpExecution status(Project project, Users hopsworksUser, Integer repositoryId) throws GitOpException, HopsSecurityException {
GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
String repositoryFullPath = inodeController.getPath(repository.getInode());
GitCommandConfiguration statusCommandConfig = new GitCommandConfigurationBuilder().setCommandType(GitCommandType.STATUS).setPath(repositoryFullPath).build();
return executionController.createExecution(statusCommandConfig, project, hopsworksUser, repository);
}
Aggregations