Use REST endpoint to create project in SSH create-project command
Change-Id: Icb0e5fa8b156486fffaf40e71b60274d68260e06 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
parent
b71ac62312
commit
6ff9928f64
@ -45,19 +45,19 @@ import java.util.List;
|
|||||||
@RequiresCapability(GlobalCapability.CREATE_PROJECT)
|
@RequiresCapability(GlobalCapability.CREATE_PROJECT)
|
||||||
public class CreateProject implements RestModifyView<TopLevelResource, Input> {
|
public class CreateProject implements RestModifyView<TopLevelResource, Input> {
|
||||||
public static class Input {
|
public static class Input {
|
||||||
String name;
|
public String name;
|
||||||
String parent;
|
public String parent;
|
||||||
String description;
|
public String description;
|
||||||
boolean permissionsOnly;
|
public boolean permissionsOnly;
|
||||||
boolean createEmptyCommit;
|
public boolean createEmptyCommit;
|
||||||
SubmitType submitType;
|
public SubmitType submitType;
|
||||||
List<String> branches;
|
public List<String> branches;
|
||||||
List<String> owners;
|
public List<String> owners;
|
||||||
InheritableBoolean useContributorAgreements;
|
public InheritableBoolean useContributorAgreements;
|
||||||
InheritableBoolean useSignedOffBy;
|
public InheritableBoolean useSignedOffBy;
|
||||||
InheritableBoolean useContentMerge;
|
public InheritableBoolean useContentMerge;
|
||||||
InheritableBoolean requireChangeId;
|
public InheritableBoolean requireChangeId;
|
||||||
String maxObjectSizeLimit;
|
public String maxObjectSizeLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface Factory {
|
public static interface Factory {
|
||||||
|
@ -14,24 +14,31 @@
|
|||||||
|
|
||||||
package com.google.gerrit.sshd.commands;
|
package com.google.gerrit.sshd.commands;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.common.data.GlobalCapability;
|
import com.google.gerrit.common.data.GlobalCapability;
|
||||||
import com.google.gerrit.common.errors.ProjectCreationFailedException;
|
import com.google.gerrit.common.errors.ProjectCreationFailedException;
|
||||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||||
|
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||||
|
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
|
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
|
||||||
import com.google.gerrit.reviewdb.client.Project.SubmitType;
|
import com.google.gerrit.reviewdb.client.Project.SubmitType;
|
||||||
import com.google.gerrit.server.project.PerformCreateProject;
|
import com.google.gerrit.server.project.CreateProject;
|
||||||
import com.google.gerrit.server.project.CreateProjectArgs;
|
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||||
import com.google.gerrit.server.project.ProjectControl;
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
import com.google.gerrit.server.project.SuggestParentCandidates;
|
import com.google.gerrit.server.project.SuggestParentCandidates;
|
||||||
import com.google.gerrit.sshd.CommandMetaData;
|
import com.google.gerrit.sshd.CommandMetaData;
|
||||||
import com.google.gerrit.sshd.SshCommand;
|
import com.google.gerrit.sshd.SshCommand;
|
||||||
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
import org.kohsuke.args4j.Argument;
|
import org.kohsuke.args4j.Argument;
|
||||||
import org.kohsuke.args4j.Option;
|
import org.kohsuke.args4j.Option;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** Create a new project. **/
|
/** Create a new project. **/
|
||||||
@ -120,35 +127,46 @@ final class CreateProjectCommand extends SshCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PerformCreateProject.Factory factory;
|
private Provider<CreateProject.Factory> createProjectFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private SuggestParentCandidates.Factory suggestParentCandidatesFactory;
|
private SuggestParentCandidates.Factory suggestParentCandidatesFactory;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run() throws Exception {
|
protected void run() throws UnloggedFailure {
|
||||||
try {
|
try {
|
||||||
if (!suggestParent) {
|
if (!suggestParent) {
|
||||||
if (projectName == null) {
|
if (projectName == null) {
|
||||||
throw new UnloggedFailure(1, "fatal: Project name is required.");
|
throw new UnloggedFailure(1, "fatal: Project name is required.");
|
||||||
}
|
}
|
||||||
final CreateProjectArgs args = new CreateProjectArgs();
|
|
||||||
args.setProjectName(projectName);
|
|
||||||
args.ownerIds = ownerIds;
|
|
||||||
args.newParent = newParent;
|
|
||||||
args.permissionsOnly = permissionsOnly;
|
|
||||||
args.projectDescription = projectDescription;
|
|
||||||
args.submitType = submitType;
|
|
||||||
args.contributorAgreements = contributorAgreements;
|
|
||||||
args.signedOffBy = signedOffBy;
|
|
||||||
args.contentMerge = contentMerge;
|
|
||||||
args.changeIdRequired = requireChangeID;
|
|
||||||
args.branch = branch;
|
|
||||||
args.createEmptyCommit = createEmptyCommit;
|
|
||||||
args.maxObjectSizeLimit = maxObjectSizeLimit;
|
|
||||||
|
|
||||||
final PerformCreateProject createProject = factory.create(args);
|
CreateProject.Input input = new CreateProject.Input();
|
||||||
createProject.createProject();
|
input.name = projectName;
|
||||||
|
if (ownerIds != null) {
|
||||||
|
input.owners = Lists.transform(ownerIds,
|
||||||
|
new Function<AccountGroup.UUID, String>() {
|
||||||
|
@Override
|
||||||
|
public String apply(AccountGroup.UUID uuid) {
|
||||||
|
return uuid.get();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (newParent != null) {
|
||||||
|
input.parent = newParent.getProject().getName();
|
||||||
|
}
|
||||||
|
input.permissionsOnly = permissionsOnly;
|
||||||
|
input.description = projectDescription;
|
||||||
|
input.submitType = submitType;
|
||||||
|
input.useContributorAgreements = contributorAgreements;
|
||||||
|
input.useSignedOffBy = signedOffBy;
|
||||||
|
input.useContentMerge = contentMerge;
|
||||||
|
input.requireChangeId = requireChangeID;
|
||||||
|
input.branches = branch;
|
||||||
|
input.createEmptyCommit = createEmptyCommit;
|
||||||
|
input.maxObjectSizeLimit = maxObjectSizeLimit;
|
||||||
|
|
||||||
|
createProjectFactory.get().create(projectName)
|
||||||
|
.apply(TopLevelResource.INSTANCE, input);
|
||||||
} else {
|
} else {
|
||||||
List<Project.NameKey> parentCandidates =
|
List<Project.NameKey> parentCandidates =
|
||||||
suggestParentCandidatesFactory.create().getNameKeys();
|
suggestParentCandidatesFactory.create().getNameKeys();
|
||||||
@ -157,7 +175,8 @@ final class CreateProjectCommand extends SshCommand {
|
|||||||
stdout.print(parent + "\n");
|
stdout.print(parent + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ProjectCreationFailedException err) {
|
} catch (RestApiException | ProjectCreationFailedException | IOException
|
||||||
|
| NoSuchProjectException | OrmException err) {
|
||||||
throw new UnloggedFailure(1, "fatal: " + err.getMessage(), err);
|
throw new UnloggedFailure(1, "fatal: " + err.getMessage(), err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user