diff --git a/mozilla/webtools/litmus/scripts/daily_report.pl b/mozilla/webtools/litmus/scripts/daily_report.pl index abe6d44d3cd..5fd1548d029 100755 --- a/mozilla/webtools/litmus/scripts/daily_report.pl +++ b/mozilla/webtools/litmus/scripts/daily_report.pl @@ -36,6 +36,7 @@ use Getopt::Long; use Litmus::DBI; use Litmus::Config; use Litmus::Mailer qw( sendMessage ); +use Litmus::DB::Testcase; use vars qw( $litmus_dbh @@ -51,7 +52,8 @@ $litmus_dbh = Litmus::DBI->db_ReadOnly() or die; my $help; my $html_mail; -GetOptions('help|?' => \$help,'html' => \$html_mail); +my $batch; +GetOptions('help|?' => \$help,'html' => \$html_mail,'batch' => \$batch); if ($help) { &usage; @@ -63,7 +65,7 @@ my ($sql,$sth); $sql= qq{ SELECT tr.testresult_id, pr.name AS product, br.name AS branch, pl.name AS platform, o.name AS opsys, u.email, tc.summary FROM test_results tr, platforms pl, opsyses o, products pr, branches br, users u, testcases tc -WHERE tr.result_status_id=2 AND +WHERE tr.result_status_id=? AND tr.valid=1 AND tr.submission_time>=DATE_SUB(NOW(), INTERVAL 1 DAY) AND tr.testcase_id=tc.testcase_id AND @@ -77,22 +79,112 @@ ORDER BY pr.name ASC, br.name ASC, pl.name ASC, o.name ASC; }; $sth = $litmus_dbh->prepare($sql); -$sth->execute(); +$sth->execute(2); my @failed_results; while (my $hashref = $sth->fetchrow_hashref) { $hashref->{'branch'} =~ s/ Branch//; push @failed_results, $hashref; } + +my $combined_message_body = ""; + +my $failed_results_message_body = ""; +if (scalar @failed_results > 0) { + $failed_results_message_body = &format_results(\@failed_results, 'Failed', $html_mail); +} else { + # No Failed Results today. +} + +if ($failed_results_message_body ne "") { + if (!$batch) { + my $title = 'Failed results submitted to Litmus in the past day'; + my $rv = &create_and_send_message($title, + $failed_results_message_body, + $html_mail); + } else { + $combined_message_body .= $failed_results_message_body; + } +} + +$sth->execute(3); +my @unclear_results; +while (my $hashref = $sth->fetchrow_hashref) { + $hashref->{'branch'} =~ s/ Branch//; + push @unclear_results, $hashref; +} $sth->finish; -if (scalar @failed_results > 0) { - if ($html_mail) { - &send_html_mail(\@failed_results); - } else { - &send_plaintext_mail(\@failed_results); - } +my $unclear_results_message_body = ""; +if (scalar @unclear_results > 0) { + $unclear_results_message_body = &format_results(\@unclear_results, 'Unclear', $html_mail); } else { - # No Results today. + # No Unclear Results today. +} + +if ($unclear_results_message_body ne "") { + if (!$batch) { + my $title = 'Unclear results submitted to Litmus in the past day'; + my $rv = &create_and_send_message($title, + $unclear_results_message_body, + $html_mail); + } else { + $combined_message_body .= $unclear_results_message_body; + } +} + +my $match_limit = 100; + +my @added_testcases = Litmus::DB::Testcase->getNewTestcases( + 1, + $match_limit + ); + +my $added_testcases_message_body = ""; +if (scalar @added_testcases > 0) { + $added_testcases_message_body = &format_testcases(\@added_testcases, 'Added to', $html_mail); +} else { + # No testcases added today. +} + +if ($added_testcases_message_body ne "") { + if (!$batch) { + my $title = 'Testcases added to Litmus in the past day'; + my $rv = &create_and_send_message($title, + $added_testcases_message_body, + $html_mail); + } else { + $combined_message_body .= $added_testcases_message_body; + } +} + +my @changed_testcases = Litmus::DB::Testcase->getRecentlyUpdated( + 1, + $match_limit + ); + +my $changed_testcases_message_body = ""; +if (scalar @changed_testcases > 0) { + $changed_testcases_message_body = &format_testcases(\@changed_testcases, 'Changed in', $html_mail); +} else { + # No testcases added today. +} + +if ($changed_testcases_message_body ne "") { + if (!$batch) { + my $title = 'Testcases changed in Litmus in the past day'; + my $rv = &create_and_send_message($title, + $changed_testcases_message_body, + $html_mail); + } else { + $combined_message_body .= $changed_testcases_message_body; + } +} + +if ($batch and $combined_message_body ne "") { + my $title = ''; + my $rv = &create_and_send_message($title, + $combined_message_body, + $html_mail); } exit; @@ -103,76 +195,27 @@ sub usage { } ######################################################################### -sub message_header { +sub message_header($$) { + my ($title,$html_mail) = @_; my $today = &UnixDate("today","%Y/%m/%d"); - my $subject = "[litmus] Daily Report - $today"; + my $subject = "[litmus] Daily Report"; + if ($title) { + $subject .= " - $title"; + } + $subject .= " - $today"; my $header .= "Subject: $subject\n"; $header .= "Content-Type: text/html\n"; $header .= "To: " . join(',',@Litmus::Config::nightly_report_recipients) . "\n\n"; - return $header; -} - -######################################################################### -sub send_plaintext_mail(\@) { - my ($failed_results) = @_; - - my $message = &message_header(); - $message .= "Failed results submitted to Litmus in the past day:\n\n"; - - my $header = sprintf( - "%-8s %-8s %-6s %-8s %-8s %-15s %-20s", - "ID", - "Product", - "Branch", - "Platform", - "Opsys", - "Tester", - "Testcase Summary" - ); - - $message .= "$header\n"; - - foreach my $hashref (@$failed_results) { - my $result_link = sprintf("%-8d", - $hashref->{'testresult_id'}, - $hashref->{'testresult_id'} - ); - $message .= $result_link; - - my $result = sprintf( - " %-8.8s %-6.6s %-8.8s %-8.8s %-15.15s %-20.20s", - $hashref->{'product'}, - $hashref->{'branch'}, - $hashref->{'platform'}, - $hashref->{'opsys'}, - $hashref->{'email'}, - $hashref->{'summary'} - ); - $message .= "$result\n"; - } - - $message .= "\n"; - $message .= "Visit Litmus: http:/litmus.mozilla.org/\n\n"; - - my $rv = sendMessage($message); - if (!$rv) { - warn('[litmus] FAIL - Unable to send daily report'); - } -} - -######################################################################### -sub send_html_mail(\@) { - my ($failed_results) = @_; - - my $message = &message_header(); - - $message .= ' + if ($html_mail) { + $header .= '
-Visit Litmus: http:/litmus.mozilla.org/
\n"; + $footer .= "\n\n\n"; + } else { + $footer = "Visit Litmus: http:/litmus.mozilla.org/\n\n"; + } + return $footer; +} + +######################################################################### +sub format_results(\@$$) { + my ($results, $result_type, $html_mail) = @_; + + my $formatted_results = ""; + if ($html_mail) { + $formatted_results = "| ID | @@ -242,36 +310,142 @@ td {||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ' . - $hashref->{'testresult_id'} . " | \n"; + my $class='odd'; + foreach my $hashref (@$results) { + if ($class eq 'odd') { + $class = 'even'; + } else { + $class = 'odd'; + } + $formatted_results .= '||||||||||||
| ' . + $hashref->{'testresult_id'} . " | \n"; - $message .= '' . $hashref->{'product'} . " | \n"; - $message .= '' . $hashref->{'branch'} . " | \n"; - $message .= '' . $hashref->{'platform'} . " | \n"; - $message .= '' . $hashref->{'opsys'} . " | \n"; - $message .= '' . $hashref->{'email'} . " | \n"; - $message .= '' . $hashref->{'summary'} . " | \n"; + $formatted_results .= '' . $hashref->{'product'} . " | \n"; + $formatted_results .= '' . $hashref->{'branch'} . " | \n"; + $formatted_results .= '' . $hashref->{'platform'} . " | \n"; + $formatted_results .= '' . $hashref->{'opsys'} . " | \n"; + $formatted_results .= '' . $hashref->{'email'} . " | \n"; + $formatted_results .= '' . $hashref->{'summary'} . " | \n"; - $message .= "
| ID | +Summary | +
|---|---|
| ' . + $hashref->{'testcase_id'} . " | \n"; + + $formatted_testcases .= '' . $hashref->{'summary'} . " | \n"; + $formatted_testcases .= "
Visit Litmus: http:/litmus.mozilla.org/
\n"; + return $formatted_testcases; +} - $message .= "