Example #1
0
def setup_branches(opts):
    """
    set up git branches, starting from master
    """
    do_push = not opts.no_remote
    LOGGER.info("setting up branches master={} develop={}".format(
        opts.master, opts.develop))
    with working_dir(opts.repo):
        initializer = RepoInitializer(opts.repo)
        initializer.init_branch(opts.master, opts.origin, remote=do_push)
        initializer.init_branch(opts.develop, opts.origin, remote=do_push)
        branch(opts.repo, opts.develop, opts.master)
    LOGGER.info("Working on {}".format(get_active_branch(opts.repo)))
Example #2
0
def create_pull_request(
        repo_dir,
        pr_info,
        token=None):
    """
    Creates a pull_request on GitHub and returns the html url of the
    pull request created

    :param repo_dir: directory of git repository
    :param pr_info: dictionary containing title and body of pull request
    :param token: auth token
    """
    if repo_dir is None:
        raise RuntimeError('repo_dir is None')
    if 'title' not in pr_info:
        raise RuntimeError('title is None')
    if 'body' not in pr_info:
        raise RuntimeError('body is None')
    config = load_configuration()

    url = 'https://api.github.com/repos/{0}/{1}/pulls'.format(
        config.organisation_name(),
        config.package_name())

    if token is None:
        token = get_github_auth()[1]

    headers = {
        'Authorization': 'token {0}'.format(token),
        'Content-Type': 'application/json'}

    data = {
        'title': pr_info['title'],
        'head': get_active_branch(repo_dir).name,
        'base': config.gitflow_branch_name(),
        'body': pr_info['body']}

    resp = requests.post(url, data=json.dumps(data), headers=headers)
    if resp.status_code == 422:
        LOGGER.error(
            (
                "POST to GitHub api returned {0}"
                "Have you committed your changes and pushed to remote?"
            ).format(resp.status_code)
        )

    resp.raise_for_status()
    resp_json = resp.json()

    return resp_json['html_url']
Example #3
0
def create_pull_request(
        repo_dir,
        pr_info,
        token=None):
    """
    Creates a pull_request on GitHub and returns the html url of the
    pull request created

    :param repo_dir: directory of git repository
    :param pr_info: dictionary containing title and body of pull request
    :param token: auth token
    """
    if repo_dir is None:
        raise RuntimeError('repo_dir is None')
    if 'title' not in pr_info:
        raise RuntimeError('title is None')
    if 'body' not in pr_info:
        raise RuntimeError('body is None')
    config = load_configuration()

    url = 'https://api.github.com/repos/{0}/{1}/pulls'.format(
        config.organisation_name(),
        config.package_name())

    if token is None:
        token = get_github_auth()[1]

    headers = {
        'Authorization': 'token {0}'.format(token),
        'Content-Type': 'application/json'}

    data = {
        'title': pr_info['title'],
        'head': get_active_branch(repo_dir).name,
        'base': config.gitflow_branch_name(),
        'body': pr_info['body']}

    resp = requests.post(url, data=json.dumps(data), headers=headers)
    if resp.status_code == 422:
        LOGGER.error(
            (
                "POST to GitHub api returned {0}"
                "Have you committed your changes and pushed to remote?"
            ).format(resp.status_code)
        )

    resp.raise_for_status()
    resp_json = resp.json()

    return resp_json['html_url']
Example #4
0
def setup_branches(opts):
    """
    set up git branches, starting from master
    """
    do_push = not opts.no_remote
    LOGGER.info("setting up branches master={} develop={}".format(
        opts.master, opts.develop))
    with working_dir(opts.repo):
        branch(opts.repo, opts.master, opts.master)
        branch(opts.repo, opts.develop, opts.master)
        if do_push:
            LOGGER.info("Pushing {}...".format(opts.develop))
            push(opts.repo)

    LOGGER.info("Working on {}".format(get_active_branch(opts.repo)))
Example #5
0
 def test_get_active_branch(self):
     """
     _test_get_active_branch_
     """
     get_active_branch(None)
     self.failUnless(self.mock_git.Repo.called)
Example #6
0
 def test_get_active_branch(self):
     """
     _test_get_active_branch_
     """
     get_active_branch(None)
     self.failUnless(self.mock_git.Repo.called)