use of com.google.gerrit.server.project.ProjectResource in project gerrit by GerritCodeReview.
the class ListTags method apply.
@Override
public Response<ImmutableList<TagInfo>> apply(ProjectResource resource) throws IOException, ResourceNotFoundException, RestApiException, PermissionBackendException {
resource.getProjectState().checkStatePermitsRead();
List<TagInfo> tags = new ArrayList<>();
PermissionBackend.ForProject perm = permissionBackend.currentUser().project(resource.getNameKey());
try (Repository repo = getRepository(resource.getNameKey());
RevWalk rw = new RevWalk(repo)) {
Collection<Ref> all = visibleTags(resource.getNameKey(), repo, repo.getRefDatabase().getRefsByPrefix(Constants.R_TAGS));
for (Ref ref : all) {
tags.add(createTagInfo(perm.ref(ref.getName()), ref, rw, resource.getProjectState(), links));
}
}
tags.sort(comparing(t -> t.ref));
return Response.ok(new RefFilter<TagInfo>(Constants.R_TAGS).start(start).limit(limit).subString(matchSubstring).regex(matchRegex).filter(tags));
}
use of com.google.gerrit.server.project.ProjectResource in project gerrit by GerritCodeReview.
the class SetParentCommand method getChildrenForReparenting.
/**
* Returns the children of the specified parent project that should be reparented. The returned
* list of child projects does not contain projects that were specified to be excluded from
* reparenting.
*/
private List<Project.NameKey> getChildrenForReparenting(ProjectState parent) throws Exception {
final List<Project.NameKey> childProjects = new ArrayList<>();
final List<Project.NameKey> excluded = new ArrayList<>(excludedChildren.size());
for (ProjectState excludedChild : excludedChildren) {
excluded.add(excludedChild.getProject().getNameKey());
}
final List<Project.NameKey> automaticallyExcluded = new ArrayList<>(excludedChildren.size());
if (newParentKey != null) {
automaticallyExcluded.addAll(getAllParents(newParentKey));
}
for (ProjectInfo child : listChildProjects.apply(new ProjectResource(parent, user)).value()) {
final Project.NameKey childName = Project.nameKey(child.name);
if (!excluded.contains(childName)) {
if (!automaticallyExcluded.contains(childName)) {
childProjects.add(childName);
} else {
stdout.println("Automatically excluded '" + childName + "' " + "from reparenting because it is in the parent " + "line of the new parent '" + newParentKey + "'.");
}
}
}
return childProjects;
}
use of com.google.gerrit.server.project.ProjectResource in project gerrit by GerritCodeReview.
the class SetProjectCommand method run.
@Override
protected void run() throws Failure {
enableGracefulStop();
ConfigInput configInput = new ConfigInput();
configInput.requireChangeId = requireChangeID;
configInput.submitType = submitType;
configInput.useContentMerge = contentMerge;
configInput.useContributorAgreements = contributorAgreements;
configInput.useSignedOffBy = signedOffBy;
configInput.state = state;
configInput.maxObjectSizeLimit = maxObjectSizeLimit;
// keeping the existing description, it would delete it.
if (Strings.emptyToNull(projectDescription) != null) {
configInput.description = projectDescription;
} else {
configInput.description = projectState.getProject().getDescription();
}
try {
putConfig.apply(new ProjectResource(projectState, user), configInput);
} catch (RestApiException | PermissionBackendException e) {
throw die(e);
}
}
use of com.google.gerrit.server.project.ProjectResource in project gerrit by GerritCodeReview.
the class LabelApiImpl method create.
@Override
public LabelApi create(LabelDefinitionInput input) throws RestApiException {
try {
createLabel.apply(project, IdString.fromDecoded(label), input);
// recreate project resource because project state was updated by creating the new label and
// needs to be reloaded
project = new ProjectResource(projectCache.get(project.getNameKey()).orElseThrow(illegalState(project.getNameKey())), project.getUser());
return this;
} catch (Exception e) {
throw asRestApiException("Cannot create branch", e);
}
}
use of com.google.gerrit.server.project.ProjectResource in project gerrit by GerritCodeReview.
the class ConfigInfoCreator method constructInfo.
@SuppressWarnings("deprecation")
public static ConfigInfo constructInfo(boolean serverEnableSignedPush, ProjectState projectState, CurrentUser user, DynamicMap<ProjectConfigEntry> pluginConfigEntries, PluginConfigFactory cfgFactory, AllProjectsName allProjects, UiActions uiActions, DynamicMap<RestView<ProjectResource>> views) {
ConfigInfo configInfo = new ConfigInfo();
Project p = projectState.getProject();
configInfo.description = Strings.emptyToNull(p.getDescription());
ProjectState parentState = Iterables.getFirst(projectState.parents(), null);
for (BooleanProjectConfig cfg : BooleanProjectConfig.values()) {
InheritedBooleanInfo info = new InheritedBooleanInfo();
info.configuredValue = p.getBooleanConfig(cfg);
if (parentState != null) {
info.inheritedValue = parentState.is(cfg);
}
BooleanProjectConfigTransformations.set(cfg, configInfo, info);
}
if (!serverEnableSignedPush) {
configInfo.enableSignedPush = null;
configInfo.requireSignedPush = null;
}
configInfo.maxObjectSizeLimit = getMaxObjectSizeLimit(projectState, p);
configInfo.defaultSubmitType = new SubmitTypeInfo();
configInfo.defaultSubmitType.value = projectState.getSubmitType();
configInfo.defaultSubmitType.configuredValue = MoreObjects.firstNonNull(projectState.getConfig().getProject().getSubmitType(), Project.DEFAULT_SUBMIT_TYPE);
ProjectState parent = projectState.isAllProjects() ? projectState : projectState.parents().get(0);
configInfo.defaultSubmitType.inheritedValue = parent.getSubmitType();
configInfo.submitType = configInfo.defaultSubmitType.value;
configInfo.state = p.getState() != com.google.gerrit.extensions.client.ProjectState.ACTIVE ? p.getState() : null;
configInfo.commentlinks = new LinkedHashMap<>();
for (CommentLinkInfo cl : projectState.getCommentLinks()) {
configInfo.commentlinks.put(cl.name, cl);
}
configInfo.pluginConfig = getPluginConfig(projectState, pluginConfigEntries, cfgFactory, allProjects);
configInfo.actions = new TreeMap<>();
for (UiAction.Description d : uiActions.from(views, new ProjectResource(projectState, user))) {
configInfo.actions.put(d.getId(), new ActionInfo(d));
}
configInfo.extensionPanelNames = projectState.getConfig().getExtensionPanelSections();
return configInfo;
}
Aggregations