[AzureDevOpsBuild] Support badge on a specific stage or job (#4583)
* Support Azure DevOps badge on a specific stage or job * Add samples * Fix tests * Restart CI * Changes per @PyvesB review Co-authored-by: Pierre-Yves B. <PyvesDev@gmail.com>
This commit is contained in:
committed by
Pierre-Yves B
parent
62fa0d2177
commit
201c282605
@@ -1,9 +1,15 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('@hapi/joi')
|
||||
const { renderBuildStatusBadge } = require('../build-status')
|
||||
const { keywords, fetch } = require('./azure-devops-helpers')
|
||||
const { BaseSvgScrapingService, NotFound } = require('..')
|
||||
|
||||
const queryParamSchema = Joi.object({
|
||||
stage: Joi.string(),
|
||||
job: Joi.string(),
|
||||
})
|
||||
|
||||
const documentation = `
|
||||
<p>
|
||||
A badge requires three pieces of information: <code>ORGANIZATION</code>,
|
||||
@@ -36,6 +42,7 @@ module.exports = class AzureDevOpsBuild extends BaseSvgScrapingService {
|
||||
return {
|
||||
base: 'azure-devops/build',
|
||||
pattern: ':organization/:projectId/:definitionId/:branch*',
|
||||
queryParamSchema,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,14 +73,50 @@ module.exports = class AzureDevOpsBuild extends BaseSvgScrapingService {
|
||||
keywords,
|
||||
documentation,
|
||||
},
|
||||
{
|
||||
title: 'Azure DevOps builds (stage)',
|
||||
namedParams: {
|
||||
organization: 'totodem',
|
||||
projectId: '8cf3ec0e-d0c2-4fcd-8206-ad204f254a96',
|
||||
definitionId: '5',
|
||||
},
|
||||
queryParams: {
|
||||
stage: 'Successful Stage',
|
||||
},
|
||||
staticPreview: renderBuildStatusBadge({ status: 'succeeded' }),
|
||||
keywords,
|
||||
documentation,
|
||||
},
|
||||
{
|
||||
title: 'Azure DevOps builds (job)',
|
||||
namedParams: {
|
||||
organization: 'totodem',
|
||||
projectId: '8cf3ec0e-d0c2-4fcd-8206-ad204f254a96',
|
||||
definitionId: '5',
|
||||
},
|
||||
queryParams: {
|
||||
stage: 'Successful Stage',
|
||||
job: 'Successful Job',
|
||||
},
|
||||
staticPreview: renderBuildStatusBadge({ status: 'succeeded' }),
|
||||
keywords,
|
||||
documentation,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
async handle({ organization, projectId, definitionId, branch }) {
|
||||
async handle(
|
||||
{ organization, projectId, definitionId, branch },
|
||||
{ stage, job }
|
||||
) {
|
||||
// Microsoft documentation: https://docs.microsoft.com/en-us/rest/api/vsts/build/status/get
|
||||
const { status } = await fetch(this, {
|
||||
url: `https://dev.azure.com/${organization}/${projectId}/_apis/build/status/${definitionId}`,
|
||||
qs: { branchName: branch },
|
||||
qs: {
|
||||
branchName: branch,
|
||||
stageName: stage,
|
||||
jobName: job,
|
||||
},
|
||||
errorMessages: {
|
||||
404: 'user or project not found',
|
||||
},
|
||||
|
||||
@@ -20,6 +20,22 @@ t.create('named branch')
|
||||
message: isBuildStatus,
|
||||
})
|
||||
|
||||
t.create('stage badge')
|
||||
.get('/totodem/Shields.io/5.json?stage=Successful%20Stage')
|
||||
.expectBadge({
|
||||
label: 'build',
|
||||
message: isBuildStatus,
|
||||
})
|
||||
|
||||
t.create('job badge')
|
||||
.get(
|
||||
'/totodem/Shields.io/5.json?stage=Successful%20Stage&job=Successful%20Job'
|
||||
)
|
||||
.expectBadge({
|
||||
label: 'build',
|
||||
message: isBuildStatus,
|
||||
})
|
||||
|
||||
t.create('never built definition')
|
||||
.get('/swellaby/opensource/112.json')
|
||||
.expectBadge({ label: 'build', message: 'never built' })
|
||||
|
||||
Reference in New Issue
Block a user