ci_diff_helper.travis module¶
Set of utilities for dealing with Travis CI.
This module provides a custom configuration type
Travis for the Travis CI system.
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.
Travis Configuration Type¶
When running in Travis, you can automatically detect your current environment and get the configuration object:
>>> import ci_diff_helper
>>> config = ci_diff_helper.get_config()
>>> config
<Travis (active=True)>
To use the Travis configuration type directly:
>>> config = ci_diff_helper.Travis()
>>> config
<Travis (active=True)>
>>> config.active
True
>>> config.in_pr
True
>>> config.branch
'master'
In addition this configuration provides extra features for determining a diffbase.
>>> config = ci_diff_helper.Travis()
>>> config.event_type
<TravisEventType.pull_request: 'pull_request'>
>>> config.slug
'organization/repository'
>>> config.repo_url
'https://github.com/organization/repository'
>>> config.pr
1234
>>> config.tag is None
True
>>> config.base
'master'
Not only is this object valuable during a pull request build, it can also be used to find relevant information in a “push” build:
>>> config = ci_diff_helper.Travis()
>>> config.event_type
<TravisEventType.push: 'push'>
>>> config.pr is None
True
>>> config.tag
'0.13.37'
>>> config.base
'4ad7349dc7223ebc02175a16dc577a013044a538'
Though the base property can be useful as a diffbase
of a given commit, it may be inappropriate. In a “push” build,
base will be computed from the TRAVIS_COMMIT_RANGE
environment variable, and this value is not particularly reliable.
Instead, merged_pr provides a way to determine the
PR that was merged:
>>> config.is_merge
True
>>> config.merged_pr
1355
-
class
ci_diff_helper.travis.Travis[source]¶ Bases:
ci_diff_helper._config_base.ConfigRepresent Travis state and cache return values.
-
__delattr__¶ x.__delattr__(‘name’) <==> del x.name
-
__format__()¶ default object formatter
-
__getattribute__¶ x.__getattribute__(‘name’) <==> x.name
-
__hash__¶
-
__reduce__()¶ helper for pickle
-
__reduce_ex__()¶ helper for pickle
-
__setattr__¶ x.__setattr__(‘name’, value) <==> x.name = value
-
__sizeof__() → int¶ size of object in memory, in bytes
-
__str__¶
-
active¶ bool: Indicates if currently running in the target CI system.
-
base¶ str: The
gitobject that current build is changed against.The
gitobject can be any of a branch name, tag, a commit SHA or a special reference.Note
This will throw an
OSErroron the very first “push” build for a branch. This is because Travis leaves the value empty in builds triggered by the initial commit of a new branch.Warning
This property is only meant to be used in a “pull request” or “push” build.
-
branch¶ bool: Indicates the current branch in the target CI system.
This may indicate the active branch or the base branch of a pull request.
-
event_type¶ bool: Indicates if currently running in Travis.
-
in_pr¶ bool: Indicates if currently running in Travis pull request.
This uses the
TRAVIS_EVENT_TYPEenvironment variable to check if currently in a pull request. Though it doesn’t use theTRAVIS_PULL_REQUESTenvironment variable, checking that the value is set to an integer would be a perfectly valid approach.
-
is_merge¶ bool: Indicates if the HEAD commit is a merge commit.
-
merged_pr¶ int: The pull request corresponding to a merge commit at HEAD.
If not currently in a push build, returns
None. If the HEAD commit is not a merge commit, returnsNone.Note
This only uses the
gitcheckout to determine the pull request ID. A more comprehensive check would involve veriying the ID by using the GitHub API.Warning
This property is only meant to be used in a “pull request” or “push” build.
-
pr¶ int: The current Travis pull request (if any).
If there is no active pull request, returns
None.
-
repo_url¶ str: The URL of the current repository being built.
Of the form
https://github.com/{organization}/{repository}.
-
slug¶ str: The current slug in the Travis build.
Of the form
{organization}/{repository}.
-
tag¶ str: The
gittag of the current Travis build.Note
We only expect the
TRAVIS_TAGenvironment variable to be set during a tag “push” build, but we don’t verify that we are in a push build before checking for the tag.
-