Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Commit

Permalink
Non strict SSL, debug.
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Jul 29, 2014
1 parent 0623a48 commit abc1f0a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ npm install jenkins-badge
-V, --version output the version number
-u, --url <url> Jenkins url (http://user@password:url:port) <url>
-p, --port [port] Port (default 2323)
--no-strict Use non-strict SSL
```

Then you can include this type of markdown in your page:
Expand Down
25 changes: 20 additions & 5 deletions bin/jenkins-badge
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var express = require('express');
var async = require('async');
var program = require('commander');
var pkg = require('../package.json');
var debug = require('debug')('jenkins-badge');

/**
* Parse argv.
Expand All @@ -15,6 +16,7 @@ program
.version(pkg.version)
.option('-u, --url <url>', 'Jenkins url (http://user@password:url:port) <url>')
.option('-p, --port [port]', 'Port (default 2323)', 2323)
.option('--no-strict', 'Use non-strict SSL')
.parse(process.argv);

if (! program.url) program.help();
Expand All @@ -28,9 +30,14 @@ if (! program.url) program.help();
*/

function queryLastBuild(name, branch, cb) {
var url = program.url + '/job/' + name + '/lastBuild/git/api/json';

debug('GET %s', url);

request.get({
url: program.url + '/job/' + name + '/lastBuild/git/api/json',
json: true
url: url,
json: true,
strictSSL: program.strict
}, function (err, res) {
if (err) return cb(err);
cb(null, _.find(res.body.buildsByBranchName, function (value, name) {
Expand All @@ -48,9 +55,14 @@ function queryLastBuild(name, branch, cb) {
*/

function queryBuild(name, number, cb) {
var url = program.url + '/job/' + name + '/' + number + '/api/json';

debug('GET %s', url);

request.get({
url: program.url + '/job/' + name + '/' + number + '/api/json',
json: true
url: url,
json: true,
strictSSL: program.strict
}, function (err, res) {
if (err) return cb(err);
cb(null, res.body);
Expand Down Expand Up @@ -89,7 +101,10 @@ var app = express();

app.get('/:name', function (req, res) {
getBuild(req.params.name, req.query.branch || 'master', function (err, build) {
if (err) return res.redirect('http://img.shields.io/badge/jenkins-error-lightgrey.svg');
if (err) {
debug('ERROR', err);
return res.redirect('http://img.shields.io/badge/jenkins-error-lightgrey.svg');
}
if (! build) return res.redirect('http://img.shields.io/badge/jenkins-unknown-lightgrey.svg');
var status = build.result === 'SUCCESS' ? 'passing' : 'failing';
var color = build.result === 'SUCCESS' ? 'brightgreen' : 'red';
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dependencies": {
"async": "^0.9.0",
"commander": "^2.2.0",
"debug": "^1.0.4",
"express": "^4.5.1",
"lodash": "^2.4.1",
"request": "^2.37.0"
Expand Down

0 comments on commit abc1f0a

Please sign in to comment.