Search in sources :

Example 76 with ChangeInfo

use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.

the class CreateChangeIT method createNewChangeSignedOffByFooterWithChangeId.

@Test
public void createNewChangeSignedOffByFooterWithChangeId() throws Exception {
    setSignedOffByFooter(true);
    try {
        ChangeInput ci = newChangeInput(ChangeStatus.NEW);
        String changeId = "I1234000000000000000000000000000000000000";
        String changeIdLine = "Change-Id: " + changeId;
        ci.subject = "Subject\n\n" + changeIdLine;
        ChangeInfo info = assertCreateSucceeds(ci);
        assertThat(info.changeId).isEqualTo(changeId);
        String message = info.revisions.get(info.currentRevision).commit.message;
        assertThat(message).contains(changeIdLine);
        assertThat(message).contains(String.format("%sAdministrator <%s>", SIGNED_OFF_BY_TAG, admin.newIdent().getEmailAddress()));
    } finally {
        setSignedOffByFooter(false);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 77 with ChangeInfo

use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.

the class QueryChanges method query.

private List<List<ChangeInfo>> query() throws QueryParseException, PermissionBackendException {
    ChangeQueryProcessor queryProcessor = queryProcessorProvider.get();
    if (queryProcessor.isDisabled()) {
        throw new QueryParseException("query disabled");
    }
    if (limit != null) {
        queryProcessor.setUserProvidedLimit(limit);
    }
    if (start != null) {
        queryProcessor.setStart(start);
    }
    if (noLimit != null) {
        queryProcessor.setNoLimit(noLimit);
    }
    if (skipVisibility != null) {
        queryProcessor.enforceVisibility(!skipVisibility);
    }
    dynamicBeans.forEach((p, b) -> queryProcessor.setDynamicBean(p, b));
    if (queries == null || queries.isEmpty()) {
        queries = Collections.singletonList("status:open");
    } else if (queries.size() > 10) {
        // users from submitting too much to the server in a single call.
        throw new QueryParseException("limit of 10 queries");
    }
    int cnt = queries.size();
    List<QueryResult<ChangeData>> results = queryProcessor.query(qb.parse(queries));
    List<List<ChangeInfo>> res = json.create(options, queryProcessor.getInfosFactory()).format(results);
    for (int n = 0; n < cnt; n++) {
        List<ChangeInfo> info = res.get(n);
        if (results.get(n).more() && !info.isEmpty()) {
            Iterables.getLast(info)._moreChanges = true;
        }
    }
    return res;
}
Also used : QueryResult(com.google.gerrit.index.query.QueryResult) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeQueryProcessor(com.google.gerrit.server.query.change.ChangeQueryProcessor) ArrayList(java.util.ArrayList) List(java.util.List) QueryParseException(com.google.gerrit.index.query.QueryParseException)

Example 78 with ChangeInfo

use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.

the class Rebase method apply.

@Override
public Response<ChangeInfo> apply(RevisionResource rsrc, RebaseInput input) throws UpdateException, RestApiException, IOException, PermissionBackendException {
    // Not allowed to rebase if the current patch set is locked.
    patchSetUtil.checkPatchSetNotLocked(rsrc.getNotes());
    rsrc.permissions().check(ChangePermission.REBASE);
    projectCache.get(rsrc.getProject()).orElseThrow(illegalState(rsrc.getProject())).checkStatePermitsWrite();
    Change change = rsrc.getChange();
    try (Repository repo = repoManager.openRepository(change.getProject());
        ObjectInserter oi = repo.newObjectInserter();
        ObjectReader reader = oi.newReader();
        RevWalk rw = CodeReviewCommit.newRevWalk(reader);
        BatchUpdate bu = updateFactory.create(change.getProject(), rsrc.getUser(), TimeUtil.now())) {
        if (!change.isNew()) {
            throw new ResourceConflictException("change is " + ChangeUtil.status(change));
        } else if (!hasOneParent(rw, rsrc.getPatchSet())) {
            throw new ResourceConflictException("cannot rebase merge commits or commit with no ancestor");
        }
        RebaseChangeOp rebaseOp = rebaseFactory.create(rsrc.getNotes(), rsrc.getPatchSet(), findBaseRev(repo, rw, rsrc, input)).setForceContentMerge(true).setAllowConflicts(input.allowConflicts).setValidationOptions(getValidateOptionsAsMultimap(input.validationOptions)).setFireRevisionCreated(true);
        // TODO(dborowitz): Why no notification? This seems wrong; dig up blame.
        bu.setNotify(NotifyResolver.Result.none());
        bu.setRepository(repo, rw, oi);
        bu.addOp(change.getId(), rebaseOp);
        bu.execute();
        ChangeInfo changeInfo = json.create(OPTIONS).format(change.getProject(), change.getId());
        changeInfo.containsGitConflicts = !rebaseOp.getRebasedCommit().getFilesWithGitConflicts().isEmpty() ? true : null;
        return Response.ok(changeInfo);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ObjectReader(org.eclipse.jgit.lib.ObjectReader) Change(com.google.gerrit.entities.Change) RebaseChangeOp(com.google.gerrit.server.change.RebaseChangeOp) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 79 with ChangeInfo

use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.

the class AbstractPushForReview method testPushInitialCommitSeriesForMasterBranch.

private void testPushInitialCommitSeriesForMasterBranch() throws Exception {
    RevCommit c = testRepo.commit().message("Initial commit").insertChangeId().create();
    String id = GitUtil.getChangeId(testRepo, c).get();
    testRepo.reset(c);
    RevCommit c2 = testRepo.commit().parent(c).message("Second commit").insertChangeId().create();
    String id2 = GitUtil.getChangeId(testRepo, c2).get();
    testRepo.reset(c2);
    String r = "refs/for/master";
    PushResult pr = pushHead(testRepo, r, false);
    assertPushOk(pr, r);
    ChangeInfo change = gApi.changes().id(id).info();
    assertThat(change.branch).isEqualTo("master");
    assertThat(change.status).isEqualTo(ChangeStatus.NEW);
    ChangeInfo change2 = gApi.changes().id(id2).info();
    assertThat(change2.branch).isEqualTo("master");
    assertThat(change2.status).isEqualTo(ChangeStatus.NEW);
    try (Repository repo = repoManager.openRepository(project)) {
        assertThat(repo.resolve("master")).isNull();
    }
    gApi.changes().id(change.id).current().review(ReviewInput.approve());
    gApi.changes().id(change.id).current().submit();
    try (Repository repo = repoManager.openRepository(project)) {
        assertThat(repo.resolve("master")).isEqualTo(c);
    }
    gApi.changes().id(change2.id).current().review(ReviewInput.approve());
    gApi.changes().id(change2.id).current().submit();
    try (Repository repo = repoManager.openRepository(project)) {
        assertThat(repo.resolve("master")).isEqualTo(c2);
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushResult(org.eclipse.jgit.transport.PushResult) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 80 with ChangeInfo

use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushForMasterWithInvalidPercentEncodedMessage.

@Test
public void pushForMasterWithInvalidPercentEncodedMessage() throws Exception {
    PushOneCommit.Result r = pushTo("refs/for/master%m=not_percent_decodable_%%oops%20");
    r.assertOkStatus();
    r.assertChange(Change.Status.NEW, null);
    ChangeInfo ci = get(r.getChangeId(), MESSAGES, ALL_REVISIONS);
    Collection<ChangeMessageInfo> changeMessages = ci.messages;
    assertThat(changeMessages).hasSize(1);
    for (ChangeMessageInfo cm : changeMessages) {
        assertThat(cm.message).isEqualTo("Uploaded patch set 1.\nnot percent decodable %%oops%20");
    }
    Collection<RevisionInfo> revisions = ci.revisions.values();
    assertThat(revisions).hasSize(1);
    for (RevisionInfo ri : revisions) {
        assertThat(ri.description).isEqualTo("not percent decodable %%oops%20");
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)504 Test (org.junit.Test)434 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)393 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)276 Change (com.google.gerrit.entities.Change)73 RevCommit (org.eclipse.jgit.revwalk.RevCommit)67 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)52 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)50 Project (com.google.gerrit.entities.Project)45 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)45 ChangeInput (com.google.gerrit.extensions.common.ChangeInput)36 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)36 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)35 Repository (org.eclipse.jgit.lib.Repository)35 CommitInfo (com.google.gerrit.extensions.common.CommitInfo)32 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)32 TestRepository (org.eclipse.jgit.junit.TestRepository)32 ObjectId (org.eclipse.jgit.lib.ObjectId)30 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)29 List (java.util.List)29