view bzgit.py @ 0:89e0c87f09ca

initial (STUB) commit
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 11 Dec 2012 16:41:39 -0800
parents
children 240f98f19ee3
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)

    # ...and move all the things
    bz = bzconsole

if __name__ == '__main__':
    main()