forked from freebsd/bugzilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweeklyreminder.pl
executable file
·179 lines (152 loc) · 5.26 KB
/
weeklyreminder.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/local/bin/perl -w
use strict;
use warnings;
use lib qw(. lib);
use Bugzilla;
use Bugzilla::Mailer;
use Bugzilla::Constants;
use Bugzilla::Util;
use Email::MIME;
use constant {
# Consider bugs, for which nothing happened for more than X days
WAIT => 7
};
my $urlbase = Bugzilla->params->{'urlbase'};
my $MAIL_TXT_HEADER = "To view an individual PR, use:
${urlbase}show_bug.cgi?id=(Bug Id).
";
my $MAIL_HTML_HEADER = '<pre style="font-family: monospace;">';
my $MAIL_COMMON = "
The following is a listing of current problems submitted by FreeBSD users,
which need special attention. These represent problem reports covering
all versions including experimental development code and obsolete releases.
Status | Bug Id | Description
------------+-----------+---------------------------------------------------
%s
%d problems total for which you should take action.
";
my $MAIL_TXT_FOOTER = "";
my $MAIL_HTML_FOOTER = '</pre>';
my $TBLROW = "%-11s | %9s | %-50.49s\n";
my $TBLROW_HTML = "%-11s | <a href=\"%s\">%9s</a> | <a href=\"%s\">%s</a>\n";
# We're a non-interactive user
Bugzilla->usage_mode(USAGE_MODE_CMDLINE);
# Get the db conection and query the db directly.
my $dbh = Bugzilla->dbh;
my $dnow = $dbh->sql_to_days("NOW()");
my $mfcquery = q{
SELECT DISTINCT
bugs.bug_id, bugs.short_desc, bugs.bug_status, p.login_name, bugs.assigned_to
FROM
bugs
JOIN bug_status bs ON (bs.value = bugs.bug_status AND bs.is_open != 0)
JOIN flags ON (bugs.bug_id = flags.bug_id AND flags.status = '?')
JOIN flagtypes ON (flags.type_id = flagtypes.id)
JOIN profiles p ON (p.userid = bugs.assigned_to AND p.is_enabled = 1)
WHERE
flagtypes.name IN (?, ?, ?)
AND } . $dnow . " - " . $dbh->sql_to_days("bugs.delta_ts") . " >= " . WAIT .
" ORDER BY bugs.assigned_to, bugs.bug_status, bugs.bug_id;";
my $openbugs = $dbh->selectall_arrayref(
$mfcquery,
undef,
'merge-quarterly',
'mfc-stable13',
'mfc-stable14');
my $kwdquery = q{
SELECT DISTINCT
bugs.bug_id, bugs.short_desc, bugs.bug_status, p.login_name, bugs.assigned_to
FROM
bugs
JOIN bug_status bs ON (bs.value = bugs.bug_status AND bs.is_open != 0)
JOIN keywords ON (keywords.bug_id = bugs.bug_id)
JOIN keyworddefs ON (keywords.keywordid = keyworddefs.id)
JOIN profiles p ON (p.userid = bugs.assigned_to AND p.is_enabled = 1)
WHERE
keyworddefs.name IN (?)
AND } . $dnow . " - " . $dbh->sql_to_days("bugs.delta_ts") . " >= " . WAIT .
" ORDER BY bugs.assigned_to, bugs.bug_status, bugs.bug_id;";
my $kwdbugs = $dbh->selectall_arrayref(
$kwdquery,
undef,
'patch-ready');
push(@$openbugs, @$kwdbugs);
my $reqquery = "
SELECT DISTINCT
bugs.bug_id, bugs.short_desc, bugs.bug_status, p.login_name, bugs.assigned_to
FROM
bugs
JOIN flags ON (bugs.bug_id = flags.bug_id AND flags.status = '?' AND flags.requestee_id IS NOT NULL)
JOIN bug_status bs ON (bs.value = bugs.bug_status AND bs.is_open != 0)
JOIN profiles p ON (p.userid = flags.requestee_id)
WHERE
bugs.assigned_to != flags.requestee_id";
my $reqbugs = $dbh->selectall_arrayref($reqquery, undef);
push(@$openbugs, @$reqbugs);
# If there are no bugs (hah!), exit gracefully
if (scalar(@$openbugs) == 0) {
exit 0;
}
# Create a hash table based on the assigned logins (email):
# bugs{email} = [list of bugs].
my %bugs;
foreach my $bug (@$openbugs) {
my ($id, $desc, $status, $mail) = @$bug;
if (!defined($bugs{$mail})) {
$bugs{$mail} = [];
}
push(@{$bugs{$mail}}, $bug);
}
foreach my $mail (keys %bugs) {
# Prep mail content
my $tblbugs = "";
my $tblbugs_html = "";
my $bugcount = scalar(@{$bugs{$mail}});
foreach my $bug (@{$bugs{$mail}}) {
my ($id, $desc, $status, $mail__, @assignedto) = @$bug;
$tblbugs .= sprintf($TBLROW, $status, $id, $desc);
# we can not use %50s format on HTML-escaped string
# sut it implicitly
my $desc_cut = html_quote(substr($desc, 0, 49));
my $url = "${urlbase}show_bug.cgi?id=$id";
$tblbugs_html .= sprintf($TBLROW_HTML, $status, $url, $id, $url, $desc_cut);
$tblbugs_html =~ s/(<a href=".*?">)(\s+)/$2$1/;
}
my $body_txt = $MAIL_TXT_HEADER;
$body_txt .= sprintf($MAIL_COMMON, $tblbugs, $bugcount);
$body_txt .= $MAIL_TXT_FOOTER;
my $body_html = $MAIL_HTML_HEADER;
$body_html .= sprintf($MAIL_COMMON, $tblbugs_html, $bugcount);
$body_html .= $MAIL_HTML_FOOTER;
# parts should go from least rich to most rich format
my @parts = (
Email::MIME->create(
attributes => {
content_type => "text/plain",
charset => "UTF-8"
},
body => $body_txt
),
Email::MIME->create(
attributes => {
content_type => "text/html",
charset => "UTF-8"
},
body => $body_html
),
);
my $mailmsg = Email::MIME->create(
header_str => [
From => '[email protected]',
To => [ $mail ],
Subject => "Problem reports for $mail that need special attention"
],
attributes => {
content_type => "multipart/alternative"
},
parts => [ @parts ],
);
# Send the mail via the bugzilla configuration.
# print $mailmsg->as_string;
MessageToMTA($mailmsg, 1);
}