forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-lerna-json.service.js
More file actions
61 lines (54 loc) · 1.62 KB
/
Copy pathgithub-lerna-json.service.js
File metadata and controls
61 lines (54 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict'
const Joi = require('joi')
const { renderVersionBadge } = require('../version')
const { semver } = require('../validators')
const { ConditionalGithubAuthV3Service } = require('./github-auth-service')
const { fetchJsonFromRepo } = require('./github-common-fetch')
const { documentation } = require('./github-helpers')
const versionSchema = Joi.object({
version: Joi.alternatives().try(semver, Joi.equal('independent').required()),
}).required()
module.exports = class GithubLernaJson extends ConditionalGithubAuthV3Service {
static category = 'version'
static route = {
base: 'github/lerna-json/v',
pattern: ':user/:repo/:branch*',
}
static examples = [
{
title: 'Github lerna version',
pattern: ':user/:repo',
namedParams: { user: 'babel', repo: 'babel' },
staticPreview: this.render({ version: '7.6.4' }),
documentation,
},
{
title: 'Github lerna version (branch)',
pattern: ':user/:repo/:branch',
namedParams: { user: 'jneander', repo: 'jneander', branch: 'colors' },
staticPreview: this.render({
version: 'independent',
branch: 'colors',
}),
documentation,
},
]
static defaultBadgeData = { label: 'lerna' }
static render({ version, branch }) {
return renderVersionBadge({
version,
tag: branch,
defaultLabel: 'lerna',
})
}
async handle({ user, repo, branch }) {
const { version } = await fetchJsonFromRepo(this, {
schema: versionSchema,
user,
repo,
branch,
filename: 'lerna.json',
})
return this.constructor.render({ version, branch })
}
}