forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 1
/
microbadger-layers.service.js
48 lines (42 loc) · 1.13 KB
/
microbadger-layers.service.js
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
'use strict'
const BaseMicrobadgerService = require('./microbadger-base')
module.exports = class MicrobadgerLayers extends BaseMicrobadgerService {
static get route() {
return {
base: 'microbadger/layers',
pattern: ':user/:repo/:tag*',
}
}
static get examples() {
return [
{
title: 'MicroBadger Layers',
pattern: ':user/:repo',
namedParams: { user: '_', repo: 'alpine' },
staticPreview: this.render({ layers: 15 }),
keywords: ['docker'],
},
{
title: 'MicroBadger Layers (tag)',
pattern: ':user/:repo/:tag',
namedParams: { user: '_', repo: 'alpine', tag: '2.7' },
staticPreview: this.render({ layers: 12 }),
keywords: ['docker'],
},
]
}
static get defaultBadgeData() {
return { label: 'layers' }
}
static render({ layers }) {
return {
message: layers,
color: 'blue',
}
}
async handle({ user, repo, tag }) {
const data = await this.fetch({ user, repo })
const image = this.constructor.getImage(data, tag)
return this.constructor.render({ layers: image.LayerCount })
}
}