Add REST endpoint to get a label definition of a project
Bug: Issue 11522 Signed-off-by: Edwin Kempin <ekempin@google.com> Change-Id: I41e5c015d6067653c5794595df5ba7b97ca679a3
This commit is contained in:
49
java/com/google/gerrit/server/api/projects/LabelApiImpl.java
Normal file
49
java/com/google/gerrit/server/api/projects/LabelApiImpl.java
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2019 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.server.api.projects;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.projects.LabelApi;
|
||||
import com.google.gerrit.extensions.common.LabelDefinitionInfo;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.project.LabelResource;
|
||||
import com.google.gerrit.server.restapi.project.GetLabel;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
public class LabelApiImpl implements LabelApi {
|
||||
interface Factory {
|
||||
LabelApiImpl create(LabelResource rsrc);
|
||||
}
|
||||
|
||||
private final GetLabel getLabel;
|
||||
private final LabelResource rsrc;
|
||||
|
||||
@Inject
|
||||
LabelApiImpl(GetLabel getLabel, @Assisted LabelResource rsrc) {
|
||||
this.getLabel = getLabel;
|
||||
this.rsrc = rsrc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LabelDefinitionInfo get() throws RestApiException {
|
||||
try {
|
||||
return getLabel.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get label", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -28,5 +28,6 @@ public class Module extends FactoryModule {
|
||||
factory(ChildProjectApiImpl.Factory.class);
|
||||
factory(CommitApiImpl.Factory.class);
|
||||
factory(DashboardApiImpl.Factory.class);
|
||||
factory(LabelApiImpl.Factory.class);
|
||||
}
|
||||
}
|
||||
|
@@ -37,6 +37,7 @@ import com.google.gerrit.extensions.api.projects.DeleteTagsInput;
|
||||
import com.google.gerrit.extensions.api.projects.DescriptionInput;
|
||||
import com.google.gerrit.extensions.api.projects.HeadInput;
|
||||
import com.google.gerrit.extensions.api.projects.IndexProjectInput;
|
||||
import com.google.gerrit.extensions.api.projects.LabelApi;
|
||||
import com.google.gerrit.extensions.api.projects.ParentInput;
|
||||
import com.google.gerrit.extensions.api.projects.ProjectApi;
|
||||
import com.google.gerrit.extensions.api.projects.ProjectInput;
|
||||
@@ -72,6 +73,7 @@ import com.google.gerrit.server.restapi.project.GetHead;
|
||||
import com.google.gerrit.server.restapi.project.GetParent;
|
||||
import com.google.gerrit.server.restapi.project.Index;
|
||||
import com.google.gerrit.server.restapi.project.IndexChanges;
|
||||
import com.google.gerrit.server.restapi.project.LabelsCollection;
|
||||
import com.google.gerrit.server.restapi.project.ListBranches;
|
||||
import com.google.gerrit.server.restapi.project.ListDashboards;
|
||||
import com.google.gerrit.server.restapi.project.ListLabels;
|
||||
@@ -130,6 +132,8 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
private final Index index;
|
||||
private final IndexChanges indexChanges;
|
||||
private final Provider<ListLabels> listLabels;
|
||||
private final LabelsCollection labels;
|
||||
private final LabelApiImpl.Factory labelApi;
|
||||
|
||||
@AssistedInject
|
||||
ProjectApiImpl(
|
||||
@@ -166,6 +170,8 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
Index index,
|
||||
IndexChanges indexChanges,
|
||||
Provider<ListLabels> listLabels,
|
||||
LabelApiImpl.Factory labelApi,
|
||||
LabelsCollection labels,
|
||||
@Assisted ProjectResource project) {
|
||||
this(
|
||||
permissionBackend,
|
||||
@@ -202,6 +208,8 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
index,
|
||||
indexChanges,
|
||||
listLabels,
|
||||
labelApi,
|
||||
labels,
|
||||
null);
|
||||
}
|
||||
|
||||
@@ -240,6 +248,8 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
Index index,
|
||||
IndexChanges indexChanges,
|
||||
Provider<ListLabels> listLabels,
|
||||
LabelApiImpl.Factory labelApi,
|
||||
LabelsCollection labels,
|
||||
@Assisted String name) {
|
||||
this(
|
||||
permissionBackend,
|
||||
@@ -276,6 +286,8 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
index,
|
||||
indexChanges,
|
||||
listLabels,
|
||||
labelApi,
|
||||
labels,
|
||||
name);
|
||||
}
|
||||
|
||||
@@ -314,6 +326,8 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
Index index,
|
||||
IndexChanges indexChanges,
|
||||
Provider<ListLabels> listLabels,
|
||||
LabelApiImpl.Factory labelApi,
|
||||
LabelsCollection labels,
|
||||
String name) {
|
||||
this.permissionBackend = permissionBackend;
|
||||
this.createProject = createProject;
|
||||
@@ -350,6 +364,8 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
this.index = index;
|
||||
this.indexChanges = indexChanges;
|
||||
this.listLabels = listLabels;
|
||||
this.labelApi = labelApi;
|
||||
this.labels = labels;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -695,4 +711,13 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public LabelApi label(String labelName) throws RestApiException {
|
||||
try {
|
||||
return labelApi.create(labels.parse(checkExists(), IdString.fromDecoded(labelName)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot parse label", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user