• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

badges / shields / 45774165149

22 Nov 2026 09:43PM UTC coverage: 79.735% (-18.4%) from 98.17%
45774165149

push

github

web-flow
[Endpoint] Support message override and position it after label in API docs (#12235)

* [Endpoint] Support message override and position it after label in API docs

* Preserve error message when a message override is provided

3371 of 3616 branches covered (93.22%)

43 of 53 new or added lines in 3 files covered. (81.13%)

9589 existing lines in 490 files now uncovered.

41514 of 52065 relevant lines covered (79.73%)

51.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.88
/services/github/github-deployments.service.js
1
import gql from 'graphql-tag'
2 ✔
2
import Joi from 'joi'
2 ✔
3
import { NotFound, pathParams } from '../index.js'
2 ✔
4
import { GithubAuthV4Service } from './github-auth-service.js'
2 ✔
5
import { documentation, transformErrors } from './github-helpers.js'
2 ✔
6

2 ✔
7
const greenStates = ['SUCCESS']
2 ✔
8
const redStates = ['ERROR', 'FAILURE']
2 ✔
9
const blueStates = ['INACTIVE']
2 ✔
10
const otherStates = ['IN_PROGRESS', 'QUEUED', 'PENDING', 'NO_STATUS', 'WAITING']
2 ✔
11

2 ✔
12
const stateToMessageMappings = {
2 ✔
13
  IN_PROGRESS: 'in progress',
2 ✔
14
  NO_STATUS: 'no status yet',
2 ✔
15
}
2 ✔
16

2 ✔
17
const allState = greenStates
2 ✔
18
  .concat(redStates)
2 ✔
19
  .concat(blueStates)
2 ✔
20
  .concat(otherStates)
2 ✔
21

2 ✔
22
const isDeploymentState = Joi.equal(...allState)
2 ✔
23

2 ✔
24
const schema = Joi.object({
2 ✔
25
  data: Joi.object({
2 ✔
26
    repository: Joi.object({
2 ✔
27
      deployments: Joi.object({
2 ✔
28
        nodes: Joi.array()
2 ✔
29
          .items(
2 ✔
30
            Joi.object({
2 ✔
31
              latestStatus: Joi.alternatives([
2 ✔
32
                Joi.object({
2 ✔
33
                  state: isDeploymentState,
2 ✔
34
                }),
2 ✔
35
                null,
2 ✔
36
              ]),
2 ✔
37
            }),
2 ✔
38
          )
2 ✔
39
          .required(),
2 ✔
40
      }).required(),
2 ✔
41
    }).required(),
2 ✔
42
  }).required(),
2 ✔
43
}).required()
2 ✔
44

2 ✔
45
export default class GithubDeployments extends GithubAuthV4Service {
2 ✔
46
  static category = 'other'
2 ✔
47
  static route = {
2 ✔
48
    base: 'github/deployments',
2 ✔
49
    pattern: ':user/:repo/:environment',
2 ✔
50
  }
2 ✔
51

2 ✔
52
  static openApi = {
2 ✔
53
    '/github/deployments/{user}/{repo}/{environment}': {
2 ✔
54
      get: {
2 ✔
55
        summary: 'GitHub deployments',
2 ✔
56
        description: documentation,
2 ✔
57
        parameters: pathParams(
2 ✔
58
          {
2 ✔
59
            name: 'user',
2 ✔
60
            example: 'badges',
2 ✔
61
          },
2 ✔
62
          {
2 ✔
63
            name: 'repo',
2 ✔
64
            example: 'shields',
2 ✔
65
          },
2 ✔
66
          {
2 ✔
67
            name: 'environment',
2 ✔
68
            example: 'shields-staging',
2 ✔
69
          },
2 ✔
70
        ),
2 ✔
71
      },
2 ✔
72
    },
2 ✔
73
  }
2 ✔
74

2 ✔
75
  static defaultBadgeData = { label: 'state' }
2 ✔
76

2 ✔
77
  static render({ state }) {
2 ✔
78
    let color
5 ✔
79
    if (greenStates.includes(state)) {
5 ✔
80
      color = 'brightgreen'
1 ✔
81
    } else if (redStates.includes(state)) {
5 ✔
82
      color = 'red'
1 ✔
83
    } else if (blueStates.includes(state)) {
4 !
84
      color = 'blue'
×
85
    }
×
86

5 ✔
87
    let message = stateToMessageMappings[state]
5 ✔
88
    if (!message) {
5 ✔
89
      message = state.toLowerCase()
3 ✔
90
    }
3 ✔
91

5 ✔
92
    return {
5 ✔
93
      message,
5 ✔
94
      color,
5 ✔
95
    }
5 ✔
96
  }
5 ✔
97

2 ✔
98
  async fetch({ user, repo, environment }) {
2 ✔
UNCOV
99
    return this._requestGraphql({
×
UNCOV
100
      query: gql`
×
UNCOV
101
        query ($user: String!, $repo: String!, $environment: String!) {
×
UNCOV
102
          repository(owner: $user, name: $repo) {
×
UNCOV
103
            deployments(last: 1, environments: [$environment]) {
×
UNCOV
104
              nodes {
×
UNCOV
105
                latestStatus {
×
UNCOV
106
                  state
×
UNCOV
107
                }
×
UNCOV
108
              }
×
UNCOV
109
            }
×
UNCOV
110
          }
×
UNCOV
111
        }
×
UNCOV
112
      `,
×
UNCOV
113
      variables: { user, repo, environment },
×
UNCOV
114
      schema,
×
UNCOV
115
      transformErrors,
×
UNCOV
116
    })
×
UNCOV
117
  }
×
118

2 ✔
119
  transform({ data }) {
2 ✔
120
    if (data.repository.deployments.nodes.length === 0) {
3 ✔
121
      throw new NotFound({ prettyMessage: 'environment not found' })
1 ✔
122
    }
1 ✔
123
    // This happens for the brief moment a deployment is created, but no
2 ✔
124
    // status is created for the deployment (yet).
2 ✔
125
    if (data.repository.deployments.nodes[0].latestStatus == null) {
3 ✔
126
      return { state: 'NO_STATUS' }
1 ✔
127
    }
1 ✔
128

1 ✔
129
    const state = data.repository.deployments.nodes[0].latestStatus.state
1 ✔
130
    return { state }
1 ✔
131
  }
3 ✔
132

2 ✔
133
  async handle({ user, repo, environment }) {
2 ✔
UNCOV
134
    const json = await this.fetch({ user, repo, environment })
×
UNCOV
135
    const { state } = this.transform({ data: json.data })
×
UNCOV
136
    return this.constructor.render({ state })
×
UNCOV
137
  }
×
138
}
2 ✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc