view bzgit.py @ 5:6c1ca906ffa4

stubbing
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 17 Dec 2012 11:32:47 -0800
parents 9fb08361ac8d
children 7138a453ecf7
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] http://github.com/url/of/pull/request'
    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(pull_request, github_user, github_project)

    # move all the things
    bz = bzconsole.BZapi()
#    new = bz.new()
#

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

    # close pull request
    # TODO

if __name__ == '__main__':
    main()