Skip to content

Commit

Permalink
[bitrise] Added new build service Bitrise.io (#1227)
Browse files Browse the repository at this point in the history
Close #574.
  • Loading branch information
freezy-sk authored and paulmelnikow committed Oct 31, 2017
1 parent 37fbef5 commit ad4a8b4
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/all-badge-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ const allBadgeExamples = [
keywords: [
'documentation'
]
},
{
title: 'Bitrise',
previewUri: '/bitrise/cde737473028420d/master.svg?token=GCIdEzacE4GW32jLVrZb7A',
exampleUri: '/bitrise/APP-ID/BRANCH.svg?token=APP-STATUS-BADGE-TOKEN'
}
]
},
Expand Down
41 changes: 41 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5491,6 +5491,47 @@ cache({
},
}));

camp.route(/^\/bitrise\/([^/]+)(?:\/(.+))?\.(svg|png|gif|jpg|json)$/,
cache({
queryParams: ['token'],
handler: (data, match, sendBadge, request) => {
const appId = match[1];
const branch = match[2];
const format = match[3];
const token = data.token;
const badgeData = getBadgeData('bitrise', data);
let apiUrl = 'https://www.bitrise.io/app/' + appId + '/status.json?token=' + token;
if (typeof branch !== 'undefined') {
apiUrl += '&branch=' + branch;
}

const statusColorScheme = {
success: 'brightgreen',
error: 'red',
unknown: 'lightgrey'
};

request(apiUrl, {json: true}, function(err, res, data) {
try {
if (!res || err !== null || res.statusCode !== 200) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return;
}

badgeData.text[1] = data.status;
badgeData.colorscheme = statusColorScheme[data.status];

sendBadge(format, badgeData);
}
catch(e) {
badgeData.text[1] = 'invalid';
sendBadge(format, badgeData);
}
});
},
}));

// CircleCI build integration.
// https://circleci.com/api/v1/project/BrightFlair/PHP.Gt?circle-token=0a5143728784b263d9f0238b8d595522689b3af2&limit=1&filter=completed
camp.route(/^\/circleci\/(?:token\/(\w+))?[+/]?project\/(?:(github|bitbucket)\/)?([^/]+\/[^/]+)(?:\/(.*))?\.(svg|png|gif|jpg|json)$/,
Expand Down
53 changes: 53 additions & 0 deletions service-tests/bitrise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

const Joi = require('joi');
const ServiceTester = require('./runner/service-tester');

const t = new ServiceTester({ id: 'bitrise', title: 'Bitrise' });
module.exports = t;

t.create('deploy status')
.get('/cde737473028420d/master.json?token=GCIdEzacE4GW32jLVrZb7A')
.expectJSONTypes(Joi.object().keys({
name: 'bitrise',
value: Joi.equal(
'success',
'error',
'unknown'
)
}));

t.create('deploy status without branch')
.get('/cde737473028420d.json?token=GCIdEzacE4GW32jLVrZb7A')
.expectJSONTypes(Joi.object().keys({
name: 'bitrise',
value: Joi.equal(
'success',
'error',
'unknown'
)
}));

t.create('unknown branch')
.get('/cde737473028420d/unknown.json?token=GCIdEzacE4GW32jLVrZb7A')
.expectJSON({ name: 'bitrise', value: 'unknown' });

t.create('invalid token')
.get('/cde737473028420d/unknown.json?token=token')
.expectJSON({ name: 'bitrise', value: 'inaccessible' });

t.create('invalid App ID')
.get('/invalid/master.json?token=GCIdEzacE4GW32jLVrZb7A')
.expectJSON({ name: 'bitrise', value: 'inaccessible' });

t.create('server error')
.get('/AppID/branch.json?token=token')
.intercept(nock => nock('https://www.bitrise.io')
.get('/app/AppID/status.json?token=token&branch=branch')
.reply(500, 'Something went wrong'))
.expectJSON({ name: 'bitrise', value: 'inaccessible' });

t.create('connection error')
.get('/AppID/branch.json?token=token')
.networkOff()
.expectJSON({ name: 'bitrise', value: 'inaccessible' });

0 comments on commit ad4a8b4

Please sign in to comment.