travis-builds-reporter-core is a package that makes easy to fetch builds (to do whatever you want) for a Travis enabled public repository.
You can find the source code inside the src
directory, while testing code is inside the test
directory (pretty standard staff for nodejs pacakges).
You can find an example usage of this library here.
Assuming you have an already functioning node project:
- Install this package alongside axios in your project as a dependency. Type this in your favourite terminal/prompt:
npm i -S travis-builds-reporter-core
- In a
*.js
file in your project:- Require the modules contained in this package.
const { createClient, fetch } = require('travis-builds-reporter-core');
- Create the pre-configured axios instance.
const travis = createClient();
- Fetch the builds from Travis using the promise returned by fetcher
or in an async function:
fetch(travis, 'some/repository') .then(model => { // This is a BuildsModel instance // do something with the builds console.log(model.builds); }).catch((error) => { // remember to catch any errors console.error(error); });
try { const model = await fetch(client, 'some/repo'); console.log(model); } catch (error) { // Handle error here console.error(error); }
- Require the modules contained in this package.
Creates a preconfigured axios instance that, by default, works with the public Travis APIs available for Open Source projects.
The object returned by this function can and should be reused upon multiple fetch
invocations.
Type: object
Type: string
Default: niktekusho/travis-builds-reporter-core/{PACKAGE_VERSION}
Custom user agent.
The User-Agent cannot be turned off since Travis APIs require a valid and identifiable User Agent header.
The createClient
function will therefore check for its presence and validity.
Type: number
Default: 10000
Requests timeout in milliseconds. The default is 10 seconds.
Type: string
Default: https://api.travis-ci.org
Base url to fetch builds from. The default can be used to query the Travis APIs for Open Source projects.
Type: string
Default: api.travis-ci.org
Host to fetch builds from. The default can be used to query the Travis APIs for Open Source projects.
This function does the following:
- validates Travis APIs connections and responses
- initializes basic informations needed for the asynchonous fetcher function
- actually makes the concurrent calls to fetch the builds
Returns a Promise<
BuildsModel
>
with the fetched builds.
Type: object
A configured axios instance. Use the createClient
function to create one.
Type: string
Name of the repository from which the module will try to fetch builds
Class that contains repository's builds info.
Constructs a new model.
Type: string
Name of the repository from which the module fetched the builds.
Type: object[]
Array of all builds received from Travis APIs. Each build
object is as specified in the Travis API specification for the Build object.
Type: Date
Default: new Date()
Date in which the builds are fetched.
Returns the shortest builds duration in seconds (number
).
Type: object[]
Array of build objects. Each build object must have a duration property of type number
.
Returns the longest builds duration in seconds (number
).
Type: object[]
Array of build objects. Each build object must have a duration property of type number
.
Returns the average builds duration in seconds (eventually rounded to specified decimals if the appropriate argument is defined).
Type: object[]
Array of build objects. Each build object must have a duration property of type number
.
Type: number
Default: undefined
Number of decimals to round the average to.
Returns: object[][]
Returns an array of arrays of builds divided by date. Builds are in the same child array if and only if build.started_at
or build.finished_at
are the same date (time is ignored).
Type: object[]
Array of build objects. Each build object must have at least one of two properties:
started_at
of typeDate
;finished_at
of typeDate
.
Priority is given to started_at
property.
Returns: object[]
Get an array containing only successful builds.
Builds are successful if the state
property equals to passed
.
Type: object[]
Array of build objects. Each build object must have a state
property of type string
.
Returns: number
Get the number of successful builds. See getSuccessfulBuilds for details.
Returns: object[]
Get an array containing only canceled builds.
Builds are canceled if the state
property equals to canceled
.
Type: object[]
Array of build objects. Each build object must have a state
property of type string
.
Returns: number
Get the number of canceled builds. See getCanceledBuilds for details.
Returns: object[]
Get an array containing only failed builds.
Builds are failed if the state
property equals to failed
.
Type: object[]
Array of build objects. Each build object must have a state
property of type string
.
Returns: number
Get the number of failed builds. See getFailedBuilds for details.
Returns: object[]
Get an array containing only errored builds.
Builds are errored if the state
property equals to errored
.
Type: object[]
Array of build objects. Each build object must have a state
property of type string
.
Returns: number
Get the number of errored builds. See getErroredBuilds for details.
Returns: number
Minimum: 0
Maximum: 1
Get the percentage of successful builds.
Type: object[]
Array of build objects. Each build object must have a state
property of type string
.
Returns: object
Generate a report object containing all metrics exposed by this module.
Type: number
Number of examined builds.
Type: number
Average duration (same as getAverageBuildsDuration).
Type: number
Maximum duration (same as getMaximumBuildsDuration).
Type: number
Minimum duration (same as getMinimumBuildsDuration).
Type: number
Successful builds count (same as getSuccessfulBuildsCount).
Type: number
Canceled builds count (same as getCanceledBuildsCount).
Type: number
Failed builds count (same as getFailedBuildsCount).
Type: number
Errored builds count (same as getErroredBuildsCount).
Type: number
Successful builds rate, between 0 and 100.
Deserialization method with properties validation.
Returns a BuildsModel
object if the json represents a valid BuildsModel
instance.
Throws if the json arguments:
- cannot be parsed into a JavaScript object
- the parsed object does not contain the
builds
andrepository
properties
Type: string
Stringified JSON object of a BuildsModel
instance.