Linking Launchpad and Bugzilla

While the Bugzilla command line tool does a lot of useful things, one feature it is missing is the ability to link a bug to an upstream bug in a remote tracker. Working with the Web UI can be slow. Martin Kozek, of FreeIPA fame, wrote a simple Python program to link them together for me using direct XML-API calls. Thanks Martin:

#!/usr/bin/python
#
# Authors:
#   Martin Kosek: mkosek@redhat.com
#
# Copyright (C) 2013  Red Hat
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see http://www.gnu.org/licenses/.

import bugzilla
import sys
import xmlrpclib

URL = 'https://bugzilla.redhat.com/xmlrpc.cgi'
USER = 'user@redhat.com'
PASSWORD = 'bar'

try:
    bz_id = int(sys.argv[1])
    launchpad_id = int(sys.argv[2])
except Exception:
    sys.exit("Usage: bz_lp_link bz_id lp_id")

proxy = bugzilla.RHBugzilla3(url=URL, user=USER, password=PASSWORD)
proxy.connect(URL)

LAUNCHPAD_TRACKER_ID = 29

try:
    proxy._proxy.ExternalBugs.add_external_bug(
        {'bug_ids':[bz_id],
         'external_bugs': [{'ext_type_id': LAUNCHPAD_TRACKER_ID,
                            'ext_bz_bug_id': launchpad_id}]
        })
except xmlrpclib.Fault, e:
    sys.exit(e.faultString)

2 thoughts on “Linking Launchpad and Bugzilla

  1. #!/usr/bin/python
    should be
    #!/usr/bin/env python

    remember that python is usually not in /usr/bin

  2. Bob,

    Python is *always* in /usr/bin for me. It just might not be the Python you want for a specific application, but for a Fedora based system, running standard libraries, you want the system version.

    But I appreciate the input. I suspect that what you say is correct for many people out there.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.