forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-milestone.service.js
More file actions
81 lines (72 loc) · 1.79 KB
/
Copy pathgithub-milestone.service.js
File metadata and controls
81 lines (72 loc) · 1.79 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import Joi from 'joi'
import { metric } from '../text-formatters.js'
import { GithubAuthV3Service } from './github-auth-service.js'
import { documentation, errorMessagesFor } from './github-helpers.js'
const schema = Joi.array()
.items(
Joi.object({
state: Joi.string().required(),
})
)
.required()
export default class GithubMilestone extends GithubAuthV3Service {
static category = 'issue-tracking'
static route = {
base: 'github/milestones',
pattern: ':variant(open|closed|all)/:user/:repo',
}
static examples = [
{
title: 'GitHub milestones',
namedParams: {
user: 'badges',
repo: 'shields',
variant: 'open',
},
staticPreview: {
label: 'milestones',
message: '2',
color: 'red',
},
documentation,
},
]
static defaultBadgeData = {
label: 'milestones',
color: 'informational',
}
static render({ user, repo, variant, milestones }) {
const milestoneLength = milestones.length
let color
let label = ''
switch (variant) {
case 'all':
color = 'blue'
break
case 'open':
color = 'red'
label = 'active'
break
case 'closed':
color = 'green'
label = 'completed'
break
}
return {
label: `${label} milestones`,
message: metric(milestoneLength),
color,
}
}
async fetch({ user, repo, variant }) {
return this._requestJson({
url: `/repos/${user}/${repo}/milestones?state=${variant}`,
schema,
errorMessages: errorMessagesFor(`repo not found`),
})
}
async handle({ user, repo, variant }) {
const milestones = await this.fetch({ user, repo, variant })
return this.constructor.render({ user, repo, variant, milestones })
}
}