Add REST endpoint to list label definitions of a project

Review labels are defined in the project.config file inside the
refs/meta/config branch. Viewing and updating the label definitions of
a project is currently only possible via git access to the
refs/meta/config branch.

We want to allow editing review labels from the UI. For this the backend
must provide REST endpoints to list and update the labels of a project.

This change implements a new REST endpoint that allows listing the label
definitions of one project. Inherited label definitions are not returned
yet, but a follow-up change should add an option on the List Labels REST
endpoint to include them. This is why in the Java extension API the
labels() method returns a ListLabelsRequest instead of directly the list
of labels. The ListLabelsRequest will allow callers to set options on
the request before executing it.

Planned follow-up changes:
- Add option on List Labels REST endpoint to include inherited labels
- Add REST endpoint to get a single label
- Add REST endpoint to update an existing label
- Add REST endpoint to add a new label
- Add REST endpoint to remove a label
- Implement a UI for editing labels

Bug: Issue 11522
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Ia65760bbf893ea81747627fcdd0306f6e750f4dd
This commit is contained in:
Edwin Kempin
2019-10-24 09:22:34 +02:00
parent 40555feee8
commit 44098d0219
11 changed files with 556 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
// 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.project;
import com.google.gerrit.common.data.LabelType;
import com.google.gerrit.extensions.restapi.RestResource;
import com.google.gerrit.extensions.restapi.RestView;
import com.google.inject.TypeLiteral;
public class LabelResource implements RestResource {
public static final TypeLiteral<RestView<LabelResource>> LABEL_KIND =
new TypeLiteral<RestView<LabelResource>>() {};
private final ProjectResource project;
private final LabelType labelType;
public LabelResource(ProjectResource project, LabelType labelType) {
this.project = project;
this.labelType = labelType;
}
public ProjectResource getProject() {
return project;
}
public LabelType getLabelType() {
return labelType;
}
}