Search in sources :

Example 21 with ChangeNotes

use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method extensionApiReturnsUpdatedValueAfterFix.

@Test
public void extensionApiReturnsUpdatedValueAfterFix() throws Exception {
    ChangeNotes notes = insertChange();
    ObjectId commitId = psUtil.current(notes).commitId();
    serverSideTestRepo.branch(notes.getChange().getDest().branch()).update(serverSideTestRepo.getRevWalk().parseCommit(commitId));
    ChangeInfo info = gApi.changes().id(notes.getChangeId().get()).info();
    assertThat(info.status).isEqualTo(ChangeStatus.NEW);
    info = gApi.changes().id(notes.getChangeId().get()).check(new FixInput());
    assertThat(info.status).isEqualTo(ChangeStatus.MERGED);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) FixInput(com.google.gerrit.extensions.api.changes.FixInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 22 with ChangeNotes

use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method patchSetRefMissing.

@Test
public void patchSetRefMissing() throws Exception {
    ChangeNotes notes = insertChange();
    serverSideTestRepo.update("refs/other/foo", psUtil.current(notes).commitId());
    String refName = notes.getChange().currentPatchSetId().toRefName();
    deleteRef(refName);
    assertProblems(notes, null, problem("Ref missing: " + refName));
}
Also used : ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 23 with ChangeNotes

use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method newChangeIsMerged.

@Test
public void newChangeIsMerged() throws Exception {
    ChangeNotes notes = insertChange();
    ObjectId commitId = psUtil.current(notes).commitId();
    serverSideTestRepo.branch(notes.getChange().getDest().branch()).update(serverSideTestRepo.getRevWalk().parseCommit(commitId));
    assertProblems(notes, null, problem("Patch set 1 (" + commitId.name() + ") is merged into destination ref" + " refs/heads/master (" + commitId.name() + "), but change status is NEW"));
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 24 with ChangeNotes

use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.

the class CatServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
    String keyStr = req.getPathInfo();
    // We shouldn't have to do this extra decode pass, but somehow we
    // are now receiving our "^1" suffix as "%5E1", which confuses us
    // downstream. Other times we get our embedded "," as "%2C", which
    // is equally bad. And yet when these happen a "%2F" is left as-is,
    // rather than escaped as "%252F", which makes me feel really really
    // uncomfortable with a blind decode right here.
    // 
    keyStr = Url.decode(keyStr);
    if (!keyStr.startsWith("/")) {
        rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    keyStr = keyStr.substring(1);
    final Patch.Key patchKey;
    final int side;
    {
        final int c = keyStr.lastIndexOf('^');
        if (c == 0) {
            rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        if (c < 0) {
            side = 0;
        } else {
            try {
                side = Integer.parseInt(keyStr.substring(c + 1));
                keyStr = keyStr.substring(0, c);
            } catch (NumberFormatException e) {
                rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }
        }
        try {
            patchKey = Patch.Key.parse(keyStr);
        } catch (NumberFormatException e) {
            rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
    }
    final Change.Id changeId = patchKey.patchSetId().changeId();
    String revision;
    try {
        ChangeNotes notes = changeNotesFactory.createCheckedUsingIndexLookup(changeId);
        permissionBackend.currentUser().change(notes).check(ChangePermission.READ);
        projectCache.get(notes.getProjectName()).orElseThrow(illegalState(notes.getProjectName())).checkStatePermitsRead();
        if (patchKey.patchSetId().get() == 0) {
            // change edit
            Optional<ChangeEdit> edit = changeEditUtil.byChange(notes);
            if (edit.isPresent()) {
                revision = ObjectId.toString(edit.get().getEditCommit());
            } else {
                rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }
        } else {
            PatchSet patchSet = psUtil.get(notes, patchKey.patchSetId());
            if (patchSet == null) {
                rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }
            revision = patchSet.commitId().name();
        }
    } catch (ResourceConflictException | NoSuchChangeException | AuthException e) {
        rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    } catch (PermissionBackendException | IOException e) {
        getServletContext().log("Cannot query database", e);
        rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return;
    }
    String path = patchKey.fileName();
    String restUrl = String.format("%s/changes/%d/revisions/%s/files/%s/download?parent=%d", req.getContextPath(), changeId.get(), revision, Url.encode(path), side);
    rsp.sendRedirect(restUrl);
}
Also used : ChangeEdit(com.google.gerrit.server.edit.ChangeEdit) AuthException(com.google.gerrit.extensions.restapi.AuthException) PatchSet(com.google.gerrit.entities.PatchSet) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) Change(com.google.gerrit.entities.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IOException(java.io.IOException) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) Patch(com.google.gerrit.entities.Patch)

Example 25 with ChangeNotes

use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.

the class CommentCumulativeSizeValidator method validateComments.

@Override
public ImmutableList<CommentValidationFailure> validateComments(CommentValidationContext ctx, ImmutableList<CommentForValidation> comments) {
    ChangeNotes notes = notesFactory.createChecked(Project.nameKey(ctx.getProject()), Change.id(ctx.getChangeId()));
    int existingCumulativeSize = Stream.concat(notes.getHumanComments().values().stream(), notes.getRobotComments().values().stream()).mapToInt(Comment::getApproximateSize).sum() + notes.getChangeMessages().stream().mapToInt(cm -> cm.getMessage().length()).sum();
    int newCumulativeSize = comments.stream().mapToInt(CommentForValidation::getApproximateSize).sum();
    ImmutableList.Builder<CommentValidationFailure> failures = ImmutableList.builder();
    if (!comments.isEmpty() && !isEnoughSpace(notes, newCumulativeSize, maxCumulativeSize)) {
        // This warning really applies to the set of all comments, but we need to pick one to attach
        // the message to.
        CommentForValidation commentForFailureMessage = Iterables.getLast(comments);
        failures.add(commentForFailureMessage.failValidation(String.format("Exceeding maximum cumulative size of comments and change messages:" + " %d (existing) + %d (new) > %d", existingCumulativeSize, newCumulativeSize, maxCumulativeSize)));
    }
    return failures.build();
}
Also used : Comment(com.google.gerrit.entities.Comment) CommentValidationFailure(com.google.gerrit.extensions.validators.CommentValidationFailure) ImmutableList(com.google.common.collect.ImmutableList) CommentForValidation(com.google.gerrit.extensions.validators.CommentForValidation) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes)

Aggregations

ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)134 Test (org.junit.Test)54 Change (com.google.gerrit.entities.Change)47 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)43 PatchSet (com.google.gerrit.entities.PatchSet)42 ObjectId (org.eclipse.jgit.lib.ObjectId)33 StorageException (com.google.gerrit.exceptions.StorageException)22 Change (com.google.gerrit.reviewdb.client.Change)21 Project (com.google.gerrit.entities.Project)17 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)16 FixInput (com.google.gerrit.extensions.api.changes.FixInput)16 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)14 HumanComment (com.google.gerrit.entities.HumanComment)13 TestChanges.newPatchSet (com.google.gerrit.testing.TestChanges.newPatchSet)12 IOException (java.io.IOException)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)11 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)10 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)10 AuthException (com.google.gerrit.extensions.restapi.AuthException)9