Comment 3 for bug 1172944

Revision history for this message
Jeremy Stanley (fungi) wrote :

To properly map a Gerrit account to the corresponding Launchpad account, we piggyback on the only real existing relationship between them: authentication data. Here is an example of how we go about it in our infrastructure...

    https://github.com/openstack-infra/jeepyb/blob/master/jeepyb/cmd/update_bug.py

    query = """SELECT t.external_id FROM account_external_ids t
               INNER JOIN (
               SELECT t.account_id FROM account_external_ids t
               WHERE t.email_address = %s )
               original ON t.account_id = original.account_id
               AND t.external_id LIKE 'https://login.launchpad.net%%'"""
    cursor = jeepyb.gerritdb.connect().cursor()
    cursor.execute(query, searchkey)
    data = cursor.fetchone()
    if data:
        assignee = launchpad.people.getByOpenIDIdentifier(identifier=data[0])

In short, look up the OpenID URL associated with the Gerrit account, then query the Launchpad API for the user belonging to that URL. The example above used direct MySQL queries to Gerrit's backend database, but something similar could almost certainly be accomplished via grsql queries through Gerrit's SSH API interface instead if sufficient privileges are already in place. Alternatively, I could set up a data dump containing this mapping on demand, given some advance warning.