Skip to content

Commit c290f3e

Browse files
committed
Bug 1146774: treeherder/tbpl comments are not automatically collapsed
1 parent ac09f71 commit c290f3e

File tree

6 files changed

+69
-19
lines changed

6 files changed

+69
-19
lines changed

Bugzilla/Comment.pm

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,25 +213,31 @@ sub tags {
213213

214214
sub collapsed {
215215
my ($self) = @_;
216-
return 0 unless Bugzilla->params->{'comment_taggers_group'};
217216
return $self->{collapsed} if exists $self->{collapsed};
217+
return 0 unless Bugzilla->params->{'comment_taggers_group'};
218218
$self->{collapsed} = 0;
219219
Bugzilla->request_cache->{comment_tags_collapsed}
220-
||= [ split(/\s*,\s*/, Bugzilla->params->{'collapsed_comment_tags'}) ];
220+
||= [ split(/\s*,\s*/, lc(Bugzilla->params->{'collapsed_comment_tags'})) ];
221221
my @collapsed_tags = @{ Bugzilla->request_cache->{comment_tags_collapsed} };
222-
foreach my $my_tag (@{ $self->tags }) {
223-
$my_tag = lc($my_tag);
222+
my @reason;
223+
foreach my $my_tag (map { lc } @{ $self->tags }) {
224224
foreach my $collapsed_tag (@collapsed_tags) {
225-
if ($my_tag eq lc($collapsed_tag)) {
226-
$self->{collapsed} = 1;
227-
last;
228-
}
225+
push @reason, $my_tag if $my_tag eq $collapsed_tag;
229226
}
230-
last if $self->{collapsed};
227+
}
228+
if (@reason) {
229+
$self->{collapsed} = 1;
230+
$self->{collapsed_reason} = join(', ', sort @reason);
231231
}
232232
return $self->{collapsed};
233233
}
234234

235+
sub collapsed_reason {
236+
my ($self) = @_;
237+
return 0 unless $self->collapsed;
238+
return $self->{collapsed_reason};
239+
}
240+
235241
sub bug {
236242
my $self = shift;
237243
require Bugzilla::Bug;

extensions/BugModal/Extension.pm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ sub template_before_process {
254254
}
255255
}
256256
$vars->{tracking_flags_table} = \@tracking_table;
257+
258+
# for the "view -> hide treeherder comments" menu item
259+
$vars->{treeherder} = Bugzilla->treeherder_user;
257260
}
258261

259262
sub bug_start_of_set_all {

extensions/BugModal/lib/ActivityStream.pm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,21 @@ sub _add_activity_to_stream {
109109
sub _add_comments_to_stream {
110110
my ($bug, $stream) = @_;
111111
my $user = Bugzilla->user;
112+
my $treeherder_id = Bugzilla->treeherder_user->id;
112113

113114
my $raw_comments = $bug->comments();
114115
foreach my $comment (@$raw_comments) {
115116
next if $comment->type == CMT_HAS_DUPE;
116-
next if $comment->is_private && !($user->is_insider || $user->id == $comment->author->id);
117+
my $author_id = $comment->author->id;
118+
next if $comment->is_private && !($user->is_insider || $user->id == $author_id);
117119
next if $comment->body eq '' && ($comment->work_time - 0) != 0 && !$user->is_timetracker;
120+
121+
# treeherder is so spammy we hide its comments by default
122+
if ($author_id == $treeherder_id) {
123+
$comment->{collapsed} = 1;
124+
$comment->{collapsed_reason} = $comment->author->name;
125+
}
126+
118127
_add_comment_to_stream($stream, date_str_to_time($comment->creation_ts), $comment->author->id, $comment);
119128
}
120129
}

extensions/BugModal/lib/MonkeyPatches.pm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88
package Bugzilla::Extension::BugModal::MonkeyPatches;
99
1;
1010

11+
package Bugzilla;
12+
use strict;
13+
use warnings;
14+
15+
use Bugzilla::User;
16+
17+
sub treeherder_user {
18+
return Bugzilla->process_cache->{treeherder_user} //=
19+
Bugzilla::User->new({ name => 'tbplbot@gmail.com', cache => 1 })
20+
|| Bugzilla::User->new({ name => 'treeherder@bots.tld', cache => 1 })
21+
|| Bugzilla::User->new();
22+
}
23+
1124
package Bugzilla::Bug;
1225
use strict;
1326
use warnings;

extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@
1919
<menuitem id="view-comments-only" label="Comments Only"></menuitem>
2020
<hr>
2121
<menuitem id="view-toggle-cc" label="Show CC Changes"></menuitem>
22-
[% Hook.process('comments-toggle-menu') %]
22+
<menuitem id="view-toggle-treeherder" label="Hide Treeherder Comments" data-userid="[% treeherder.id FILTER none %]"></menuitem>
2323
</menu>
2424

2525
[%
2626
PROCESS bug/time.html.tmpl;
2727

2828
FOREACH change_set IN bug.activity_stream;
29+
extra_class = change_set.comment.collapsed ? " ca-" _ change_set.comment.author.id : "";
2930
IF change_set.cc_only;
30-
'<div class="change-set cc-only" id="' _ change_set.id _ '" style="display:none">';
31+
'<div class="change-set cc-only' _ extra_class _ '" id="' _ change_set.id _ '" style="display:none">';
3132
ELSE;
32-
'<div class="change-set" id="' _ change_set.id _ '">';
33+
'<div class="change-set' _ extra_class _ '" id="' _ change_set.id _ '">';
3334
END;
3435

3536
extra_class = "";
@@ -155,7 +156,7 @@
155156
<tr>
156157
<td class="comment-collapse-reason"
157158
title="[% comment.author.moz_nick FILTER html %] [[% comment.creation_ts FILTER time_duration FILTER html %]]">
158-
Comment hidden ([% comment.tags.join(', ') FILTER html %])
159+
Comment hidden ([% comment.collapsed_reason FILTER html %])
159160
</td>
160161
<td class="comment-actions">
161162
<button type="button" class="change-spinner minor" id="ccs-[% comment.count FILTER none %]">

extensions/BugModal/web/comments.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ $(function() {
7272
$('#c' + id).find('.comment-tags').hide();
7373
$('#c' + id).find('.gravatar').css('width', '16px').css('height', '16px');
7474
$('#cr-' + id).hide();
75-
spinner.text('+');
75+
realSpinner.text('+');
7676
}
7777
else if (forced == 'show') {
7878
if (defaultCollapsed) {
@@ -87,14 +87,14 @@ $(function() {
8787
$('#c' + id).find('.comment-tags').show();
8888
$('#c' + id).find('.gravatar').css('width', '32px').css('height', '32px');
8989
$('#cr-' + id).show();
90-
spinner.text('-');
90+
realSpinner.text('-');
9191
}
9292
else {
9393
$('#ct-' + id).slideToggle('fast', function() {
9494
$('#c' + id).find(activitySelector).toggle();
95-
$('#c' + id).find('.comment-tags').toggle();
9695
if ($('#ct-' + id + ':visible').length) {
97-
spinner.text('-');
96+
$('#c' + id).find('.comment-tags').show();
97+
realSpinner.text('-');
9898
$('#cr-' + id).show();
9999
if (BUGZILLA.user.id !== 0)
100100
$('#ctag-' + id).show();
@@ -105,7 +105,8 @@ $(function() {
105105
}
106106
}
107107
else {
108-
spinner.text('+');
108+
$('#c' + id).find('.comment-tags').hide();
109+
realSpinner.text('+');
109110
$('#cr-' + id).hide();
110111
if (BUGZILLA.user.id !== 0)
111112
$('#ctag-' + id).hide();
@@ -171,6 +172,23 @@ $(function() {
171172
}
172173
});
173174

175+
$('#view-toggle-treeherder')
176+
.click(function() {
177+
var that = $(this);
178+
console.log(that.data('userid'));
179+
var item = $('.context-menu-item.hover');
180+
if (that.data('hidden') === '1') {
181+
that.data('hidden', '0');
182+
item.text('Hide Treeherder Comments');
183+
$('.ca-' + that.data('userid')).show();
184+
}
185+
else {
186+
that.data('hidden', '1');
187+
item.text('Show Treeherder Comments');
188+
$('.ca-' + that.data('userid')).hide();
189+
}
190+
});
191+
174192
$.contextMenu({
175193
selector: '#view-menu-btn',
176194
trigger: 'left',

0 commit comments

Comments
 (0)