|
| 1 | +#!/usr/bin/perl |
| 2 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | +# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | +# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | +# |
| 6 | +# This Source Code Form is "Incompatible With Secondary Licenses", as |
| 7 | +# defined by the Mozilla Public License, v. 2.0. |
| 8 | + |
| 9 | +use strict; |
| 10 | +use warnings; |
| 11 | + |
| 12 | +use FindBin qw($RealBin); |
| 13 | +use lib "$RealBin/../../.."; |
| 14 | + |
| 15 | +use Bugzilla; |
| 16 | +use Bugzilla::Component; |
| 17 | +use Bugzilla::Constants qw( USAGE_MODE_CMDLINE ); |
| 18 | +use Bugzilla::Field; |
| 19 | +use Bugzilla::Product; |
| 20 | +use Bugzilla::User; |
| 21 | + |
| 22 | +Bugzilla->usage_mode(USAGE_MODE_CMDLINE); |
| 23 | + |
| 24 | +my $dbh = Bugzilla->dbh; |
| 25 | + |
| 26 | +my $infra = Bugzilla::Product->check({ name => 'Infrastructure & Operations' }); |
| 27 | +my $relops_id = Bugzilla::Component->check({ product => $infra, name => 'RelOps' })->id; |
| 28 | +my $puppet_id = Bugzilla::Component->check({ product => $infra, name => 'RelOps: Puppet' })->id; |
| 29 | +my $infra_id = $infra->id; |
| 30 | +my $components = $dbh->sql_in('component_id', [ $relops_id, $puppet_id ]); |
| 31 | + |
| 32 | +print "Searching for bugs..\n"; |
| 33 | +my $bugs = $dbh->selectall_arrayref(<<EOF, { Slice => {} }); |
| 34 | + SELECT |
| 35 | + bug_id, |
| 36 | + product_id, |
| 37 | + component_id, |
| 38 | + status_whiteboard |
| 39 | + FROM |
| 40 | + bugs |
| 41 | + WHERE |
| 42 | + ( |
| 43 | + (product_id = $infra_id) |
| 44 | + AND NOT ($components) |
| 45 | + AND (status_whiteboard LIKE '%[kanban:engops:https://mozilla.kanbanize.com/ctrl_board/6/%') |
| 46 | + ) OR ( |
| 47 | + status_whiteboard LIKE '%[kanban:engops:https://kanbanize.com/ctrl_board/6/%' |
| 48 | + ) |
| 49 | +EOF |
| 50 | +die "No suitable bugs found\n" unless @$bugs; |
| 51 | +printf "About to fix %s bugs\n", scalar(@$bugs); |
| 52 | +print "Press <Ctrl-C> to stop or <Enter> to continue...\n"; |
| 53 | +getc(); |
| 54 | + |
| 55 | +my $nobody = Bugzilla::User->check({ name => 'nobody@mozilla.org' }); |
| 56 | +my $field = Bugzilla::Field->check({ name => 'status_whiteboard' }); |
| 57 | +my $when = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); |
| 58 | + |
| 59 | +my $sth_bugs = $dbh->prepare(" |
| 60 | + UPDATE bugs |
| 61 | + SET status_whiteboard = ?, |
| 62 | + delta_ts = ?, |
| 63 | + lastdiffed = ? |
| 64 | + WHERE bug_id = ? |
| 65 | +"); |
| 66 | +my $sth_activity = $dbh->prepare(" |
| 67 | + INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) |
| 68 | + VALUES (?, ?, ?, ?, ?, ?) |
| 69 | +"); |
| 70 | + |
| 71 | +$dbh->bz_start_transaction(); |
| 72 | +foreach my $bug (@$bugs) { |
| 73 | + my $bug_id = $bug->{bug_id}; |
| 74 | + my $whiteboard = $bug->{status_whiteboard}; |
| 75 | + print "bug $bug_id\n $whiteboard\n"; |
| 76 | + |
| 77 | + my $updated = $whiteboard; |
| 78 | + $updated =~ s#\[kanban:engops:https://kanbanize\.com/ctrl_board/6/[^\]]*\]\s*##g; |
| 79 | + if ($bug->{product_id} == $infra->id |
| 80 | + && $bug->{component_id} != $relops_id |
| 81 | + && $bug->{component_id} != $puppet_id |
| 82 | + ) { |
| 83 | + $updated =~ s#\[kanban:engops:https://mozilla\.kanbanize\.com/ctrl_board/6/[^\]]*\]\s*##g; |
| 84 | + } |
| 85 | + print " $updated\n"; |
| 86 | + |
| 87 | + $sth_bugs->execute($updated, $when, $when, $bug_id); |
| 88 | + $sth_activity->execute($bug_id, $nobody->id, $when, $field->id, $whiteboard, $updated); |
| 89 | +} |
| 90 | +$dbh->bz_commit_transaction(); |
| 91 | + |
| 92 | +print "Done.\n"; |
0 commit comments