-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
codeship.service.js
86 lines (75 loc) · 2.06 KB
/
codeship.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
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
82
83
84
85
86
'use strict'
const Joi = require('@hapi/joi')
const { isBuildStatus, renderBuildStatusBadge } = require('../build-status')
const { BaseSvgScrapingService } = require('..')
const schema = Joi.object({
message: Joi.alternatives()
.try(
isBuildStatus,
Joi.equal('project not found', 'branch not found', 'ignored', 'blocked')
)
.required(),
}).required()
const pendingStatus = 'pending'
const notBuiltStatus = 'not built'
const statusMap = {
testing: pendingStatus,
waiting: pendingStatus,
initiated: pendingStatus,
stopped: notBuiltStatus,
ignored: notBuiltStatus,
blocked: notBuiltStatus,
infrastructure_failure: 'failed',
}
module.exports = class Codeship extends BaseSvgScrapingService {
static get category() {
return 'build'
}
static get route() {
return {
base: 'codeship',
pattern: ':projectId/:branch*',
}
}
static get examples() {
return [
{
title: 'Codeship',
pattern: ':projectId',
namedParams: {
projectId: 'd6c1ddd0-16a3-0132-5f85-2e35c05e22b1',
},
staticPreview: renderBuildStatusBadge({ status: 'passing' }),
},
{
title: 'Codeship (branch)',
pattern: ':projectId/:branch',
namedParams: {
projectId: '0bdb0440-3af5-0133-00ea-0ebda3a33bf6',
branch: 'master',
},
staticPreview: renderBuildStatusBadge({ status: 'passing' }),
},
]
}
static get defaultBadgeData() {
return { label: 'build' }
}
static render({ status }) {
status = statusMap[status] || status
return renderBuildStatusBadge({ status })
}
async fetch({ projectId, branch }) {
const url = `https://app.codeship.com/projects/${projectId}/status`
return this._requestSvg({
schema,
url,
options: { qs: { branch } },
valueMatcher: /<g id="status_2">(?:[.\s\S]*)\/><\/g><g id="([\w\s]*)"/,
})
}
async handle({ projectId, branch }) {
const { message: status } = await this.fetch({ projectId, branch })
return this.constructor.render({ status })
}
}