Merge "Add label data into GET /project/ REST endpoint"
This commit is contained in:
@@ -346,7 +346,16 @@ describes the project.
|
||||
"name": "plugins/replication",
|
||||
"parent": "Public-Plugins",
|
||||
"description": "Copies to other servers using the Git protocol",
|
||||
"state": "ACTIVE"
|
||||
"state": "ACTIVE",
|
||||
"labels": {
|
||||
"Code-Review": {
|
||||
"values": {
|
||||
" 0": "No score",
|
||||
"+1": "Approved"
|
||||
},
|
||||
"default_value": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
@@ -389,7 +398,16 @@ describes the created project.
|
||||
"id": "MyProject",
|
||||
"name": "MyProject",
|
||||
"parent": "All-Projects",
|
||||
"description": "This is a demo project."
|
||||
"description": "This is a demo project.",
|
||||
"labels": {
|
||||
"Code-Review": {
|
||||
"values": {
|
||||
" 0": "No score",
|
||||
"+1": "Approved"
|
||||
},
|
||||
"default_value": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
@@ -2732,6 +2750,19 @@ The boolean value inherited from the parent. +
|
||||
Not set if there is no parent.
|
||||
|================================
|
||||
|
||||
|
||||
[[label-type-info]]
|
||||
=== LabelTypeInfo
|
||||
The `LabelTypeInfo` entity contains metadata about the labels that a
|
||||
project has.
|
||||
|
||||
[options="header",cols="1,^2,4"]
|
||||
|================================
|
||||
|Field Name ||Description
|
||||
|`values` ||Map of the available values to their description.
|
||||
|`default_value` ||The default value of this label.
|
||||
|================================
|
||||
|
||||
[[max-object-size-limit-info]]
|
||||
=== MaxObjectSizeLimitInfo
|
||||
The `MaxObjectSizeLimitInfo` entity contains information about the
|
||||
@@ -2809,6 +2840,11 @@ is increased for each non-visible project).
|
||||
|`description` |optional|The description of the project.
|
||||
|`state` |optional|`ACTIVE`, `READ_ONLY` or `HIDDEN`.
|
||||
|`branches` |optional|Map of branch names to HEAD revisions.
|
||||
|`labels` |optional|
|
||||
Map of label names to
|
||||
link:#label-type-info[LabelTypeInfo] entries.
|
||||
This field is filled for link:#create-project[Create Project] and
|
||||
link:#get-project[Get Project] calls.
|
||||
|`web_links` |optional|
|
||||
Links to the project in external sites as a list of
|
||||
link:rest-api-changes.html#web-link-info[WebLinkInfo] entries.
|
||||
|
||||
@@ -57,6 +57,11 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
r.assertCreated();
|
||||
ProjectInfo p = newGson().fromJson(r.getReader(), ProjectInfo.class);
|
||||
assertThat(p.name).isEqualTo(newProjectName);
|
||||
|
||||
// Check that we populate the label data in the HTTP path. See GetProjectIT#getProject
|
||||
// for more extensive coverage of the LabelTypeInfo.
|
||||
assertThat(p.labels).hasSize(1);
|
||||
|
||||
ProjectState projectState = projectCache.get(new Project.NameKey(newProjectName));
|
||||
assertThat(projectState).isNotNull();
|
||||
assertProjectInfo(projectState.getProject(), p);
|
||||
|
||||
@@ -16,8 +16,10 @@ package com.google.gerrit.acceptance.rest.project;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.extensions.common.LabelTypeInfo;
|
||||
import com.google.gerrit.extensions.common.ProjectInfo;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import org.junit.Test;
|
||||
@@ -30,6 +32,19 @@ public class GetProjectIT extends AbstractDaemonTest {
|
||||
String name = project.get();
|
||||
ProjectInfo p = gApi.projects().name(name).get();
|
||||
assertThat(p.name).isEqualTo(name);
|
||||
|
||||
assertThat(p.labels).hasSize(1);
|
||||
LabelTypeInfo l = p.labels.get("Code-Review");
|
||||
|
||||
ImmutableMap<String, String> want =
|
||||
ImmutableMap.of(
|
||||
" 0", "No score",
|
||||
"-1", "I would prefer this is not merged as is",
|
||||
"-2", "This shall not be merged",
|
||||
"+1", "Looks good to me, but someone else must approve",
|
||||
"+2", "Looks good to me, approved");
|
||||
assertThat(l.values).isEqualTo(want);
|
||||
assertThat(l.defaultValue).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2017 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class LabelTypeInfo {
|
||||
public Map<String, String> values;
|
||||
public short defaultValue;
|
||||
}
|
||||
@@ -26,4 +26,5 @@ public class ProjectInfo {
|
||||
public ProjectState state;
|
||||
public Map<String, String> branches;
|
||||
public List<WebLinkInfo> webLinks;
|
||||
public Map<String, LabelTypeInfo> labels;
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
if (project == null) {
|
||||
throw new ResourceNotFoundException(name);
|
||||
}
|
||||
return projectJson.format(project);
|
||||
return projectJson.format(project.getControl());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -205,19 +205,20 @@ public class CreateProject implements RestModifyView<TopLevelResource, ProjectIn
|
||||
|
||||
Project p = createProject(args);
|
||||
|
||||
if (input.pluginConfigValues != null) {
|
||||
ProjectControl projectControl;
|
||||
try {
|
||||
ProjectControl projectControl =
|
||||
projectControlFactory.controlFor(p.getNameKey(), identifiedUser.get());
|
||||
ConfigInput in = new ConfigInput();
|
||||
in.pluginConfigValues = input.pluginConfigValues;
|
||||
putConfig.get().apply(projectControl, in);
|
||||
projectControl= projectControlFactory.controlFor(p.getNameKey(), identifiedUser.get());
|
||||
} catch (NoSuchProjectException e) {
|
||||
throw new ResourceNotFoundException(p.getName());
|
||||
}
|
||||
|
||||
if (input.pluginConfigValues != null) {
|
||||
ConfigInput in = new ConfigInput();
|
||||
in.pluginConfigValues = input.pluginConfigValues;
|
||||
putConfig.get().apply(projectControl, in);
|
||||
}
|
||||
|
||||
return Response.created(json.format(p));
|
||||
return Response.created(json.format(projectControl));
|
||||
}
|
||||
|
||||
private Project createProject(CreateProjectArgs args)
|
||||
|
||||
@@ -31,6 +31,6 @@ class GetProject implements RestReadView<ProjectResource> {
|
||||
|
||||
@Override
|
||||
public ProjectInfo apply(ProjectResource rsrc) {
|
||||
return json.format(rsrc);
|
||||
return json.format(rsrc.getControl());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
package com.google.gerrit.server.project;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelValue;
|
||||
import com.google.gerrit.extensions.common.LabelTypeInfo;
|
||||
import com.google.gerrit.extensions.common.ProjectInfo;
|
||||
import com.google.gerrit.extensions.common.WebLinkInfo;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
@@ -23,7 +26,10 @@ import com.google.gerrit.server.WebLinks;
|
||||
import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Singleton
|
||||
public class ProjectJson {
|
||||
@@ -37,8 +43,20 @@ public class ProjectJson {
|
||||
this.webLinks = webLinks;
|
||||
}
|
||||
|
||||
public ProjectInfo format(ProjectResource rsrc) {
|
||||
return format(rsrc.getControl().getProject());
|
||||
public ProjectInfo format(ProjectControl ctl) {
|
||||
ProjectInfo info = format(ctl.getProject());
|
||||
info.labels = new HashMap<>();
|
||||
for (LabelType t : ctl.getLabelTypes().getLabelTypes()) {
|
||||
LabelTypeInfo labelInfo = new LabelTypeInfo();
|
||||
labelInfo.values =
|
||||
t.getValues()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(LabelValue::formatValue, LabelValue::getText));
|
||||
labelInfo.defaultValue = t.getDefaultValue();
|
||||
info.labels.put(t.getName(), labelInfo);
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
public ProjectInfo format(Project p) {
|
||||
|
||||
Reference in New Issue
Block a user