use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.
the class WatchConfigTest method parseWatchConfig.
@Test
public void parseWatchConfig() throws Exception {
Config cfg = new Config();
cfg.fromText("[project \"myProject\"]\n" + " notify = * [ALL_COMMENTS, NEW_PATCHSETS]\n" + " notify = branch:master [NEW_CHANGES]\n" + " notify = branch:master [NEW_PATCHSETS]\n" + " notify = branch:foo []\n" + "[project \"otherProject\"]\n" + " notify = [NEW_PATCHSETS]\n" + " notify = * [NEW_PATCHSETS, ALL_COMMENTS]\n");
Map<ProjectWatchKey, Set<NotifyType>> projectWatches = WatchConfig.parse(new Account.Id(1000000), cfg, this);
assertThat(validationErrors).isEmpty();
Project.NameKey myProject = new Project.NameKey("myProject");
Project.NameKey otherProject = new Project.NameKey("otherProject");
Map<ProjectWatchKey, Set<NotifyType>> expectedProjectWatches = new HashMap<>();
expectedProjectWatches.put(ProjectWatchKey.create(myProject, null), EnumSet.of(NotifyType.ALL_COMMENTS, NotifyType.NEW_PATCHSETS));
expectedProjectWatches.put(ProjectWatchKey.create(myProject, "branch:master"), EnumSet.of(NotifyType.NEW_CHANGES, NotifyType.NEW_PATCHSETS));
expectedProjectWatches.put(ProjectWatchKey.create(myProject, "branch:foo"), EnumSet.noneOf(NotifyType.class));
expectedProjectWatches.put(ProjectWatchKey.create(otherProject, null), EnumSet.of(NotifyType.NEW_PATCHSETS));
expectedProjectWatches.put(ProjectWatchKey.create(otherProject, null), EnumSet.of(NotifyType.ALL_COMMENTS, NotifyType.NEW_PATCHSETS));
assertThat(projectWatches).containsExactlyEntriesIn(expectedProjectWatches);
}
use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.
the class WalkSorterTest method newChange.
private ChangeData newChange(TestRepository<Repo> tr, ObjectId id) throws Exception {
Project.NameKey project = tr.getRepository().getDescription().getProject();
Change c = TestChanges.newChange(project, userId);
ChangeData cd = ChangeData.createForTest(project, c.getId(), 1);
cd.setChange(c);
cd.currentPatchSet().setRevision(new RevId(id.name()));
cd.setPatchSets(ImmutableList.of(cd.currentPatchSet()));
return cd;
}
use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.
the class ChangeBundleTest method diffChangesSameId.
@Test
public void diffChangesSameId() throws Exception {
Change c1 = TestChanges.newChange(new Project.NameKey("project"), new Account.Id(100));
Change c2 = clone(c1);
ChangeBundle b1 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
ChangeBundle b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
assertNoDiffs(b1, b2);
c2.setTopic("topic");
assertDiffs(b1, b2, "topic differs for Change.Id " + c1.getId() + ": {null} != {topic}");
}
use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.
the class ChangeBundleTest method diffChangesTakesMaxEntityTimestampFromReviewDb.
@Test
public void diffChangesTakesMaxEntityTimestampFromReviewDb() throws Exception {
Change c1 = TestChanges.newChange(new Project.NameKey("project"), new Account.Id(100));
PatchSet ps = new PatchSet(c1.currentPatchSetId());
ps.setRevision(new RevId("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
ps.setUploader(accountId);
ps.setCreatedOn(TimeUtil.nowTs());
PatchSetApproval a = new PatchSetApproval(new PatchSetApproval.Key(c1.currentPatchSetId(), accountId, new LabelId("Code-Review")), (short) 1, TimeUtil.nowTs());
Change c2 = clone(c1);
c2.setLastUpdatedOn(a.getGranted());
// Both ReviewDb, exact match required.
ChangeBundle b1 = new ChangeBundle(c1, messages(), patchSets(ps), approvals(a), comments(), reviewers(), REVIEW_DB);
ChangeBundle b2 = new ChangeBundle(c2, messages(), patchSets(ps), approvals(a), comments(), reviewers(), REVIEW_DB);
assertDiffs(b1, b2, "effective last updated time differs for Change.Id " + c1.getId() + ":" + " {2009-09-30 17:00:00.0} != {2009-09-30 17:00:12.0}");
// NoteDb allows latest timestamp from all entities in bundle.
b2 = new ChangeBundle(c2, messages(), patchSets(ps), approvals(a), comments(), reviewers(), NOTE_DB);
assertNoDiffs(b1, b2);
}
use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.
the class AdminSetParent method run.
@Override
protected void run() throws Failure {
if (oldParent == null && children.isEmpty()) {
throw die("child projects have to be specified as " + "arguments or the --children-of option has to be set");
}
if (oldParent == null && !excludedChildren.isEmpty()) {
throw die("--exclude can only be used together with --children-of");
}
final StringBuilder err = new StringBuilder();
final Set<Project.NameKey> grandParents = new HashSet<>();
grandParents.add(allProjectsName);
if (newParent != null) {
newParentKey = newParent.getProject().getNameKey();
// Catalog all grandparents of the "parent", we want to
// catch a cycle in the parent pointers before it occurs.
//
Project.NameKey gp = newParent.getProject().getParent();
while (gp != null && grandParents.add(gp)) {
final ProjectState s = projectCache.get(gp);
if (s != null) {
gp = s.getProject().getParent();
} else {
break;
}
}
}
final List<Project.NameKey> childProjects = new ArrayList<>();
for (final ProjectControl pc : children) {
childProjects.add(pc.getProject().getNameKey());
}
if (oldParent != null) {
try {
childProjects.addAll(getChildrenForReparenting(oldParent));
} catch (PermissionBackendException e) {
throw new Failure(1, "permissions unavailable", e);
}
}
for (final Project.NameKey nameKey : childProjects) {
final String name = nameKey.get();
if (allProjectsName.equals(nameKey)) {
// Don't allow the wild card project to have a parent.
//
err.append("error: Cannot set parent of '").append(name).append("'\n");
continue;
}
if (grandParents.contains(nameKey) || nameKey.equals(newParentKey)) {
// Try to avoid creating a cycle in the parent pointers.
//
err.append("error: Cycle exists between '").append(name).append("' and '").append(newParentKey != null ? newParentKey.get() : allProjectsName.get()).append("'\n");
continue;
}
try (MetaDataUpdate md = metaDataUpdateFactory.create(nameKey)) {
ProjectConfig config = ProjectConfig.read(md);
config.getProject().setParentName(newParentKey);
md.setMessage("Inherit access from " + (newParentKey != null ? newParentKey.get() : allProjectsName.get()) + "\n");
config.commit(md);
} catch (RepositoryNotFoundException notFound) {
err.append("error: Project ").append(name).append(" not found\n");
} catch (IOException | ConfigInvalidException e) {
final String msg = "Cannot update project " + name;
log.error(msg, e);
err.append("error: ").append(msg).append("\n");
}
projectCache.evict(nameKey);
}
if (err.length() > 0) {
while (err.charAt(err.length() - 1) == '\n') {
err.setLength(err.length() - 1);
}
throw die(err.toString());
}
}
Aggregations