diff options
author | Byron Jones <glob@mozilla.com> | 2015-06-15 06:49:59 +0200 |
---|---|---|
committer | Byron Jones <glob@mozilla.com> | 2015-06-15 06:49:59 +0200 |
commit | c290f3ecabec75b741d375e6130af9060255c274 (patch) | |
tree | 7f52627f41229c6d52a7b2115429c2ac408f438e | |
parent | ac09f71cfd3e84a01a157a8cba21aec5513a0b14 (diff) | |
download | bugzilla-c290f3ecabec75b741d375e6130af9060255c274.tar.gz bugzilla-c290f3ecabec75b741d375e6130af9060255c274.tar.xz |
Bug 1146774: treeherder/tbpl comments are not automatically collapsed
-rw-r--r-- | Bugzilla/Comment.pm | 24 | ||||
-rw-r--r-- | extensions/BugModal/Extension.pm | 3 | ||||
-rw-r--r-- | extensions/BugModal/lib/ActivityStream.pm | 11 | ||||
-rw-r--r-- | extensions/BugModal/lib/MonkeyPatches.pm | 13 | ||||
-rw-r--r-- | extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl | 9 | ||||
-rw-r--r-- | extensions/BugModal/web/comments.js | 28 |
6 files changed, 69 insertions, 19 deletions
diff --git a/Bugzilla/Comment.pm b/Bugzilla/Comment.pm index 979019541..69e973c7f 100644 --- a/Bugzilla/Comment.pm +++ b/Bugzilla/Comment.pm @@ -213,25 +213,31 @@ sub tags { sub collapsed { my ($self) = @_; - return 0 unless Bugzilla->params->{'comment_taggers_group'}; return $self->{collapsed} if exists $self->{collapsed}; + return 0 unless Bugzilla->params->{'comment_taggers_group'}; $self->{collapsed} = 0; Bugzilla->request_cache->{comment_tags_collapsed} - ||= [ split(/\s*,\s*/, Bugzilla->params->{'collapsed_comment_tags'}) ]; + ||= [ split(/\s*,\s*/, lc(Bugzilla->params->{'collapsed_comment_tags'})) ]; my @collapsed_tags = @{ Bugzilla->request_cache->{comment_tags_collapsed} }; - foreach my $my_tag (@{ $self->tags }) { - $my_tag = lc($my_tag); + my @reason; + foreach my $my_tag (map { lc } @{ $self->tags }) { foreach my $collapsed_tag (@collapsed_tags) { - if ($my_tag eq lc($collapsed_tag)) { - $self->{collapsed} = 1; - last; - } + push @reason, $my_tag if $my_tag eq $collapsed_tag; } - last if $self->{collapsed}; + } + if (@reason) { + $self->{collapsed} = 1; + $self->{collapsed_reason} = join(', ', sort @reason); } return $self->{collapsed}; } +sub collapsed_reason { + my ($self) = @_; + return 0 unless $self->collapsed; + return $self->{collapsed_reason}; +} + sub bug { my $self = shift; require Bugzilla::Bug; diff --git a/extensions/BugModal/Extension.pm b/extensions/BugModal/Extension.pm index 0c007c2d9..12245dc54 100644 --- a/extensions/BugModal/Extension.pm +++ b/extensions/BugModal/Extension.pm @@ -254,6 +254,9 @@ sub template_before_process { } } $vars->{tracking_flags_table} = \@tracking_table; + + # for the "view -> hide treeherder comments" menu item + $vars->{treeherder} = Bugzilla->treeherder_user; } sub bug_start_of_set_all { diff --git a/extensions/BugModal/lib/ActivityStream.pm b/extensions/BugModal/lib/ActivityStream.pm index b66352031..a69790044 100644 --- a/extensions/BugModal/lib/ActivityStream.pm +++ b/extensions/BugModal/lib/ActivityStream.pm @@ -109,12 +109,21 @@ sub _add_activity_to_stream { sub _add_comments_to_stream { my ($bug, $stream) = @_; my $user = Bugzilla->user; + my $treeherder_id = Bugzilla->treeherder_user->id; my $raw_comments = $bug->comments(); foreach my $comment (@$raw_comments) { next if $comment->type == CMT_HAS_DUPE; - next if $comment->is_private && !($user->is_insider || $user->id == $comment->author->id); + my $author_id = $comment->author->id; + next if $comment->is_private && !($user->is_insider || $user->id == $author_id); next if $comment->body eq '' && ($comment->work_time - 0) != 0 && !$user->is_timetracker; + + # treeherder is so spammy we hide its comments by default + if ($author_id == $treeherder_id) { + $comment->{collapsed} = 1; + $comment->{collapsed_reason} = $comment->author->name; + } + _add_comment_to_stream($stream, date_str_to_time($comment->creation_ts), $comment->author->id, $comment); } } diff --git a/extensions/BugModal/lib/MonkeyPatches.pm b/extensions/BugModal/lib/MonkeyPatches.pm index 596746b32..c2e24f5ce 100644 --- a/extensions/BugModal/lib/MonkeyPatches.pm +++ b/extensions/BugModal/lib/MonkeyPatches.pm @@ -8,6 +8,19 @@ package Bugzilla::Extension::BugModal::MonkeyPatches; 1; +package Bugzilla; +use strict; +use warnings; + +use Bugzilla::User; + +sub treeherder_user { + return Bugzilla->process_cache->{treeherder_user} //= + Bugzilla::User->new({ name => 'tbplbot@gmail.com', cache => 1 }) + || Bugzilla::User->new({ name => 'treeherder@bots.tld', cache => 1 }) + || Bugzilla::User->new(); +} + package Bugzilla::Bug; use strict; use warnings; diff --git a/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl index 7ea74b469..33d8e73c6 100644 --- a/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl @@ -19,17 +19,18 @@ <menuitem id="view-comments-only" label="Comments Only"></menuitem> <hr> <menuitem id="view-toggle-cc" label="Show CC Changes"></menuitem> - [% Hook.process('comments-toggle-menu') %] + <menuitem id="view-toggle-treeherder" label="Hide Treeherder Comments" data-userid="[% treeherder.id FILTER none %]"></menuitem> </menu> [% PROCESS bug/time.html.tmpl; FOREACH change_set IN bug.activity_stream; + extra_class = change_set.comment.collapsed ? " ca-" _ change_set.comment.author.id : ""; IF change_set.cc_only; - '<div class="change-set cc-only" id="' _ change_set.id _ '" style="display:none">'; + '<div class="change-set cc-only' _ extra_class _ '" id="' _ change_set.id _ '" style="display:none">'; ELSE; - '<div class="change-set" id="' _ change_set.id _ '">'; + '<div class="change-set' _ extra_class _ '" id="' _ change_set.id _ '">'; END; extra_class = ""; @@ -155,7 +156,7 @@ <tr> <td class="comment-collapse-reason" title="[% comment.author.moz_nick FILTER html %] [[% comment.creation_ts FILTER time_duration FILTER html %]]"> - Comment hidden ([% comment.tags.join(', ') FILTER html %]) + Comment hidden ([% comment.collapsed_reason FILTER html %]) </td> <td class="comment-actions"> <button type="button" class="change-spinner minor" id="ccs-[% comment.count FILTER none %]"> diff --git a/extensions/BugModal/web/comments.js b/extensions/BugModal/web/comments.js index f9852cd0e..b18f7d3d1 100644 --- a/extensions/BugModal/web/comments.js +++ b/extensions/BugModal/web/comments.js @@ -72,7 +72,7 @@ $(function() { $('#c' + id).find('.comment-tags').hide(); $('#c' + id).find('.gravatar').css('width', '16px').css('height', '16px'); $('#cr-' + id).hide(); - spinner.text('+'); + realSpinner.text('+'); } else if (forced == 'show') { if (defaultCollapsed) { @@ -87,14 +87,14 @@ $(function() { $('#c' + id).find('.comment-tags').show(); $('#c' + id).find('.gravatar').css('width', '32px').css('height', '32px'); $('#cr-' + id).show(); - spinner.text('-'); + realSpinner.text('-'); } else { $('#ct-' + id).slideToggle('fast', function() { $('#c' + id).find(activitySelector).toggle(); - $('#c' + id).find('.comment-tags').toggle(); if ($('#ct-' + id + ':visible').length) { - spinner.text('-'); + $('#c' + id).find('.comment-tags').show(); + realSpinner.text('-'); $('#cr-' + id).show(); if (BUGZILLA.user.id !== 0) $('#ctag-' + id).show(); @@ -105,7 +105,8 @@ $(function() { } } else { - spinner.text('+'); + $('#c' + id).find('.comment-tags').hide(); + realSpinner.text('+'); $('#cr-' + id).hide(); if (BUGZILLA.user.id !== 0) $('#ctag-' + id).hide(); @@ -171,6 +172,23 @@ $(function() { } }); + $('#view-toggle-treeherder') + .click(function() { + var that = $(this); + console.log(that.data('userid')); + var item = $('.context-menu-item.hover'); + if (that.data('hidden') === '1') { + that.data('hidden', '0'); + item.text('Hide Treeherder Comments'); + $('.ca-' + that.data('userid')).show(); + } + else { + that.data('hidden', '1'); + item.text('Show Treeherder Comments'); + $('.ca-' + that.data('userid')).hide(); + } + }); + $.contextMenu({ selector: '#view-menu-btn', trigger: 'left', |