From 003c24e2c1e0384eb1eba65946412b7c1c930f2d Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Fri, 23 Nov 2018 15:49:42 +0800 Subject: [PATCH] live-fns: add Azure Pipelines (close #200) (#203) * Add Azure Pipelines (close #200) * Minor tweak --- libs/examples-live.js | 4 ++++ libs/index.md | 4 ++++ libs/live-fns/_index.js | 1 + libs/live-fns/azure-pipelines.js | 29 +++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 libs/live-fns/azure-pipelines.js diff --git a/libs/examples-live.js b/libs/examples-live.js index 7177998..8e4b14d 100644 --- a/libs/examples-live.js +++ b/libs/examples-live.js @@ -217,6 +217,10 @@ module.exports = { ['rank', '/jsdelivr/rank/npm/lodash'], ['version', '/jsdelivr/v/npm/lodash'] ], + 'azure pipelines': [ + ['build', '/azure-pipelines/yarnpkg/yarn/Yarn Acceptance Tests'], + ['build (branch)', '/azure-pipelines/yarnpkg/yarn/Yarn Acceptance Tests/azure-pipelines'] + ], /* utilities */ 'opencollective': [ ['backers', '/opencollective/backers/webpack'], diff --git a/libs/index.md b/libs/index.md index 0d7f1ef..e98d5f4 100644 --- a/libs/index.md +++ b/libs/index.md @@ -282,6 +282,10 @@ Advanced usage (for badge makers): ['rank', '/jsdelivr/rank/npm/lodash'], ['version', '/jsdelivr/v/npm/lodash'], ], + 'azure pipelines': [ + ['build', '/azure-pipelines/yarnpkg/yarn/Yarn Acceptance Tests'], + ['build (branch)', '/azure-pipelines/yarnpkg/yarn/Yarn Acceptance Tests/azure-pipelines'] + ], /* utilities */ 'opencollective': [ ['backers', '/opencollective/backers/webpack'], diff --git a/libs/live-fns/_index.js b/libs/live-fns/_index.js index f6b9451..89f94b2 100644 --- a/libs/live-fns/_index.js +++ b/libs/live-fns/_index.js @@ -3,6 +3,7 @@ module.exports = { amo: require('./amo.js'), apm: require('./apm.js'), appveyor: require('./appveyor.js'), + 'azure-pipelines': require('./azure-pipelines'), badgesize: require('./badgesize.js'), bundlephobia: require('./bundlephobia.js'), 'chrome-web-store': require('./chrome-web-store.js'), diff --git a/libs/live-fns/azure-pipelines.js b/libs/live-fns/azure-pipelines.js new file mode 100644 index 0000000..410d53b --- /dev/null +++ b/libs/live-fns/azure-pipelines.js @@ -0,0 +1,29 @@ +const got = require('../got.js') +const cheerio = require('cheerio') + +module.exports = async (organization, project, definition, branch = 'master') => { + const response = await got(`https://dev.azure.com/${organization}/${project}/_apis/build/status/${definition}?branchName=${branch}`, { json: false }) + const contentType = response.headers['content-type'] + + if (!contentType.includes('image/svg+xml')) { + return { + subject: 'Azure Pipelines', + status: 'unknown', + color: 'grey' + } + } + + const $ = cheerio.load(response.body) + const status = $('g[font-family] > text:nth-child(3)').text() + const color = { + 'succeeded': 'green', + 'partially succeeded': 'yellow', + 'failed': 'red' + }[status] + + return { + subject: 'Azure Pipelines', + status, + color + } +}