Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hhvm] #1499 - update hhvm service #1508

Merged
merged 9 commits into from
Feb 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 46 additions & 24 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1295,37 +1295,59 @@ cache(function(data, match, sendBadge, request) {
}));

// HHVM integration.
camp.route(/^\/hhvm\/([^/]+\/[^/]+)(\/.+)?\.(svg|png|gif|jpg|json)$/,
camp.route(/^\/hhvm\/([^/]+\/[^/]+)(?:\/(.+))?\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
var user = match[1]; // eg, `symfony/symfony`.
var branch = match[2];// eg, `/2.4.0.0`.
var format = match[3];
var apiUrl = 'http://hhvm.h4cc.de/badge/' + user + '.json';
if (branch) {
// Remove the leading slash.
apiUrl += '?branch=' + branch.slice(1);
const user = match[1]; // eg, `symfony/symfony`.
let branch = match[2]
? omitv(match[2])
: 'dev-master';
const format = match[3];
const apiUrl = 'https://php-eye.com/api/v1/package/'+user+'.json';
let badgeData = getBadgeData('hhvm', data);
if (branch === 'master') {
branch = 'dev-master';
}
var badgeData = getBadgeData('hhvm', data);
request(apiUrl, function dealWithData(err, res, buffer) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
if (checkErrorResponse(badgeData, err, res, 'repo not found')) {
sendBadge(format, badgeData);
return;
}
try {
var data = JSON.parse(buffer);
var status = data.hhvm_status;
if (status === 'not_tested') {
badgeData.colorscheme = 'red';
badgeData.text[1] = 'not tested';
} else if (status === 'partial') {
badgeData.colorscheme = 'yellow';
badgeData.text[1] = 'partially tested';
} else if (status === 'tested') {
badgeData.colorscheme = 'brightgreen';
badgeData.text[1] = 'tested';
} else {
badgeData.text[1] = 'maybe untested';
let data = JSON.parse(buffer);
let verInfo = {};
if (!data.versions) {
throw Error('Unexpected response.');
}
badgeData.text[1] = 'branch not found';
for (let i = 0, count = data.versions.length; i < count; i++) {
verInfo = data.versions[i];
if (verInfo.name === branch) {
if (!verInfo.travis.runtime_status) {
throw Error('Unexpected response.');
}
switch (verInfo.travis.runtime_status.hhvm) {
case 3:
// tested`
badgeData.colorscheme = 'brightgreen';
badgeData.text[1] = 'tested';
break;
case 2:
// allowed failure
badgeData.colorscheme = 'yellow';
badgeData.text[1] = 'partially tested';
break;
case 1:
// not tested
badgeData.colorscheme = 'red';
badgeData.text[1] = 'not tested';
break;
case 0:
// unknown/no config file
badgeData.text[1] = 'maybe untested';
break;
}
break;
}
}
sendBadge(format, badgeData);
} catch(e) {
Expand Down
46 changes: 46 additions & 0 deletions service-tests/hhvm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

const Joi = require('joi');
const ServiceTester = require('./runner/service-tester');
const { invalidJSON } = require('./helpers/response-fixtures');

const t = new ServiceTester({ id: 'hhvm', title: 'hhvm status' });

const isAllowedStatus = Joi.string().regex(/^(tested|partially tested|not tested|maybe untested)$/);

module.exports = t;

t.create('get default branch')
.get('/symfony/symfony.json')
.expectJSONTypes(Joi.object().keys({
name: 'hhvm',
value: isAllowedStatus
}));

t.create('get specific branch')
.get('/yiisoft/yii/1.1.19.json')
.expectJSONTypes(Joi.object().keys({
name: 'hhvm',
value: isAllowedStatus
}));

t.create('invalid repo')
.get('/frodo/is-not-a-package.json')
.expectJSON({ name: 'hhvm', value: 'repo not found' });

t.create('invalid branch')
.get('/yiisoft/yii/1.1.666.json')
.expectJSON({ name: 'hhvm', value: 'branch not found' });

t.create('connection error')
.get('/symfony/symfony.json')
.networkOff()
.expectJSON({name: 'hhvm', value: 'inaccessible'});

t.create('unexpected response')
.get('/symfony/symfony.json')
.intercept(nock => nock('https://php-eye.com')
.get('/api/v1/package/symfony/symfony.json')
.reply(invalidJSON)
)
.expectJSON({name: 'hhvm', value: 'invalid'});