ci_diff_helper.travis module

Set of utilities for dealing with Travis CI.

Since Travis only works with GitHub, the commands in this module are GitHub and git centric.

This module uses a selection of environment variables to detect the state of Travis configuration. See environment_vars for more details.

class ci_diff_helper.travis.Travis[source]

Bases: object

Represent Travis state and cache return values.

active

Indicates if currently running in Travis.

Return type:bool
base

The git object that current build is changed against.

The git object can be any of a branch name, tag or a commit SHA.

Return type:str
Raises:NotImplementedError – If not in a “pull request” or “push” build.
branch

Indicates if currently running in Travis.

Return type:bool
event_type

Indicates if currently running in Travis.

Return type:bool
in_pr

Indicates if currently running in Travis pull request.

This uses the TRAVIS_EVENT_TYPE environment variable to check if currently in a pull request. Though it doesn’t use the TRAVIS_PULL_REQUEST environment variable, checking that the value is set to an integer would be a perfectly valid approach.

Return type:bool
pr

The current Travis pull request (if any).

If there is no active pull request, returns None.

Return type:int
slug

The current slug in the Travis build.

Of the form {organization}/{repository}.

Return type:str
class ci_diff_helper.travis.TravisEventType[source]

Bases: enum.Enum

Enum representing all possible Travis event types.

api = <TravisEventType.api: 'api'>
cron = <TravisEventType.cron: 'cron'>
pull_request = <TravisEventType.pull_request: 'pull_request'>
push = <TravisEventType.push: 'push'>
ci_diff_helper.travis.in_travis()[source]

Detect if we are running in Travis.

See the Travis class for a more comprehensive way to determine the Travis configuration, with caching enabled. In particular, for this method, see Travis.active.

Return type:bool
Returns:Flag indicating if we are running on Travis.
ci_diff_helper.travis.in_travis_pr()[source]

Detect if we are running in a pull request on Travis.

See the Travis class for a more comprehensive way to determine the Travis configuration, with caching enabled. In particular, for this method, see Travis.in_pr.

Return type:bool
Returns:Flag indicating if we are in a pull request on Travis.
ci_diff_helper.travis.travis_branch()[source]

Get the current branch of the PR.

See the Travis class for a more comprehensive way to determine the Travis configuration, with caching enabled. In particular, for this method, see Travis.branch.

Note

This assumes we already know we are running in Travis during a PR.

Return type:str
Returns:The name of the branch the current pull request is changed against.