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);
}
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);
}
}
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));
}
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);
}
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;
}
Aggregations