Ejemplo n.º 1
0
def test_labels_are_created_by_bmu(system, new_pr, bmu_conf, echoserver):
    label.init()
    repo_labels = sorted(label.get_existing_labels(system.github_repo['full_name']))
    proc = echoserver.start(2)
    label_resp = github.sync_request(
        'patch',
        "repos/bmcorser/{0}/issues/{1}".format(
            system.github_repo['name'],
            new_pr['number'],
        ),
        json={'labels': repo_labels[2:4]}
    )
    assert label_resp.ok
    data = echoserver.get_data(proc)
    assert [event['payload']['action'] for event in data] == [
        'labeled',
        'labeled',
    ]
    print(bmu_conf)
    # import ipdb;ipdb.set_trace()
    comment_resp = github.sync_post(
        "repos/bmcorser/{0}/issues/{1}/comments".format(
            system.github_repo['name'],
            new_pr['number'],
        ),
        json={'body': '@bmcorser fff'}
    )
    assert comment_resp.ok
Ejemplo n.º 2
0
def new_pr(system, echoserver):
    name = "branch-{0}".format(uuid.uuid4().hex[:7])
    system.git_run(['fetch', 'origin'])
    system.git_run(['reset', '--hard', 'origin/master'])
    system.git_run(['checkout', '-b', name])
    map(system.local_repo.commit, 'abcde')
    system.git_run(['push', 'origin', name])
    print("Creating PR for {0} on GitHub  ...".format(name))
    proc = echoserver.start(1)
    create_resp = github.sync_post(
        'repos/bmcorser/{0}/pulls'.format(system.github_repo['name']),
        json={
            'title': "PR for {0}".format(name),
            'base': 'master',
            'head': name,
        }
    )
    pr_json = create_resp.json()
    assert echoserver.get_data(proc)[0]['payload']['action'] == 'opened'
    yield pr_json
    print("Closing PR for {0} on GitHub  ...".format(name))
    close_resp = github.sync_request(
        'patch',
        'repos/{0}/{1}/pulls/{2}'.format(
            config.github_user,
            system.github_repo['name'],
            pr_json['number'],
        ),
        json={'state': 'closed'},
    )
    assert close_resp.ok
Ejemplo n.º 3
0
def github_repo():
    name = "bmu-{0}".format(uuid.uuid4().hex[:7])
    print("Creating GitHub repo {0} ...".format(name))
    create_resp = github.sync_post('user/repos', json={'name': name})
    assert create_resp.ok
    yield create_resp.json()
    print("Deleting GitHub repo {0} ...".format(name))
    delete_resp = github.sync_delete("repos/bmcorser/{0}".format(name))
    assert delete_resp.ok
Ejemplo n.º 4
0
def github_webhook(ngrok_server, bmu_conf, github_repo):
    print("Creating GitHub webhook for {0} ...".format(github_repo['name']))
    create_resp = github.sync_post(
        "repos/bmcorser/{0}/hooks".format(github_repo['name']),
        json={
            'name': 'web',
            'events': [
                'pull_request',
                'issue_comment',
            ],
            'config': {
                'url': os.path.join(ngrok_server, 'github'),
                'content_type': 'json',
                'secret': config.github_webhook_secret,
            }
        }
    )
    assert create_resp.ok
    return create_resp.json()
Ejemplo n.º 5
0
def ssh_wrapper(github_repo):
    WRAPPER_TEMPLATE = '''#!/bin/bash
ssh -i {0} $1 $2'''
    key = RSA.generate(2048)

    private = tempfile.NamedTemporaryFile(delete=False)
    os.chmod(private.name, 0600)
    private.write(key.exportKey('PEM'))
    private.file.flush()
    private.close()

    public = tempfile.NamedTemporaryFile(delete=False)
    public.write(key.publickey().exportKey('OpenSSH'))
    public.file.flush()
    public.close()

    wrapper = tempfile.NamedTemporaryFile(delete=False)
    wrapper.write(WRAPPER_TEMPLATE.format(private.name))
    wrapper.file.flush()
    wrapper.close()
    os.chmod(wrapper.name, 0755)

    with open(public.name, 'r') as pubkey_file:
        pubkey_content = pubkey_file.read()
    print('Adding temp pubkey to GitHub ...')
    create_resp = github.sync_post(
        'user/keys',
        json={'title': github_repo['name'], 'key': pubkey_content}
    )
    assert create_resp.ok
    key_id = create_resp.json()['id']

    yield wrapper.name

    map(os.remove, (wrapper.name, private.name, public.name))
    print('Deleting temp pubkey from GitHub ...')
    delete_resp = github.sync_delete("user/keys/{0}".format(key_id))
    assert delete_resp.ok