summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Lawrence <dkl@mozilla.com>2017-02-17 22:30:02 +0100
committerDavid Lawrence <dkl@mozilla.com>2017-02-17 22:30:02 +0100
commit730ca1270c21d9a0af01e304479ddc4e6b1a4fa6 (patch)
treefa5e9d9ce4aeff495db1058411305ab0c03923d6
parentab5eef9afeded451e27faa44d5db3f618825f04d (diff)
downloadbugzilla-730ca1270c21d9a0af01e304479ddc4e6b1a4fa6.tar.gz
bugzilla-730ca1270c21d9a0af01e304479ddc4e6b1a4fa6.tar.xz
Bug 1336563 - Clean up accidental Pulsebot spam from Servo vendoring
-rwxr-xr-xscripts/delete_comments_csv.pl55
1 files changed, 55 insertions, 0 deletions
diff --git a/scripts/delete_comments_csv.pl b/scripts/delete_comments_csv.pl
new file mode 100755
index 000000000..5e3c0c3df
--- /dev/null
+++ b/scripts/delete_comments_csv.pl
@@ -0,0 +1,55 @@
+#!/usr/bin/perl
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+use 5.10.1;
+use strict;
+use warnings;
+use lib qw(. lib local/lib/perl5);
+
+use Bugzilla;
+use Bugzilla::Comment;
+use Bugzilla::Constants;
+
+use Text::CSV_XS;
+
+Bugzilla->usage_mode(USAGE_MODE_CMDLINE);
+
+my $auto_user = Bugzilla::User->check({ name => 'automation@bmo.tld' });
+Bugzilla->set_user($auto_user);
+
+my $dbh = Bugzilla->dbh;
+
+my $filename = shift;
+$filename || die "No CSV file provided.\n";
+
+open(CSV, $filename) || die "Could not open CSV file: $!\n";
+
+$dbh->bz_start_transaction;
+
+my $csv = Text::CSV_XS->new();
+while (my $line = <CSV>) {
+ $csv->parse($line);
+ my @values = $csv->fields();
+ next if !@values;
+ my ($bug_id, $comment_id) = @values;
+ next if $bug_id !~ /^\d+$/;
+ print "Deleting comment '$comment_id' from bug '$bug_id' ";
+ my $bug = Bugzilla::Bug->check({ id => $bug_id });
+ my $comment = Bugzilla::Comment->new($comment_id);
+ if (!$comment || $comment->bug_id ne $bug_id) {
+ print "... commment '$comment_id' does not exist ... skipping.\n";
+ next;
+ }
+ $comment->remove_from_db();
+ $bug->_sync_fulltext( update_comments => 1 );
+ print "... done.\n";
+}
+
+$dbh->bz_commit_transaction;
+
+close(CSV) || die "Could not close CSV file: $!\n";