TravisPy works just as Travis CI: it authenticates against GitHub. So as a requirement you must have a GitHub access token with the following scopes:
- read:org
- user:email
- repo_deployment
- repo:status
- write:repo_hook
With your token in hands all is easy:
>>> from travispy import TravisPy >>> t = TravisPy.github_auth(<your_github_token>) >>> user = t.user() >>> user <travispy.entities.user.User object at 0x02C26C48>
Now you can access information related to user current logged in:
>>> user.login 'travispy' >>> user['login'] 'travispy'
To get the list of repositories that you are member of:
>>> repos = t.repos(member=user.login) >>> len(repos) # Ordered by recent activity 5 >>> repos[0] <travispy.entities.repo.Repo object at 0x02C26C49> >>> repos[0].slug 'travispy/on_py34'
Or simply request for repository you want:
>>> repo = t.repo('travispy/on_py34') <travispy.entities.repo.Repo object at 0x02C26C51>
And finally, getting build information:
>>> build = t.build(repo.last_build_id) >>> build <travispy.entities.build.Build object at 0x02C26C50> >>> build.restart() True >>> build.cancel() True >>> build.cancel() # As build was already cancelled it will return False. False
Please refer to the official API to learn more about which entities are supported. Soon a specific and detailed documentation related to this library will be available.