Search code examples
travis-citravis-ci-cli

Travis CI - Enabling repository build via API


I can't find how to enable a repository to build in Travis CI through the API in the docs. It seems flicking the switch is a manual step, is that correct?

Specifically can we flick the switch shown in the image below programmatically? enter image description here


Solution

  • The end-point for this is kind of misleading and also it takes more than one step to achieve this:

    1. Force a synchronization just to make sure the repo will be there

    2. Obtain the repository ID (yes, you must have it)

    3. Flick the switch

    If you are working with Python you can use TravisPy to achieve this.

    from travispy import TravisPy
    
    travis = TravisPy.github_auth('github token')
    repo = travis.repo('menegazzo/travispy')
    repo.enable() # Switch is now on
    repo.disable() # Switch is now off