From 69071599848da7d9e94526ce343e82b27b00a3e1 Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Sat, 31 Mar 2018 05:31:18 +0000 Subject: [PATCH 1/3] BugmailFilter: Divorce from Review extension Don't include or process Mentor fields if the Review extension isn't loaded. --- extensions/BugmailFilter/Extension.pm | 6 ++-- extensions/BugmailFilter/lib/Constants.pm | 37 ++++++++++++++--------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/extensions/BugmailFilter/Extension.pm b/extensions/BugmailFilter/Extension.pm index a05953336a..497aeec858 100644 --- a/extensions/BugmailFilter/Extension.pm +++ b/extensions/BugmailFilter/Extension.pm @@ -339,8 +339,10 @@ sub _should_drop { $rel_map[8] = !$rel_map[8]; $rel_map[9] = ($relationship & $bit_watching or $relationship & $bit_compwatch); $rel_map[10] = !$rel_map[9]; - $rel_map[11] = $bug->is_mentor($user); - $rel_map[12] = !$rel_map[11]; + if (Bugzilla->have_extension('Review')) { + $rel_map[11] = $bug->is_mentor($user); + $rel_map[12] = !$rel_map[11]; + } foreach my $bool (@rel_map) { $bool = $bool ? 1 : 0; } diff --git a/extensions/BugmailFilter/lib/Constants.pm b/extensions/BugmailFilter/lib/Constants.pm index 655cd7fd66..e95e592ce7 100644 --- a/extensions/BugmailFilter/lib/Constants.pm +++ b/extensions/BugmailFilter/lib/Constants.pm @@ -67,21 +67,28 @@ use constant IGNORE_FIELDS => qw( use constant FIELD_DESCRIPTION_OVERRIDE => {bug_id => 'Bug Created',}; # relationship / int mappings -# _should_drop() also needs updating when this const is changed +# _should_drop() also needs updating when this is changed -use constant FILTER_RELATIONSHIPS => [ - {name => 'Assignee', value => 1,}, - {name => 'Not Assignee', value => 2,}, - {name => 'Reporter', value => 3,}, - {name => 'Not Reporter', value => 4,}, - {name => 'QA Contact', value => 5,}, - {name => 'Not QA Contact', value => 6,}, - {name => "CC'ed", value => 7,}, - {name => "Not CC'ed", value => 8,}, - {name => 'Watching', value => 9,}, - {name => 'Not Watching', value => 10,}, - {name => 'Mentoring', value => 11,}, - {name => 'Not Mentoring', value => 12,}, -]; +sub _gen_relations() { + my @relations; + my $index = 1; + push @relations, { name => 'Assignee', value => $index++ }; + push @relations, { name => 'Not Assignee', value => $index++ }; + push @relations, { name => 'Reporter', value => $index++ }; + push @relations, { name => 'Not Reporter', value => $index++ }; + push @relations, { name => 'QA Contact', value => $index++ }; + push @relations, { name => 'Not QA Contact', value => $index++ }; + push @relations, { name => "CC'ed", value => $index++ }; + push @relations, { name => "Not CC'ed", value => $index++ }; + push @relations, { name => 'Watching', value => $index++ }; + push @relations, { name => 'Not Watching', value => $index++ }; + if (Bugzilla->have_extension('Review')) { + push @relations, { name => 'Mentoring', value => $index++ }; + push @relations, { name => 'Not Mentoring', value => $index++ }; + } + return \@relations; +} + +use constant FILTER_RELATIONSHIPS => _gen_relations(); 1; From 84ff09ddd3d706df6a897ab354ae7a8e2c49434c Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Tue, 3 Apr 2018 10:45:32 +0000 Subject: [PATCH 2/3] BugmailFilter: Calculate FILTER_RELATIONSHIPS lazily Calculating it eagerly is problematic as it would have to be done at extension initialization, and we can't meaningfully query whether other extensions are loaded during extension initialization. Do it lazily and cache the result instead. --- extensions/BugmailFilter/lib/Constants.pm | 33 +++++++++++------------ 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/extensions/BugmailFilter/lib/Constants.pm b/extensions/BugmailFilter/lib/Constants.pm index e95e592ce7..902498ff61 100644 --- a/extensions/BugmailFilter/lib/Constants.pm +++ b/extensions/BugmailFilter/lib/Constants.pm @@ -69,26 +69,25 @@ use constant FIELD_DESCRIPTION_OVERRIDE => {bug_id => 'Bug Created',}; # relationship / int mappings # _should_drop() also needs updating when this is changed -sub _gen_relations() { - my @relations; +sub FILTER_RELATIONSHIPS() { + state $relations; + return \@$relations if $relations; my $index = 1; - push @relations, { name => 'Assignee', value => $index++ }; - push @relations, { name => 'Not Assignee', value => $index++ }; - push @relations, { name => 'Reporter', value => $index++ }; - push @relations, { name => 'Not Reporter', value => $index++ }; - push @relations, { name => 'QA Contact', value => $index++ }; - push @relations, { name => 'Not QA Contact', value => $index++ }; - push @relations, { name => "CC'ed", value => $index++ }; - push @relations, { name => "Not CC'ed", value => $index++ }; - push @relations, { name => 'Watching', value => $index++ }; - push @relations, { name => 'Not Watching', value => $index++ }; + push @$relations, { name => 'Assignee', value => $index++ }; + push @$relations, { name => 'Not Assignee', value => $index++ }; + push @$relations, { name => 'Reporter', value => $index++ }; + push @$relations, { name => 'Not Reporter', value => $index++ }; + push @$relations, { name => 'QA Contact', value => $index++ }; + push @$relations, { name => 'Not QA Contact', value => $index++ }; + push @$relations, { name => "CC'ed", value => $index++ }; + push @$relations, { name => "Not CC'ed", value => $index++ }; + push @$relations, { name => 'Watching', value => $index++ }; + push @$relations, { name => 'Not Watching', value => $index++ }; if (Bugzilla->have_extension('Review')) { - push @relations, { name => 'Mentoring', value => $index++ }; - push @relations, { name => 'Not Mentoring', value => $index++ }; + push @$relations, { name => 'Mentoring', value => $index++ }; + push @$relations, { name => 'Not Mentoring', value => $index++ }; } - return \@relations; + return \@$relations; } -use constant FILTER_RELATIONSHIPS => _gen_relations(); - 1; From d83880492ce0b65c5a011f8b55ed5229743a32c8 Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Sun, 7 Jun 2020 23:04:03 +0000 Subject: [PATCH 3/3] BugmailFilter: Update name of has_extension function --- extensions/BugmailFilter/Extension.pm | 2 +- extensions/BugmailFilter/lib/Constants.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/BugmailFilter/Extension.pm b/extensions/BugmailFilter/Extension.pm index 497aeec858..8d5d964d1c 100644 --- a/extensions/BugmailFilter/Extension.pm +++ b/extensions/BugmailFilter/Extension.pm @@ -339,7 +339,7 @@ sub _should_drop { $rel_map[8] = !$rel_map[8]; $rel_map[9] = ($relationship & $bit_watching or $relationship & $bit_compwatch); $rel_map[10] = !$rel_map[9]; - if (Bugzilla->have_extension('Review')) { + if (Bugzilla->has_extension('Review')) { $rel_map[11] = $bug->is_mentor($user); $rel_map[12] = !$rel_map[11]; } diff --git a/extensions/BugmailFilter/lib/Constants.pm b/extensions/BugmailFilter/lib/Constants.pm index 902498ff61..0051d6b371 100644 --- a/extensions/BugmailFilter/lib/Constants.pm +++ b/extensions/BugmailFilter/lib/Constants.pm @@ -83,7 +83,7 @@ sub FILTER_RELATIONSHIPS() { push @$relations, { name => "Not CC'ed", value => $index++ }; push @$relations, { name => 'Watching', value => $index++ }; push @$relations, { name => 'Not Watching', value => $index++ }; - if (Bugzilla->have_extension('Review')) { + if (Bugzilla->has_extension('Review')) { push @$relations, { name => 'Mentoring', value => $index++ }; push @$relations, { name => 'Not Mentoring', value => $index++ }; }