* Add Netlify (fixed #3129) * Update services/netlify/netlify.service.js Co-Authored-By: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> * Remove pattern from return statement Co-Authored-By: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> * Add Netlify namedLogo to return statement Co-Authored-By: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> * Change label from "build" to "netlify" in test Co-Authored-By: Caleb Cartwright <calebcartwright@users.noreply.github.com> * Change label from "build" to "netlify" in test Co-Authored-By: Caleb Cartwright <calebcartwright@users.noreply.github.com> * test(netlify): Fix failing tests Co-Authored-By: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> * Fix "netlify" spelling in label Co-Authored-By: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> * Use const instead of let for result Co-Authored-By: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> * Change "project not found" to "not found" * Use unknown as fallback response Co-Authored-By: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> * Add documentation for project ID, remove commented part * Fix documentation key in example
This commit is contained in:
committed by
Caleb Cartwright
parent
926e837457
commit
58a5239e18
75
services/netlify/netlify.service.js
Normal file
75
services/netlify/netlify.service.js
Normal file
@@ -0,0 +1,75 @@
|
||||
'use strict'
|
||||
|
||||
const { renderBuildStatusBadge } = require('../build-status')
|
||||
const { BaseSvgScrapingService } = require('..')
|
||||
|
||||
const pendingStatus = 'building'
|
||||
const notBuiltStatus = 'not built'
|
||||
|
||||
const statusMap = {
|
||||
building: pendingStatus,
|
||||
waiting: pendingStatus,
|
||||
initiated: pendingStatus,
|
||||
stopped: notBuiltStatus,
|
||||
ignored: notBuiltStatus,
|
||||
blocked: notBuiltStatus,
|
||||
infrastructure_failure: 'failed',
|
||||
}
|
||||
|
||||
module.exports = class Netlify extends BaseSvgScrapingService {
|
||||
static get category() {
|
||||
return 'build'
|
||||
}
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: 'netlify',
|
||||
pattern: ':projectId',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: 'Netlify',
|
||||
namedParams: {
|
||||
projectId: 'e6d5a4e0-dee1-4261-833e-2f47f509c68f',
|
||||
},
|
||||
documentation:
|
||||
'To locate your project id, visit your project settings, scroll to "Status badges" under "General", and copy the ID between "/api/v1/badges/" and "/deploy-status" in the code sample',
|
||||
staticPreview: renderBuildStatusBadge({ status: 'passing' }),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
static get defaultBadgeData() {
|
||||
return {
|
||||
label: 'netlify',
|
||||
}
|
||||
}
|
||||
|
||||
static render({ status }) {
|
||||
status = statusMap[status] || status
|
||||
const result = renderBuildStatusBadge({ status })
|
||||
if (result.message === 'building' && !result.color) {
|
||||
result.color = 'yellow'
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
async fetch({ projectId, branch }) {
|
||||
const url = `https://api.netlify.com/api/v1/badges/${projectId}/deploy-status`
|
||||
const { buffer } = await this._request({
|
||||
url,
|
||||
})
|
||||
if (buffer.includes('#EAFAF9')) return { message: 'passing' }
|
||||
if (buffer.includes('#FFF3F4')) return { message: 'failing' }
|
||||
if (buffer.includes('#FEFAEA')) return { message: 'building' }
|
||||
return { message: 'unknown' }
|
||||
}
|
||||
|
||||
async handle({ projectId, branch }) {
|
||||
const { message: status } = await this.fetch({ projectId, branch })
|
||||
return this.constructor.render({ status })
|
||||
}
|
||||
}
|
||||
19
services/netlify/netlify.spec.js
Normal file
19
services/netlify/netlify.spec.js
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict'
|
||||
|
||||
const { test, given } = require('sazerac')
|
||||
const Netlify = require('./netlify.service')
|
||||
|
||||
const building = { message: 'building', label: undefined, color: 'yellow' }
|
||||
const notBuilt = { message: 'not built', label: undefined, color: undefined }
|
||||
|
||||
describe('Netlify', function() {
|
||||
test(Netlify.render, () => {
|
||||
given({ status: 'building' }).expect(building)
|
||||
given({ status: 'stopped' }).expect(notBuilt)
|
||||
given({ status: 'infrastructure_failure' }).expect({
|
||||
message: 'failing',
|
||||
color: 'red',
|
||||
label: undefined,
|
||||
})
|
||||
})
|
||||
})
|
||||
15
services/netlify/netlify.tester.js
Normal file
15
services/netlify/netlify.tester.js
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict'
|
||||
|
||||
const { isBuildStatus } = require('../build-status')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('netlify (valid, no branch)')
|
||||
.get('/e6d5a4e0-dee1-4261-833e-2f47f509c68f.json')
|
||||
.expectBadge({
|
||||
label: 'netlify',
|
||||
message: isBuildStatus,
|
||||
})
|
||||
|
||||
t.create('netlify (repo not found)')
|
||||
.get('/not-a-repo.json')
|
||||
.expectBadge({ label: 'netlify', message: 'not found' })
|
||||
Reference in New Issue
Block a user