Add comment count to review notes
The `git log --notes=review` output provides a good overview about
changes and their reviews and is a good basis for a review validation
report.
The addition of the number of comments in the report can increase
confidence that these reviews really do find issues.
Change-Id: Ifc2718ad11a4a54445deb63cf2ae7fb4eea60de9
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java
index 03147fa..6f6b433 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java
@@ -75,6 +75,7 @@
private final String anonymousCowardName;
private final LabelTypes labelTypes;
private final ApprovalsUtil approvalsUtil;
+ private final ChangeData.Factory changeDataFactory;
private final ChangeNotes.Factory notesFactory;
private final NotesBranchUtil.Factory notesBranchUtilFactory;
private final Provider<InternalChangeQuery> queryProvider;
@@ -94,6 +95,7 @@
@AnonymousCowardName String anonymousCowardName,
ProjectCache projectCache,
ApprovalsUtil approvalsUtil,
+ ChangeData.Factory changeDataFactory,
ChangeNotes.Factory notesFactory,
NotesBranchUtil.Factory notesBranchUtilFactory,
Provider<InternalChangeQuery> queryProvider,
@@ -115,6 +117,7 @@
this.labelTypes = projectState.get().getLabelTypes();
}
this.approvalsUtil = approvalsUtil;
+ this.changeDataFactory = changeDataFactory;
this.notesFactory = notesFactory;
this.notesBranchUtilFactory = notesBranchUtilFactory;
this.queryProvider = queryProvider;
@@ -284,6 +287,10 @@
if (uf != null && uf.getWebUrl().isPresent()) {
fmt.appendReviewedOn(uf, notes.getChange().getProject(), ps.id().changeId());
}
+
+ ChangeData cd = changeDataFactory.create(notes);
+ fmt.appendCommentCount(cd.totalCommentCount(), cd.unresolvedCommentCount());
+
fmt.appendProject(project.get());
fmt.appendBranch(change.getDest().branch());
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/HeaderFormatter.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/HeaderFormatter.java
index 5b8ed6b..c85039d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/HeaderFormatter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/HeaderFormatter.java
@@ -135,6 +135,19 @@
.append("\n");
}
+ void appendCommentCount(int nTotal, int nUnresolved) {
+ if (nTotal > 0) {
+ sb.append("Comments-Total: ")
+ .append(nTotal)
+ .append("\n");
+ }
+ if (nUnresolved > 0) {
+ sb.append("Comments-Unresolved: ")
+ .append(nUnresolved)
+ .append("\n");
+ }
+ }
+
@Override
public String toString() {
return sb.toString();
diff --git a/src/main/resources/Documentation/refs-notes-review.md b/src/main/resources/Documentation/refs-notes-review.md
index 20fd3c7..28b65db 100644
--- a/src/main/resources/Documentation/refs-notes-review.md
+++ b/src/main/resources/Documentation/refs-notes-review.md
@@ -79,6 +79,20 @@
All review labels and scores present on the change at the time of submit are
included.
+### Comments
+
+The number of comments at the time when the change was submitted.
+
+```
+ Comments-Total: 5
+ Comments-Unresolved: 1
+```
+
+Comments-Total is the total number of comments in all threads (also including robot comments),
+Comments-Unresolved is the number of comment threads which are still unresolved.
+
+These lines are only added when there are comments.
+
### Project
The name of the project in which the commit was made.