-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
github-checks-status.service.js
81 lines (73 loc) · 2.53 KB
/
github-checks-status.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
import Joi from 'joi'
import { pathParam } from '../index.js'
import { isBuildStatus, renderBuildStatusBadge } from '../build-status.js'
import { GithubAuthV3Service } from './github-auth-service.js'
import {
documentation as commonDocumentation,
httpErrorsFor,
} from './github-helpers.js'
const description = `
Displays the status of a tag, commit, or branch, as reported by the Commit Status API.
Nowadays, GitHub Actions and many third party integrations report state via the
Checks API. If this badge does not show expected values, please try out our
corresponding Check Runs badge instead. You can read more about status checks in
the [GitHub documentation](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/about-status-checks).
${commonDocumentation}
`
const schema = Joi.object({
state: isBuildStatus,
}).required()
export default class GithubChecksStatus extends GithubAuthV3Service {
static category = 'build'
static route = {
base: 'github/checks-status',
pattern: ':user/:repo/:ref',
}
static openApi = {
'/github/checks-status/{user}/{repo}/{branch}': {
get: {
summary: 'GitHub branch status',
description,
parameters: [
pathParam({ name: 'user', example: 'badges' }),
pathParam({ name: 'repo', example: 'shields' }),
pathParam({ name: 'branch', example: 'master' }),
],
},
},
'/github/checks-status/{user}/{repo}/{commit}': {
get: {
summary: 'GitHub commit status',
description,
parameters: [
pathParam({ name: 'user', example: 'badges' }),
pathParam({ name: 'repo', example: 'shields' }),
pathParam({
name: 'commit',
example: '91b108d4b7359b2f8794a4614c11cb1157dc9fff',
}),
],
},
},
'/github/checks-status/{user}/{repo}/{tag}': {
get: {
summary: 'GitHub tag status',
description,
parameters: [
pathParam({ name: 'user', example: 'badges' }),
pathParam({ name: 'repo', example: 'shields' }),
pathParam({ name: 'tag', example: '3.3.0' }),
],
},
},
}
static defaultBadgeData = { label: 'checks' }
async handle({ user, repo, ref }) {
const { state } = await this._requestJson({
url: `/repos/${user}/${repo}/commits/${ref}/status`,
httpErrors: httpErrorsFor('ref or repo not found'),
schema,
})
return renderBuildStatusBadge({ status: state })
}
}