From: Israel Madueme Date: Mon, 29 Oct 2018 18:29:10 +0000 (-0400) Subject: Bug 1501966 - Warn when there are outdated products or components in the teams list X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f5fd68e9cf4e3a7618128c9f2de08344a08fb33;p=thirdparty%2Fbugzilla.git Bug 1501966 - Warn when there are outdated products or components in the teams list --- diff --git a/Bugzilla/Report/SecurityRisk.pm b/Bugzilla/Report/SecurityRisk.pm index 0c4c1ef2c..cb2bf8cdf 100644 --- a/Bugzilla/Report/SecurityRisk.pm +++ b/Bugzilla/Report/SecurityRisk.pm @@ -76,6 +76,10 @@ has 'sec_keywords' => (is => 'ro', required => 1, isa => ArrayRef [Str],); has 'products' => (is => 'lazy', isa => ArrayRef [Str],); +has 'missing_products' => (is => 'lazy', isa => ArrayRef [Str],); + +has 'missing_components' => (is => 'lazy', isa => ArrayRef [Str],); + has 'initial_bug_ids' => (is => 'lazy', isa => ArrayRef [Int],); has 'initial_bugs' => ( @@ -146,6 +150,65 @@ sub _build_products { return \@products; } +sub _build_missing_products { + my ($self) = @_; + my $dbh = Bugzilla->dbh; + my @products = map { $dbh->quote($_) } @{$self->products}; + my $query = qq{ + SELECT + name + FROM + products + WHERE + @{[$dbh->sql_in('products.name', \@products)]} + }; + my $found_products = Bugzilla->dbh->selectcol_arrayref($query); + return (diff_arrays($self->products, $found_products))[0]; +} + +sub _build_missing_components { + my ($self) = @_; + my $dbh = Bugzilla->dbh; + my $products = join ', ', map { $dbh->quote($_) } @{$self->products}; + my @named_components = (); + my @missing_components = (); + foreach my $team (values %{$self->teams}) { + foreach my $product (keys %$team) { + if (exists $team->{$product}->{named_components}) { + foreach my $component (@{$team->{$product}->{named_components}}) { + push @named_components, [$product, $component]; + } + } + } + } + + my @components = map { $dbh->quote($_->[1]) } @named_components; + my $query = qq{ + SELECT + product.name, + component.name + FROM + components AS component + JOIN products AS product ON component.product_id = product.id + WHERE + @{[$dbh->sql_in('component.name', \@components)]} + }; + my $found_components = Bugzilla->dbh->selectall_arrayref($query); + + foreach my $named_component (@named_components) { + my $found = 0; + foreach my $found_component (@$found_components) { + if (lc $named_component->[0] eq lc $found_component->[0] && lc $named_component->[1] eq lc $found_component->[1]) + { + $found = 1; + last; + } + } + push @missing_components, "$named_component->[0]::$named_component->[1]" if !$found; + } + return \@missing_components; +} + sub _build_initial_bug_ids { # TODO: Handle changes in product (e.g. gravyarding) by searching the events table diff --git a/scripts/secbugsreport.pl b/scripts/secbugsreport.pl index e57989857..03a3db667 100644 --- a/scripts/secbugsreport.pl +++ b/scripts/secbugsreport.pl @@ -48,19 +48,21 @@ my $report = Bugzilla::Report::SecurityRisk->new( ); my $bugs_by_team = $report->results->[-1]->{bugs_by_team}; -my @sorted_team_names = sort { ## no critic qw(BuiltinFunctions::ProhibitReverseSortBlock - @{$bugs_by_team->{$b}->{open}} <=> @{$bugs_by_team->{$a}->{open}} ## no critic qw(Freenode::DollarAB) +my @sorted_team_names = sort { ## no critic qw(BuiltinFunctions::ProhibitReverseSortBlock + @{$bugs_by_team->{$b}->{open}} <=> @{$bugs_by_team->{$a}->{open}} ## no critic qw(Freenode::DollarAB) || $a cmp $b } keys %$teams; my $vars = { - urlbase => Bugzilla->localconfig->{urlbase}, - report_week => $report_week, - teams => \@sorted_team_names, - sec_keywords => $sec_keywords, - results => $report->results, - deltas => $report->deltas, - build_bugs_link => \&build_bugs_link, + urlbase => Bugzilla->localconfig->{urlbase}, + report_week => $report_week, + teams => \@sorted_team_names, + sec_keywords => $sec_keywords, + results => $report->results, + deltas => $report->deltas, + missing_products => $report->missing_products, + missing_components => $report->missing_components, + build_bugs_link => \&build_bugs_link, }; $template->process('reports/email/security-risk.html.tmpl', $vars, \$html) or ThrowTemplateError($template->error()); diff --git a/template/en/default/reports/email/security-risk.html.tmpl b/template/en/default/reports/email/security-risk.html.tmpl index e284a7190..564a0537d 100644 --- a/template/en/default/reports/email/security-risk.html.tmpl +++ b/template/en/default/reports/email/security-risk.html.tmpl @@ -24,7 +24,7 @@ Open
[% results.reverse.0.date FILTER time('%m/%d') %] Closed
Last Week - Added
Last Week + Added
Last Week [% FOREACH result IN results.reverse %] [% NEXT IF loop.count < 2 %] [% LAST IF loop.count > 4 %] @@ -143,7 +143,7 @@ [% NEXT IF loop.count < 2 %] [% LAST IF loop.count > 4 %] - [% IF result.bugs_by_sec_keyword.$keyword.open %] + [% IF result.bugs_by_sec_keyword.$keyword.open.size %] [% result.bugs_by_sec_keyword.$keyword.open.size FILTER html %] @@ -166,5 +166,25 @@ this report treats marking a [% terms.bug %] as 'stalled' the same as closing it

Attached to this email are some graphs with stats for the past 12 months.

+[% IF missing_products.size %] +

The following products requested on this report are no longer active in BMO:  + [% FOREACH missing_product IN missing_products %] + [% missing_product FILTER html %][% ", " FILTER html IF not loop.last %] + [% END %] +

+[% END %] + +[% IF missing_components.size %] +

The following components requested on this report are no longer active in BMO:  + [% FOREACH missing_component IN missing_components %] + [% missing_component FILTER html %][% ", " FILTER html IF not loop.last %] + [% END %] +

+[% END %] + +[% IF missing_products.size || missing_components.size %] +

Please file a [% terms.bug %] in bugzilla.mozilla.org::Administration to update the team list.

+[% END %] +