7 =head1 NAME importComments.pl
9 This will import the comments from Bugzilla and update the corresponding JIRA
18 Andrew DeFaria <Andrew@ClearSCM.com>
26 Thu Mar 20 10:11:53 PDT 2014
36 $ importComments.pl [-bugzillaserver <bugshost>] [-login <login email>]
37 [-jiraserver <server>]
38 [-username <username>] [-password <password>]
39 [-bugids bugid,bugid,... | -file <filename>]
41 [-verbose] [-help] [-usage]
45 -v|erbose: Display progress output
46 -he|lp: Display full help
47 -usa|ge: Display usage
48 -[no]e|xec: Whether or not to update JIRA. -noexec says only
49 tell me what you would have updated.
50 -use|rname: Username to log into JIRA with (Default: jira-admin)
51 -p|assword: Password to log into JIRA with (Default: jira-admin's
53 -bugzillaserver: Machine where Bugzilla lives (Default: bugs-dev)
54 -jiraserver: Machine where Jira lives (Default: jira-dev)
55 -bugi|ds: Comma separated list of BugIDs to process
56 -f|ile: File of BugIDs, one per line
60 This will import the comments from Bugzilla and update the corresponding JIRA
66 use lib "$FindBin::Bin/lib";
83 bugzillaserver => $ENV{BUGZILLASERVER} || 'bugs-dev',
84 jiraserver => $ENV{JIRASERVER} || 'jira-dev:8081',
85 username => $ENV{USERNAME},
86 password => $ENV{PASSWORD},
87 usage => sub { pod2usage },
88 help => sub { pod2usage (-verbose => 2)},
89 verbose => sub { set_verbose },
98 my $p4web = 'http://p4web.audience.local:8080/@md=d&cd=//&c=vLW@/';
99 my $bugzilla = 'http://bugs.audience.com/show_bug.cgi?id=';
101 # 0x93 (147) and 0x94 (148) are "smart" quotes
102 $str =~ s/[\x93\x94]/"/gm;
103 # 0x91 (145) and 0x92 (146) are "smart" singlequotes
104 $str =~ s/[\x91\x92]/'/gm;
105 # 0x96 (150) and 0x97 (151) are emdashes
106 $str =~ s/[\x96\x97]/--/gm;
107 # 0x85 (133) is an ellipsis
108 $str =~ s/\x85/.../gm;
109 # 0x95 • replacement for unordered list
112 # Make P4Web links for "CL (\d{3,6}+)"
113 $str =~ s/CL\s*(\d{3,6}+)/CL \[$1|${p4web}$1\?ac=10\]/igm;
115 # Make Bugzilla links for "Bug ID (\d{1,5}+)"
116 $str =~ s/Bug\s*ID\s*(\d{1,5}+)/Bug \[$1|${bugzilla}$1\]/igm;
118 # Make Bugzilla links for "Bug # (\d{1,5}+)"
119 $str =~ s/Bug\s*#\s*(\d{1,5}+)/Bug \[$1|${bugzilla}$1\]/igm;
121 # Make Bugzilla links for "Bug (\d{1,5}+)"
122 $str =~ s/Bug\s*(\d{1,5}+)/Bug \[$1|${bugzilla}$1\]/igm;
124 # Convert bug URLs to be more proper
125 $str =~ s/https\:\/\/bugs\.audience\.com\/show_bug\.cgi\?id=(\d{1,5}+)/Bug \[$1|${bugzilla}$1\]/igm;
130 sub addComments ($$) {
131 my ($jiraIssue, $bugid) = @_;
133 my @comments = @{getBugComments ($bugid)};
135 # Note: In Bugzilla the first comment is considered the description.
136 my $description = shift @comments;
138 my $result = addDescription $jiraIssue, sanitize $description;
140 $total{'Descriptions added'}++;
142 return $result if $result =~ /^Unable to add comment/;
144 # Process the remaining comments
146 $result = addJIRAComment $jiraIssue, sanitize $_;
148 if ($result =~ /Comment added/) {
149 $total{'Comments imported'}++;
155 $result = '' unless $result;
161 my $startTime = time;
183 open my $file, '<', $opts{file}
184 or $log->err ("Unable to open $opts{file} - $!", 1);
186 $opts{bugids} = [<$file>];
188 chomp @{$opts{bugids}};
192 push @bugids, (split /,/, join (',', $_)) for (@{$opts{bugids}});
194 $opts{bugids} = [@bugids];
197 pod2usage 'Must specify -bugids <bugid>[,<bugid>,...] or -file <filename>'
198 unless $opts{bugids};
200 openBugzilla $opts{bugzillaserver}
201 or $log->err ("Unable to connect to $opts{bugzillaserver}", 1);
203 Connect2JIRA ($opts{username}, $opts{password}, $opts{jiraserver})
204 or $log->err ("Unable to connect to $opts{jiraserver}", 1);
206 $log->msg ("Processing comments");
208 for (@{$opts{bugids}}) {
209 my $jiraIssue = findIssue $_;
211 if ($jiraIssue =~ /^[A-Z]{1,5}-\d+$/) {
212 my $result = addComments $jiraIssue, $_;
214 if ($result =~ /^Unable/) {
215 $total{'Comment failures'}++;
217 $log->err ("Unable to add comments for $jiraIssue ($_)\n$result");
218 } elsif ($result =~ /^Comment added/) {
219 $log->msg ("Added comments for $jiraIssue ($_)");
220 } elsif ($result =~ /^Would have linked/) {
221 $total{'Comments would be added'}++;
224 $total{'Missing JIRA Issues'}++;
226 $log->err ("Unable to find JIRA Issue for Bug $_");
230 display_duration $startTime, $log;
232 Stats (\%total, $log) unless $opts{quiet};