Files
shields/services/netlify/netlify.service.js
Anand Chowdhary 58a5239e18 Add [Netlify] (fixed #3129) (#3953)
* 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
2019-09-06 12:21:17 -05:00

76 lines
2.0 KiB
JavaScript

'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 })
}
}