LCOV - code coverage report
Current view: top level - server/project - LabelDefinitionJson.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 15 15 100.0 %
Date: 2022-11-19 15:00:39 Functions: 2 2 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2019 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.server.project;
      16             : 
      17             : import static java.util.stream.Collectors.toMap;
      18             : 
      19             : import com.google.gerrit.common.Nullable;
      20             : import com.google.gerrit.entities.LabelType;
      21             : import com.google.gerrit.entities.LabelValue;
      22             : import com.google.gerrit.entities.Project;
      23             : import com.google.gerrit.extensions.common.LabelDefinitionInfo;
      24             : 
      25             : public class LabelDefinitionJson {
      26             :   public static LabelDefinitionInfo format(Project.NameKey projectName, LabelType labelType) {
      27           8 :     LabelDefinitionInfo label = new LabelDefinitionInfo();
      28           8 :     label.name = labelType.getName();
      29           8 :     label.description = labelType.getDescription().orElse(null);
      30           8 :     label.projectName = projectName.get();
      31           8 :     label.function = labelType.getFunction().getFunctionName();
      32           8 :     label.values =
      33           8 :         labelType.getValues().stream().collect(toMap(LabelValue::formatValue, LabelValue::getText));
      34           8 :     label.defaultValue = labelType.getDefaultValue();
      35           8 :     label.branches = labelType.getRefPatterns() != null ? labelType.getRefPatterns() : null;
      36           8 :     label.canOverride = toBoolean(labelType.isCanOverride());
      37           8 :     label.copyCondition = labelType.getCopyCondition().orElse(null);
      38           8 :     label.allowPostSubmit = toBoolean(labelType.isAllowPostSubmit());
      39           8 :     label.ignoreSelfApproval = toBoolean(labelType.isIgnoreSelfApproval());
      40           8 :     return label;
      41             :   }
      42             : 
      43             :   @Nullable
      44             :   private static Boolean toBoolean(boolean v) {
      45           8 :     return v ? Boolean.TRUE : null;
      46             :   }
      47             : 
      48             :   private LabelDefinitionJson() {}
      49             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750