Skip to content

Commit

Permalink
AppVeyor support.
Browse files Browse the repository at this point in the history
Part of issue #174.
  • Loading branch information
espadrine committed Jun 19, 2014
1 parent be872db commit e6a3fdc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 24 deletions.
77 changes: 53 additions & 24 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,40 +218,27 @@ cache(function(data, match, sendBadge) {
});
}));

// TeamCity CodeBetter code coverage
camp.route(/^\/teamcity\/coverage\/(.*)\.(svg|png|gif|jpg)$/,
// AppVeyor CI integration.
camp.route(/^\/appveyor\/ci\/(.*)\.(svg|png|gif|jpg)$/,
cache(function(data, match, sendBadge) {
var buildType = match[1]; // eg, `bt428`.
var repo = match[1]; // eg, `gruntjs/grunt`.
var format = match[2];
var apiUrl = 'http://teamcity.codebetter.com/app/rest/builds/buildType:(id:' + buildType + ')/statistics?guest=1';
var badgeData = getBadgeData('coverage', data);
var apiUrl = 'https://ci.appveyor.com/api/projects/' + repo;
var badgeData = getBadgeData('build', data);
request(apiUrl, { headers: { 'Accept': 'application/json' } }, function(err, res, buffer) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
}
try {
var data = JSON.parse(buffer);
var covered;
var total;

data.property.forEach(function(property) {
if (property.name === 'CodeCoverageAbsSCovered') {
covered = property.value;
} else if (property.name === 'CodeCoverageAbsSTotal') {
total = property.value;
}
})

if (covered === undefined || total === undefined) {
badgeData.text[1] = 'malformed';
sendBadge(format, badgeData);
return;
var status = data.build.status;
badgeData.text[1] = status;
if (status === 'success') {
badgeData.colorscheme = 'brightgreen';
} else {
badgeData.colorscheme = 'red';
}

var percentage = covered / total * 100;
badgeData.text[1] = percentage.toFixed(0) + '%';
badgeData.colorscheme = coveragePercentageColor(percentage);
sendBadge(format, badgeData);
} catch(e) {
badgeData.text[1] = 'invalid';
Expand Down Expand Up @@ -289,6 +276,48 @@ cache(function(data, match, sendBadge) {
});
}));

// TeamCity CodeBetter code coverage
camp.route(/^\/teamcity\/coverage\/(.*)\.(svg|png|gif|jpg)$/,
cache(function(data, match, sendBadge) {
var buildType = match[1]; // eg, `bt428`.
var format = match[2];
var apiUrl = 'http://teamcity.codebetter.com/app/rest/builds/buildType:(id:' + buildType + ')/statistics?guest=1';
var badgeData = getBadgeData('coverage', data);
request(apiUrl, { headers: { 'Accept': 'application/json' } }, function(err, res, buffer) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
}
try {
var data = JSON.parse(buffer);
var covered;
var total;

data.property.forEach(function(property) {
if (property.name === 'CodeCoverageAbsSCovered') {
covered = property.value;
} else if (property.name === 'CodeCoverageAbsSTotal') {
total = property.value;
}
})

if (covered === undefined || total === undefined) {
badgeData.text[1] = 'malformed';
sendBadge(format, badgeData);
return;
}

var percentage = covered / total * 100;
badgeData.text[1] = percentage.toFixed(0) + '%';
badgeData.colorscheme = coveragePercentageColor(percentage);
sendBadge(format, badgeData);
} catch(e) {
badgeData.text[1] = 'invalid';
sendBadge(format, badgeData);
}
});
}));

// Gittip integration.
camp.route(/^\/gittip\/(.*)\.(svg|png|gif|jpg)$/,
cache(function(data, match, sendBadge) {
Expand Down
4 changes: 4 additions & 0 deletions try.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ <h3> Build </h3>
<td><img src='/teamcity/codebetter/bt428.svg' alt=''/></td>
<td><code>http://img.shields.io/teamcity/codebetter/bt428.svg</code></td>
</tr>
<tr><th> AppVeyor: </th>
<td><img src='/appveyor/ci/gruntjs/grunt.svg' alt=''/></td>
<td><code>http://img.shields.io/appveyor/ci/gruntjs/grunt.svg</code></td>
</tr>
<tr><th> Coveralls: </th>
<td><img src='/coveralls/jekyll/jekyll.svg' alt=''/></td>
<td><code>http://img.shields.io/coveralls/jekyll/jekyll.svg</code></td>
Expand Down

0 comments on commit e6a3fdc

Please sign in to comment.