Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
github to bugzilla migration
#!/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/.
# See https://bugzilla.mozilla.org/show_bug.cgi?id=793784
use strict;
use warnings;
use HTTP::Cookies;
use JSON;
use LWP::UserAgent;
use Storable qw(dclone);
use XMLRPC::Lite;
my $config = {
github => {
repo => 'mozilla-b2g/gaia',
username => 'unknown',
password => '********',
filter => 'state=open&labels=bug',
},
bugzilla => {
url => 'https://bugzilla.mozilla.org/xmlrpc.cgi',
username => 'unknown',
password => '********',
},
bug_template => {
product => 'Boot2Gecko',
component => 'Gaia',
version => 'unspecified',
op_sys => 'ARM',
platform => 'Gonk',
},
};
my $user_map = {
'tacperez' => 'acperez@tid.es',
'adamkalis' => 'fredy@freemail.gr',
'akeybl' => 'akeybl@mozilla.com',
'albertopq' => '',
'alivedise' => 'alive@mozilla.com',
'amas@tid.es' => '',
'andreasgal' => 'gal@uci.edu',
'arcturus' => 'arcturus@ardeenelinfierno.com',
'asutherland' => 'bugmail@asutherland.org',
'authoritaire' => '',
'autonome' => 'dietrich@mozilla.com',
'aymanmaat' => '',
'b2gautomation' => '',
'basiclines' => '',
'bbajaj' => 'bbajaj@mozilla.com',
'beatrizrodriguez' => 'brg@tid.es',
'benfrancis' => 'ben@krellian.com',
'borjasalguero' => '',
'carlosmartineztoral' => '',
'caseyyee' => 'kyee@mozilla.com',
'cgjones' => 'jones.chris.g@gmail.com',
'ckerschb' => 'mozilla@christophkerschbaumer.com',
'cleemoz' => 'clee@mozilla.com',
'crdlc' => '',
'daeken' => 'cbrocious@mozilla.com',
'daleharvey' => 'dale@arandomurl.com',
'davidflanagan' => 'dflanagan@mozilla.com',
'dclarke' => 'dclarke@mozilla.com',
'dcoloma' => 'dcoloma@tid.es',
'dhylands' => 'dhylands@mozilla.com',
'dominickuo' => 'dkuo@mozilla.com',
'dpgr390' => '',
'dscravag' => 'dscravaglieri@mozilla.com',
'eric30' => 'echou@mozilla.com',
'erikziegler' => '',
'etiennesegonzac' => 'etienne@segonzac.info',
'evelynhung' => 'ehung@mozilla.com',
'fabi1cazenave' => 'kaze@kompozer.net',
'fabricedesre' => 'fabrice@mozilla.com',
'faramoz' => 'frashed@mozilla.com',
'fcampo' => 'fcampo@novanotio.es',
'ferjm' => 'ferjmoreno@gmail.com',
'flamsmark' => 'tom@mozilla.com',
'frank-lee' => '',
'fzzzy' => 'dpreston@mozilla.com',
'gaiacucumber' => '',
'geoelectric' => 'gmealer@mozilla.com',
'glandium' => 'mh+mozilla@glandium.org',
'gregorwagner' => 'anygregor@gmail.com',
'gtorodelvalle' => 'gtorodelvalle@gmail.com',
'ian-liu' => 'iliu@mozilla.com',
'Irinasandu' => 'isandu@mozilla.com',
'isabelrios' => 'isabelrios@aurigae.com',
'jammink' => 'jhammink@mozilla.com',
'jaoo' => 'josea.olivera@gmail.com',
'jcarpenter' => 'jcarpenter@mozilla.com',
'jds2501' => 'jsmith@mozilla.com',
'jhford' => 'jhford@mozilla.com',
'jlebar' => 'justin.lebar+bug@gmail.com',
'jmcanterafonseca' => '',
'johnshih' => 'jshih@mozilla.com',
'jonallengriffin' => 'jgriffin@mozilla.com',
'juanb' => 'jbecerra@mozilla.com',
'kaichih' => 'khu khu@mozilla.com',
'krupa' => 'krupa.mozbugs@gmail.com',
'lco' => 'lco@mozilla.com',
'lightsofapollo' => 'jlal@mozilla.com',
'lodr' => 'salva@unoyunodiez.com',
'lsblakk' => 'lsblakk@mozilla.com',
'm8ttyB' => 'mbrandt@mozilla.com',
'marshall' => 'marshall@mozilla.com',
'mbarone' => 'mbarone976@gmail.com',
'michaelwu' => 'mwu@mozilla.com',
'michalbe' => '',
'mlara' => 'jmlara@helphone.com',
'mozillamarcia' => 'mozillamarcia.knous@gmail.com',
'MozMatej' => 'Mnovak@Mozilla.com',
'mozsquib' => 'squibblyflabbetydoo@gmail.com',
'mrbkap' => 'mrbkap@gmail.com',
'MTreesem' => 'treese@mozilla.com',
'nhirata' => 'nhirata.bugzilla@gmail.com',
'oteo' => 'oteo@tid.es',
'overholt' => 'overholt@mozilla.com',
'patrykdesign' => 'padamczyk@mozilla.com',
'PeterLa' => 'pla@mozilla.com',
'philikon' => 'philipp@weitershausen.de',
'pivanov' => 'pivanov@mozilla.com',
'potch' => 'thepotch@gmail.com',
'pragmatictester' => 'parul@pragmatictester.com',
'qdot' => 'kyle@nonpolynomial.com',
'rafaelrebolleda' => '',
'RayCheung' => 'pzhang@mozilla.com',
'RudyLu' => 'Rudy Lu rlu@mozilla.com',
'sergivila' => '',
'shianyow' => 'swu@mozilla.com',
'silvialatzer' => '',
'stasm' => 'stas@mozilla.com',
'stephendonner' => 'stephen.donner@gmail.com',
'steveck-chung' => 'schung@mozilla.com',
'ThinkerYzu' => 'Thinker tlee@mozilla.com',
'timdream' => 'timdream+bugs@gmail.com',
'tonychung' => 'tchung@mozilla.com',
'vicamo' => 'vyang@mozilla.com',
'vingtetun' => '21@vingtetun.org',
};
#
# connect/auth
#
print "connecting to github..\n";
github('');
print "connecting to bugzilla..\n";
bugzilla(
'User.login', {
login => $config->{bugzilla}->{username},
password => $config->{bugzilla}->{password},
remember => 1,
});
#
# migration
#
print "finding issues..\n";
my $issues = github("issues?$config->{github}->{filter}&sort=created&direction=asc");
printf "found %s issue(s)\n", scalar(@$issues);
foreach my $issue (@$issues) {
print "adding issue $issue->{number}..\n";
# create bug
my $bug = dclone($config->{bug_template});
$bug->{summary} = $issue->{title};
$bug->{description} =
$issue->{body} .
"\n\nOriginal bug available at " .
"https://github.com/$config->{github}->{repo}/issues/$issue->{number}";
my @whiteboard;
foreach my $label (@{ $issue->{labels} }) {
next if $label->{name} =~ /^blocking-basecamp[\?\+\-]$/;
push @whiteboard, "[$label->{name}]";
}
$bug->{whiteboard} = join(' ', @whiteboard);
if ($issue->{assignee}
&& exists $user_map->{$issue->{assignee}->{login}}
&& $user_map->{$issue->{assignee}->{login}})
{
$bug->{assigned_to} = $user_map->{$issue->{assignee}->{login}};
}
$bug->{cf_blocking_basecamp} = '?'
if grep { $_->{name} eq 'blocking-basecamp?' } @{ $issue->{labels} };
$bug->{cf_blocking_basecamp} = '+'
if grep { $_->{name} eq 'blocking-basecamp+' } @{ $issue->{labels} };
$bug->{cf_blocking_basecamp} = '-'
if grep { $_->{name} eq 'blocking-basecamp-' } @{ $issue->{labels} };
my $result = bugzilla('Bug.create', $bug);
my $bug_id = $result->{id};
print "bug $bug_id created\n";
# add bugzilla comment
my @comments;
if ($issue->{comments} > 0) {
print "adding comments to bug $bug_id..\n";
my $comments = github("issues/$issue->{number}/comments");
foreach my $comment (@$comments) {
push @comments, $comment->{body};
}
$result = bugzilla('Bug.add_comment', {
id => $bug_id,
comment => join("\n\n", @comments),
});
}
# close github issue
print "closing github issue..\n";
github(
"issues/$issue->{number}/comments", {
body => "This bug is now being tracked in Bugzilla " .
"at https://bugzilla.mozilla.org/show_bug.cgi?id=$bug_id",
});
github(
"issues/$issue->{number}", {
state => 'closed',
});
}
#
# helpers
#
my $_bugzilla;
sub bugzilla {
my ($method, $params) = @_;
$_bugzilla ||= XMLRPC::Lite->proxy(
$config->{bugzilla}->{url},
'cookie_jar' => HTTP::Cookies->new);
my $soapresult = $_bugzilla->call($method, $params);
if ($soapresult->fault) {
my ($package, $filename, $line) = caller;
die $soapresult->faultcode . ' ' . $soapresult->faultstring .
" in SOAP call near $filename line $line.\n";
}
return $soapresult->result;
}
my $_ua;
sub github {
my ($uri_fragment, $json) = @_;
$_ua ||= LWP::UserAgent->new();
$uri_fragment = $uri_fragment
? $config->{github}->{repo} . "/$uri_fragment"
: $config->{github}->{repo};
my $url = sprintf(
'https://%s:%s@api.github.com/repos/%s',
$config->{github}->{username},
$config->{github}->{password},
$uri_fragment);
my $response;
if ($json) {
$response = $_ua->post($url, Content => to_json($json));
} else {
$response = $_ua->get($url);
}
die "GitHub request '$uri_fragment' failed: " . $response->message . "\n"
if $response->is_error;
return from_json($response->content);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment