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

[Travis] Add travis-ci.com support #1711

Merged
merged 7 commits into from
Jun 17, 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
14 changes: 12 additions & 2 deletions lib/all-badge-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,25 @@ const allBadgeExamples = [
},
examples: [
{
title: 'Travis',
title: 'Travis (.org)',
previewUri: '/travis/rust-lang/rust.svg',
exampleUri: '/travis/USER/REPO.svg'
},
{
title: 'Travis branch',
title: 'Travis (.org) branch',
previewUri: '/travis/rust-lang/rust/master.svg',
exampleUri: '/travis/USER/REPO/BRANCH.svg'
},
{
title: 'Travis (.com)',
previewUri: '/travis/com/ivandelabeldad/rackian-gateway.svg',
exampleUri: '/travis/com/USER/REPO.svg'
},
{
title: 'Travis (.com) branch',
previewUri: '/travis/com/ivandelabeldad/rackian-gateway/master.svg',
exampleUri: '/travis/com/USER/REPO/BRANCH.svg'
},
{
title: 'Wercker',
previewUri: '/wercker/ci/wercker/docs.svg'
Expand Down
28 changes: 14 additions & 14 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ cache(function(data, match, sendBadge, request) {
const format = match[3];
const options = {
method: 'GET',
uri: 'https://api.travis-ci.org/repos/' + userRepo + '/branches/' + version,
uri: `https://api.travis-ci.org/repos/${userRepo}/branches/${version}`,
};
const badgeData = getBadgeData('PHP', data);
getPhpReleases(githubAuth.request, (err, phpReleases) => {
Expand All @@ -340,7 +340,7 @@ cache(function(data, match, sendBadge, request) {
}
request(options, (err, res, buffer) => {
if (err !== null) {
log.error('Travis CI error: ' + err.stack);
log.error(`Travis CI error: ${err.stack}`);
if (res) {
log.error('' + res);
}
Expand Down Expand Up @@ -385,31 +385,32 @@ cache(function(data, match, sendBadge, request) {
});
}));

// Travis integration
camp.route(/^\/travis(-ci)?\/([^/]+\/[^/]+)(?:\/(.+))?\.(svg|png|gif|jpg|json)$/,
// Travis integration (.org and .com)
camp.route(/^\/travis(-ci)?\/(?:(com)\/)?([^/]+\/[^/]+)(?:\/(.+))?\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
var userRepo = match[2]; // eg, espadrine/sc
var branch = match[3];
var format = match[4];
var options = {
const travisDomain = match[2] || 'org'; // (com | org) org by default
const userRepo = match[3]; // eg, espadrine/sc
const branch = match[4];
const format = match[5];
const options = {
method: 'HEAD',
uri: 'https://api.travis-ci.org/' + userRepo + '.svg',
uri: `https://api.travis-ci.${travisDomain}/${userRepo}.svg`,
};
if (branch != null) {
options.uri += '?branch=' + branch;
options.uri += `?branch=${branch}`;
}
var badgeData = getBadgeData('build', data);
const badgeData = getBadgeData('build', data);
request(options, function(err, res) {
if (err != null) {
log.error('Travis error: ' + err.stack);
log.error(`Travis error: ${err.stack}`);
if (res) { log.error(''+res); }
}
if (checkErrorResponse(badgeData, err, res)) {
sendBadge(format, badgeData);
return;
}
try {
var state = res.headers['content-disposition']
const state = res.headers['content-disposition']
.match(/filename="(.+)\.svg"/)[1];
badgeData.text[1] = state;
if (state === 'passing') {
Expand All @@ -420,7 +421,6 @@ cache(function(data, match, sendBadge, request) {
badgeData.text[1] = state;
}
sendBadge(format, badgeData);

} catch(e) {
badgeData.text[1] = 'invalid';
sendBadge(format, badgeData);
Expand Down
32 changes: 32 additions & 0 deletions services/travis/travis.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,38 @@ t.create('connection error')
.networkOff()
.expectJSON({ name: 'build', value: 'inaccessible' });

// Travis (.com) CI

t.create('build status on default branch')
.get('/com/ivandelabeldad/rackian-gateway.json')
.expectJSONTypes(Joi.object().keys({
name: 'build',
value: Joi.equal('failing', 'passing', 'unknown')
}));

t.create('build status on named branch')
.get('/com/ivandelabeldad/rackian-gateway.json')
.expectJSONTypes(Joi.object().keys({
name: 'build',
value: Joi.equal('failing', 'passing', 'unknown')
}));

t.create('unknown repo')
.get('/com/this-repo/does-not-exist.json')
.expectJSON({ name: 'build', value: 'unknown' });

t.create('missing content-disposition header')
.get('/com/foo/bar.json')
.intercept(nock => nock('https://api.travis-ci.com')
.head('/foo/bar.svg')
.reply(200))
.expectJSON({ name: 'build', value: 'invalid' });

t.create('connection error')
.get('/com/foo/bar.json')
.networkOff()
.expectJSON({ name: 'build', value: 'inaccessible' });

// PHP version from .travis.yml

t.create('gets the package version of symfony')
Expand Down