Пример #1
0
def approve(pr_number, sha):
    return post_repo(FQ_REPO,
                     f'pulls/{pr_number}/reviews',
                     json={
                         "commit_id": sha,
                         "event": "APPROVE"
                     },
                     status_code=200,
                     token=oauth_tokens['user2'])
Пример #2
0
def create_pull_request(title, ref, base="master"):
    return post_repo(FQ_REPO,
                     'pulls',
                     json={
                         "title": title,
                         "head": ref,
                         "base": base
                     },
                     status_code=201,
                     token=oauth_tokens['user1'])
Пример #3
0
def approve(pr_number, sha):
    return post_repo(
        FQ_REPO,
        f'pulls/{pr_number}/reviews',
        json={
            "commit_id": sha,
            "event": "APPROVE"
        },
        status_code=200,
        token=oauth_tokens['user2'])
Пример #4
0
def create_pull_request(title, ref, base="master"):
    return post_repo(
        FQ_REPO,
        'pulls',
        json={
            "title": title,
            "head": ref,
            "base": base
        },
        status_code=201,
        token=oauth_tokens['user1'])
Пример #5
0
def test_merges_approved_pr(tmpdir):
    BRANCH_NAME = 'test_merges_approved_pr'
    pr_number = None
    try:
        status = ci_get('/status', status_code=200)
        assert '_watched_targets' in status
        assert status['_watched_targets'] == [[{
            'repo': {
                'name': REPO_NAME,
                'owner': 'hail-ci-test'
            },
            'name': 'master'
        }, True]]
        os.chdir(tmpdir)
        call(
            [
                'git', 'clone',
                f'https://{oauth_tokens["user1"]}@github.com/hail-ci-test/{REPO_NAME}.git'
            ],
            # do not leak the token
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL)
        os.chdir(REPO_NAME)
        call([
            'git', 'config', 'user.email',
            '*****@*****.**'
        ])
        call(['git', 'config', 'user.name', 'ci-automated-tests'])
        call(['git', 'remote', '-v'])

        call(['git', 'checkout', '-b', BRANCH_NAME])
        call(['git', 'commit', '--allow-empty', '-m', 'foo'])
        call(['git', 'push', 'origin', BRANCH_NAME])
        source_sha = rev_parse(BRANCH_NAME)
        gh_pr = post_repo(FQ_REPO,
                          'pulls',
                          json={
                              "title": "foo",
                              "head": BRANCH_NAME,
                              "base": "master"
                          },
                          status_code=201)
        pr_number = str(gh_pr['number'])
        post_repo(FQ_REPO,
                  f'pulls/{pr_number}/reviews',
                  json={
                      "commit_id": source_sha,
                      "event": "APPROVE"
                  },
                  status_code=200,
                  token=oauth_tokens['user2'])
        get_repo(FQ_REPO,
                 f'pulls/{pr_number}/reviews',
                 status_code=200,
                 token=oauth_tokens['user1'])
        time.sleep(7)
        poll_github_until_merged(pr_number)

        call(['git', 'fetch', 'origin'])
        merged_sha = rev_parse('origin/master')

        # deploy job takes some time
        time.sleep(7)

        deploy_artifact = run(
            ['gsutil', 'cat', f'gs://hail-ci-test/{merged_sha}'],
            stdout=subprocess.PIPE,
            check=True)
        deploy_artifact = deploy_artifact.stdout.decode('utf-8').strip()
        assert f'commit {merged_sha}' in deploy_artifact
    finally:
        call(['git', 'push', 'origin', ':' + BRANCH_NAME])
        if pr_number is not None:
            patch_repo(FQ_REPO,
                       f'pulls/{pr_number}',
                       json={"state": "closed"},
                       status_code=200)
Пример #6
0
def test_pull_request_trigger(tmpdir):
    BRANCH_NAME = 'test_pull_request_trigger'
    pr_number = None
    try:
        status = ci_get('/status', status_code=200)
        assert '_watched_targets' in status
        assert status['_watched_targets'] == [[{
            'repo': {
                'name': REPO_NAME,
                'owner': 'hail-ci-test'
            },
            'name': 'master'
        }, True]]
        os.chdir(tmpdir)
        call(
            [
                'git', 'clone',
                f'https://{oauth_tokens["user1"]}@github.com/hail-ci-test/{REPO_NAME}.git'
            ],
            # do not leak the token
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL)
        os.chdir(REPO_NAME)
        call([
            'git', 'config', 'user.email',
            '*****@*****.**'
        ])
        call(['git', 'config', 'user.name', 'ci-automated-tests'])
        call(['git', 'remote', '-v'])

        call(['git', 'checkout', '-b', BRANCH_NAME])
        call(['git', 'commit', '--allow-empty', '-m', 'foo'])
        call(['git', 'push', 'origin', BRANCH_NAME])
        source_sha = rev_parse(BRANCH_NAME)
        target_sha = rev_parse('master')
        data = post_repo(FQ_REPO,
                         'pulls',
                         json={
                             "title": "foo",
                             "head": BRANCH_NAME,
                             "base": "master"
                         },
                         status_code=201,
                         token=oauth_tokens['user1'])
        pr_number = str(data['number'])
        time.sleep(7)
        pr = poll_until_finished_pr(BRANCH_NAME)
        assertDictHasKVs(
            pr.to_json(), {
                "target": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": "master"
                    },
                    "sha": target_sha
                },
                "source": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": BRANCH_NAME
                    },
                    "sha": source_sha
                },
                "review": "pending",
                "build": {
                    "type": "Mergeable",
                    "target_sha": target_sha
                },
                "number": pr_number
            })
    finally:
        call(['git', 'push', 'origin', ':' + BRANCH_NAME])
        if pr_number is not None:
            patch_repo(FQ_REPO,
                       f'pulls/{pr_number}',
                       json={"state": "closed"},
                       status_code=200,
                       token=oauth_tokens['user1'])
Пример #7
0
def test_merges_approved_pr(tmpdir):
    BRANCH_NAME = 'test_merges_approved_pr'
    pr_number = None
    try:
        status = ci_get('/status', status_code=200)
        assert '_watched_targets' in status
        assert status['_watched_targets'] == [[{
            'repo': {
                'name': REPO_NAME,
                'owner': 'hail-ci-test'},
            'name': 'master'}, True]]
        os.chdir(tmpdir)
        call(['git', 'clone', f'https://{oauth_tokens["user1"]}@github.com/hail-ci-test/{REPO_NAME}.git'],
             # do not leak the token
             stdout=subprocess.DEVNULL,
             stderr=subprocess.DEVNULL)
        os.chdir(REPO_NAME)
        call(['git', 'config', 'user.email', '*****@*****.**'])
        call(['git', 'config', 'user.name', 'ci-automated-tests'])
        call(['git', 'remote', '-v'])

        call(['git', 'checkout', '-b', BRANCH_NAME])
        call(['git', 'commit', '--allow-empty', '-m', 'foo'])
        call(['git', 'push', 'origin', BRANCH_NAME])
        source_sha = rev_parse(BRANCH_NAME)
        gh_pr = post_repo(
            FQ_REPO,
            'pulls',
            json={
                "title": "foo",
                "head": BRANCH_NAME,
                "base": "master"
            },
            status_code=201)
        pr_number = str(gh_pr['number'])
        post_repo(
            FQ_REPO,
            f'pulls/{pr_number}/reviews',
            json={
                "commit_id": source_sha,
                "event": "APPROVE"
            },
            status_code=200,
            token=oauth_tokens['user2'])
        get_repo(
            FQ_REPO,
            f'pulls/{pr_number}/reviews',
            status_code=200,
            token=oauth_tokens['user1'])
        time.sleep(7)
        poll_github_until_merged(pr_number)

        call(['git', 'fetch', 'origin'])
        merged_sha = rev_parse('origin/master')

        poll_until_deployed_sha_is(FQRef.from_short_str(FQ_REPO+':master'),
                                   merged_sha)

        deploy_artifact = run(['gsutil', 'cat', f'gs://hail-ci-test/{merged_sha}'], stdout=subprocess.PIPE, check=True)
        deploy_artifact = deploy_artifact.stdout.decode('utf-8').strip()
        assert f'commit {merged_sha}' in deploy_artifact
    finally:
        call(['git', 'push', 'origin', ':' + BRANCH_NAME])
        if pr_number is not None:
            patch_repo(
                FQ_REPO,
                f'pulls/{pr_number}',
                json={"state": "closed"},
                status_code=200)
Пример #8
0
def test_pull_request_trigger(tmpdir):
    BRANCH_NAME = 'test_pull_request_trigger'
    pr_number = None
    try:
        status = ci_get('/status', status_code=200)
        assert '_watched_targets' in status
        assert status['_watched_targets'] == [[{
            'repo': {
                'name': REPO_NAME,
                'owner': 'hail-ci-test'},
            'name': 'master'}, True]]
        os.chdir(tmpdir)
        call(['git', 'clone', f'https://{oauth_tokens["user1"]}@github.com/hail-ci-test/{REPO_NAME}.git'],
             # do not leak the token
             stdout=subprocess.DEVNULL,
             stderr=subprocess.DEVNULL)
        os.chdir(REPO_NAME)
        call(['git', 'config', 'user.email', '*****@*****.**'])
        call(['git', 'config', 'user.name', 'ci-automated-tests'])
        call(['git', 'remote', '-v'])

        call(['git', 'checkout', '-b', BRANCH_NAME])
        call(['git', 'commit', '--allow-empty', '-m', 'foo'])
        call(['git', 'push', 'origin', BRANCH_NAME])
        source_sha = rev_parse(BRANCH_NAME)
        target_sha = rev_parse('master')
        data = post_repo(
            FQ_REPO,
            'pulls',
            json={
                "title": "foo",
                "head": BRANCH_NAME,
                "base": "master"
            },
            status_code=201,
            token=oauth_tokens['user1'])
        pr_number = str(data['number'])
        time.sleep(7)
        pr = poll_until_finished_pr(BRANCH_NAME)
        assertDictHasKVs(
            pr.to_dict(),
            {
                "target": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": "master"
                    },
                    "sha": target_sha
                },
                "source": {
                    "ref": {
                        "repo": {
                            "owner": "hail-ci-test",
                            "name": REPO_NAME
                        },
                        "name": BRANCH_NAME
                    },
                    "sha": source_sha
                },
                "review": "pending",
                "build": {
                    "type": "Mergeable",
                    "target_sha": target_sha
                },
                "number": pr_number
            })
    finally:
        call(['git', 'push', 'origin', ':' + BRANCH_NAME])
        if pr_number is not None:
            patch_repo(
                FQ_REPO,
                f'pulls/{pr_number}',
                json={"state": "closed"},
                status_code=200,
                token=oauth_tokens['user1'])