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

Customise AppVeyor Test 'passed', 'failed', 'skipped' status #1321

Closed
wants to merge 11 commits into from
40 changes: 36 additions & 4 deletions lib/all-badge-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ const githubDoc = `
</p>
`;

const appveyorDoc = `
<p>
You may change the "passed", "failed" and "skipped" text on this badge by supplying query parameters <code>&passed=</code>, <code>&failed=</code> and <code>&skipped=</code> respectively.
<br>
There is also a <code>&compactValue</code> query parameter, when present, will default to displaying ✔, ✘ and ●, separated by a horizontal bar |.
<br>
For example, if you want to use a different terminology
<br>
<code>/appveyor/tests/NZSmartie/coap-net-iu0to.svg?passed=good&failed=bad&skipped=n/a</code>
<br>
Or, use Unicode characters:
<br>
<code>/appveyor/tests/NZSmartie/coap-net-iu0to.svg?passed=%E2%9C%94&failed=%E2%9D%8C&skipped=%E2%9D%97</code>
<br>
Or emoji:
<br>
<code>/appveyor/tests/NZSmartie/coap-net-iu0to.svg?passed=%F0%9F%8E%89&failed=%F0%9F%92%A2&skipped=%F0%9F%A4%B7</code>
</p>
`;

const jiraSprintCompletionDoc = `
<p>
To get the <code>Sprint ID</code>, go to your Backlog view in your project,
Expand Down Expand Up @@ -140,19 +160,31 @@ const allBadgeExamples = [
},
{
title: 'AppVeyor',
previewUri: '/appveyor/ci/gruntjs/grunt.svg'
previewUri: '/appveyor/ci/gruntjs/grunt.svg',
},
{
title: 'AppVeyor branch',
previewUri: '/appveyor/ci/gruntjs/grunt/master.svg'
previewUri: '/appveyor/ci/gruntjs/grunt/master.svg',
},
{
title: 'AppVeyor tests',
previewUri: '/appveyor/tests/NZSmartie/coap-net-iu0to.svg'
previewUri: '/appveyor/tests/NZSmartie/coap-net-iu0to.svg',
documentation: appveyorDoc,
},
{
title: 'AppVeyor tests branch',
previewUri: '/appveyor/tests/NZSmartie/coap-net-iu0to/master.svg'
previewUri: '/appveyor/tests/NZSmartie/coap-net-iu0to/feature/blockwise.svg',
documentation: appveyorDoc,
},
{
title: 'AppVeyor tests with custom labels',
previewUri: '/appveyor/tests/NZSmartie/coap-net-iu0to.svg?passed=good&failed=bad&skipped=n/a',
documentation: appveyorDoc,
},
{
title: 'AppVeyor tests (compact)',
previewUri: '/appveyor/tests/NZSmartie/coap-net-iu0to.svg?compactValue',
documentation: appveyorDoc,
},
{
title: 'Codeship',
Expand Down
16 changes: 11 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,16 @@ cache(function(data, match, sendBadge, request) {

// AppVeyor test status integration.
camp.route(/^\/appveyor\/tests\/([^/]+\/[^/]+)(?:\/(.+))?\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
cache({
queryParams: ['passed', 'failed', 'skipped', 'compactValue'],
handler: function(data, match, sendBadge, request) {
var repo = match[1]; // eg, `gruntjs/grunt`.
var branch = match[2];
var format = match[3];
var compact = data.compactValue !== undefined;
var passed = data.passed || (compact ? '✔' : 'passed');
var failed = data.failed || (compact ? '✘' : 'failed');
var skipped = data.skipped || (compact ? '●' : 'skipped');
var apiUrl = 'https://ci.appveyor.com/api/projects/' + repo;
if (branch != null) {
apiUrl += '/branch/' + branch;
Expand Down Expand Up @@ -854,19 +860,19 @@ cache(function(data, match, sendBadge, request) {
badgeData.colorscheme = 'orange';
}

badgeData.text[1] = testsPassed + ' passed';
badgeData.text[1] = compact ? (passed + ' ' + testsPassed) : (testsPassed + ' ' + passed);
if (testsFailed > 0)
badgeData.text[1] += ', ' + testsFailed + ' failed';
badgeData.text[1] += compact ? (' | ' + failed + ' ' + testsFailed) : (', ' + testsFailed + ' ' + failed);
if (testsSkipped > 0)
badgeData.text[1] += ', ' + testsSkipped + ' skipped';
badgeData.text[1] += compact ? (' | ' + skipped + ' ' + testsSkipped) : (', ' + testsSkipped + ' ' + skipped);

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

// Old url for CodeBetter TeamCity instance.
camp.route(/^\/teamcity\/codebetter\/(.*)\.(svg|png|gif|jpg|json)$/,
Expand Down
19 changes: 19 additions & 0 deletions service-tests/appveyor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const ServiceTester = require('./runner/service-tester');
const isAppveyorBuildState = Joi.equal('failing', 'passing', 'running', 'queued');
const isAppveyorTestTotals =
Joi.string().regex(/^(?:[0-9]+ (?:passed|skipped|failed)(?:, )?)+$/);
const isCustomAppveyorTestTotals =
Joi.string().regex(/^(?:[0-9]* ?(?:good|bad|n\/a) ?[0-9]*(?:,? )?)+$/);
const isEmojiAppveyorTestTotals =
Joi.string().regex(/^(?:[0-9]* ?(?:✔|✘|●) ?[0-9]*(?:, | \| )?)+$/);

const t = new ServiceTester({ id: 'appveyor', title: 'AppVeyor' });
module.exports = t;
Expand Down Expand Up @@ -35,6 +39,21 @@ t.create('tests status on master branch')
.get('/tests/NZSmartie/coap-net-iu0to/master.json')
.expectJSONTypes(Joi.object().keys({ name: 'tests', value: isAppveyorTestTotals }));

// Test AppVeyor tests status badge with custom label
t.create('tests status with custom labels')
.get('/tests/NZSmartie/coap-net-iu0to.json?passed=good&failed=bad&skipped=n/a')
.expectJSONTypes(Joi.object().keys({ name: 'tests', value: isCustomAppveyorTestTotals }));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we leave off passed, failed, and skipped and just support compact? While translation could be a use case it is not something we support right now, and if we did, we'd let the user specify a language rather than individual strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be willing to let me keep it so that I may use Emoji for the less-serious/more-fun projects? 😛


// Test AppVeyor tests status badge with emoji
t.create('tests status with emoji labels')
.get('/tests/NZSmartie/coap-net-iu0to.json?passed=%E2%9C%94&failed=%E2%9C%98&skipped=%E2%97%8F')
.expectJSONTypes(Joi.object().keys({ name: 'tests', value: isEmojiAppveyorTestTotals }));

// Test AppVeyor tests status badge with compact value
t.create('tests status with compact value')
.get('/tests/NZSmartie/coap-net-iu0to.json?compactValue')
.expectJSONTypes(Joi.object().keys({ name: 'tests', value: isEmojiAppveyorTestTotals }));

// Test AppVeyor tests status badge for a non-existing project
t.create('tests 404')
.get('/tests/somerandomproject/thatdoesntexits.json')
Expand Down