view bzgit.py @ 1:240f98f19ee3

notes to self
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 12 Dec 2012 10:05:57 -0800
parents 89e0c87f09ca
children 9fb08361ac8d
line wrap: on
line source

#!/usr/bin/env python

"""
bzgit
github <-> bugzilla.m.o bridge
"""

import bzconsole
import optparse
import sys
import urlparse
from pygithub3 import Github

def path_segments(path):
    """return path segments"""
    segments = path.strip('/').split('/')
    if segments == ['']:
        return []
    return segments

def add_options(parser):
    """add bzgit options to an OptionParser instance"""


def main(args=sys.argv[1:]):

    # parse command line arguments
    usage = '%prog [options] ...'
    class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
        """description formatter"""
        def format_description(self, description):
            if description:
                return description.strip() + '\n'
            else:
                return ''
    parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
    add_options(parser)
    options, args = parser.parse_args(args)
    if not args:
        parser.print_usage()
        parser.exit()

    # parse resource
    assert len(args) == 1 # for now
    resource = args[0]
    scheme, hostspec, path, query, anchor = urlparse.urlsplit(resource)
    segments = path_segments(path)
    assert len(segments) > 2 # for now
    github_user = segments[0]
    github_project = segments[1]

    assert len(segments) == 4 # for now
    assert segments[2] == 'pull'
    pull_request = int(segments[3])

    # connect to gh
    gh = Github() # TODO: auth
    pull = gh.pull_requests.get(44, github_user, github_project)

    # move all the things [TODO]
    bz = bzconsole

    # comment on pull request wrt bugzilla.m.o issue location
    # TODO

    # close pull request
    # TODO

if __name__ == '__main__':
    main()