Merge "Add robot comment count to patchset dropdown in findings tab"

This commit is contained in:
Dhruv Srivastava 2020-02-28 10:18:49 +00:00 committed by Gerrit Code Review
commit 82033aaaaa
2 changed files with 75 additions and 5 deletions

View File

@ -332,7 +332,8 @@
_robotCommentsPatchSetDropdownItems: {
type: Array,
value() { return []; },
computed: '_computeRobotCommentsPatchSetDropdownItems(_change)',
computed: '_computeRobotCommentsPatchSetDropdownItems(_change, ' +
'_commentThreads)',
},
_currentRobotCommentsPatchSet: {
type: Number,
@ -631,13 +632,35 @@
return false;
}
_computeRobotCommentsPatchSetDropdownItems(change) {
if (!change.revisions) return [];
_robotCommentCountPerPatchSet(threads) {
return threads.reduce((robotCommentCountMap, thread) => {
const comments = thread.comments;
const robotCommentsCount = comments.reduce((acc, comment) =>
(comment.robot_id ? acc + 1 : acc), 0);
robotCommentCountMap[comments[0].patch_set] =
(robotCommentCountMap[comments[0].patch_set] || 0) +
robotCommentsCount;
return robotCommentCountMap;
}, {});
}
_computeText(patch, commentThreads) {
const commentCount = this._robotCommentCountPerPatchSet(commentThreads);
const commentCnt = commentCount[patch._number] || 0;
if (commentCnt === 0) return `Patchset ${patch._number}`;
const findingsText = commentCnt === 1 ? 'finding' : 'findings';
return `Patchset ${patch._number}`
+ ` (${commentCnt} ${findingsText})`;
}
_computeRobotCommentsPatchSetDropdownItems(change, commentThreads) {
if (!change || !commentThreads || !change.revisions) return [];
return Object.values(change.revisions)
.filter(patch => patch._number !== 'edit')
.map(patch => {
return {
text: 'Patchset ' + patch._number,
text: this._computeText(patch, commentThreads),
value: patch._number,
};
})

View File

@ -73,6 +73,21 @@ limitations under the License.
const THREADS = [
{
comments: [
{
__path: '/COMMIT_MSG',
author: {
_account_id: 1000000,
name: 'user',
username: 'user',
},
patch_set: 2,
robot_id: 'rb1',
id: 'ecf9fa_fe1a5f62',
line: 5,
updated: '2018-02-08 18:49:18.000000000',
message: 'test',
unresolved: true,
},
{
__path: '/COMMIT_MSG',
author: {
@ -109,6 +124,21 @@ limitations under the License.
},
{
comments: [
{
__path: '/COMMIT_MSG',
author: {
_account_id: 1000000,
name: 'user',
username: 'user',
},
patch_set: 3,
id: 'ecf0b9fa_fe5f62',
robot_id: 'rb2',
line: 5,
updated: '2018-02-08 18:49:18.000000000',
message: 'test',
unresolved: true,
},
{
__path: 'test.txt',
author: {
@ -735,6 +765,23 @@ limitations under the License.
done();
});
});
test('robot comments count per patchset', () => {
const count = element._robotCommentCountPerPatchSet(THREADS);
const expectedCount = {
2: 1,
3: 1,
4: 2,
};
assert.deepEqual(count, expectedCount);
assert.equal(element._computeText({_number: 2}, THREADS),
'Patchset 2 (1 finding)');
assert.equal(element._computeText({_number: 4}, THREADS),
'Patchset 4 (2 findings)');
assert.equal(element._computeText({_number: 5}, THREADS),
'Patchset 5');
});
test('only robot comments are rendered', () => {
assert.equal(element._robotCommentThreads.length, 2);
assert.equal(element._robotCommentThreads[0].comments[0].robot_id,
@ -745,7 +792,7 @@ limitations under the License.
test('changing patchsets resets robot comments', done => {
element.set('_change.current_revision', 'rev3');
flush(() => {
assert.equal(element._robotCommentThreads.length, 0);
assert.equal(element._robotCommentThreads.length, 1);
done();
});
});