示例#1
0
def review_task(options):
    """Create a bitbucket issue for reviewing a module.
    """
    module = _get_module(options)
    if not module:
        raise RuntimeError('could not determine which module to use')

    cfg_filename = path('~/.bitbucketrc').expanduser()
    cfg = configparser.ConfigParser()
    if not cfg.read(cfg_filename):
        raise RuntimeError(
            'Did not find configuration file {}'.format(cfg_filename))

    auth = pybb_auth.OAuth1Authenticator(
        client_key=cfg['bitbucket']['client_key'],
        client_secret=cfg['bitbucket']['client_secret'],
        client_email=cfg['bitbucket']['email'],
    )

    client = pybb_bb.Client(auth)

    repo = pybb_repo.Repository.find_repository_by_name_and_owner(
        repository_name='pymotw-3',
        owner='dhellmann',
        client=client,
    )

    # The client library doesn't have issue support yet, so we have to
    # do it by hand.
    url_template = repo.v1.get_link_template('issues')
    url = uritemplate.expand(
        url_template,
        {
            'bitbucket_url': client.get_bitbucket_url(),
            'owner': 'dhellmann',
            'repository_name': 'pymotw-3',
        },
    )
    args = {
        'title': 'technical review for {}'.format(module),
        'content': 'Perform the technical review for {}'.format(module),
        'kind': 'task',
        'priority': 'minor',
    }
    encoded = urllib.parse.urlencode(args)

    response = repo.v1.post(
        url=url,
        client=client,
        data=encoded,
    )
    pprint.pprint(response)
    print()
    task_url = 'https://bitbucket.org/dhellmann/pymotw-3/issues/{}'.format(
        response['local_id'])
    print(task_url)
示例#2
0
    def get_pull_request(username, password, email, repository_name, owner,
                         branch_name):
        """Returns the latest updated OPEN pull request for a particular branch."""
        client = bitbucket.Client(
            pybitbucket.auth.BasicAuthenticator(username, password, email))
        bb = bitbucket.Bitbucket(client)
        bb.add_remote_relationship_methods(PR_BY_QUERY_ENDPOINT)

        res = bb.repositoryPullRequestsByQuery(
            owner=owner,
            repository_name=repository_name,
            q='source.branch.name = "%s" AND state = "OPEN"' % branch_name,
            sort="-updated_on")

        pr = next(res)
        # This is weird, but if there's no data, we're getting a dict back.
        if isinstance(pr, dict):
            return None
        user = next(bb.userForMyself())
        return PullRequest(pr, user)
示例#3
0
 def _client(self):
     return pybb_bitbucket.Client(self._authenticator())