From: Kohei Yoshino Date: Mon, 1 Apr 2019 16:47:44 +0000 (-0400) Subject: Bug 1522348 part 2 - Add support for bugbug-generated bug list X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e6dbe3a354702aba638cf145941201cc09a65898;p=thirdparty%2Fbugzilla.git Bug 1522348 part 2 - Add support for bugbug-generated bug list --- diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm index 9cc35f9ca..65a3c4ec9 100644 --- a/extensions/BMO/Extension.pm +++ b/extensions/BMO/Extension.pm @@ -2565,6 +2565,9 @@ sub install_filesystem { contents => $json->encode($version_obj), }; + $files->{"$extensions_dir/BMO/bin/migrate-bug-type.pl"} + = {perms => Bugzilla::Install::Filesystem::OWNER_EXECUTE}; + $files->{"$extensions_dir/BMO/bin/migrate-github-pull-requests.pl"} = {perms => Bugzilla::Install::Filesystem::OWNER_EXECUTE}; } diff --git a/extensions/BMO/bin/migrate-bug-type.pl b/extensions/BMO/bin/migrate-bug-type.pl index 335866318..c05057630 100644 --- a/extensions/BMO/bin/migrate-bug-type.pl +++ b/extensions/BMO/bin/migrate-bug-type.pl @@ -14,6 +14,8 @@ use 5.10.1; use lib qw(. lib local/lib/perl5); use Bugzilla; +use Mojo::File qw(path); +use Mojo::Util qw(getopt); # List of products and components that use a bug type other than "defect" my @MIGRATION_MAP = ( @@ -108,22 +110,17 @@ my @MIGRATION_MAP = ( ); my $dbh = Bugzilla->dbh; - $dbh->bz_start_transaction; +say 'Change the type of all bugs with the "enhancement" severity to "enhancement"'; +$dbh->do('UPDATE bugs SET bug_type = "enhancement" WHERE bug_severity = "enhancement"'); + say 'Disable the "enhancement" severity'; $dbh->do('UPDATE bug_severity SET isactive = 0 WHERE value = "enhancement"'); -say 'Change the type of all bugs to "defect"'; -$dbh->do('UPDATE bugs SET bug_type = "defect"'); - -$dbh->bz_commit_transaction; - foreach my $target (@MIGRATION_MAP) { my ($product, $component, $type) = @$target; - $dbh->bz_start_transaction; - say 'Select bugs in the product (and component)'; my $bug_ids = $dbh->selectcol_arrayref( 'SELECT bug_id FROM bugs AS bug @@ -151,8 +148,31 @@ foreach my $target (@MIGRATION_MAP) { $dbh->do('UPDATE components SET default_bug_type = ? WHERE ' . $dbh->sql_in('id', $comp_ids), undef, ($type)); } +} + +my $csv_file; +getopt \@ARGV, 'csv=s' => \$csv_file; + +if ($csv_file) { + my $fh = path($csv_file)->open('<'); + say 'Change the type of bugs according to bugbug'; + my $bug_ids = {defect => [], enhancement => []}; + + while (my $line = <$fh>) { + if ($line =~ /^(\d+),(\w)/) { + push(@{$bug_ids->{$2 eq 'e' ? 'enhancement' : 'defect'}}, $1); + } + } - $dbh->bz_commit_transaction; + $dbh->do('UPDATE bugs SET bug_type = "defect" WHERE ' . + $dbh->sql_in('bug_id', $bug_ids->{defect})); + $dbh->do('UPDATE bugs SET bug_type = "enhancement" WHERE ' . + $dbh->sql_in('bug_id', $bug_ids->{enhancement})); } +say 'Change the type of all other bugs to "defect"'; +$dbh->do('UPDATE bugs SET bug_type = "defect" WHERE bug_type = NULL'); + +$dbh->bz_commit_transaction; + Bugzilla->memcached->clear_all();