Search in sources :

Example 96 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class GetFixPreview method apply.

@Override
public Response<Map<String, DiffInfo>> apply(FixResource resource) throws PermissionBackendException, ResourceNotFoundException, ResourceConflictException, AuthException, IOException, InvalidChangeOperationException {
    Map<String, DiffInfo> result = new HashMap<>();
    PatchSet patchSet = resource.getRevisionResource().getPatchSet();
    ChangeNotes notes = resource.getRevisionResource().getNotes();
    Change change = notes.getChange();
    ProjectState state = projectCache.get(change.getProject()).orElseThrow(illegalState(change.getProject()));
    Map<String, List<FixReplacement>> fixReplacementsPerFilePath = resource.getFixReplacements().stream().collect(groupingBy(fixReplacement -> fixReplacement.path));
    try {
        try (Repository git = repoManager.openRepository(notes.getProjectName())) {
            for (Map.Entry<String, List<FixReplacement>> entry : fixReplacementsPerFilePath.entrySet()) {
                String fileName = entry.getKey();
                DiffInfo diffInfo = getFixPreviewForSingleFile(git, patchSet, state, notes, fileName, ImmutableList.copyOf(entry.getValue()));
                result.put(fileName, diffInfo);
            }
        }
    } catch (NoSuchChangeException e) {
        throw new ResourceNotFoundException(e.getMessage(), e);
    } catch (LargeObjectException e) {
        throw new ResourceConflictException(e.getMessage(), e);
    }
    return Response.ok(result);
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) ProjectCache(com.google.gerrit.server.project.ProjectCache) Inject(com.google.inject.Inject) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) HashMap(java.util.HashMap) Response(com.google.gerrit.extensions.restapi.Response) PatchScriptFactoryForAutoFix(com.google.gerrit.server.patch.PatchScriptFactoryForAutoFix) PatchScript(com.google.gerrit.common.data.PatchScript) ImmutableList(com.google.common.collect.ImmutableList) InvalidChangeOperationException(com.google.gerrit.server.project.InvalidChangeOperationException) Map(java.util.Map) AuthException(com.google.gerrit.extensions.restapi.AuthException) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) Change(com.google.gerrit.entities.Change) PatchSet(com.google.gerrit.entities.PatchSet) FixReplacement(com.google.gerrit.entities.FixReplacement) ProjectCache.illegalState(com.google.gerrit.server.project.ProjectCache.illegalState) DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) RestReadView(com.google.gerrit.extensions.restapi.RestReadView) LargeObjectException(com.google.gerrit.server.git.LargeObjectException) ProjectState(com.google.gerrit.server.project.ProjectState) MoreObjects(com.google.common.base.MoreObjects) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IOException(java.io.IOException) DiffSide(com.google.gerrit.server.diff.DiffSide) DiffWebLinksProvider(com.google.gerrit.server.diff.DiffWebLinksProvider) WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) List(java.util.List) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) DiffWebLinkInfo(com.google.gerrit.extensions.common.DiffWebLinkInfo) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) DiffInfoCreator(com.google.gerrit.server.diff.DiffInfoCreator) FixResource(com.google.gerrit.server.change.FixResource) Repository(org.eclipse.jgit.lib.Repository) Singleton(com.google.inject.Singleton) HashMap(java.util.HashMap) PatchSet(com.google.gerrit.entities.PatchSet) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Change(com.google.gerrit.entities.Change) LargeObjectException(com.google.gerrit.server.git.LargeObjectException) Repository(org.eclipse.jgit.lib.Repository) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) ProjectState(com.google.gerrit.server.project.ProjectState) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) HashMap(java.util.HashMap) Map(java.util.Map) DiffInfo(com.google.gerrit.extensions.common.DiffInfo)

Example 97 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class GetContent method getMergeList.

private byte[] getMergeList(ChangeNotes notes) throws IOException {
    Change.Id changeId = notes.getChangeId();
    PatchSet ps = psUtil.current(notes);
    if (ps == null) {
        throw new NoSuchChangeException(changeId);
    }
    try (Repository git = gitManager.openRepository(notes.getProjectName());
        RevWalk revWalk = new RevWalk(git)) {
        return Text.forMergeList(ComparisonType.againstAutoMerge(), revWalk.getObjectReader(), ps.commitId()).getContent();
    } catch (RepositoryNotFoundException e) {
        throw new NoSuchChangeException(changeId, e);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) RevWalk(org.eclipse.jgit.revwalk.RevWalk)

Example 98 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class ListPortedComments method apply.

@Override
public Response<Map<String, List<CommentInfo>>> apply(RevisionResource revisionResource) throws PermissionBackendException {
    PatchSet targetPatchset = revisionResource.getPatchSet();
    List<HumanComment> allComments = commentsUtil.publishedHumanCommentsByChange(revisionResource.getNotes());
    ImmutableList<HumanComment> portedComments = commentPorter.portComments(revisionResource.getNotes(), targetPatchset, allComments, ImmutableList.of(new UnresolvedCommentFilter()));
    return Response.ok(format(portedComments));
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) HumanComment(com.google.gerrit.entities.HumanComment)

Example 99 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class Mergeable method apply.

@Override
public Response<MergeableInfo> apply(RevisionResource resource) throws AuthException, ResourceConflictException, BadRequestException, IOException {
    Change change = resource.getChange();
    PatchSet ps = resource.getPatchSet();
    MergeableInfo result = new MergeableInfo();
    if (!change.isNew()) {
        throw new ResourceConflictException("change is " + ChangeUtil.status(change));
    } else if (!ps.id().equals(change.currentPatchSetId())) {
        // Only the current revision is mergeable. Others always fail.
        return Response.ok(result);
    }
    ChangeData cd = changeDataFactory.create(resource.getNotes());
    result.submitType = getSubmitType(cd);
    try (Repository git = gitManager.openRepository(change.getProject())) {
        ObjectId commit = ps.commitId();
        Ref ref = git.getRefDatabase().exactRef(change.getDest().branch());
        ProjectState projectState = projectCache.get(change.getProject()).orElseThrow(illegalState(change.getProject()));
        String strategy = mergeUtilFactory.create(projectState).mergeStrategyName();
        result.strategy = strategy;
        result.mergeable = isMergable(git, change, commit, ref, result.submitType, strategy);
        if (otherBranches) {
            result.mergeableInto = new ArrayList<>();
            Optional<BranchOrderSection> branchOrder = projectState.getBranchOrderSection();
            if (branchOrder.isPresent()) {
                int prefixLen = Constants.R_HEADS.length();
                List<String> names = branchOrder.get().getMoreStable(ref.getName());
                Map<String, Ref> refs = git.getRefDatabase().exactRef(names.toArray(new String[names.size()]));
                for (String n : names) {
                    Ref other = refs.get(n);
                    if (other == null) {
                        continue;
                    }
                    if (cache.get(commit, other, SubmitType.CHERRY_PICK, strategy, change.getDest(), git)) {
                        result.mergeableInto.add(other.getName().substring(prefixLen));
                    }
                }
            }
        }
    }
    return Response.ok(result);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) BranchOrderSection(com.google.gerrit.entities.BranchOrderSection) ChangeData(com.google.gerrit.server.query.change.ChangeData) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) MergeableInfo(com.google.gerrit.extensions.common.MergeableInfo) ProjectState(com.google.gerrit.server.project.ProjectState)

Example 100 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class GetRelated method newChangeAndCommit.

static RelatedChangeAndCommitInfo newChangeAndCommit(Project.NameKey project, @Nullable Change change, @Nullable PatchSet ps, RevCommit c) {
    RelatedChangeAndCommitInfo info = new RelatedChangeAndCommitInfo();
    info.project = project.get();
    if (change != null) {
        info.changeId = change.getKey().get();
        info._changeNumber = change.getChangeId();
        info._revisionNumber = ps != null ? ps.number() : null;
        PatchSet.Id curr = change.currentPatchSetId();
        info._currentRevisionNumber = curr != null ? curr.get() : null;
        info.status = ChangeUtil.status(change).toUpperCase(Locale.US);
    }
    info.commit = new CommitInfo();
    info.commit.commit = c.name();
    info.commit.parents = Lists.newArrayListWithCapacity(c.getParentCount());
    for (int i = 0; i < c.getParentCount(); i++) {
        CommitInfo p = new CommitInfo();
        p.commit = c.getParent(i).name();
        info.commit.parents.add(p);
    }
    info.commit.author = CommonConverters.toGitPerson(c.getAuthorIdent());
    info.commit.subject = c.getShortMessage();
    return info;
}
Also used : RelatedChangeAndCommitInfo(com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo) PatchSet(com.google.gerrit.entities.PatchSet) RelatedChangeAndCommitInfo(com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo) CommitInfo(com.google.gerrit.extensions.common.CommitInfo)

Aggregations

PatchSet (com.google.gerrit.entities.PatchSet)123 Change (com.google.gerrit.entities.Change)61 Test (org.junit.Test)48 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)41 ObjectId (org.eclipse.jgit.lib.ObjectId)35 RevCommit (org.eclipse.jgit.revwalk.RevCommit)29 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)28 Project (com.google.gerrit.entities.Project)25 StorageException (com.google.gerrit.exceptions.StorageException)25 Repository (org.eclipse.jgit.lib.Repository)22 IOException (java.io.IOException)20 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)19 ChangeData (com.google.gerrit.server.query.change.ChangeData)18 HumanComment (com.google.gerrit.entities.HumanComment)16 RevWalk (org.eclipse.jgit.revwalk.RevWalk)16 Inject (com.google.inject.Inject)14 Map (java.util.Map)14 List (java.util.List)13 ImmutableList (com.google.common.collect.ImmutableList)12 AuthException (com.google.gerrit.extensions.restapi.AuthException)11