'use strict' const { renderBuildStatusBadge } = require('../build-status') const { keywords, fetch } = require('./azure-devops-helpers') const { BaseSvgScrapingService } = require('..') const documentation = `

To obtain your own badge, you need to get 4 pieces of information: ORGANIZATION, PROJECT_ID, DEFINITION_ID and ENVIRONMENT_ID.

First, you need to enable badges for each required environments in the options of your release definition. Once you have save the change, look at badge url:

ORGANIZATION is after the dev.azure.com part, PROJECT_ID is after the badge part, DEFINITION_ID and ENVIRONMENT_ID are right after that.

Your badge will then have the form: https://img.shields.io/vso/release/ORGANIZATION/PROJECT_ID/DEFINITION_ID/ENVIRONMENT_ID.svg.

` module.exports = class AzureDevOpsRelease extends BaseSvgScrapingService { static get category() { return 'build' } static get route() { return { base: 'azure-devops/release', pattern: ':organization/:projectId/:definitionId/:environmentId', } } static get examples() { return [ { title: 'Azure DevOps releases', namedParams: { organization: 'totodem', projectId: '8cf3ec0e-d0c2-4fcd-8206-ad204f254a96', definitionId: '1', environmentId: '1', }, staticPreview: renderBuildStatusBadge({ status: 'succeeded' }), keywords, documentation, }, ] } static get defaultBadgeData() { return { label: 'deployment', } } async handle({ organization, projectId, definitionId, environmentId }) { // Microsoft documentation: ? const props = await fetch(this, { url: `https://vsrm.dev.azure.com/${organization}/_apis/public/Release/badge/${projectId}/${definitionId}/${environmentId}`, errorMessages: { 400: 'project not found', 404: 'user or environment not found', 500: 'inaccessible or definition not found', }, }) return renderBuildStatusBadge(props) } }