summaryrefslogtreecommitdiffstats
path: root/extensions/BMO/bin/migrate-github-pull-requests.pl
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/BMO/bin/migrate-github-pull-requests.pl')
-rwxr-xr-xextensions/BMO/bin/migrate-github-pull-requests.pl67
1 files changed, 30 insertions, 37 deletions
diff --git a/extensions/BMO/bin/migrate-github-pull-requests.pl b/extensions/BMO/bin/migrate-github-pull-requests.pl
index c39778a4a..c8afdedfb 100755
--- a/extensions/BMO/bin/migrate-github-pull-requests.pl
+++ b/extensions/BMO/bin/migrate-github-pull-requests.pl
@@ -22,9 +22,9 @@ use Bugzilla::Install::Util qw(indicate_progress);
use Bugzilla::User;
use Bugzilla::Util qw(trim);
-my $dbh = Bugzilla->dbh;
-my $nobody = Bugzilla::User->check({ name => Bugzilla->params->{'nobody_user'} });
-my $field = Bugzilla::Field->check({ name => 'attachments.mimetype' });
+my $dbh = Bugzilla->dbh;
+my $nobody = Bugzilla::User->check({name => Bugzilla->params->{'nobody_user'}});
+my $field = Bugzilla::Field->check({name => 'attachments.mimetype'});
# grab list of suitable attachments
@@ -42,7 +42,7 @@ SELECT attachments.attach_id,
AND LENGTH(thedata) <= 256
EOF
print "Searching for suitable attachments..\n";
-my $attachments = $dbh->selectall_arrayref($sql, { Slice => {} });
+my $attachments = $dbh->selectall_arrayref($sql, {Slice => {}});
my ($current, $total, $updated) = (1, scalar(@$attachments), 0);
die "No suitable attachments found\n" unless $total;
@@ -52,39 +52,32 @@ print "Press <enter> to start, or ^C to cancel...\n";
<>;
foreach my $attachment (@$attachments) {
- indicate_progress({ current => $current++, total => $total, every => 25 });
-
- # check payload
- my $url = trim($attachment->{thedata});
- next if $url =~ /\s/;
- next unless $url =~ m#^https://github\.com/[^/]+/[^/]+/pull/\d+\/?$#i;
-
- $dbh->bz_start_transaction;
-
- # set content-type
- $dbh->do(
- "UPDATE attachments SET mimetype = ? WHERE attach_id = ?",
- undef,
- 'text/x-github-pull-request', $attachment->{attach_id}
- );
-
- # insert into bugs_activity
- my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)');
- $dbh->do(
- "INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added)
- VALUES (?, ?, ?, ?, ?, ?)",
- undef,
- $attachment->{bug_id}, $nobody->id, $timestamp, $field->id,
- $attachment->{mimetype}, 'text/x-github-pull-request'
- );
- $dbh->do(
- "UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?",
- undef,
- $timestamp, $timestamp, $attachment->{bug_id}
- );
-
- $dbh->bz_commit_transaction;
- $updated++;
+ indicate_progress({current => $current++, total => $total, every => 25});
+
+ # check payload
+ my $url = trim($attachment->{thedata});
+ next if $url =~ /\s/;
+ next unless $url =~ m#^https://github\.com/[^/]+/[^/]+/pull/\d+\/?$#i;
+
+ $dbh->bz_start_transaction;
+
+ # set content-type
+ $dbh->do("UPDATE attachments SET mimetype = ? WHERE attach_id = ?",
+ undef, 'text/x-github-pull-request', $attachment->{attach_id});
+
+ # insert into bugs_activity
+ my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)');
+ $dbh->do(
+ "INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added)
+ VALUES (?, ?, ?, ?, ?, ?)", undef, $attachment->{bug_id},
+ $nobody->id, $timestamp, $field->id, $attachment->{mimetype},
+ 'text/x-github-pull-request'
+ );
+ $dbh->do("UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?",
+ undef, $timestamp, $timestamp, $attachment->{bug_id});
+
+ $dbh->bz_commit_transaction;
+ $updated++;
}
print "Attachments updated: $updated\n";