use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.
the class ChangeBundleTest method diffChangesConsidersEmptyReviewDbTopicEquivalentToNullInNoteDb.
@Test
public void diffChangesConsidersEmptyReviewDbTopicEquivalentToNullInNoteDb() throws Exception {
Change c1 = TestChanges.newChange(new Project.NameKey("project"), new Account.Id(100));
c1.setTopic("");
Change c2 = clone(c1);
c2.setTopic(null);
// Both ReviewDb, exact match required.
ChangeBundle b1 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
ChangeBundle b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
assertDiffs(b1, b2, "topic differs for Change.Id " + c1.getId() + ": {} != {null}");
// Topic ignored if ReviewDb is empty and NoteDb is null.
b1 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
assertNoDiffs(b1, b2);
// Exact match still required if NoteDb has empty value (not realistic).
b1 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
assertDiffs(b1, b2, "topic differs for Change.Id " + c1.getId() + ": {} != {null}");
// Null is not equal to a non-empty string.
Change c3 = clone(c1);
c3.setTopic("topic");
b1 = new ChangeBundle(c3, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
assertDiffs(b1, b2, "topic differs for Change.Id " + c1.getId() + ": {topic} != {null}");
// Null is equal to a string that is all whitespace.
Change c4 = clone(c1);
c4.setTopic(" ");
b1 = new ChangeBundle(c4, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
assertNoDiffs(b1, b2);
assertNoDiffs(b2, b1);
}
use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.
the class ChangeIT method createNewDraftPatchSetOnDraftChange.
@Test
public void createNewDraftPatchSetOnDraftChange() throws Exception {
// Create new project with clean permissions
Project.NameKey p = createProject("addPatchSet4");
// Clone separate repositories of the same project as admin and as user
TestRepository<?> adminTestRepo = cloneProject(p, admin);
TestRepository<?> userTestRepo = cloneProject(p, user);
// Block default permission
block(p, "refs/for/*", Permission.ADD_PATCH_SET, REGISTERED_USERS);
// Create change as admin
PushOneCommit push = pushFactory.create(db, admin.getIdent(), adminTestRepo);
PushOneCommit.Result r1 = push.to("refs/drafts/master");
r1.assertOkStatus();
// Add user as reviewer
AddReviewerInput in = new AddReviewerInput();
in.reviewer = user.email;
gApi.changes().id(r1.getChangeId()).addReviewer(in);
// Fetch change
GitUtil.fetch(userTestRepo, r1.getPatchSet().getRefName() + ":ps");
userTestRepo.reset("ps");
// Amend change as user
PushOneCommit.Result r2 = amendChange(r1.getChangeId(), "refs/drafts/master", user, userTestRepo);
r2.assertErrorStatus("cannot add patch set to " + r1.getChange().getId().id + ".");
}
use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.
the class SetParentIT method setInvalidParent_Conflict.
@Test
public void setInvalidParent_Conflict() throws Exception {
RestResponse r = adminRestSession.put("/projects/" + project.get() + "/parent", newParentInput(project.get()));
r.assertConflict();
r.consume();
Project.NameKey child = createProject("child", project, true);
r = adminRestSession.put("/projects/" + project.get() + "/parent", newParentInput(child.get()));
r.assertConflict();
r.consume();
String grandchild = createProject("grandchild", child, true).get();
r = adminRestSession.put("/projects/" + project.get() + "/parent", newParentInput(grandchild));
r.assertConflict();
r.consume();
}
use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.
the class CherryPickCommit method applyImpl.
@Override
public ChangeInfo applyImpl(BatchUpdate.Factory updateFactory, CommitResource rsrc, CherryPickInput input) throws OrmException, IOException, UpdateException, RestApiException {
RevCommit commit = rsrc.getCommit();
String message = Strings.nullToEmpty(input.message).trim();
input.message = message.isEmpty() ? commit.getFullMessage() : message;
String destination = Strings.nullToEmpty(input.destination).trim();
input.parent = input.parent == null ? 1 : input.parent;
if (destination.isEmpty()) {
throw new BadRequestException("destination must be non-empty");
}
ProjectControl projectControl = rsrc.getProject();
Capable capable = projectControl.canPushToAtLeastOneRef();
if (capable != Capable.OK) {
throw new AuthException(capable.getMessage());
}
String refName = RefNames.fullName(destination);
RefControl refControl = projectControl.controlForRef(refName);
if (!refControl.canUpload()) {
throw new AuthException("Not allowed to cherry pick " + commit + " to " + destination);
}
Project.NameKey project = projectControl.getProject().getNameKey();
try {
Change.Id cherryPickedChangeId = cherryPickChange.cherryPick(updateFactory, null, null, null, null, project, commit, input, refName, refControl);
return json.noOptions().format(project, cherryPickedChangeId);
} catch (InvalidChangeOperationException e) {
throw new BadRequestException(e.getMessage());
} catch (IntegrationException e) {
throw new ResourceConflictException(e.getMessage());
}
}
use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.
the class ApplyFix method apply.
@Override
public Response<EditInfo> apply(FixResource fixResource, Void nothing) throws AuthException, OrmException, ResourceConflictException, IOException, ResourceNotFoundException, PermissionBackendException {
RevisionResource revisionResource = fixResource.getRevisionResource();
Project.NameKey project = revisionResource.getProject();
ProjectState projectState = revisionResource.getControl().getProjectControl().getProjectState();
PatchSet patchSet = revisionResource.getPatchSet();
ObjectId patchSetCommitId = ObjectId.fromString(patchSet.getRevision().get());
try (Repository repository = gitRepositoryManager.openRepository(project)) {
List<TreeModification> treeModifications = fixReplacementInterpreter.toTreeModifications(repository, projectState, patchSetCommitId, fixResource.getFixReplacements());
ChangeEdit changeEdit = changeEditModifier.combineWithModifiedPatchSetTree(repository, revisionResource.getControl(), patchSet, treeModifications);
return Response.ok(changeEditJson.toEditInfo(changeEdit, false));
} catch (InvalidChangeOperationException e) {
throw new ResourceConflictException(e.getMessage());
}
}
Aggregations