tasks/lib/status.js
function (commit, until) {
            var checker = this;

            until = !isNaN(until) ? until : (new Date()).getTime() + (this.getOption('timeout'));

            if ((new Date()).getTime() > until) {
                return this.handleError('Timeout');
            }

            return this.getBuilds()
                .then(function (builds) {
                    if (undefined !== builds.message) {
                        return checker.handleError(builds.message);
                    }

                    var finder = new BuildFinder(builds),
                        builds = finder.findByCommit(commit);

                    if (null === builds) {
                        return checker.handleError('Build not found');
                    }

                    return builds;
                }, this.handleError)

                .then(function (builds) {
                    var successfulBuilds = 0;

                    for (var i = 0; i < builds.length; i++) {
                        if (builds[i].isSuccess()) {
                            successfulBuilds++;
                        } else if (builds[i].isFailure() || !checker.getOption('retryOnRunning')) {
                            return checker.handleError('Invalid status for CircleCI build: "' + builds[i].getStatus() + '"')
                        }
                    }

                    if (successfulBuilds === builds.length) {
                        return true;
                    }

                    // Sleep for 10 seconds by default
                    var promise = sleep(checker.getOption('retryAfter'));

                    return promise.then(function () {
                        return checker.checkCommit(commit, until);
                    });
                }, this.handleError);
        }
function (commit, until) {
            var checker = this;

            until = !isNaN(until) ? until : (new Date()).getTime() + (this.getOption('timeout'));

            if ((new Date()).getTime() > until) {
                return this.handleError('Timeout');
            }

            return this.getBuilds()
                .then(function (builds) {
                    if (undefined !== builds.message) {
                        return checker.handleError(builds.message);
                    }

                    var finder = new BuildFinder(builds),
                        builds = finder.findByCommit(commit);

                    if (null === builds) {
                        return checker.handleError('Build not found');
                    }

                    return builds;
                }, this.handleError)

                .then(function (builds) {
                    var successfulBuilds = 0;

                    for (var i = 0; i < builds.length; i++) {
                        if (builds[i].isSuccess()) {
                            successfulBuilds++;
                        } else if (builds[i].isFailure() || !checker.getOption('retryOnRunning')) {
                            return checker.handleError('Invalid status for CircleCI build: "' + builds[i].getStatus() + '"')
                        }
                    }

                    if (successfulBuilds === builds.length) {
                        return true;
                    }

                    // Sleep for 10 seconds by default
                    var promise = sleep(checker.getOption('retryAfter'));

                    return promise.then(function () {
                        return checker.checkCommit(commit, until);
                    });
                }, this.handleError);
        }
function ( commit , until ) { var checker = this ; until = ! isNaN ( until ) ? until : ( new Date ( ) ) . getTime ( ) + ( this . getOption ( 'timeout' ) ) ; if ( ( new Date ( ) ) . getTime ( ) > until ) { return this . handleError ( 'Timeout' ) ; } return this . getBuilds ( ) . then ( function ( builds ) { if ( undefined !== builds . message ) { return checker . handleError ( builds . message ) ; } var finder = new BuildFinder ( builds ) , builds = finder . findByCommit ( commit ) ; if ( null === builds ) { return checker . handleError ( 'Build not found' ) ; } return builds ; } , this . handleError ) . then ( function ( builds ) { var successfulBuilds = 0 ; for ( var i = 0 ; i < builds . length ; i ++ ) { if ( builds [ i ] . isSuccess ( ) ) { successfulBuilds ++ ; } else if ( builds [ i ] . isFailure ( ) || ! checker . getOption ( 'retryOnRunning' ) ) { return checker . handleError ( 'Invalid status for CircleCI build: "' + builds [ i ] . getStatus ( ) + '"' ) } } if ( successfulBuilds === builds . length ) { return true ; } // Sleep for 10 seconds by default var promise = sleep ( checker . getOption ( 'retryAfter' ) ) ; return promise . then ( function ( ) { return checker . checkCommit ( commit , until ) ; } ) ; } , this . handleError ) ; }
Checks the build status of a commit

@param {String} commit  The commit hash
@param {Number} [until] For how long should be check if the build
is still running
@returns {*|!Promise}
Checks the build status of a commit