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.schema; 16 : 17 : import com.google.auto.value.AutoValue; 18 : import com.google.common.collect.ImmutableList; 19 : import com.google.common.collect.ImmutableMap; 20 : import com.google.gerrit.common.UsedAt; 21 : import com.google.gerrit.entities.BooleanProjectConfig; 22 : import com.google.gerrit.entities.GroupReference; 23 : import com.google.gerrit.entities.LabelType; 24 : import com.google.gerrit.entities.LabelValue; 25 : import com.google.gerrit.extensions.client.ChangeKind; 26 : import com.google.gerrit.extensions.client.InheritableBoolean; 27 : import com.google.gerrit.server.notedb.Sequences; 28 : import java.util.Optional; 29 : 30 : @AutoValue 31 151 : public abstract class AllProjectsInput { 32 : 33 : /** Default boolean configs set when initializing All-Projects. */ 34 : public static final ImmutableMap<BooleanProjectConfig, InheritableBoolean> 35 151 : DEFAULT_BOOLEAN_PROJECT_CONFIGS = 36 151 : ImmutableMap.of( 37 : BooleanProjectConfig.REQUIRE_CHANGE_ID, 38 : InheritableBoolean.TRUE, 39 : BooleanProjectConfig.USE_CONTENT_MERGE, 40 : InheritableBoolean.TRUE, 41 : BooleanProjectConfig.USE_CONTRIBUTOR_AGREEMENTS, 42 : InheritableBoolean.FALSE, 43 : BooleanProjectConfig.USE_SIGNED_OFF_BY, 44 : InheritableBoolean.FALSE, 45 : BooleanProjectConfig.ENABLE_SIGNED_PUSH, 46 : InheritableBoolean.FALSE); 47 : 48 : @UsedAt(UsedAt.Project.GOOGLE) 49 : public static LabelType getDefaultCodeReviewLabel() { 50 151 : return LabelType.builder( 51 : "Code-Review", 52 151 : ImmutableList.of( 53 151 : LabelValue.create((short) 2, "Looks good to me, approved"), 54 151 : LabelValue.create((short) 1, "Looks good to me, but someone else must approve"), 55 151 : LabelValue.create((short) 0, "No score"), 56 151 : LabelValue.create((short) -1, "I would prefer this is not submitted as is"), 57 151 : LabelValue.create((short) -2, "This shall not be submitted"))) 58 151 : .setCopyCondition( 59 151 : String.format( 60 : "changekind:%s OR changekind:%s OR is:MIN", 61 151 : ChangeKind.NO_CHANGE, ChangeKind.TRIVIAL_REBASE.name())) 62 151 : .build(); 63 : } 64 : 65 : /** The administrator group which gets default permissions granted. */ 66 : public abstract Optional<GroupReference> administratorsGroup(); 67 : 68 : /** The group which gets stream-events permission granted and appropriate properties set. */ 69 : public abstract Optional<GroupReference> serviceUsersGroup(); 70 : 71 : /** The commit message used when commit the project config change. */ 72 : public abstract Optional<String> commitMessage(); 73 : 74 : /** The first change-id used in this host. */ 75 : @UsedAt(UsedAt.Project.GOOGLE) 76 : public abstract int firstChangeIdForNoteDb(); 77 : 78 : /** The "Code-Review" label to be defined in All-Projects. */ 79 : @UsedAt(UsedAt.Project.GOOGLE) 80 : public abstract Optional<LabelType> codeReviewLabel(); 81 : 82 : /** Description for the All-Projects. */ 83 : public abstract Optional<String> projectDescription(); 84 : 85 : /** Boolean project configs to be set in All-Projects. */ 86 : public abstract ImmutableMap<BooleanProjectConfig, InheritableBoolean> booleanProjectConfigs(); 87 : 88 : /** Whether initializing default access sections in All-Projects. */ 89 : public abstract boolean initDefaultAcls(); 90 : 91 : public abstract Builder toBuilder(); 92 : 93 : public static Builder builder() { 94 151 : Builder builder = 95 : new AutoValue_AllProjectsInput.Builder() 96 151 : .codeReviewLabel(getDefaultCodeReviewLabel()) 97 151 : .firstChangeIdForNoteDb(Sequences.FIRST_CHANGE_ID) 98 151 : .initDefaultAcls(true); 99 151 : DEFAULT_BOOLEAN_PROJECT_CONFIGS.forEach(builder::addBooleanProjectConfig); 100 : 101 151 : return builder; 102 : } 103 : 104 : public static Builder builderWithNoDefault() { 105 1 : return new AutoValue_AllProjectsInput.Builder(); 106 : } 107 : 108 : @AutoValue.Builder 109 151 : public abstract static class Builder { 110 : public abstract Builder administratorsGroup(GroupReference adminGroup); 111 : 112 : public abstract Builder serviceUsersGroup(GroupReference serviceGroup); 113 : 114 : public abstract Builder commitMessage(String commitMessage); 115 : 116 : public abstract Builder firstChangeIdForNoteDb(int firstChangeId); 117 : 118 : @UsedAt(UsedAt.Project.GOOGLE) 119 : public abstract Builder codeReviewLabel(LabelType codeReviewLabel); 120 : 121 : @UsedAt(UsedAt.Project.GOOGLE) 122 : public abstract Builder projectDescription(String projectDescription); 123 : 124 : public abstract ImmutableMap.Builder<BooleanProjectConfig, InheritableBoolean> 125 : booleanProjectConfigsBuilder(); 126 : 127 : public Builder addBooleanProjectConfig( 128 : BooleanProjectConfig booleanProjectConfig, InheritableBoolean inheritableBoolean) { 129 151 : booleanProjectConfigsBuilder().put(booleanProjectConfig, inheritableBoolean); 130 151 : return this; 131 : } 132 : 133 : @UsedAt(UsedAt.Project.GOOGLE) 134 : public abstract Builder initDefaultAcls(boolean initDefaultACLs); 135 : 136 : public abstract AllProjectsInput build(); 137 : } 138 : }