Пример #1
0
def enable_ci_for_repo(repo, gh_token):
    """ Enable the travis hook for the given repo. """

    access_token = travis_utils.get_access_token(gh_token)
    repo_id      = travis_utils.get_repo_id(repo, access_token)
    enabled = travis_utils.enable_hook(repo_id, access_token)
    if enabled:
        print('Enabled GitHub/Travis hook for %s' % repo)

    else:
        print('Failed to enable GitHub/Travis hook for %s' % repo)
Пример #2
0

def get_gh_token(bogus):
    """ Returns the GH token to use. """
    # fixme: Change this to check if we are rate limited, an use BOGUS if so.

    token = os.environ.get('GH_TOKEN', bogus)

    return token

BOGUS = 'this-is-a-bogus-token'
THIS_REPO = 'punchagan/statiki'
GH_TOKEN = get_gh_token(BOGUS)
TRAVIS_TOKEN = (
    BOGUS if GH_TOKEN == BOGUS else
    travis_utils.get_access_token(GH_TOKEN)
)


@unittest.skipIf(TRAVIS_TOKEN == BOGUS, 'Need a real GitHubtoken...')
class TestTravisUtils(unittest.TestCase):

    def test_should_find_existing_hook(self):
        self.assertTrue(
            travis_utils.hook_exists(THIS_REPO, TRAVIS_TOKEN)
        )

    def test_should_not_find_bogus_hook(self):
        self.assertFalse(
            travis_utils.hook_exists(THIS_REPO+BOGUS, TRAVIS_TOKEN)
        )