├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── bin └── jenkins ├── etc ├── README.md ├── botch-osx └── botch-ubuntu ├── npm-shrinkwrap.json ├── package.json ├── src ├── api │ ├── check-base-url.ls │ ├── get-all-jobs.ls │ ├── get-build.ls │ ├── get-last-build.ls │ ├── list-jobs.ls │ └── tail-build.ls ├── cli │ ├── configure.ls │ ├── format-build-info.ls │ ├── index.ls │ ├── list-choice.ls │ ├── list.ls │ ├── parse.ls │ ├── setup.ls │ └── tail.ls ├── config.ls ├── constants.ls ├── debug.ls ├── index.ls └── utils │ ├── build-result-color.ls │ ├── ensure-res-body.ls │ ├── format-url.ls │ ├── fuzzy-filter.ls │ ├── index.ls │ ├── jobs-filter-by-str.ls │ ├── jobs-table.ls │ └── sort-abc.ls └── test ├── _globals.ls ├── check-base-url.ls ├── cli-commands.ls ├── cli-configure.ls ├── cli-help.ls ├── cli-list.ls ├── cli-parse.ls ├── cli-setup.ls ├── cli-tail.ls ├── data └── list-jobs.json ├── format-build-info.ls ├── get-all-jobs.ls ├── get-build.ls ├── jobs-table.ls ├── list-jobs.ls ├── mocha.opts └── test-util.ls /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /node_modules 3 | npm-debug.log 4 | /lib 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src/* 2 | test 3 | *.ls 4 | *.js.map 5 | .gitignore 6 | Makefile 7 | .travis.yml 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.12" 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Raine Virta 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any 4 | purpose with or without fee is hereby granted, provided that the above 5 | copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: test 2 | 3 | SRC = $(shell find src -name "*.ls" -type f | sort) 4 | LIB = $(patsubst src/%.ls, lib/%.js, $(SRC)) 5 | 6 | MOCHA = ./node_modules/.bin/mocha 7 | LSC = ./node_modules/.bin/lsc 8 | NAME = $(shell node -e "console.log(require('./package.json').name)") 9 | REPORTER ?= spec 10 | GREP ?= ".*" 11 | MOCHA_ARGS = --harmony-generators --grep $(GREP) 12 | 13 | default: all 14 | 15 | lib: 16 | mkdir -p lib/ 17 | 18 | lib/%.js: src/%.ls lib 19 | $(LSC) --compile --map=linked --output "$(@D)" "$<" 20 | 21 | all: compile 22 | 23 | compile: $(LIB) package.json 24 | 25 | shrinkwrap: package.json 26 | npm-shrinkwrap 27 | 28 | install: clean all 29 | npm install -g . 30 | 31 | reinstall: clean 32 | $(MAKE) uninstall 33 | $(MAKE) install 34 | 35 | uninstall: 36 | npm uninstall -g ${NAME} 37 | 38 | dev-install: package.json 39 | npm install . 40 | 41 | clean: 42 | rm -rf lib 43 | 44 | publish: all test 45 | git push --tags origin HEAD:master 46 | npm publish 47 | 48 | test: 49 | @$(MOCHA) $(MOCHA_ARGS) --reporter $(REPORTER) 50 | 51 | test-w: 52 | @$(MOCHA) $(MOCHA_ARGS) --reporter min --watch 53 | 54 | prepublish: 55 | @if [ -z "$$TRAVIS" -a -e lib/index.js ]; then \ 56 | sed -i '' '/source-map-support/d' lib/index.js; \ 57 | fi 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ez-jenkins [![Build Status](https://api.travis-ci.org/raine/ez-jenkins.svg?branch=master)](https://travis-ci.org/raine/ez-jenkins) [![npm version](https://badge.fury.io/js/ez-jenkins.svg)](https://www.npmjs.com/package/ez-jenkins) 2 | 3 |

4 | 5 | 6 | 7 |

8 | 9 | CLI for Jenkins CI, written in [LiveScript](livescript.net) 10 | 11 | ```sh 12 | npm install -g ez-jenkins 13 | jenkins setup 14 | jenkins list 15 | jenkins tail 16 | ``` 17 | 18 | ## features 19 | 20 | - **`list`** jobs in a table, usable as [terminal walldisplay](https://github.com/raine/ez-jenkins/tree/master/etc) 21 | - **`tail`** a job (or jobs matching a pattern) for output and wait for the next build 22 | - example use case: tail build logs in the same window for multiple jobs where 23 | one job's completion triggers the next job 24 | - open job configuration view in browser with **`configure`** 25 | - fuzzy search: provides suggestions when a job name provides no exact match 26 | 27 | ## requirements 28 | 29 | - node `>= v0.11.3` 30 | 31 | ## usage 32 | 33 | ``` 34 | $ jenkins 35 | Usage: jenkins [options] 36 | 37 | Commands: 38 | list list jobs 39 | tail read build logs 40 | configure open configure view in browser for a job 41 | setup interactively configure jenkins base url 42 | ``` 43 | 44 | ## upcoming features 45 | 46 | - [ ] start and stop builds 47 | - [x] tail multiple builds 48 | 49 | General feedback, bug reports and feature requests are welcome via [issues](https://github.com/raine/ez-jenkins/issues) or you can [contact me on Twitter](https://twitter.com/rane). 50 | 51 | ## screenshots 52 | 53 | [![](https://raw.githubusercontent.com/raine/ez-jenkins/media/iojs-build-smaller.png)](https://raw.githubusercontent.com/raine/ez-jenkins/media/iojs-build.png) 54 | 55 | [![](https://raw.githubusercontent.com/raine/ez-jenkins/media/list-smaller.png)](https://raw.githubusercontent.com/raine/ez-jenkins/media/list.png) 56 | -------------------------------------------------------------------------------- /bin/jenkins: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ":" //# comment; exec /usr/bin/env node --harmony "$0" "$@" 3 | 4 | var generators; 5 | try { 6 | eval('(function* () {})()'); 7 | generators = true; 8 | } catch (e) { 9 | generators = false; 10 | } 11 | 12 | var name = require('../package.json').name; 13 | if (generators) { 14 | require('../lib'); 15 | } else { 16 | console.log('ERROR: ' + name + ' requires node >= v0.11.3 for generators'); 17 | process.exit(1); 18 | } 19 | -------------------------------------------------------------------------------- /etc/README.md: -------------------------------------------------------------------------------- 1 | ## botch 2 | 3 | Useful for running `jenkins list` as a walldisplay 4 | 5 | ```sh 6 | botch "FORCE_COLOR=1 jenkins list" 7 | ``` 8 | 9 | Credit for this handy tool goes to https://excess.org/article/2009/07/watch1-bash-unicode/ 10 | -------------------------------------------------------------------------------- /etc/botch-osx: -------------------------------------------------------------------------------- 1 | botch() { 2 | printf '\e[?25l' 3 | while true; do 4 | (echo -en '\033[H' 5 | CMD="$@" 6 | bash -c "$CMD" | while read LINE; do 7 | echo -n "$LINE" 8 | echo -e '\033[0K' 9 | done 10 | echo -en '\033[J') | tac | tac 11 | sleep 2 12 | done 13 | } 14 | -------------------------------------------------------------------------------- /etc/botch-ubuntu: -------------------------------------------------------------------------------- 1 | botch() { 2 | printf '\e[?25l' 3 | clear 4 | while true; do 5 | (echo '\033[H' 6 | CMD="$@" 7 | bash -c "$CMD" | while read LINE; do 8 | echo -n "$LINE" 9 | echo '\033[0K' 10 | done 11 | echo '\033[J') | tac | tac 12 | sleep 2 13 | done 14 | } 15 | -------------------------------------------------------------------------------- /npm-shrinkwrap.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ez-jenkins", 3 | "version": "1.3.2", 4 | "npm-shrinkwrap-version": "5.2.0", 5 | "node-version": "v0.12.0", 6 | "dependencies": { 7 | "bluebird": { 8 | "version": "2.9.13", 9 | "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-2.9.13.tgz" 10 | }, 11 | "chalk": { 12 | "version": "1.0.0", 13 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.0.0.tgz", 14 | "dependencies": { 15 | "ansi-regex": { 16 | "version": "1.1.1", 17 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-1.1.1.tgz" 18 | }, 19 | "ansi-styles": { 20 | "version": "2.0.1", 21 | "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.0.1.tgz" 22 | }, 23 | "escape-string-regexp": { 24 | "version": "1.0.3", 25 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.3.tgz" 26 | }, 27 | "has-ansi": { 28 | "version": "1.0.3", 29 | "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-1.0.3.tgz" 30 | }, 31 | "strip-ansi": { 32 | "version": "2.0.1", 33 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-2.0.1.tgz" 34 | }, 35 | "supports-color": { 36 | "version": "1.3.0", 37 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-1.3.0.tgz" 38 | } 39 | } 40 | }, 41 | "cli-table": { 42 | "version": "0.3.1", 43 | "resolved": "https://registry.npmjs.org/cli-table/-/cli-table-0.3.1.tgz", 44 | "dependencies": { 45 | "colors": { 46 | "version": "1.0.3", 47 | "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz" 48 | } 49 | } 50 | }, 51 | "data.maybe": { 52 | "version": "1.2.0", 53 | "resolved": "https://registry.npmjs.org/data.maybe/-/data.maybe-1.2.0.tgz" 54 | }, 55 | "debug": { 56 | "version": "2.1.2", 57 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.1.2.tgz", 58 | "dependencies": { 59 | "ms": { 60 | "version": "0.7.0", 61 | "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.0.tgz" 62 | } 63 | } 64 | }, 65 | "fuzzy": { 66 | "version": "0.1.0", 67 | "resolved": "https://registry.npmjs.org/fuzzy/-/fuzzy-0.1.0.tgz" 68 | }, 69 | "get-stdin": { 70 | "version": "4.0.1", 71 | "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz" 72 | }, 73 | "js-yaml": { 74 | "version": "3.2.7", 75 | "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.2.7.tgz", 76 | "dependencies": { 77 | "argparse": { 78 | "version": "1.0.1", 79 | "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.1.tgz", 80 | "dependencies": { 81 | "lodash": { 82 | "version": "3.2.0", 83 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.2.0.tgz" 84 | }, 85 | "sprintf-js": { 86 | "version": "1.0.2", 87 | "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.2.tgz" 88 | } 89 | } 90 | }, 91 | "esprima": { 92 | "version": "2.0.0", 93 | "resolved": "https://registry.npmjs.org/esprima/-/esprima-2.0.0.tgz" 94 | } 95 | } 96 | }, 97 | "mkdirp": { 98 | "version": "0.5.0", 99 | "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz", 100 | "dependencies": { 101 | "minimist": { 102 | "version": "0.0.8", 103 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz" 104 | } 105 | } 106 | }, 107 | "open": { 108 | "version": "0.0.5", 109 | "resolved": "https://registry.npmjs.org/open/-/open-0.0.5.tgz" 110 | }, 111 | "pretty-ms": { 112 | "version": "1.1.0", 113 | "resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-1.1.0.tgz", 114 | "dependencies": { 115 | "parse-ms": { 116 | "version": "1.0.0", 117 | "resolved": "https://registry.npmjs.org/parse-ms/-/parse-ms-1.0.0.tgz" 118 | } 119 | } 120 | }, 121 | "ramda": { 122 | "version": "0.13.0", 123 | "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.13.0.tgz" 124 | }, 125 | "readable-stream": { 126 | "version": "1.0.33", 127 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.33.tgz", 128 | "dependencies": { 129 | "core-util-is": { 130 | "version": "1.0.1", 131 | "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.1.tgz" 132 | }, 133 | "inherits": { 134 | "version": "2.0.1", 135 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz" 136 | }, 137 | "isarray": { 138 | "version": "0.0.1", 139 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz" 140 | }, 141 | "string_decoder": { 142 | "version": "0.10.31", 143 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz" 144 | } 145 | } 146 | }, 147 | "readline-sync": { 148 | "version": "0.7.5", 149 | "resolved": "https://registry.npmjs.org/readline-sync/-/readline-sync-0.7.5.tgz" 150 | }, 151 | "request": { 152 | "version": "2.53.0", 153 | "resolved": "https://registry.npmjs.org/request/-/request-2.53.0.tgz", 154 | "dependencies": { 155 | "aws-sign2": { 156 | "version": "0.5.0", 157 | "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.5.0.tgz" 158 | }, 159 | "bl": { 160 | "version": "0.9.4", 161 | "resolved": "https://registry.npmjs.org/bl/-/bl-0.9.4.tgz" 162 | }, 163 | "caseless": { 164 | "version": "0.9.0", 165 | "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.9.0.tgz" 166 | }, 167 | "combined-stream": { 168 | "version": "0.0.7", 169 | "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-0.0.7.tgz", 170 | "dependencies": { 171 | "delayed-stream": { 172 | "version": "0.0.5", 173 | "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-0.0.5.tgz" 174 | } 175 | } 176 | }, 177 | "forever-agent": { 178 | "version": "0.5.2", 179 | "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.5.2.tgz" 180 | }, 181 | "form-data": { 182 | "version": "0.2.0", 183 | "resolved": "https://registry.npmjs.org/form-data/-/form-data-0.2.0.tgz", 184 | "dependencies": { 185 | "async": { 186 | "version": "0.9.0", 187 | "resolved": "https://registry.npmjs.org/async/-/async-0.9.0.tgz" 188 | } 189 | } 190 | }, 191 | "hawk": { 192 | "version": "2.3.1", 193 | "resolved": "https://registry.npmjs.org/hawk/-/hawk-2.3.1.tgz", 194 | "dependencies": { 195 | "boom": { 196 | "version": "2.6.1", 197 | "resolved": "https://registry.npmjs.org/boom/-/boom-2.6.1.tgz" 198 | }, 199 | "cryptiles": { 200 | "version": "2.0.4", 201 | "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-2.0.4.tgz" 202 | }, 203 | "hoek": { 204 | "version": "2.11.1", 205 | "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.11.1.tgz" 206 | }, 207 | "sntp": { 208 | "version": "1.0.9", 209 | "resolved": "https://registry.npmjs.org/sntp/-/sntp-1.0.9.tgz" 210 | } 211 | } 212 | }, 213 | "http-signature": { 214 | "version": "0.10.1", 215 | "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-0.10.1.tgz", 216 | "dependencies": { 217 | "asn1": { 218 | "version": "0.1.11", 219 | "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.1.11.tgz" 220 | }, 221 | "assert-plus": { 222 | "version": "0.1.5", 223 | "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-0.1.5.tgz" 224 | }, 225 | "ctype": { 226 | "version": "0.5.3", 227 | "resolved": "https://registry.npmjs.org/ctype/-/ctype-0.5.3.tgz" 228 | } 229 | } 230 | }, 231 | "isstream": { 232 | "version": "0.1.2", 233 | "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz" 234 | }, 235 | "json-stringify-safe": { 236 | "version": "5.0.0", 237 | "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.0.tgz" 238 | }, 239 | "mime-types": { 240 | "version": "2.0.9", 241 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.0.9.tgz", 242 | "dependencies": { 243 | "mime-db": { 244 | "version": "1.7.0", 245 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.7.0.tgz" 246 | } 247 | } 248 | }, 249 | "node-uuid": { 250 | "version": "1.4.3", 251 | "resolved": "https://registry.npmjs.org/node-uuid/-/node-uuid-1.4.3.tgz" 252 | }, 253 | "oauth-sign": { 254 | "version": "0.6.0", 255 | "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.6.0.tgz" 256 | }, 257 | "qs": { 258 | "version": "2.3.3", 259 | "resolved": "https://registry.npmjs.org/qs/-/qs-2.3.3.tgz" 260 | }, 261 | "stringstream": { 262 | "version": "0.0.4", 263 | "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.4.tgz" 264 | }, 265 | "tough-cookie": { 266 | "version": "0.12.1", 267 | "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-0.12.1.tgz", 268 | "dependencies": { 269 | "punycode": { 270 | "version": "1.3.2", 271 | "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz" 272 | } 273 | } 274 | }, 275 | "tunnel-agent": { 276 | "version": "0.4.0", 277 | "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.4.0.tgz" 278 | } 279 | } 280 | }, 281 | "split2": { 282 | "version": "0.2.1", 283 | "resolved": "https://registry.npmjs.org/split2/-/split2-0.2.1.tgz" 284 | }, 285 | "strftime": { 286 | "version": "0.8.4", 287 | "resolved": "https://registry.npmjs.org/strftime/-/strftime-0.8.4.tgz" 288 | }, 289 | "through2": { 290 | "version": "0.6.3", 291 | "resolved": "https://registry.npmjs.org/through2/-/through2-0.6.3.tgz", 292 | "dependencies": { 293 | "xtend": { 294 | "version": "4.0.0", 295 | "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.0.tgz" 296 | } 297 | } 298 | }, 299 | "yargs": { 300 | "version": "3.5.4", 301 | "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.5.4.tgz", 302 | "dependencies": { 303 | "camelcase": { 304 | "version": "1.0.2", 305 | "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.0.2.tgz" 306 | }, 307 | "decamelize": { 308 | "version": "1.0.0", 309 | "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.0.0.tgz" 310 | }, 311 | "window-size": { 312 | "version": "0.1.0", 313 | "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz" 314 | }, 315 | "wordwrap": { 316 | "version": "0.0.2", 317 | "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz" 318 | } 319 | } 320 | } 321 | } 322 | } 323 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ez-jenkins", 3 | "version": "1.3.2", 4 | "description": "cli for jenkins ci", 5 | "repository": "raine/ez-jenkins", 6 | "preferGlobal": true, 7 | "keywords": [ 8 | "jenkins", 9 | "cli" 10 | ], 11 | "scripts": { 12 | "test": "make test", 13 | "prepublish": "make prepublish" 14 | }, 15 | "bin": { 16 | "jenkins": "./bin/jenkins" 17 | }, 18 | "author": "Raine Virta ", 19 | "license": "ISC", 20 | "devDependencies": { 21 | "LiveScript": "git://github.com/Diggsey/LiveScript#sourcemaps", 22 | "chai": "^2.1.1", 23 | "mocha": "2.2.1", 24 | "nock": "^1.1.0", 25 | "proxyquire": "^1.4.0", 26 | "sinon": "^1.13.0", 27 | "source-map-support": "^0.2.9" 28 | }, 29 | "dependencies": { 30 | "bluebird": "^2.9.13", 31 | "chalk": "^1.0.0", 32 | "cli-table": "^0.3.1", 33 | "data.maybe": "^1.2.0", 34 | "debug": "^2.1.2", 35 | "fuzzy": "^0.1.0", 36 | "js-yaml": "^3.2.7", 37 | "mkdirp": "^0.5.0", 38 | "open": "0.0.5", 39 | "pretty-ms": "^1.1.0", 40 | "ramda": "^0.13.0", 41 | "readline-sync": "^0.7.5", 42 | "request": "^2.53.0", 43 | "split2": "^0.2.1", 44 | "strftime": "^0.8.4", 45 | "through2": "^0.6.3", 46 | "yargs": "^3.5.4" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/api/check-base-url.ls: -------------------------------------------------------------------------------- 1 | require! 'data.maybe': Maybe 2 | require! bluebird: Promise 3 | require! ramda: {prop} 4 | request = Promise.promisify require 'request' 5 | debug = require '../debug' <| __filename 6 | 7 | module.exports = check-base-url = (base-url) -> 8 | url = "#base-url/api/json".replace // /?$ //, '' 9 | debug url 10 | request { 11 | url 12 | qs: { tree: \primaryView } 13 | +json 14 | } 15 | .tap -> debug 'req done' 16 | .get \1 17 | .then (Maybe.from-nullable . prop \primaryView) 18 | -------------------------------------------------------------------------------- /src/api/get-all-jobs.ls: -------------------------------------------------------------------------------- 1 | require! bluebird: Promise 2 | require! '../utils': {format-url, ensure-res-body} 3 | request = Promise.promisify require 'request' 4 | debug = require '../debug' <| __filename 5 | require! ramda: {prop, map} 6 | 7 | module.exports = get-all-jobs = -> 8 | debug 'req start' 9 | ensure-res-body request { 10 | url: format-url '/api/json' 11 | qs: { tree: 'jobs[name]' } 12 | +json 13 | } 14 | .tap -> debug 'req done' 15 | .get \1 16 | .then (map prop \name) . prop \jobs 17 | -------------------------------------------------------------------------------- /src/api/get-build.ls: -------------------------------------------------------------------------------- 1 | require! { 2 | bluebird: Promise 3 | '../utils': { format-url } 4 | '../constants': { BUILD_KEYS } 5 | 'data.maybe': Maybe 6 | } 7 | request = Promise.promisify require 'request' 8 | debug = require '../debug' <| __filename 9 | 10 | module.exports = (job-name, number) -> 11 | debug 'job-name=%s number=%d', job-name, number 12 | 13 | request { 14 | url: format-url "/job/#job-name/#number/api/json" 15 | qs: { tree: BUILD_KEYS } 16 | +json 17 | } 18 | .spread (res, body) -> 19 | debug {res.status-code, body} 20 | switch res.status-code 21 | | 200 => Maybe.Just body 22 | | otherwise => Maybe.Nothing! 23 | -------------------------------------------------------------------------------- /src/api/get-last-build.ls: -------------------------------------------------------------------------------- 1 | require! { 2 | bluebird: Promise 3 | '../utils': { format-url } 4 | '../constants': { BUILD_KEYS } 5 | 'data.maybe': Maybe 6 | } 7 | {merge} = require \ramda 8 | request = Promise.promisify require 'request' 9 | debug = require '../debug' <| __filename 10 | 11 | module.exports = (job-name) -> 12 | debug 'job-name=%s', job-name 13 | tree = "lastBuild[#{BUILD_KEYS}]" 14 | request { 15 | url: format-url "/job/#job-name/api/json" 16 | qs: { depth: 2, tree } 17 | +json 18 | } 19 | .get 1 20 | .get \lastBuild 21 | .then -> 22 | Maybe.from-nullable it 23 | .map merge {job-name} 24 | -------------------------------------------------------------------------------- /src/api/list-jobs.ls: -------------------------------------------------------------------------------- 1 | # lastCompletedBuild and lastBuild can be null in the API 2 | 3 | require! { 4 | bluebird: Promise 5 | '../utils': {format-url, ensure-res-body} 6 | '../constants': {BUILD_KEYS} 7 | 'data.maybe': Maybe 8 | } 9 | require! ramda: {pipe, merge, prop, map} 10 | request = Promise.promisify require 'request' 11 | debug = require '../debug' <| __filename 12 | 13 | module.exports = -> 14 | debug 'req start' 15 | tree = "jobs[name,lastBuild[#{BUILD_KEYS}],lastCompletedBuild[result]]" 16 | ensure-res-body request { 17 | url: format-url "/api/json" 18 | qs: {tree} 19 | +json 20 | } 21 | .tap -> debug 'req done' 22 | .get \1 23 | .then pipe do 24 | prop \jobs 25 | map (job) -> merge job.last-build, 26 | {job-name: job.name, job.last-completed-build} 27 | -------------------------------------------------------------------------------- /src/api/tail-build.ls: -------------------------------------------------------------------------------- 1 | require! { 2 | '../constants': { POLL_DELAY_MS } 3 | '../utils': { format-url } 4 | './get-last-build' 5 | './get-build' 6 | bluebird: Promise 7 | stream: { Readable } 8 | through2: through 9 | split2, 10 | 'data.maybe': Maybe 11 | } 12 | 13 | {merge, pick} = require \ramda 14 | request = Promise.promisify require 'request' 15 | debug = require '../debug' <| __filename 16 | async = Promise.coroutine 17 | 18 | tail-build = (job-name, build-number) -> 19 | debug 'tail-build job-name=%s build-number=%d', job-name, build-number 20 | reading = false 21 | start = 0 22 | url = format-url "/job/#job-name/#build-number/logText/progressiveText" 23 | 24 | get-next-chunk = async (start) ->* 25 | debug 'get-next-chunk start=%d', start 26 | [res, body] = yield request { 27 | url 28 | method: \post, 29 | form: { start } 30 | } 31 | 32 | debug pick <[ x-text-size x-more-data content-length ]> res.headers 33 | more-data = res.headers.'x-more-data' is 'true' 34 | next-start = res.headers.'x-text-size' 35 | got-data = next-start is not start 36 | start := next-start 37 | 38 | if got-data 39 | # remove last newline if build is done, workaround for 40 | # https://github.com/dominictarr/split/issues/13 41 | body := body - /\r\n$/ unless more-data 42 | stop = not log-stream.push body, 'utf8' 43 | debug 'stop=%s', stop 44 | 45 | unless more-data 46 | debug 'no more data' 47 | return log-stream.push null 48 | 49 | if stop is not true 50 | set-timeout (-> get-next-chunk next-start), POLL_DELAY_MS 51 | 52 | log-stream = new Readable! 53 | .._read = !-> 54 | debug '_read reading=%s', reading 55 | unless reading 56 | reading := true 57 | get-next-chunk start 58 | 59 | log-stream .pipe split2! 60 | 61 | wait-for-build = async (job-name, build-number) ->* 62 | debug 'wait-for-build job-name=%s build-number=%d', job-name, build-number 63 | build = yield get-build job-name, build-number 64 | 65 | switch 66 | | build.is-just => 67 | return yield Promise.resolve merge {job-name}, build.get! 68 | | otherwise 69 | yield Promise.delay POLL_DELAY_MS 70 | return yield wait-for-build job-name, build-number 71 | 72 | recur-tail = (output, follow, build) !--> 73 | debug 'recur-tail job-name=%s build-number=%d', build.job-name, build.number 74 | recur = recur-tail output, follow 75 | 76 | stream = tail-build build.job-name, build.number 77 | .once \data !-> 78 | output.write merge {build}, event: \GOT_BUILD 79 | 80 | .on \end, async ->* 81 | debug 'stream ended build-number=%d', build.number 82 | build-info = unless build.building then Maybe.of build 83 | else yield get-build build.job-name, build.number 84 | build-info.chain (build-info) -> 85 | output.write merge {build-info}, event: \BUILD_INFO 86 | output.end! unless follow 87 | 88 | if follow 89 | output.write event: \WAITING_FOR_BUILD 90 | next-build = yield wait-for-build build.job-name, build.number + 1 91 | recur next-build 92 | 93 | .pipe output, end: false 94 | 95 | module.exports = async (job-name, build-number, follow) ->* 96 | debug 'tail job-name=%s build-number=%d follow=%s', job-name, build-number, follow 97 | 98 | build = yield switch 99 | | build-number? 100 | get-build job-name, build-number 101 | | otherwise 102 | get-last-build job-name 103 | 104 | return build 105 | .map merge {job-name} 106 | .map (build) -> 107 | output = through.obj! 108 | recur-tail output, (not build-number and follow), build 109 | output 110 | -------------------------------------------------------------------------------- /src/cli/configure.ls: -------------------------------------------------------------------------------- 1 | {curry} = require 'ramda' 2 | {coroutine: async} = require \bluebird 3 | debug = require '../debug' <| __filename 4 | list-choice = curry require './list-choice' 5 | get-all-jobs = require '../api/get-all-jobs' 6 | {format-url} = require '../utils' 7 | {fuzzy-filter} = require '../utils' 8 | require! open 9 | 10 | cli-configure = async (argv) ->* 11 | debug argv, 'configure' 12 | job-name = argv.__ 13 | 14 | return (fuzzy-filter job-name, yield get-all-jobs!) 15 | .map list-choice 'no such job, did you mean one of these?\n' 16 | .cata do 17 | Just: (job-name) -> 18 | open format-url "/job/#job-name/configure" 19 | Nothing: -> 20 | "Unable to find job: #{job-name}" |> console.error 21 | 22 | module.exports = cli-configure 23 | -------------------------------------------------------------------------------- /src/cli/format-build-info.ls: -------------------------------------------------------------------------------- 1 | require! chalk 2 | require! strftime 3 | require! ramda: {join} 4 | require! util: {format: fmt} 5 | require! 'pretty-ms' 6 | 7 | offset-color = -> 8 | | it < 0 => \green 9 | | it is 0 => \dim 10 | | it > 0 => \yellow 11 | 12 | offset-symbol = -> 13 | | it < 0 => '-' 14 | | it > 0 => '+' 15 | | otherwise => '' 16 | 17 | format-offset = (offset) -> 18 | color = chalk[offset-color offset] 19 | symbol = offset-symbol offset 20 | color "(#symbol#{pretty-ms Math.abs offset})" 21 | 22 | result-color = -> 23 | switch it 24 | | \SUCCESS => \green 25 | | \ABORTED => \inverse 26 | | \FAILURE => \red 27 | 28 | format-result = (result) -> 29 | color = chalk.bold[result-color result] 30 | color fmt "[%s]", result 31 | 32 | module.exports = (build) -> 33 | offset = build.duration - build.estimated-duration 34 | finished = build.duration + build.timestamp 35 | since-build = Date.now! - finished 36 | 37 | result = format-result build.result 38 | 39 | duration = [ 40 | * chalk.bold 'Duration:' 41 | * pretty-ms build.duration 42 | * format-offset offset 43 | ] |> join ' ' 44 | 45 | finished = [ 46 | * chalk.bold 'Finished:' 47 | * strftime '%F %T', new Date build.timestamp 48 | * "(#{pretty-ms since-build, compact: true} ago)" 49 | ] |> join ' ' 50 | 51 | [result, duration, finished] |> join ' ' 52 | -------------------------------------------------------------------------------- /src/cli/index.ls: -------------------------------------------------------------------------------- 1 | require! './parse' 2 | require-cmd = -> require "./#it" 3 | 4 | module.exports = (raw-argv) -> 5 | {command, argv} = parse raw-argv 6 | require-cmd command <| argv 7 | -------------------------------------------------------------------------------- /src/cli/list-choice.ls: -------------------------------------------------------------------------------- 1 | debug = require '../debug' <| __filename 2 | readline-sync = require 'readline-sync' 3 | {map-indexed, join, is-nil, is-empty} = require 'ramda' 4 | 5 | option-to-entry = (opt, i) -> "#{i+1}) #opt" 6 | numbered-list = (join '\n') . map-indexed option-to-entry 7 | 8 | module.exports = list-choice = (question, list) -> 9 | debug {question, list} 10 | throw new Error 'empty list' if is-empty list 11 | if list.length is 1 then return list.0 12 | 13 | console.log question if question 14 | console.log numbered-list list 15 | num = readline-sync.prompt! 16 | choice = list[num - 1] 17 | 18 | if is-nil choice 19 | list-choice ... 20 | else 21 | choice 22 | -------------------------------------------------------------------------------- /src/cli/list.ls: -------------------------------------------------------------------------------- 1 | {format-jobs-table, die, jobs-filter-by-str} = require '../utils' 2 | require! '../api/list-jobs' 3 | require! ramda: {identity, is-empty, filter, prop, pick, pick-by, prop-eq, keys, to-pairs, map, apply, complement, lens, head, tail, any-pass, is-nil} 4 | debug = require '../debug' <| __filename 5 | 6 | negate-if-false = (fn, bool) -> 7 | | not bool => complement fn 8 | | otherwise => fn 9 | 10 | head-lens = lens do 11 | head, (val, list) -> [val] ++ tail list 12 | 13 | PREDICATES = 14 | building : prop-eq \building, true 15 | successful : prop-eq \result, \SUCCESS 16 | failed : prop-eq \result, \FAILURE 17 | recent : (job) -> (Date.now! - job.timestamp) < 1000 * 60 * 10min 18 | 19 | get-predicates = (argv) -> 20 | pick-by (complement is-nil), argv 21 | |> to-pairs . pick (keys PREDICATES), _ 22 | |> map head-lens.map (prop _, PREDICATES) 23 | |> map apply negate-if-false 24 | 25 | filter-by-predicates = (argv) -> 26 | ps = get-predicates argv 27 | switch 28 | | is-empty ps => identity 29 | | otherwise => filter (any-pass ps) 30 | 31 | cli-list = (argv) -> 32 | {__: input} = argv 33 | 34 | list-jobs! 35 | .then jobs-filter-by-str input 36 | .then filter-by-predicates argv 37 | .then (jobs) -> 38 | unless is-empty jobs 39 | console.log format-jobs-table jobs 40 | else 41 | console.error 'Nothing found with given parameters' 42 | .catch die 43 | 44 | module.exports = cli-list 45 | -------------------------------------------------------------------------------- /src/cli/parse.ls: -------------------------------------------------------------------------------- 1 | yargs = require \yargs 2 | debug = require '../debug' <| __filename 3 | require! ramda: {join, merge} 4 | 5 | module.exports = (argv) -> 6 | debug argv 7 | 8 | command = yargs.reset! 9 | .usage 'Usage: jenkins [options]' 10 | .command \list, 'list jobs' 11 | .command \tail, 'read build logs' 12 | .command \configure, 'open job configuration view in browser' 13 | .command \setup, 'interactively configure jenkins base url' 14 | .demand 1, null 15 | .parse argv ._.0 16 | 17 | parsed-argv = switch command 18 | | \list 19 | yargs.reset! 20 | .usage 'Usage: jenkins list [options] []' 21 | .demand 1, null 22 | .option \b, 23 | type : \boolean 24 | description : "list building jobs" 25 | alias : \building 26 | default : void 27 | .option \s, 28 | type : \boolean 29 | description : "list successful jobs" 30 | alias : \successful 31 | default : void 32 | .option \f, 33 | type : \boolean 34 | description : "list failed jobs" 35 | alias : \failed 36 | default : void 37 | .option \r, 38 | type : \boolean 39 | description : "list recent jobs (<10min)" 40 | alias : \recent 41 | default : void 42 | .example 'jenkins list' 43 | .example 'jenkins list my-build' 44 | .example 'jenkins list --building --failed' 45 | .epilogue do 46 | """ 47 | can be a regex or fuzzily matching string 48 | 49 | multiple predicates are combined in OR fashion 50 | """ 51 | .help \h, 'show help' 52 | .alias \h, \help 53 | .parse argv 54 | | \tail 55 | yargs.reset! 56 | .usage 'Usage: jenkins tail [options] ' 57 | .demand 2, null 58 | .option \f, 59 | type : \boolean 60 | description : "follow a job's build logs indefinitely (think tail -f)" 61 | alias : \follow 62 | .option \b, 63 | type : \number 64 | description : 'show output for a specific build' 65 | alias : \build-number 66 | .option \m, 67 | type : \boolean 68 | description : 'tail and follow multiple jobs' 69 | alias : \multi 70 | .example 'jenkins tail my-build -f' 71 | .example 'jenkins tail my-build -b 70' 72 | .example 'jenkins tail "/deploy-(develop|staging)"' 73 | .epilogue do 74 | """ 75 | can be a regex or fuzzily matching string 76 | 77 | --multi works so that when the given pattern matches multiple jobs, 78 | ez-jenkins will always tail one of the jobs that has a build running 79 | """ 80 | .help \h, 'show help' 81 | .alias \h, \help 82 | .parse argv 83 | | \configure 84 | yargs.reset! 85 | .usage 'Usage: jenkins configure ' 86 | .demand 2, null 87 | .example 'jenkins configure my-build' 88 | .help \h, 'show help' 89 | .alias \h, \help 90 | .parse argv 91 | | \setup 92 | yargs.reset! 93 | .help \h, 'show help' 94 | .alias \h, \help 95 | .parse argv 96 | | otherwise 97 | debug 'no command matched, showing help' 98 | yargs.show-help! 99 | process.exit 1 100 | 101 | __ = parsed-argv._.slice 1 |> join ' ' 102 | 103 | command : command 104 | argv : merge parsed-argv, {__} 105 | -------------------------------------------------------------------------------- /src/cli/setup.ls: -------------------------------------------------------------------------------- 1 | require! bluebird: {coroutine: async} 2 | require! \readline-sync 3 | require! '../api/check-base-url' 4 | require! '../config' 5 | require! chalk: {bold} 6 | require! '../utils': {die} 7 | require! ramda: {bind} 8 | 9 | module.exports = async ->* 10 | write = bind process.stdout.write, process.stdout 11 | 12 | """ 13 | Enter jenkins base url (abort with ^C) 14 | Base url is the url of jenkins' main view 15 | """ |> console.log 16 | 17 | base-url = readline-sync.prompt! 18 | 19 | write 'Checking URL..' 20 | interval = set-interval (-> write '.'), 200 21 | 22 | check-base-url base-url 23 | .tap -> clear-interval interval 24 | .then -> 25 | it.cata do 26 | Just: -> 27 | write bold.green ' OK!\n' 28 | config.save url: base-url 29 | 30 | """ 31 | Configuration written to #{config.path} 32 | Ready to go! 33 | """ |> console.log 34 | Nothing: -> 35 | write '\n' 36 | die "Error: Could not find jenkins API in the given URL" 37 | 38 | .catch -> 39 | write '\n' 40 | die it 41 | -------------------------------------------------------------------------------- /src/cli/tail.ls: -------------------------------------------------------------------------------- 1 | {curry, sort-by, prop, prop-eq, find, map, chain, tap, is-empty, partial, compose-p} = require 'ramda' 2 | 3 | Promise = require \bluebird 4 | {coroutine: async} = require \bluebird 5 | through = require 'through2' 6 | {cyan} = require \chalk 7 | tail-build = require '../api/tail-build' 8 | get-all-jobs = require '../api/get-all-jobs' 9 | {die} = require '../utils' 10 | list-choice = curry require './list-choice' 11 | debug = require '../debug' <| __filename 12 | format-build-info = require './format-build-info' 13 | {fuzzy-filter, jobs-filter-by-str} = require '../utils' 14 | require! '../api/list-jobs' 15 | require! 'data.maybe': Maybe 16 | 17 | error = (job-name, build-number) -> 18 | str = 'Unable to find job' 19 | switch 20 | | build-number? => "#str or build: #job-name [##{build-number}]" 21 | | otherwise => "#str: #job-name" 22 | 23 | format-line = (build, line) -> 24 | build-number = cyan "[##{build.number}]" 25 | "#build-number #line" 26 | 27 | format-tail-output = -> 28 | cur-build = null 29 | 30 | through.obj (chunk, enc, next) -> 31 | push-line = ~> @push new Buffer "#it\n" 32 | 33 | switch typeof! chunk 34 | | \String 35 | push-line format-line cur-build, chunk 36 | | \Object 37 | debug chunk, 'chunk' 38 | switch chunk.event 39 | | \GOT_BUILD => cur-build := chunk.build 40 | | \WAITING_FOR_BUILD => push-line 'Waiting for the next build...' 41 | | \BUILD_INFO => push-line format-build-info chunk.build-info 42 | 43 | next! 44 | 45 | # :: Job -> Bool 46 | is-building = prop-eq \building, true 47 | sort-by-started = sort-by prop \timestamp 48 | 49 | # :: [Job] -> Maybe Job 50 | find-earliest-building-job = Maybe.from-nullable . (find is-building) . sort-by-started 51 | 52 | die-if-empty = tap (jobs) -> 53 | if is-empty jobs 54 | die 'Given pattern matched no jobs' 55 | 56 | cli-multi-tail = async (argv) ->* 57 | debug 'cli-multi-tail' 58 | {__: input} = argv 59 | retry = partial cli-multi-tail, argv 60 | wait = partial Promise.delay, 1000 61 | wait-and-retry = compose-p retry, wait 62 | 63 | tail-job = async (job-name) ->* 64 | output = yield tail-build job-name 65 | output.cata do 66 | Just: (stream) -> 67 | stream 68 | .pipe format-tail-output! 69 | .pipe process.stdout 70 | stream.on \end, retry 71 | Nothing: -> 72 | die 'Something went wrong' 73 | 74 | (yield list-jobs!) 75 | |> jobs-filter-by-str input 76 | |> die-if-empty 77 | |> find-earliest-building-job 78 | |> map prop \jobName 79 | |> (.cata Just: tail-job, Nothing: wait-and-retry) 80 | 81 | cli-tail = (argv, second-time) -> 82 | {__: job-name, build-number, follow, multi} = argv 83 | 84 | return cli-multi-tail argv if argv.multi 85 | 86 | tail-build job-name, build-number, follow 87 | .then (output) -> 88 | output.cata do 89 | Just: (output) -> 90 | output 91 | .pipe format-tail-output! 92 | .pipe process.stdout 93 | Nothing: async ->* 94 | print-err = -> error job-name, build-number |> console.error 95 | return print-err! if second-time 96 | 97 | return (fuzzy-filter job-name, yield get-all-jobs!) 98 | .map list-choice 'No such job, did you mean one of these?\n' 99 | .cata do 100 | Just: (job-name) -> 101 | cli-tail {__: job-name, build-number, follow}, true 102 | Nothing: print-err 103 | 104 | .catch die 105 | 106 | module.exports = cli-tail 107 | -------------------------------------------------------------------------------- /src/config.ls: -------------------------------------------------------------------------------- 1 | yaml = require 'js-yaml' 2 | fs = require 'fs' 3 | mkdirp = require 'mkdirp' 4 | require! path: {dirname, join} 5 | require! ramda: {prop} 6 | 7 | debug = require './debug' <| __filename 8 | home = process.env.HOME 9 | config-path = join home, \.config, \ez-jenkins, \config.yaml 10 | debug config-path 11 | 12 | safe-read = (path) -> 13 | debug 'reading path=%s', path 14 | 15 | if fs.exists-sync path 16 | yaml-str = fs.read-file-sync path, 'utf8' 17 | yaml.safe-load yaml-str 18 | else 19 | # ugly 20 | """ 21 | config unavailable (#config-path) 22 | run `jenkins setup` 23 | """ |> console.log 24 | 25 | process.exit 1 26 | 27 | read-config = do -> 28 | config = null 29 | -> config ?:= safe-read config-path 30 | 31 | export path = config-path 32 | 33 | export get = do -> 34 | config = null 35 | 36 | (key) -> 37 | debug 'get key=%s', key 38 | prop key, read-config! 39 | 40 | export save = (obj) -> 41 | debug 'save obj=%s', JSON.stringify obj 42 | mkdirp.sync dirname config-path 43 | yaml-str = yaml.safe-dump obj 44 | fs.write-file-sync config-path, yaml-str 45 | -------------------------------------------------------------------------------- /src/constants.ls: -------------------------------------------------------------------------------- 1 | export BUILD_KEYS = 2 | <[ building timestamp estimatedDuration duration result number ]> * ',' 3 | 4 | export POLL_DELAY_MS = 1000 5 | -------------------------------------------------------------------------------- /src/debug.ls: -------------------------------------------------------------------------------- 1 | require! debug 2 | require! path: { basename, extname } 3 | 4 | without-ext = -> 5 | basename it, extname it 6 | 7 | format-name = without-ext . basename 8 | 9 | module.exports = (filename) -> 10 | debug format-name filename 11 | -------------------------------------------------------------------------------- /src/index.ls: -------------------------------------------------------------------------------- 1 | require! ramda: {has} 2 | 3 | # force colors in both chalk and colors.js 4 | if has \FORCE_COLOR, process.env 5 | process.argv.push '--color' 6 | 7 | require 'source-map-support' .install! 8 | require('./cli') process.argv.slice 2 9 | -------------------------------------------------------------------------------- /src/utils/build-result-color.ls: -------------------------------------------------------------------------------- 1 | require! 'data.maybe': Maybe 2 | 3 | module.exports = -> 4 | switch it 5 | | \SUCCESS => \green 6 | | \ABORTED => \inverse 7 | | \FAILURE => \red 8 | | otherwise => null 9 | |> Maybe.from-nullable 10 | -------------------------------------------------------------------------------- /src/utils/ensure-res-body.ls: -------------------------------------------------------------------------------- 1 | require! ramda: {eq-deep} 2 | 3 | export ensure-res-body = (req-promise) -> 4 | req-promise.tap ([, body]) -> 5 | if eq-deep body, {} 6 | throw new Error 'Got an empty response' 7 | -------------------------------------------------------------------------------- /src/utils/format-url.ls: -------------------------------------------------------------------------------- 1 | config = require '../config' 2 | debug = require '../debug' <| __filename 3 | 4 | module.exports = (path) -> 5 | base-url = config.get \url .replace // /?$ //, '' 6 | url = base-url + path 7 | debug url 8 | url 9 | -------------------------------------------------------------------------------- /src/utils/fuzzy-filter.ls: -------------------------------------------------------------------------------- 1 | {curry-n, map, prop, take, is-empty} = require 'ramda' 2 | Maybe = require 'data.maybe' 3 | 4 | fuzzy = curry-n 2, (require \fuzzy .filter) 5 | export fuzzy-filter-prop = (property, pattern, list) --> 6 | # if more than n, could get only the ones with top score 7 | fuzzy pattern, list, extract: prop property 8 | |> map prop \original 9 | 10 | export fuzzy-filter = (pattern, list) --> 11 | filtered = map (prop \string), fuzzy pattern, list 12 | 13 | if is-empty filtered 14 | Maybe.Nothing! 15 | else 16 | Maybe.of filtered .map take 10 17 | -------------------------------------------------------------------------------- /src/utils/index.ls: -------------------------------------------------------------------------------- 1 | require! chalk: {red} 2 | require! ramda: {reduce, map, tap} 3 | merge = (xs) -> reduce (<<<), {}, xs 4 | require-obj = (obj) -> 5 | {[k, require v] for k, v of obj} 6 | 7 | die = (err) -> 8 | console.error red err.to-string! 9 | process.exit 1 10 | 11 | module.exports = merge [ 12 | require-obj do 13 | sort-abc : './sort-abc' 14 | format-url : './format-url' 15 | build-result-color : './build-result-color' 16 | require './jobs-table' 17 | require './fuzzy-filter' 18 | require './ensure-res-body' 19 | require './jobs-filter-by-str' 20 | {die} 21 | ] 22 | -------------------------------------------------------------------------------- /src/utils/jobs-filter-by-str.ls: -------------------------------------------------------------------------------- 1 | require! ramda: {identity, prop, filter} 2 | require! './fuzzy-filter': {fuzzy-filter-prop} 3 | 4 | REGEX = /\/([^/]+)\/?[gi]*?/ 5 | is-regex = -> REGEX.test it 6 | str-to-regex = -> 7 | new RegExp (it.match REGEX .1), 'i' 8 | 9 | prop-test = (property, re, obj) --> 10 | re.test prop property, obj 11 | 12 | # :: String -> ([Job] -> [Job]) 13 | export jobs-filter-by-str = (str) -> 14 | | str is undefined => identity 15 | | is-regex str => filter prop-test \jobName, (str-to-regex str) 16 | | otherwise => fuzzy-filter-prop \jobName, str 17 | -------------------------------------------------------------------------------- /src/utils/jobs-table.ls: -------------------------------------------------------------------------------- 1 | {__, prop, merge, for-each, map, pick-all, any, values, is-nil, slice, identity} = require 'ramda' 2 | require! 'cli-table': Table 3 | require! './build-result-color' 4 | debug = require '../debug' <| __filename 5 | require! 'data.maybe': Maybe 6 | require! \pretty-ms 7 | require! chalk 8 | 9 | pick-props = (props, obj) --> 10 | [obj[k] for k in props] 11 | 12 | safe-props = (props, obj) --> 13 | picked = pick-all props, obj 14 | unless any is-nil, values picked 15 | Maybe.of picked 16 | else 17 | Maybe.Nothing! 18 | 19 | limit-to = (n, x) --> 20 | if x > n then n else x 21 | 22 | pct = (it) -> 23 | (+ '%') <| (it * 100).to-fixed 0 24 | 25 | format-activity = (obj) -> 26 | if not obj.building 27 | finished = obj.timestamp + obj.duration 28 | since-build = Date.now! - finished 29 | str = (+ ' ago') <| pretty-ms since-build, compact: true 30 | 31 | color-fn = switch 32 | | since-build < 1000 * 60 * 10min => chalk.bold 33 | | since-build > 1000 * 60 * 60 * 1h => chalk.dim 34 | | otherwise => identity 35 | 36 | color-fn str 37 | else 38 | duration = Date.now! - obj.timestamp 39 | progress = duration / obj.estimated-duration 40 | str = "building (#{pct progress})" 41 | 42 | char-progress = (limit-to str.length) Math.round progress * str.length 43 | 44 | done-str = chalk.inverse slice 0, char-progress, str 45 | left-str = slice char-progress, str.length, str 46 | done-str + left-str 47 | 48 | # obj.result can be null 49 | format-name = (obj) -> 50 | color-str = if obj.building and obj.last-completed-build 51 | obj.last-completed-build.result 52 | else 53 | obj.result 54 | 55 | build-result-color color-str 56 | .map prop __, chalk 57 | .map (c) -> if obj.building then c.bold else c 58 | .ap Maybe.of obj.job-name 59 | .get! 60 | 61 | # TODO: truncate job name and maybe other fields as well 62 | # TODO: what happens if first build doesn't have estimatedDuration 63 | export format-row-obj = (obj) -> 64 | merge obj, 65 | number : obj.number or 'N/A' 66 | job-name : format-name obj 67 | activity : safe-props <[ building timestamp duration estimatedDuration ]>, obj 68 | .map format-activity 69 | .get-or-else 'never' 70 | 71 | export format-jobs-table = (jobs) -> 72 | HEAD = <[ # job activity ]> 73 | ROWS = <[ number jobName activity ]> 74 | 75 | table = new Table head: HEAD, style: { head: <[cyan bold]> } 76 | rows = map ((pick-props ROWS) . format-row-obj), jobs 77 | 78 | for-each table~push, rows 79 | table.to-string! 80 | -------------------------------------------------------------------------------- /src/utils/sort-abc.ls: -------------------------------------------------------------------------------- 1 | {sort} = require 'ramda' 2 | 3 | module.exports = sort (a, b) -> 4 | switch 5 | | a < b => -1 6 | | a > b => 1 7 | | _ => 0 8 | -------------------------------------------------------------------------------- /test/_globals.ls: -------------------------------------------------------------------------------- 1 | global.assert = require \chai .assert 2 | global.deep-eq = (a, b) --> a `assert.deepEqual` b 3 | global.eq = assert.strict-equal 4 | global.ok = assert.ok 5 | 6 | global.JENKINS_URL = 'https://ci.jenkins.com' 7 | global.fake-format-url = (path) -> 8 | JENKINS_URL + path 9 | -------------------------------------------------------------------------------- /test/check-base-url.ls: -------------------------------------------------------------------------------- 1 | {nock, async, qs} = require './test-util' 2 | {always} = require \ramda 3 | 4 | require! '../src/api/check-base-url' 5 | 6 | JSON_DATA = 7 | primary-view: 'foo' 8 | 9 | describe 'check-base-url' (,) -> 10 | after-each -> nock.clean-all! 11 | 12 | req = -> 13 | nock 'http://ci.example.com' 14 | .get '/api/json?' + qs tree: 'primaryView' 15 | 16 | it 'returns Just if it finds primaryView' async ->* 17 | req!.reply 200, JSON_DATA 18 | res = yield check-base-url 'http://ci.example.com' 19 | ok res.is-just 20 | 21 | it "returns Nothing if doesn't find primaryView" async ->* 22 | req!.reply 200, {} 23 | res = yield check-base-url 'http://ci.example.com' 24 | ok res.is-nothing 25 | 26 | it "returns Nothing if it doesn't find JSON" async ->* 27 | req!.reply 500, 'notjson' 28 | res = yield check-base-url 'http://ci.example.com' 29 | ok res.is-nothing 30 | -------------------------------------------------------------------------------- /test/cli-commands.ls: -------------------------------------------------------------------------------- 1 | {proxyquire, sinon} = require './test-util' 2 | {called, called-with, called-with-exactly} = sinon.assert 3 | 4 | list = sinon.spy! 5 | tail = sinon.spy! 6 | setup = sinon.spy! 7 | configure = sinon.spy! 8 | 9 | cli = proxyquire '../src/cli/', 10 | './tail' : tail 11 | './setup' : setup 12 | './configure' : configure 13 | './list' : list 14 | 15 | describe 'list' (,) -> 16 | before-each -> list.reset! 17 | 18 | it 'is called with input' -> 19 | cli <[ list foo ]> 20 | called-with list, sinon.match do 21 | __: \foo 22 | 23 | it 'is called with options' -> 24 | cli <[ list foo --building --failed --recent --successful ]> 25 | called-with list, sinon.match do 26 | building: true 27 | failed: true 28 | recent: true 29 | successful: true 30 | 31 | describe 'tail' (,) -> 32 | before-each -> tail.reset! 33 | 34 | it 'is called with job name' -> 35 | cli <[ tail test-job-1234 ]> 36 | called-with tail, sinon.match do 37 | __: \test-job-1234 38 | 39 | it 'is called with --follow' -> 40 | cli <[ tail test-job-1234 -f ]> 41 | called-with tail, sinon.match do 42 | __: \test-job-1234 43 | follow: true 44 | 45 | it 'is called with --build-number' -> 46 | cli <[ tail test-job-1234 -b 100 ]> 47 | called-with tail, sinon.match do 48 | __: \test-job-1234 49 | build-number: 100 50 | 51 | it 'is called with --multi' -> 52 | cli <[ tail test-job-1234 -m ]> 53 | called-with tail, sinon.match do 54 | __: \test-job-1234 55 | multi: true 56 | 57 | describe 'setup' (,) -> 58 | before-each -> setup.reset! 59 | 60 | it 'is called' -> 61 | cli <[ setup ]> 62 | called setup 63 | 64 | describe 'configure' (,) -> 65 | before-each -> configure.reset! 66 | 67 | it 'is called with job name' -> 68 | cli <[ configure test-job-1234 ]> 69 | called-with-exactly configure, sinon.match do 70 | __: \test-job-1234 71 | -------------------------------------------------------------------------------- /test/cli-configure.ls: -------------------------------------------------------------------------------- 1 | {nock, proxyquire, async, qs, sinon} = require './test-util' 2 | require! bluebird: Promise 3 | require! 'data.maybe': Maybe 4 | {merge} = require 'ramda' 5 | {called-with, called-with-exactly, not-called} = sinon.assert 6 | 7 | open = sinon.spy! 8 | cli-configure = null 9 | sandbox = null 10 | 11 | proxyquire-defaults = 12 | 'open': open 13 | '../utils': { '@global': true, format-url: fake-format-url } 14 | 15 | describe 'cli-configure' (,) -> 16 | before-each -> 17 | sandbox := sinon.sandbox.create! 18 | sandbox.stub console, 'error' 19 | open.reset! 20 | 21 | after-each -> 22 | sandbox.restore! 23 | 24 | describe 'with job matches' (,) -> 25 | before -> 26 | cli-configure := proxyquire '../src/cli/configure', merge proxyquire-defaults, 27 | '../api/get-all-jobs': -> Promise.resolve <[ test-job-1234 ]> 28 | 29 | it 'opens url in browser' async ->* 30 | yield cli-configure __: \test-job-1234 31 | called-with-exactly open, JENKINS_URL + '/job/test-job-1234/configure' 32 | 33 | describe 'without job matches' (,) -> 34 | before -> 35 | cli-configure := proxyquire '../src/cli/configure', merge proxyquire-defaults, 36 | '../api/get-all-jobs': -> Promise.resolve [] 37 | 38 | it "doesn't open browser" async ->* 39 | yield cli-configure __: \test-job-1234 40 | not-called open 41 | 42 | it 'shows an error' async ->* 43 | yield cli-configure __: \test-job-1000 44 | called-with console.error, 'Unable to find job: test-job-1000' 45 | -------------------------------------------------------------------------------- /test/cli-help.ls: -------------------------------------------------------------------------------- 1 | {async, strip-trailing} = require './test-util' 2 | exec = require \child_process .exec 3 | require! util 4 | 5 | describe 'bin/jenkins' (,) -> 6 | it 'displays help' (done) -> 7 | # TODO: slow as hell, figure out a way to capture process.stderr without 8 | # spawning a new process 9 | (,, stderr) <- exec 'DEBUG=0 ./node_modules/.bin/lsc ./src/index.ls' 10 | stderr := strip-trailing stderr 11 | 12 | help = 13 | """ 14 | Usage: jenkins [options] 15 | 16 | Commands: 17 | list list jobs 18 | tail read build logs 19 | configure open job configuration view in browser 20 | setup interactively configure jenkins base url\n\n 21 | """ 22 | 23 | eq help, stderr 24 | done! 25 | -------------------------------------------------------------------------------- /test/cli-list.ls: -------------------------------------------------------------------------------- 1 | {nock, proxyquire, async, qs, sinon} = require './test-util' 2 | require! bluebird: Promise 3 | {called-with, called-with-exactly, not-called} = sinon.assert 4 | 5 | cli-list = null 6 | sandbox = null 7 | format-jobs-table = sinon.spy! 8 | 9 | describe 'cli-list' (,) -> 10 | before-each -> 11 | sandbox := sinon.sandbox.create! 12 | sandbox.stub console, 'error' 13 | sandbox.stub console, 'log' 14 | 15 | after-each -> 16 | sandbox.restore! 17 | 18 | describe 'input filtering with job matches' (,) -> 19 | before-each -> format-jobs-table.reset! 20 | 21 | before -> 22 | cli-list := proxyquire '../src/cli/list', 23 | '../utils': 24 | format-jobs-table: format-jobs-table 25 | '../api/list-jobs': -> Promise.resolve [ 26 | * job-name: \test 27 | * job-name: \test-123 28 | ] 29 | 30 | # TODO: test output instead of what format-jobs-table was called with? 31 | it 'filters by fuzzy matching if input is string' async ->* 32 | yield cli-list __: \tst 33 | called-with format-jobs-table, [ 34 | * job-name: \test 35 | * job-name: \test-123 36 | ] 37 | 38 | it 'filters by regex if input is regex-like' async ->* 39 | yield cli-list __: '/test$/' 40 | called-with format-jobs-table, [ 41 | * job-name: \test 42 | ] 43 | 44 | describe 'predicate arguments' (,) -> 45 | var JOBS, clock 46 | before-each -> format-jobs-table.reset! 47 | before -> 48 | clock := sinon.use-fake-timers Date.now! 49 | 50 | JOBS := [ 51 | * job-name : \test1 52 | building : false 53 | timestamp : Date.now! - 1000 * 60 * 1m # recent 54 | result : \SUCCESS 55 | * job-name : \test2 56 | building : true 57 | timestamp : Date.now! - 1000 * 60 * 15m 58 | result : null 59 | * job-name : \test3 60 | building : false 61 | timestamp : Date.now! - 1000 * 60 * 15m 62 | result : \FAILURE 63 | ] 64 | 65 | cli-list := proxyquire '../src/cli/list', 66 | '../utils': format-jobs-table: format-jobs-table 67 | '../api/list-jobs': -> Promise.resolve JOBS 68 | 69 | after -> clock.restore! 70 | 71 | it 'filters by successful' async ->* 72 | yield cli-list __: \test, successful: true 73 | called-with format-jobs-table, [JOBS.0] 74 | 75 | it 'filters by building' async ->* 76 | yield cli-list __: \test, building: true 77 | called-with format-jobs-table, [JOBS.1] 78 | 79 | it 'filters by failed' async ->* 80 | yield cli-list __: \test, failed: true 81 | called-with format-jobs-table, [JOBS.2] 82 | 83 | it 'filters by recent' async ->* 84 | yield cli-list __: \test, recent: true 85 | called-with format-jobs-table, [JOBS.0] 86 | 87 | it 'filters by failed and building together (OR)' async ->* 88 | yield cli-list __: \test, failed: true, building: true 89 | called-with format-jobs-table, [JOBS.1, JOBS.2] 90 | 91 | describe 'without job matches' (,) -> 92 | before -> 93 | cli-list := proxyquire '../src/cli/list', 94 | '../api/list-jobs': -> Promise.resolve [] 95 | 96 | it 'shows an error' async ->* 97 | yield cli-list __: \foo 98 | called-with console.error, 'Nothing found with given parameters' 99 | -------------------------------------------------------------------------------- /test/cli-parse.ls: -------------------------------------------------------------------------------- 1 | require! ramda: {prop, path} 2 | require! '../src/cli/parse' 3 | 4 | describe 'parse' (,) -> 5 | it 'returns command' -> 6 | eq 'setup', prop \command, parse <[ setup foo bar xyz ]> 7 | 8 | it 'returns list of args after a command in __ as a string' -> 9 | eq 'foo bar xyz', path <[ argv __ ]>, parse <[ setup foo bar xyz ]> 10 | -------------------------------------------------------------------------------- /test/cli-setup.ls: -------------------------------------------------------------------------------- 1 | {nock, proxyquire, async, qs, sinon, Maybe, Promise} = require './test-util' 2 | {called, called-with, called-with-exactly, not-called} = sinon.assert 3 | require! ramda: {for-each} 4 | 5 | require! \readline-sync 6 | 7 | save = sinon.spy! 8 | die = sinon.spy! 9 | 10 | var cli-setup, check-base-url-stub, prompt-stub, sandbox 11 | 12 | describe 'cli-setup' (,) -> 13 | before -> 14 | prompt-stub := sinon.stub readline-sync, \prompt 15 | check-base-url-stub := sinon.stub! 16 | 17 | # makes proxyquire not load modules' original code. important because 18 | # every time proxyquire is called without noCallThru it will load all 19 | # requires of the module which doesn't make sense if the module is 20 | # completely stubbed. '../api/check-base-url' for example promisifies 21 | # request every time which is a very slow operation 22 | proxyquire.no-call-thru! 23 | 24 | cli-setup := proxyquire '../src/cli/setup', 25 | 'readline-sync': {prompt: prompt-stub} 26 | '../api/check-base-url': check-base-url-stub 27 | '../config': {save}, 28 | '../utils': {die} 29 | 30 | before-each -> 31 | sandbox := sinon.sandbox.create! 32 | sandbox.stub process.stdout, 'write' 33 | sandbox.stub console, 'log' 34 | sandbox.stub console, 'error' 35 | 36 | after -> 37 | prompt-stub.restore! 38 | proxyquire.call-thru! 39 | 40 | after-each -> 41 | [ prompt-stub, check-base-url-stub, save ].for-each -> it.reset! 42 | sandbox.restore! 43 | 44 | describe 'general' (,) -> 45 | before -> 46 | prompt-stub.returns 'http://www.google.com' 47 | check-base-url-stub.returns Promise.resolve Maybe.Just! 48 | 49 | it 'prompts for base url' async ->* 50 | yield cli-setup! 51 | called prompt-stub 52 | 53 | it 'checks the given URL for working jenkins API' async ->* 54 | yield cli-setup! 55 | called-with check-base-url-stub, 'http://www.google.com' 56 | 57 | describe 'with working URL' (,) -> 58 | before -> 59 | prompt-stub.returns 'http://www.google.com' 60 | check-base-url-stub.returns Promise.resolve Maybe.Just! 61 | 62 | it 'prints OK' 63 | it 'saves URL to config' async ->* 64 | yield cli-setup! 65 | called-with save, url: 'http://www.google.com' 66 | 67 | describe 'with bad URL' (,) -> 68 | before -> 69 | prompt-stub.returns \whatever 70 | check-base-url-stub.returns Promise.resolve Maybe.Nothing! 71 | 72 | it 'prints an error' async ->* 73 | yield cli-setup! 74 | called die 75 | -------------------------------------------------------------------------------- /test/cli-tail.ls: -------------------------------------------------------------------------------- 1 | {nock, proxyquire, async, qs, sinon} = require './test-util' 2 | require! bluebird: Promise 3 | require! 'data.maybe': Maybe 4 | {called-with, called-with-exactly, not-called} = sinon.assert 5 | 6 | cli-tail = null 7 | sandbox = null 8 | 9 | describe 'cli-tail' (,) -> 10 | before-each -> 11 | sandbox := sinon.sandbox.create! 12 | sandbox.stub console, 'error' 13 | 14 | after-each -> 15 | sandbox.restore! 16 | 17 | describe 'with job matches' (,) -> 18 | # TODO: needs a way to capture process.stdout 19 | it 'tails a build' 20 | 21 | describe 'without job matches' (,) -> 22 | it 'shows an error' async ->* 23 | cli-tail := proxyquire '../src/cli/tail', 24 | '../api/tail-build' : -> Promise.resolve Maybe.Nothing! 25 | '../api/get-all-jobs' : -> Promise.resolve [] 26 | 27 | yield cli-tail __: \test-job-1000 28 | called-with console.error, 'Unable to find job: test-job-1000' 29 | -------------------------------------------------------------------------------- /test/data/list-jobs.json: -------------------------------------------------------------------------------- 1 | { 2 | "jobs": [ 3 | { 4 | "lastBuild": { 5 | "building": false, 6 | "duration": 62, 7 | "estimatedDuration": 49, 8 | "number": 133, 9 | "result": "SUCCESS", 10 | "timestamp": 1344503360000 11 | }, 12 | "lastCompletedBuild": { 13 | "result": "SUCCESS" 14 | }, 15 | "name": "foo-1" 16 | }, 17 | { 18 | "lastBuild": { 19 | "building": false, 20 | "duration": 1168836, 21 | "estimatedDuration": 1154187, 22 | "number": 139, 23 | "result": "SUCCESS", 24 | "timestamp": 1344503365000 25 | }, 26 | "lastCompletedBuild": { 27 | "result": "FAILURE" 28 | }, 29 | "name": "foo-2" 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /test/format-build-info.ls: -------------------------------------------------------------------------------- 1 | {strip-trailing, sinon} = require './test-util' 2 | require! '../src/cli/format-build-info' 3 | require! \pretty-ms 4 | require! strftime 5 | 6 | BUILD_DATA = 7 | building: false, 8 | duration: 13903, 9 | estimatedDuration: 11364, 10 | number: 82, 11 | result: 'SUCCESS', 12 | timestamp: 1425683052872 13 | 14 | clock = null 15 | describe 'format-build-info' (,) -> 16 | before -> 17 | clock := sinon.use-fake-timers Date.now! 18 | 19 | after -> 20 | clock.restore! 21 | 22 | it 'formats build info' -> 23 | finished = BUILD_DATA.duration + BUILD_DATA.timestamp 24 | since-build = Date.now! - finished 25 | since-str = pretty-ms since-build, compact: true 26 | finished-str = strftime '%F %T', new Date BUILD_DATA.timestamp 27 | 28 | eq "\u001b[1m\u001b[32m[SUCCESS]\u001b[39m\u001b[22m " + 29 | "\u001b[1mDuration:\u001b[22m 13.9s \u001b[33m(+2.5s)\u001b[39m " + 30 | "\u001b[1mFinished:\u001b[22m #finished-str (#since-str ago)", 31 | format-build-info BUILD_DATA 32 | -------------------------------------------------------------------------------- /test/get-all-jobs.ls: -------------------------------------------------------------------------------- 1 | {nock, proxyquire, async, qs} = require './test-util' 2 | {always} = require \ramda 3 | 4 | get-all-jobs = proxyquire '../src/api/get-all-jobs', 5 | '../utils': { '@global': true, format-url: fake-format-url } 6 | 7 | JSON_DATA = 8 | jobs: 9 | * name: \foo-1 10 | * name: \foo-2 11 | * name: \foo-3 12 | * name: \foo-4 13 | 14 | describe 'get-all-jobs' (,) -> 15 | after-each -> nock.clean-all! 16 | 17 | it 'gets jobs as a list' async ->* 18 | nock JENKINS_URL 19 | .get '/api/json?' + qs tree: 'jobs[name]' 20 | .reply 200, JSON_DATA 21 | 22 | jobs = yield get-all-jobs! 23 | deep-eq <[ foo-1 foo-2 foo-3 foo-4 ]>, jobs 24 | -------------------------------------------------------------------------------- /test/get-build.ls: -------------------------------------------------------------------------------- 1 | {nock, proxyquire, async, qs} = require './test-util' 2 | {always} = require \ramda 3 | 4 | get-build = proxyquire '../src/api/get-build', 5 | '../utils': { '@global': true, format-url: fake-format-url } 6 | 7 | JSON_DATA = 8 | building: false, 9 | duration: 10146, 10 | estimated-duration: 10116, 11 | number: 76, 12 | result: 'SUCCESS', 13 | timestamp: 1425590308372 14 | 15 | my-nock = -> 16 | nock JENKINS_URL 17 | .get '/job/test-job-1234/30/api/json?' + 18 | qs tree: 'building,timestamp,estimatedDuration,duration,result,number' 19 | 20 | describe 'get-build' (,) -> 21 | after-each -> nock.clean-all! 22 | 23 | it 'gets Just if found' async ->* 24 | my-nock!.reply 200, JSON_DATA 25 | 26 | build = yield get-build \test-job-1234, 30 27 | ok build.is-just 28 | deep-eq JSON_DATA, build.get! 29 | 30 | it 'gets Nothing if not found' async ->* 31 | my-nock!.reply 404 32 | 33 | build = yield get-build \test-job-1234, 30 34 | ok build.is-nothing 35 | -------------------------------------------------------------------------------- /test/jobs-table.ls: -------------------------------------------------------------------------------- 1 | {sinon} = require './test-util' 2 | require! '../src/utils': {format-jobs-table, format-row-obj} 3 | require! ramda: {prop, merge} 4 | require! chalk: {red, green, inverse, strip-color, bold, dim} 5 | 6 | JOBS = [ 7 | job-name : \foo-1 8 | result : \SUCCESS 9 | number : 1 10 | ] 11 | 12 | describe 'format-jobs-table' (,) -> 13 | it 'formats a table with jobs' -> 14 | eq do 15 | strip-color format-jobs-table JOBS 16 | 17 | """ 18 | ┌───┬───────┬──────────┐ 19 | │ # │ job │ activity │ 20 | ├───┼───────┼──────────┤ 21 | │ 1 │ foo-1 │ never │ 22 | └───┴───────┴──────────┘ 23 | """ 24 | 25 | describe 'format-row-obj' (,) -> 26 | describe 'build number' (,) -> 27 | it 'exists' -> 28 | eq 1, prop \number, format-row-obj number: 1 29 | 30 | it 'formatted as N/A if not defined' -> 31 | eq 'N/A', prop \number, format-row-obj number: undefined 32 | 33 | describe 'name' (,) -> 34 | describe 'without job building' (,) -> 35 | it 'shows simply job name if no other data exists' -> 36 | eq \foo, prop \jobName, format-row-obj job-name: \foo 37 | 38 | it 'is green if build is successful' -> 39 | eq (green \foo), prop \jobName, format-row-obj do 40 | job-name : \foo 41 | result : \SUCCESS 42 | building : false 43 | last-completed-build : result: \SUCCESS 44 | 45 | it 'is red if build is unsuccessful' -> 46 | eq (red \foo), prop \jobName, format-row-obj do 47 | job-name : \foo 48 | result : \FAILURE 49 | building : false 50 | last-completed-build : result: \SUCCESS 51 | 52 | describe 'with job building' (,) -> 53 | it 'shows the name with color of the previous build with bold' -> 54 | eq (green.bold \foo), prop \jobName, format-row-obj do 55 | job-name : \foo 56 | result : null 57 | building : true 58 | last-completed-build : result: \SUCCESS 59 | 60 | it 'shows the name without color if there is no previous build' -> 61 | eq \foo, prop \jobName, format-row-obj do 62 | job-name : \foo 63 | result : null 64 | building : true 65 | 66 | clock = null 67 | describe 'activity' (,) -> 68 | before -> 69 | clock := sinon.use-fake-timers Date.now! 70 | 71 | after -> 72 | clock.restore! 73 | 74 | describe 'with no data for job' (,) -> 75 | it 'shows "never"' -> 76 | eq \never, prop \activity, format-row-obj job-name: \foo 77 | 78 | describe 'without job building' (,) -> 79 | base-data = 80 | building : false 81 | timestamp : Date.now! - 120000 82 | estimatedDuration : 1 # unimportant values 83 | duration : 1 # but have to exist in job 84 | 85 | get-activity = (prop \activity) . format-row-obj . merge base-data 86 | 87 | it 'is time ago str' -> 88 | eq '~1m ago', strip-color get-activity do 89 | timestamp: Date.now! - 1000 * 60 * 2m 90 | 91 | it 'is bold if last build < 10min' -> 92 | eq (bold '~4m ago'), get-activity do 93 | timestamp: Date.now! - 1000 * 60 * 5m 94 | 95 | it 'is dimmed if last build > 1h' -> 96 | eq (dim '~1h ago'), get-activity do 97 | timestamp: Date.now! - 1000 * 60 * 60 * 2h 98 | 99 | it 'is normal color if 10min < last build < 1h' -> 100 | eq '~29m ago', get-activity do 101 | timestamp: Date.now! - 1000 * 60 * 30m 102 | 103 | describe 'with job building' (,) -> 104 | base-data = 105 | building : true 106 | duration : 0 107 | timestamp : Date.now! - 20000 108 | estimated-duration : 10000 109 | 110 | get-activity = (prop \activity) . format-row-obj . merge base-data 111 | 112 | it 'is progress bar' -> 113 | eq (inverse 'buildin') + 'g (50%)', get-activity do 114 | timestamp: Date.now! - 5000 115 | 116 | it 'shows percentage above 100%' -> 117 | eq 'building (150%)', strip-color get-activity do 118 | timestamp: Date.now! - 15000 119 | -------------------------------------------------------------------------------- /test/list-jobs.ls: -------------------------------------------------------------------------------- 1 | {nock, proxyquire, async, qs} = require './test-util' 2 | {always} = require \ramda 3 | 4 | list-jobs = proxyquire '../src/api/list-jobs', 5 | '../utils': { '@global': true, format-url: fake-format-url } 6 | 7 | JSON_DATA = require './data/list-jobs.json' 8 | 9 | _nock = -> 10 | nock JENKINS_URL 11 | .get '/api/json?' + 12 | qs tree: 'jobs[name,lastBuild[building,timestamp,estimatedDuration,duration,result,number],lastCompletedBuild[result]]' 13 | 14 | describe 'list-jobs' (,) -> 15 | after-each -> nock.clean-all! 16 | 17 | it 'transforms data into flat list of objects' async ->* 18 | _nock!.reply 200, JSON_DATA 19 | jobs = yield list-jobs! 20 | 21 | deep-eq jobs, [ 22 | * job-name : \foo-1 23 | building : false 24 | duration : 62 25 | estimated-duration : 49 26 | number : 133 27 | result : \SUCCESS 28 | timestamp : 1344503360000 29 | last-completed-build : result: \SUCCESS 30 | 31 | * job-name : \foo-2 32 | building : false 33 | duration : 1168836 34 | estimated-duration : 1154187 35 | number : 139 36 | result : \SUCCESS 37 | timestamp : 1344503365000 38 | last-completed-build : result: \FAILURE 39 | ] 40 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --timeout 20000 2 | --compilers ls:LiveScript 3 | --require ./test/_globals.ls 4 | --recursive 5 | -------------------------------------------------------------------------------- /test/test-util.ls: -------------------------------------------------------------------------------- 1 | {split, map, join, replace, gte} = require \ramda 2 | 3 | rtrim = replace /\s*$/g, '' 4 | lines = join '\n' 5 | unlines = split '\n' 6 | strip-trailing = lines . (map rtrim) . unlines 7 | 8 | module.exports = 9 | sinon : require \sinon 10 | nock : require \nock 11 | proxyquire : require \proxyquire 12 | async : require \bluebird .coroutine 13 | qs : require \querystring .stringify 14 | util : require \util 15 | Maybe : require \data.maybe 16 | Promise : require \bluebird 17 | 18 | module.exports <<< {strip-trailing} 19 | --------------------------------------------------------------------------------