Merge changes I580ed457,Ibf346b7b,I3dfa9388,I43bd6cbf,Idca2a304
* changes: GroupBundle: Warn if input entity lists are not unique Clean up ProjectConfigTest Tests for group names with extra whitespace Update JGit to 4.9.0.201710071750-r.65-g8b3ab4343 ProjectConfig: Trim LabelValues when emitting label config
This commit is contained in:
@@ -95,7 +95,7 @@ adding the following to `project.config` in `All-Projects`:
|
||||
[label "Verified"]
|
||||
function = MaxWithBlock
|
||||
value = -1 Fails
|
||||
value = 0 No score
|
||||
value = 0 No score
|
||||
value = +1 Verified
|
||||
copyAllScoresIfNoCodeChange = true
|
||||
----
|
||||
@@ -379,7 +379,7 @@ but has different names/labels:
|
||||
[label "Copyright-Check"]
|
||||
function = MaxWithBlock
|
||||
value = -1 Do not have copyright
|
||||
value = 0 No score
|
||||
value = 0 No score
|
||||
value = +1 Copyright clear
|
||||
----
|
||||
|
||||
@@ -401,7 +401,7 @@ user permissions. Assume the configuration below.
|
||||
value = -3 Ohh, hell no!
|
||||
value = -2 Hmm, I'm not a fan
|
||||
value = -1 I'm not sure I like this
|
||||
value = 0 No score
|
||||
value = 0 No score
|
||||
value = +1 I like, but need another to like it as well
|
||||
value = +2 Hmm, this is pretty nice
|
||||
value = +3 Ohh, hell yes!
|
||||
|
@@ -61,7 +61,7 @@ public class InitLabels implements InitStep {
|
||||
KEY_LABEL,
|
||||
LABEL_VERIFIED,
|
||||
KEY_VALUE,
|
||||
Arrays.asList(new String[] {"-1 Fails", " 0 No score", "+1 Verified"}));
|
||||
Arrays.asList(new String[] {"-1 Fails", "0 No score", "+1 Verified"}));
|
||||
cfg.setBoolean(KEY_LABEL, LABEL_VERIFIED, KEY_COPY_ALL_SCORES_IF_NO_CODE_CHANGE, true);
|
||||
allProjectsConfig.save("Configure 'Verified' label");
|
||||
}
|
||||
|
@@ -1421,7 +1421,7 @@ public class ProjectConfig extends VersionedMetaData implements ValidationError.
|
||||
rc, LABEL, name, KEY_CAN_OVERRIDE, label.canOverride(), LabelType.DEF_CAN_OVERRIDE);
|
||||
List<String> values = Lists.newArrayListWithCapacity(label.getValues().size());
|
||||
for (LabelValue value : label.getValues()) {
|
||||
values.add(value.format());
|
||||
values.add(value.format().trim());
|
||||
}
|
||||
rc.setStringList(LABEL, name, KEY_VALUE, values);
|
||||
}
|
||||
|
@@ -31,8 +31,11 @@ import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* A bundle of all entities rooted at a single {@link AccountGroup} entity.
|
||||
@@ -42,6 +45,8 @@ import org.eclipse.jgit.lib.Repository;
|
||||
*/
|
||||
@AutoValue
|
||||
public abstract class GroupBundle {
|
||||
private static final Logger log = LoggerFactory.getLogger(GroupBundle.class);
|
||||
|
||||
static {
|
||||
// Initialization-time checks that the column set hasn't changed since the
|
||||
// last time this file was updated.
|
||||
@@ -63,6 +68,22 @@ public abstract class GroupBundle {
|
||||
checkColumns(AccountGroupMemberAudit.class, 1, 2, 3, 4);
|
||||
}
|
||||
|
||||
public enum Source {
|
||||
REVIEW_DB("ReviewDb"),
|
||||
NOTE_DB("NoteDb");
|
||||
|
||||
private final String name;
|
||||
|
||||
private Source(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class Factory {
|
||||
private final AuditLogReader auditLogReader;
|
||||
@@ -78,11 +99,12 @@ public abstract class GroupBundle {
|
||||
throw new OrmException("Group " + id + " not found");
|
||||
}
|
||||
return create(
|
||||
Source.REVIEW_DB,
|
||||
group,
|
||||
db.accountGroupMembers().byGroup(id),
|
||||
db.accountGroupMembersAudit().byGroup(id),
|
||||
db.accountGroupById().byGroup(id),
|
||||
db.accountGroupByIdAud().byGroup(id));
|
||||
db.accountGroupMembers().byGroup(id).toList(),
|
||||
db.accountGroupMembersAudit().byGroup(id).toList(),
|
||||
db.accountGroupById().byGroup(id).toList(),
|
||||
db.accountGroupByIdAud().byGroup(id).toList());
|
||||
}
|
||||
|
||||
public GroupBundle fromNoteDb(Repository repo, AccountGroup.UUID uuid)
|
||||
@@ -102,6 +124,7 @@ public abstract class GroupBundle {
|
||||
accountGroup.setVisibleToAll(internalGroup.isVisibleToAll());
|
||||
|
||||
return create(
|
||||
Source.NOTE_DB,
|
||||
accountGroup,
|
||||
internalGroup
|
||||
.getMembers()
|
||||
@@ -123,20 +146,43 @@ public abstract class GroupBundle {
|
||||
}
|
||||
|
||||
public static GroupBundle create(
|
||||
Source source,
|
||||
AccountGroup group,
|
||||
Iterable<AccountGroupMember> members,
|
||||
Iterable<AccountGroupMemberAudit> memberAudit,
|
||||
Iterable<AccountGroupById> byId,
|
||||
Iterable<AccountGroupByIdAud> byIdAudit) {
|
||||
Collection<AccountGroupMember> members,
|
||||
Collection<AccountGroupMemberAudit> memberAudit,
|
||||
Collection<AccountGroupById> byId,
|
||||
Collection<AccountGroupByIdAud> byIdAudit) {
|
||||
AccountGroup.UUID uuid = group.getGroupUUID();
|
||||
return new AutoValue_GroupBundle.Builder()
|
||||
.group(group)
|
||||
.members(members)
|
||||
.memberAudit(memberAudit)
|
||||
.byId(byId)
|
||||
.byIdAudit(byIdAudit)
|
||||
.members(logIfNotUnique(source, uuid, members, AccountGroupMember.class))
|
||||
.memberAudit(logIfNotUnique(source, uuid, memberAudit, AccountGroupMemberAudit.class))
|
||||
.byId(logIfNotUnique(source, uuid, byId, AccountGroupById.class))
|
||||
.byIdAudit(logIfNotUnique(source, uuid, byIdAudit, AccountGroupByIdAud.class))
|
||||
.build();
|
||||
}
|
||||
|
||||
private static <T> ImmutableSet<T> logIfNotUnique(
|
||||
Source source, AccountGroup.UUID uuid, Collection<T> collection, Class<T> clazz) {
|
||||
ImmutableSet<T> set = ImmutableSet.copyOf(collection);
|
||||
if (set.size() != collection.size()) {
|
||||
// One way this can happen is that distinct audit entities can compare equal, because
|
||||
// AccountGroup{MemberAudit,ByIdAud}.Key does not include the addedOn timestamp in its
|
||||
// members() list. However, this particular issue only applies to pure adds, since removedOn
|
||||
// *is* included in equality. As a result, if this happens, it means the audit log is already
|
||||
// corrupt, and it's not clear if we can programmatically repair it. For migrating to NoteDb,
|
||||
// we'll try our best to recreate it, but no guarantees it will match the real sequence of
|
||||
// attempted operations, which is in any case lost in the mists of time.
|
||||
log.warn(
|
||||
"group {} in {} has duplicate {} entities: {}",
|
||||
uuid,
|
||||
source,
|
||||
clazz.getSimpleName(),
|
||||
collection);
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
static Builder builder() {
|
||||
return new AutoValue_GroupBundle.Builder().members().memberAudit().byId().byIdAudit();
|
||||
}
|
||||
|
@@ -1187,6 +1187,17 @@ public class GroupsIT extends AbstractDaemonTest {
|
||||
assertStaleGroupAndReindex(groupUuid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groupNamesWithLeadingAndTrailingWhitespace() throws Exception {
|
||||
for (String leading : ImmutableList.of("", " ", " ")) {
|
||||
for (String trailing : ImmutableList.of("", " ", " ")) {
|
||||
String name = leading + name("group") + trailing;
|
||||
GroupInfo g = gApi.groups().create(name).get();
|
||||
assertThat(g.name).isEqualTo(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void assertStaleGroupAndReindex(AccountGroup.UUID groupUuid) throws IOException {
|
||||
// Evict group from cache to be sure that we use the index state for staleness checks. This has
|
||||
// to happen directly on the groupsByUUID cache because GroupsCacheImpl triggers a reindex for
|
||||
|
@@ -29,8 +29,8 @@ import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.server.config.PluginConfig;
|
||||
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
|
||||
import com.google.gwtorm.client.KeyUtil;
|
||||
import com.google.gwtorm.server.StandardKeyEncoder;
|
||||
import com.google.gerrit.server.project.testing.Util;
|
||||
import com.google.gerrit.testing.GerritBaseTests;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -38,7 +38,8 @@ import java.util.Map;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
|
||||
import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
|
||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.RefUpdate;
|
||||
@@ -48,26 +49,25 @@ import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevObject;
|
||||
import org.eclipse.jgit.util.RawParseUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
public class ProjectConfigTest extends GerritBaseTests {
|
||||
private static final String LABEL_SCORES_CONFIG =
|
||||
" copyMinScore = "
|
||||
+ !LabelType.DEF_COPY_MIN_SCORE
|
||||
+ "\n" //
|
||||
+ "\n"
|
||||
+ " copyMaxScore = "
|
||||
+ !LabelType.DEF_COPY_MAX_SCORE
|
||||
+ "\n" //
|
||||
+ "\n"
|
||||
+ " copyAllScoresOnMergeFirstParentUpdate = "
|
||||
+ !LabelType.DEF_COPY_ALL_SCORES_ON_MERGE_FIRST_PARENT_UPDATE
|
||||
+ "\n" //
|
||||
+ "\n"
|
||||
+ " copyAllScoresOnTrivialRebase = "
|
||||
+ !LabelType.DEF_COPY_ALL_SCORES_ON_TRIVIAL_REBASE
|
||||
+ "\n" //
|
||||
+ "\n"
|
||||
+ " copyAllScoresIfNoCodeChange = "
|
||||
+ !LabelType.DEF_COPY_ALL_SCORES_IF_NO_CODE_CHANGE
|
||||
+ "\n" //
|
||||
+ "\n"
|
||||
+ " copyAllScoresIfNoChange = "
|
||||
+ !LabelType.DEF_COPY_ALL_SCORES_IF_NO_CHANGE
|
||||
+ "\n";
|
||||
@@ -77,46 +77,36 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
private final GroupReference staff = new GroupReference(new AccountGroup.UUID("Y"), "Staff");
|
||||
|
||||
private Repository db;
|
||||
private TestRepository<Repository> util;
|
||||
private TestRepository<?> tr;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpOnce() {
|
||||
KeyUtil.setEncoderImpl(new StandardKeyEncoder());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
db = createBareRepository();
|
||||
util = new TestRepository<>(db);
|
||||
db = new InMemoryRepository(new DfsRepositoryDescription("repo"));
|
||||
tr = new TestRepository<>(db);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readConfig() throws Exception {
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[access \"refs/heads/*\"]\n" //
|
||||
+ " exclusiveGroupPermissions = read submit create\n" //
|
||||
+ " submit = group Developers\n" //
|
||||
+ " push = group Developers\n" //
|
||||
+ " read = group Developers\n" //
|
||||
+ "[accounts]\n" //
|
||||
+ " sameGroupVisibility = deny group Developers\n" //
|
||||
+ " sameGroupVisibility = block group Staff\n" //
|
||||
+ "[contributor-agreement \"Individual\"]\n" //
|
||||
+ " description = A simple description\n" //
|
||||
+ " accepted = group Developers\n" //
|
||||
+ " accepted = group Staff\n" //
|
||||
+ " autoVerify = group Developers\n" //
|
||||
+ " agreementUrl = http://www.example.com/agree\n")) //
|
||||
));
|
||||
tr.commit()
|
||||
.add("groups", group(developers))
|
||||
.add(
|
||||
"project.config",
|
||||
"[access \"refs/heads/*\"]\n"
|
||||
+ " exclusiveGroupPermissions = read submit create\n"
|
||||
+ " submit = group Developers\n"
|
||||
+ " push = group Developers\n"
|
||||
+ " read = group Developers\n"
|
||||
+ "[accounts]\n"
|
||||
+ " sameGroupVisibility = deny group Developers\n"
|
||||
+ " sameGroupVisibility = block group Staff\n"
|
||||
+ "[contributor-agreement \"Individual\"]\n"
|
||||
+ " description = A simple description\n"
|
||||
+ " accepted = group Developers\n"
|
||||
+ " accepted = group Staff\n"
|
||||
+ " autoVerify = group Developers\n"
|
||||
+ " agreementUrl = http://www.example.com/agree\n")
|
||||
.create();
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
assertThat(cfg.getAccountsSection().getSameGroupVisibility()).hasSize(2);
|
||||
@@ -147,18 +137,36 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
@Test
|
||||
public void readConfigLabelDefaultValue() throws Exception {
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ " value = -1 Negative\n" //
|
||||
+ " value = 0 No Score\n" //
|
||||
+ " value = 1 Positive\n")) //
|
||||
));
|
||||
tr.commit()
|
||||
.add("groups", group(developers))
|
||||
.add(
|
||||
"project.config",
|
||||
"[label \"CustomLabel\"]\n"
|
||||
+ " value = -1 Negative\n"
|
||||
// No leading space before 0.
|
||||
+ " value = 0 No Score\n"
|
||||
+ " value = 1 Positive\n")
|
||||
.create();
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
Map<String, LabelType> labels = cfg.getLabelSections();
|
||||
Short dv = labels.entrySet().iterator().next().getValue().getDefaultValue();
|
||||
assertThat((int) dv).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readConfigLabelOldStyleWithLeadingSpace() throws Exception {
|
||||
RevCommit rev =
|
||||
tr.commit()
|
||||
.add("groups", group(developers))
|
||||
.add(
|
||||
"project.config",
|
||||
"[label \"CustomLabel\"]\n"
|
||||
+ " value = -1 Negative\n"
|
||||
// Leading space before 0.
|
||||
+ " value = 0 No Score\n"
|
||||
+ " value = 1 Positive\n")
|
||||
.create();
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
Map<String, LabelType> labels = cfg.getLabelSections();
|
||||
@@ -169,19 +177,16 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
@Test
|
||||
public void readConfigLabelDefaultValueInRange() throws Exception {
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ " value = -1 Negative\n" //
|
||||
+ " value = 0 No Score\n" //
|
||||
+ " value = 1 Positive\n" //
|
||||
+ " defaultValue = -1\n")) //
|
||||
));
|
||||
tr.commit()
|
||||
.add("groups", group(developers))
|
||||
.add(
|
||||
"project.config",
|
||||
"[label \"CustomLabel\"]\n"
|
||||
+ " value = -1 Negative\n"
|
||||
+ " value = 0 No Score\n"
|
||||
+ " value = 1 Positive\n"
|
||||
+ " defaultValue = -1\n")
|
||||
.create();
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
Map<String, LabelType> labels = cfg.getLabelSections();
|
||||
@@ -192,19 +197,16 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
@Test
|
||||
public void readConfigLabelDefaultValueNotInRange() throws Exception {
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ " value = -1 Negative\n" //
|
||||
+ " value = 0 No Score\n" //
|
||||
+ " value = 1 Positive\n" //
|
||||
+ " defaultValue = -2\n")) //
|
||||
));
|
||||
tr.commit()
|
||||
.add("groups", group(developers))
|
||||
.add(
|
||||
"project.config",
|
||||
"[label \"CustomLabel\"]\n"
|
||||
+ " value = -1 Negative\n"
|
||||
+ " value = 0 No Score\n"
|
||||
+ " value = 1 Positive\n"
|
||||
+ " defaultValue = -2\n")
|
||||
.create();
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
assertThat(cfg.getValidationErrors()).hasSize(1);
|
||||
@@ -215,16 +217,10 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
@Test
|
||||
public void readConfigLabelScores() throws Exception {
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ LABEL_SCORES_CONFIG)) //
|
||||
));
|
||||
tr.commit()
|
||||
.add("groups", group(developers))
|
||||
.add("project.config", "[label \"CustomLabel\"]\n" + LABEL_SCORES_CONFIG)
|
||||
.create();
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
Map<String, LabelType> labels = cfg.getLabelSections();
|
||||
@@ -244,29 +240,26 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
@Test
|
||||
public void editConfig() throws Exception {
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[access \"refs/heads/*\"]\n" //
|
||||
+ " exclusiveGroupPermissions = read submit\n" //
|
||||
+ " submit = group Developers\n" //
|
||||
+ " upload = group Developers\n" //
|
||||
+ " read = group Developers\n" //
|
||||
+ "[accounts]\n" //
|
||||
+ " sameGroupVisibility = deny group Developers\n" //
|
||||
+ " sameGroupVisibility = block group Staff\n" //
|
||||
+ "[contributor-agreement \"Individual\"]\n" //
|
||||
+ " description = A simple description\n" //
|
||||
+ " accepted = group Developers\n" //
|
||||
+ " autoVerify = group Developers\n" //
|
||||
+ " agreementUrl = http://www.example.com/agree\n" //
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ LABEL_SCORES_CONFIG)) //
|
||||
));
|
||||
tr.commit()
|
||||
.add("groups", group(developers))
|
||||
.add(
|
||||
"project.config",
|
||||
"[access \"refs/heads/*\"]\n"
|
||||
+ " exclusiveGroupPermissions = read submit\n"
|
||||
+ " submit = group Developers\n"
|
||||
+ " upload = group Developers\n"
|
||||
+ " read = group Developers\n"
|
||||
+ "[accounts]\n"
|
||||
+ " sameGroupVisibility = deny group Developers\n"
|
||||
+ " sameGroupVisibility = block group Staff\n"
|
||||
+ "[contributor-agreement \"Individual\"]\n"
|
||||
+ " description = A simple description\n"
|
||||
+ " accepted = group Developers\n"
|
||||
+ " autoVerify = group Developers\n"
|
||||
+ " agreementUrl = http://www.example.com/agree\n"
|
||||
+ "[label \"CustomLabel\"]\n"
|
||||
+ LABEL_SCORES_CONFIG)
|
||||
.create();
|
||||
update(rev);
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
@@ -282,41 +275,62 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
rev = commit(cfg);
|
||||
assertThat(text(rev, "project.config"))
|
||||
.isEqualTo(
|
||||
"" //
|
||||
+ "[access \"refs/heads/*\"]\n" //
|
||||
+ " exclusiveGroupPermissions = read submit\n" //
|
||||
+ " submit = group Developers\n" //
|
||||
+ "\tsubmit = group Staff\n" //
|
||||
+ " upload = group Developers\n" //
|
||||
+ " read = group Developers\n" //
|
||||
+ "[accounts]\n" //
|
||||
+ " sameGroupVisibility = group Staff\n" //
|
||||
+ "[contributor-agreement \"Individual\"]\n" //
|
||||
+ " description = A new description\n" //
|
||||
+ " accepted = group Staff\n" //
|
||||
"[access \"refs/heads/*\"]\n"
|
||||
+ " exclusiveGroupPermissions = read submit\n"
|
||||
+ " submit = group Developers\n"
|
||||
+ "\tsubmit = group Staff\n"
|
||||
+ " upload = group Developers\n"
|
||||
+ " read = group Developers\n"
|
||||
+ "[accounts]\n"
|
||||
+ " sameGroupVisibility = group Staff\n"
|
||||
+ "[contributor-agreement \"Individual\"]\n"
|
||||
+ " description = A new description\n"
|
||||
+ " accepted = group Staff\n"
|
||||
+ " agreementUrl = http://www.example.com/agree\n"
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ "[label \"CustomLabel\"]\n"
|
||||
+ LABEL_SCORES_CONFIG
|
||||
+ "\tfunction = MaxWithBlock\n" // label gets this function when it is created
|
||||
+ "\tdefaultValue = 0\n"); // label gets this value when it is created
|
||||
}
|
||||
|
||||
@Test
|
||||
public void editConfigLabelValues() throws Exception {
|
||||
RevCommit rev = tr.commit().create();
|
||||
update(rev);
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
cfg.getLabelSections()
|
||||
.put(
|
||||
"My-Label",
|
||||
Util.category(
|
||||
"My-Label",
|
||||
Util.value(-1, "Negative"),
|
||||
Util.value(0, "No score"),
|
||||
Util.value(1, "Positive")));
|
||||
rev = commit(cfg);
|
||||
assertThat(text(rev, "project.config"))
|
||||
.isEqualTo(
|
||||
"[label \"My-Label\"]\n"
|
||||
+ "\tfunction = MaxWithBlock\n"
|
||||
+ "\tdefaultValue = 0\n"
|
||||
+ "\tvalue = -1 Negative\n"
|
||||
+ "\tvalue = 0 No score\n"
|
||||
+ "\tvalue = +1 Positive\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void editConfigMissingGroupTableEntry() throws Exception {
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[access \"refs/heads/*\"]\n" //
|
||||
+ " exclusiveGroupPermissions = read submit\n" //
|
||||
+ " submit = group People Who Can Submit\n" //
|
||||
+ " upload = group Developers\n" //
|
||||
+ " read = group Developers\n")) //
|
||||
));
|
||||
tr.commit()
|
||||
.add("groups", group(developers))
|
||||
.add(
|
||||
"project.config",
|
||||
"[access \"refs/heads/*\"]\n"
|
||||
+ " exclusiveGroupPermissions = read submit\n"
|
||||
+ " submit = group People Who Can Submit\n"
|
||||
+ " upload = group Developers\n"
|
||||
+ " read = group Developers\n")
|
||||
.create();
|
||||
update(rev);
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
@@ -326,29 +340,25 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
rev = commit(cfg);
|
||||
assertThat(text(rev, "project.config"))
|
||||
.isEqualTo(
|
||||
"" //
|
||||
+ "[access \"refs/heads/*\"]\n" //
|
||||
+ " exclusiveGroupPermissions = read submit\n" //
|
||||
+ " submit = group People Who Can Submit\n" //
|
||||
+ "\tsubmit = group Staff\n" //
|
||||
+ " upload = group Developers\n" //
|
||||
"[access \"refs/heads/*\"]\n"
|
||||
+ " exclusiveGroupPermissions = read submit\n"
|
||||
+ " submit = group People Who Can Submit\n"
|
||||
+ "\tsubmit = group Staff\n"
|
||||
+ " upload = group Developers\n"
|
||||
+ " read = group Developers\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readExistingPluginConfig() throws Exception {
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[plugin \"somePlugin\"]\n" //
|
||||
+ " key1 = value1\n" //
|
||||
+ " key2 = value2a\n"
|
||||
+ " key2 = value2b\n")) //
|
||||
));
|
||||
tr.commit()
|
||||
.add(
|
||||
"project.config",
|
||||
"[plugin \"somePlugin\"]\n"
|
||||
+ " key1 = value1\n"
|
||||
+ " key2 = value2a\n"
|
||||
+ " key2 = value2b\n")
|
||||
.create();
|
||||
update(rev);
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
@@ -369,17 +379,14 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
@Test
|
||||
public void editPluginConfig() throws Exception {
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[plugin \"somePlugin\"]\n" //
|
||||
+ " key1 = value1\n" //
|
||||
+ " key2 = value2a\n" //
|
||||
+ " key2 = value2b\n")) //
|
||||
));
|
||||
tr.commit()
|
||||
.add(
|
||||
"project.config",
|
||||
"[plugin \"somePlugin\"]\n"
|
||||
+ " key1 = value1\n"
|
||||
+ " key2 = value2a\n"
|
||||
+ " key2 = value2b\n")
|
||||
.create();
|
||||
update(rev);
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
@@ -389,28 +396,19 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
rev = commit(cfg);
|
||||
assertThat(text(rev, "project.config"))
|
||||
.isEqualTo(
|
||||
"" //
|
||||
+ "[plugin \"somePlugin\"]\n" //
|
||||
+ "\tkey1 = updatedValue1\n" //
|
||||
+ "\tkey2 = updatedValue2a\n" //
|
||||
"[plugin \"somePlugin\"]\n"
|
||||
+ "\tkey1 = updatedValue1\n"
|
||||
+ "\tkey2 = updatedValue2a\n"
|
||||
+ "\tkey2 = updatedValue2b\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readPluginConfigGroupReference() throws Exception {
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[plugin \"somePlugin\"]\n" //
|
||||
+ "key1 = "
|
||||
+ developers.toConfigValue()
|
||||
+ "\n")) //
|
||||
));
|
||||
tr.commit()
|
||||
.add("groups", group(developers))
|
||||
.add("project.config", "[plugin \"somePlugin\"]\nkey1 = " + developers.toConfigValue())
|
||||
.create();
|
||||
update(rev);
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
@@ -422,18 +420,10 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
@Test
|
||||
public void readPluginConfigGroupReferenceNotInGroupsFile() throws Exception {
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[plugin \"somePlugin\"]\n" //
|
||||
+ "key1 = "
|
||||
+ staff.toConfigValue()
|
||||
+ "\n")) //
|
||||
));
|
||||
tr.commit()
|
||||
.add("groups", group(developers))
|
||||
.add("project.config", "[plugin \"somePlugin\"]\nkey1 = " + staff.toConfigValue())
|
||||
.create();
|
||||
update(rev);
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
@@ -446,18 +436,10 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
@Test
|
||||
public void editPluginConfigGroupReference() throws Exception {
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[plugin \"somePlugin\"]\n" //
|
||||
+ "key1 = "
|
||||
+ developers.toConfigValue()
|
||||
+ "\n")) //
|
||||
));
|
||||
tr.commit()
|
||||
.add("groups", group(developers))
|
||||
.add("project.config", "[plugin \"somePlugin\"]\nkey1 = " + developers.toConfigValue())
|
||||
.create();
|
||||
update(rev);
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
@@ -468,16 +450,11 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
pluginCfg.setGroupReference("key1", staff);
|
||||
rev = commit(cfg);
|
||||
assertThat(text(rev, "project.config"))
|
||||
.isEqualTo(
|
||||
"" //
|
||||
+ "[plugin \"somePlugin\"]\n" //
|
||||
+ "\tkey1 = "
|
||||
+ staff.toConfigValue()
|
||||
+ "\n");
|
||||
.isEqualTo("[plugin \"somePlugin\"]\n\tkey1 = " + staff.toConfigValue() + "\n");
|
||||
assertThat(text(rev, "groups"))
|
||||
.isEqualTo(
|
||||
"# UUID\tGroup Name\n" //
|
||||
+ "#\n" //
|
||||
"# UUID\tGroup Name\n"
|
||||
+ "#\n"
|
||||
+ staff.getUUID().get()
|
||||
+ " \t"
|
||||
+ staff.getName()
|
||||
@@ -494,13 +471,13 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
throws IOException, MissingObjectException, IncorrectObjectTypeException {
|
||||
try (MetaDataUpdate md =
|
||||
new MetaDataUpdate(GitReferenceUpdated.DISABLED, cfg.getProject().getNameKey(), db)) {
|
||||
util.tick(5);
|
||||
util.setAuthorAndCommitter(md.getCommitBuilder());
|
||||
tr.tick(5);
|
||||
tr.setAuthorAndCommitter(md.getCommitBuilder());
|
||||
md.setMessage("Edit\n");
|
||||
cfg.commit(md);
|
||||
|
||||
Ref ref = db.exactRef(RefNames.REFS_CONFIG);
|
||||
return util.getRevWalk().parseCommit(ref.getObjectId());
|
||||
return tr.getRevWalk().parseCommit(ref.getObjectId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,7 +492,7 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
}
|
||||
|
||||
private String text(RevCommit rev, String path) throws Exception {
|
||||
RevObject blob = util.get(rev.getTree(), path);
|
||||
RevObject blob = tr.get(rev.getTree(), path);
|
||||
byte[] data = db.open(blob).getCachedBytes(Integer.MAX_VALUE);
|
||||
return RawParseUtils.decode(data);
|
||||
}
|
||||
|
@@ -403,6 +403,18 @@ public class GroupRebuilderTest extends AbstractGroupTest {
|
||||
assertThat(GroupTestUtil.readNameToUuidMap(repo)).containsExactly("a", "a-1", "b", "b-2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groupNamesWithLeadingAndTrailingWhitespace() throws Exception {
|
||||
for (String leading : ImmutableList.of("", " ", " ")) {
|
||||
for (String trailing : ImmutableList.of("", " ", " ")) {
|
||||
AccountGroup g = newGroup(leading + "a" + trailing);
|
||||
GroupBundle b = builder().group(g).build();
|
||||
rebuilder.rebuild(repo, b, null);
|
||||
assertThat(reload(g)).isEqualTo(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GroupBundle reload(AccountGroup g) throws Exception {
|
||||
return bundleFactory.fromNoteDb(repo, g.getGroupUUID());
|
||||
}
|
||||
@@ -412,7 +424,7 @@ public class GroupRebuilderTest extends AbstractGroupTest {
|
||||
return new AccountGroup(
|
||||
new AccountGroup.NameKey(name),
|
||||
new AccountGroup.Id(id),
|
||||
new AccountGroup.UUID(name + "-" + id),
|
||||
new AccountGroup.UUID(name.trim() + "-" + id),
|
||||
TimeUtil.nowTs());
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
load("//tools/bzl:maven_jar.bzl", "GERRIT", "MAVEN_LOCAL", "MAVEN_CENTRAL", "maven_jar")
|
||||
|
||||
_JGIT_VERS = "4.9.0.201710071750-r.30-g651e17bac"
|
||||
_JGIT_VERS = "4.9.0.201710071750-r.65-g8b3ab4343"
|
||||
|
||||
_DOC_VERS = "4.9.0.201710071750-r" # Set to _JGIT_VERS unless using a snapshot
|
||||
|
||||
@@ -26,28 +26,28 @@ def jgit_maven_repos():
|
||||
name = "jgit_lib",
|
||||
artifact = "org.eclipse.jgit:org.eclipse.jgit:" + _JGIT_VERS,
|
||||
repository = _JGIT_REPO,
|
||||
sha1 = "5f0ab69e6dd369c9efcf2fc23f7ae923113d6d3d",
|
||||
src_sha1 = "8dcfff9612815fc1b2bb0e8d032c9b99a6ed89e4",
|
||||
sha1 = "5e9a6147583d2071da3a4eb55b1da5955793da45",
|
||||
src_sha1 = "61fee1a923b718b81b1e0f763865a222a78ed3d5",
|
||||
unsign = True,
|
||||
)
|
||||
maven_jar(
|
||||
name = "jgit_servlet",
|
||||
artifact = "org.eclipse.jgit:org.eclipse.jgit.http.server:" + _JGIT_VERS,
|
||||
repository = _JGIT_REPO,
|
||||
sha1 = "58629a74278c502f7fb6926b9a4b483da46072b5",
|
||||
sha1 = "f769fd0052de1eb5d78760683ca8d5cdb2c28e8a",
|
||||
unsign = True,
|
||||
)
|
||||
maven_jar(
|
||||
name = "jgit_archive",
|
||||
artifact = "org.eclipse.jgit:org.eclipse.jgit.archive:" + _JGIT_VERS,
|
||||
repository = _JGIT_REPO,
|
||||
sha1 = "a31a98bac30977bbad867aa89a0338d3260eb46a",
|
||||
sha1 = "ea97248007428a3e5a552eb93ae9b71fc041fcb9",
|
||||
)
|
||||
maven_jar(
|
||||
name = "jgit_junit",
|
||||
artifact = "org.eclipse.jgit:org.eclipse.jgit.junit:" + _JGIT_VERS,
|
||||
repository = _JGIT_REPO,
|
||||
sha1 = "358989980e6faf77c3af955f5eea268020a6407d",
|
||||
sha1 = "b9ddbf0819f6411ecb616eabcabdbd3ea4ead9a3",
|
||||
unsign = True,
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user