[github] Commit merge status badge (#1709)

* Basic version of commit-status badge added

* Support for case with no common ancestor

* Handle unknown branch

* Service tests with error responses

* Handle unexpected 404 responses from github

* Branch is a base

* Tests reordered

* Using not the newest commit in tests

* Test for checked commit identical with the newest commit in branch

* Code refactoring

* Example for Github commit merge status
This commit is contained in:
Marcin Mielnicki
2018-05-30 18:51:52 +02:00
committed by GitHub
parent 7c7c9f5f04
commit 9d90bd1f95
3 changed files with 158 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ const colorscheme = require('../../lib/colorscheme.json');
const {licenseToColor} = require('../../lib/licenses');
const {makeColor} = require('../../lib/badge-data');
const mapValues = require('lodash.mapvalues');
const { invalidJSON } = require('../response-fixtures');
const t = new ServiceTester({ id: 'github', title: 'Github' });
module.exports = t;
@@ -511,3 +512,108 @@ t.create('repository size')
name: 'repo size',
value: isFileSize,
}));
// Commit status
t.create('commit status - commit in branch')
.get('/commit-status/badges/shields/master/5d4ab86b1b5ddfb3c4a70a70bd19932c52603b8c.json?style=_shields_test')
.expectJSON({
name: 'commit status',
value: 'in master',
colorB: colorsB.brightgreen
});
t.create('commit status - checked commit is identical with the newest commit in branch')
.get('/commit-status/badges/shields/master/5d4ab86b1b5ddfb3c4a70a70bd19932c52603b8c.json?style=_shields_test')
.intercept(nock => nock('https://api.github.com')
.get('/repos/badges/shields/compare/master...5d4ab86b1b5ddfb3c4a70a70bd19932c52603b8c')
.reply(200, { status: 'identical' }))
.expectJSON({
name: 'commit status',
value: 'in master',
colorB: colorsB.brightgreen
});
t.create('commit status - commit not in branch')
.get('/commit-status/badges/shields/master/960c5bf72d7d1539fcd453343eed3f8617427a41.json?style=_shields_test')
.expectJSON({
name: 'commit status',
value: 'commit or branch not found',
colorB: colorsB.lightgrey
});
t.create('commit status - unknown commit id')
.get('/commit-status/atom/atom/v1.27.1/7dfb45eb61a48a4ce18a0dd2e31f944ed4467ae3.json?style=_shields_test')
.expectJSON({
name: 'commit status',
value: 'not in v1.27.1',
colorB: colorsB.yellow
});
t.create('commit status - unknown branch')
.get('/commit-status/badges/shields/this-branch-does-not-exist/b551a3a8daf1c48dba32a3eab1edf99b10c28863.json?style=_shields_test')
.expectJSON({
name: 'commit status',
value: 'commit or branch not found',
colorB: colorsB.lightgrey
});
t.create('commit status - no common ancestor between commit and branch')
.get('/commit-status/badges/shields/master/b551a3a8daf1c48dba32a3eab1edf99b10c28863.json?style=_shields_test')
.expectJSON({
name: 'commit status',
value: 'no common ancestor',
colorB: colorsB.lightgrey
});
t.create('commit status - invalid JSON')
.get('/commit-status/badges/shields/master/5d4ab86b1b5ddfb3c4a70a70bd19932c52603b8c.json?style=_shields_test')
.intercept(nock => nock('https://api.github.com')
.get('/repos/badges/shields/compare/master...5d4ab86b1b5ddfb3c4a70a70bd19932c52603b8c')
.reply(invalidJSON))
.expectJSON({
name: 'commit status',
value: 'invalid',
colorB: colorsB.lightgrey
});
t.create('commit status - network error')
.get('/commit-status/badges/shields/master/5d4ab86b1b5ddfb3c4a70a70bd19932c52603b8c.json?style=_shields_test')
.networkOff()
.expectJSON({
name: 'commit status',
value: 'inaccessible',
colorB: colorsB.red
});
t.create('commit status - github server error')
.get('/commit-status/badges/shields/master/5d4ab86b1b5ddfb3c4a70a70bd19932c52603b8c.json?style=_shields_test')
.intercept(nock => nock('https://api.github.com')
.get('/repos/badges/shields/compare/master...5d4ab86b1b5ddfb3c4a70a70bd19932c52603b8c')
.reply(500))
.expectJSON({
name: 'commit status',
value: 'invalid',
colorB: colorsB.lightgrey
});
t.create('commit status - 404 with empty JSON form github')
.get('/commit-status/badges/shields/master/5d4ab86b1b5ddfb3c4a70a70bd19932c52603b8c.json?style=_shields_test')
.intercept(nock => nock('https://api.github.com')
.get('/repos/badges/shields/compare/master...5d4ab86b1b5ddfb3c4a70a70bd19932c52603b8c')
.reply(404, {}))
.expectJSON({
name: 'commit status',
value: 'invalid',
colorB: colorsB.lightgrey
});
t.create('commit status - 404 with invalid JSON form github')
.get('/commit-status/badges/shields/master/5d4ab86b1b5ddfb3c4a70a70bd19932c52603b8c.json?style=_shields_test')
.intercept(nock => nock('https://api.github.com')
.get('/repos/badges/shields/compare/master...5d4ab86b1b5ddfb3c4a70a70bd19932c52603b8c')
.reply(404, invalidJSON))
.expectJSON({
name: 'commit status',
value: 'invalid',
colorB: colorsB.lightgrey
});