use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.
the class ProjectConfigTest method readConfig.
@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"))));
ProjectConfig cfg = read(rev);
assertThat(cfg.getAccountsSection().getSameGroupVisibility()).hasSize(2);
ContributorAgreement ca = cfg.getContributorAgreement("Individual");
assertThat(ca.getName()).isEqualTo("Individual");
assertThat(ca.getDescription()).isEqualTo("A simple description");
assertThat(ca.getAgreementUrl()).isEqualTo("http://www.example.com/agree");
assertThat(ca.getAccepted()).hasSize(2);
assertThat(ca.getAccepted().get(0).getGroup()).isEqualTo(developers);
assertThat(ca.getAccepted().get(1).getGroup().getName()).isEqualTo("Staff");
assertThat(ca.getAutoVerify().getName()).isEqualTo("Developers");
AccessSection section = cfg.getAccessSection("refs/heads/*");
assertThat(section).isNotNull();
assertThat(cfg.getAccessSection("refs/*")).isNull();
Permission create = section.getPermission(Permission.CREATE);
Permission submit = section.getPermission(Permission.SUBMIT);
Permission read = section.getPermission(Permission.READ);
Permission push = section.getPermission(Permission.PUSH);
assertThat(create.getExclusiveGroup()).isTrue();
assertThat(submit.getExclusiveGroup()).isTrue();
assertThat(read.getExclusiveGroup()).isTrue();
assertThat(push.getExclusiveGroup()).isFalse();
}
use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.
the class ProjectConfigTest method readConfigLabelDefaultValueInRange.
@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"))));
ProjectConfig cfg = read(rev);
Map<String, LabelType> labels = cfg.getLabelSections();
Short dv = labels.entrySet().iterator().next().getValue().getDefaultValue();
assertThat((int) dv).isEqualTo(-1);
}
use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.
the class ProjectConfigTest method editConfig.
@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))));
update(rev);
ProjectConfig cfg = read(rev);
AccessSection section = cfg.getAccessSection("refs/heads/*");
cfg.getAccountsSection().setSameGroupVisibility(Collections.singletonList(new PermissionRule(cfg.resolve(staff))));
Permission submit = section.getPermission(Permission.SUBMIT);
submit.add(new PermissionRule(cfg.resolve(staff)));
ContributorAgreement ca = cfg.getContributorAgreement("Individual");
ca.setAccepted(Collections.singletonList(new PermissionRule(cfg.resolve(staff))));
ca.setAutoVerify(null);
ca.setDescription("A new description");
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" + " agreementUrl = http://www.example.com/agree\n" + //
"[label \"CustomLabel\"]\n" + LABEL_SCORES_CONFIG + // label gets this function when it is created
"\tfunction = MaxWithBlock\n" + // label gets this value when it is created
"\tdefaultValue = 0\n");
}
use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.
the class ProjectConfigTest method editConfigMissingGroupTableEntry.
@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"))));
update(rev);
ProjectConfig cfg = read(rev);
AccessSection section = cfg.getAccessSection("refs/heads/*");
Permission submit = section.getPermission(Permission.SUBMIT);
submit.add(new PermissionRule(cfg.resolve(staff)));
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" + " read = group Developers\n");
}
use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.
the class ChangeIT method noteDbCommitsOnPatchSetCreation.
@Test
public void noteDbCommitsOnPatchSetCreation() throws Exception {
assume().that(notesMigration.readChanges()).isTrue();
PushOneCommit.Result r = createChange();
pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "b.txt", "4711", r.getChangeId()).to("refs/for/master").assertOkStatus();
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
try (Repository repo = repoManager.openRepository(project);
RevWalk rw = new RevWalk(repo)) {
RevCommit commitPatchSetCreation = rw.parseCommit(repo.exactRef(changeMetaRef(new Change.Id(c._number))).getObjectId());
assertThat(commitPatchSetCreation.getShortMessage()).isEqualTo("Create patch set 2");
PersonIdent expectedAuthor = changeNoteUtil.newIdent(accountCache.get(admin.id).getAccount(), c.updated, serverIdent.get(), AnonymousCowardNameProvider.DEFAULT);
assertThat(commitPatchSetCreation.getAuthorIdent()).isEqualTo(expectedAuthor);
assertThat(commitPatchSetCreation.getCommitterIdent()).isEqualTo(new PersonIdent(serverIdent.get(), c.updated));
assertThat(commitPatchSetCreation.getParentCount()).isEqualTo(1);
RevCommit commitChangeCreation = rw.parseCommit(commitPatchSetCreation.getParent(0));
assertThat(commitChangeCreation.getShortMessage()).isEqualTo("Create change");
expectedAuthor = changeNoteUtil.newIdent(accountCache.get(admin.id).getAccount(), c.created, serverIdent.get(), AnonymousCowardNameProvider.DEFAULT);
assertThat(commitChangeCreation.getAuthorIdent()).isEqualTo(expectedAuthor);
assertThat(commitChangeCreation.getCommitterIdent()).isEqualTo(new PersonIdent(serverIdent.get(), c.created));
assertThat(commitChangeCreation.getParentCount()).isEqualTo(0);
}
}
Aggregations