use of com.google.gerrit.server.patch.PatchList in project gerrit by GerritCodeReview.
the class ChangeEmail method getChangeDetail.
/** Create the change message and the affected file list. */
public String getChangeDetail() {
try {
StringBuilder detail = new StringBuilder();
if (patchSetInfo != null) {
detail.append(patchSetInfo.getMessage().trim()).append("\n");
} else {
detail.append(change.getSubject().trim()).append("\n");
}
if (patchSet != null) {
detail.append("---\n");
PatchList patchList = getPatchList();
for (PatchListEntry p : patchList.getPatches()) {
if (Patch.isMagic(p.getNewName())) {
continue;
}
detail.append(p.getChangeType().getCode()).append(" ").append(p.getNewName()).append("\n");
}
detail.append(MessageFormat.format(//
"" + //
"{0,choice,0#0 files|1#1 file|1<{0} files} changed, " + //
"{1,choice,0#0 insertions|1#1 insertion|1<{1} insertions}(+), " + //
"{2,choice,0#0 deletions|1#1 deletion|1<{2} deletions}(-)" + "\n", //
patchList.getPatches().size() - 1, //
patchList.getInsertions(), patchList.getDeletions()));
detail.append("\n");
}
return detail.toString();
} catch (Exception err) {
log.warn("Cannot format change detail", err);
return "";
}
}
use of com.google.gerrit.server.patch.PatchList in project gerrit by GerritCodeReview.
the class CommentSender method getGroupedInlineComments.
/**
* @return a list of FileCommentGroup objects representing the inline comments grouped by the
* file.
*/
private List<CommentSender.FileCommentGroup> getGroupedInlineComments(Repository repo) {
List<CommentSender.FileCommentGroup> groups = new ArrayList<>();
// Get the patch list:
PatchList patchList = null;
if (repo != null) {
try {
patchList = getPatchList();
} catch (PatchListNotAvailableException e) {
log.error("Failed to get patch list", e);
}
}
// Loop over the comments and collect them into groups based on the file
// location of the comment.
FileCommentGroup currentGroup = null;
for (Comment c : inlineComments) {
// If it's a new group:
if (currentGroup == null || !c.key.filename.equals(currentGroup.filename) || c.key.patchSetId != currentGroup.patchSetId) {
currentGroup = new FileCommentGroup();
currentGroup.filename = c.key.filename;
currentGroup.patchSetId = c.key.patchSetId;
groups.add(currentGroup);
if (patchList != null) {
try {
currentGroup.fileData = new PatchFile(repo, patchList, c.key.filename);
} catch (IOException e) {
log.warn(String.format("Cannot load %s from %s in %s", c.key.filename, patchList.getNewId().name(), projectState.getProject().getName()), e);
currentGroup.fileData = null;
}
}
}
if (currentGroup.fileData != null) {
currentGroup.comments.add(c);
}
}
Collections.sort(groups, Comparator.comparing(g -> g.filename, FilenameComparator.INSTANCE));
return groups;
}
use of com.google.gerrit.server.patch.PatchList in project gerrit by GerritCodeReview.
the class EventFactory method addPatchSetFileNames.
public void addPatchSetFileNames(PatchSetAttribute patchSetAttribute, Change change, PatchSet patchSet) {
try {
PatchList patchList = patchListCache.get(change, patchSet);
for (PatchListEntry patch : patchList.getPatches()) {
if (patchSetAttribute.files == null) {
patchSetAttribute.files = new ArrayList<>();
}
PatchAttribute p = new PatchAttribute();
p.file = patch.getNewName();
p.fileOld = patch.getOldName();
p.type = patch.getChangeType();
p.deletions -= patch.getDeletions();
p.insertions = patch.getInsertions();
patchSetAttribute.files.add(p);
}
} catch (PatchListNotAvailableException e) {
log.warn("Cannot get patch list", e);
}
}
Aggregations