• 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

75.08
/services/github/github-package-json.service.js
1
import Joi from 'joi'
2 ✔
2
import { pathParam, pathParams, queryParam } from '../index.js'
2 ✔
3
import { renderVersionBadge } from '../version.js'
2 ✔
4
import { transformAndValidate, renderDynamicBadge } from '../dynamic-common.js'
2 ✔
5
import {
2 ✔
6
  isPackageJsonWithDependencies,
2 ✔
7
  getDependencyVersion,
2 ✔
8
} from '../package-json-helpers.js'
2 ✔
9
import { semver } from '../validators.js'
2 ✔
10
import { ConditionalGithubAuthV3Service } from './github-auth-service.js'
2 ✔
11
import { fetchJsonFromRepo } from './github-common-fetch.js'
2 ✔
12
import { documentation } from './github-helpers.js'
2 ✔
13

2 ✔
14
const versionSchema = Joi.object({
2 ✔
15
  version: semver,
2 ✔
16
}).required()
2 ✔
17

2 ✔
18
const subfolderQueryParamSchema = Joi.object({
2 ✔
19
  filename: Joi.string(),
2 ✔
20
}).required()
2 ✔
21

2 ✔
22
class GithubPackageJsonVersion extends ConditionalGithubAuthV3Service {
2 ✔
23
  static category = 'version'
2 ✔
24
  static route = {
2 ✔
25
    base: 'github/package-json/v',
2 ✔
26
    pattern: ':user/:repo/:branch*',
2 ✔
27
    queryParamSchema: subfolderQueryParamSchema,
2 ✔
28
  }
2 ✔
29

2 ✔
30
  static openApi = {
2 ✔
31
    '/github/package-json/v/{user}/{repo}': {
2 ✔
32
      get: {
2 ✔
33
        summary: 'GitHub package.json version',
2 ✔
34
        description: documentation,
2 ✔
35
        parameters: [
2 ✔
36
          pathParam({ name: 'user', example: 'badges' }),
2 ✔
37
          pathParam({ name: 'repo', example: 'shields' }),
2 ✔
38
          queryParam({ name: 'filename', example: 'badge-maker/package.json' }),
2 ✔
39
        ],
2 ✔
40
      },
2 ✔
41
    },
2 ✔
42
    '/github/package-json/v/{user}/{repo}/{branch}': {
2 ✔
43
      get: {
2 ✔
44
        summary: 'GitHub package.json version (branch)',
2 ✔
45
        description: documentation,
2 ✔
46
        parameters: [
2 ✔
47
          pathParam({ name: 'user', example: 'badges' }),
2 ✔
48
          pathParam({ name: 'repo', example: 'shields' }),
2 ✔
49
          pathParam({ name: 'branch', example: 'master' }),
2 ✔
50
          queryParam({ name: 'filename', example: 'badge-maker/package.json' }),
2 ✔
51
        ],
2 ✔
52
      },
2 ✔
53
    },
2 ✔
54
  }
2 ✔
55

2 ✔
56
  static render({ version, branch }) {
2 ✔
UNCOV
57
    return renderVersionBadge({
×
UNCOV
58
      version,
×
UNCOV
59
      tag: branch,
×
UNCOV
60
      defaultLabel: 'version',
×
UNCOV
61
    })
×
UNCOV
62
  }
×
63

2 ✔
64
  async handle({ user, repo, branch }, { filename = 'package.json' }) {
2 ✔
UNCOV
65
    const { version } = await fetchJsonFromRepo(this, {
×
UNCOV
66
      schema: versionSchema,
×
UNCOV
67
      user,
×
UNCOV
68
      repo,
×
UNCOV
69
      branch,
×
UNCOV
70
      filename,
×
UNCOV
71
    })
×
UNCOV
72
    return this.constructor.render({ version, branch })
×
UNCOV
73
  }
×
74
}
2 ✔
75

2 ✔
76
const packageNameDescription =
2 ✔
77
  'This may be the name of an unscoped package like `package-name` or a [scoped package](https://docs.npmjs.com/about-scopes) like `@author/package-name`'
2 ✔
78

2 ✔
79
class GithubPackageJsonDependencyVersion extends ConditionalGithubAuthV3Service {
2 ✔
80
  static category = 'platform-support'
2 ✔
81
  static route = {
2 ✔
82
    base: 'github/package-json/dependency-version',
2 ✔
83
    pattern:
2 ✔
84
      ':user/:repo/:kind(dev|peer|optional)?/:scope(@[^/]+)?/:packageName/:branch*',
2 ✔
85
    queryParamSchema: subfolderQueryParamSchema,
2 ✔
86
  }
2 ✔
87

2 ✔
88
  static openApi = {
2 ✔
89
    '/github/package-json/dependency-version/{user}/{repo}/{packageName}': {
2 ✔
90
      get: {
2 ✔
91
        summary: 'GitHub package.json prod dependency version',
2 ✔
92
        description: documentation,
2 ✔
93
        parameters: [
2 ✔
94
          pathParam({ name: 'user', example: 'badges' }),
2 ✔
95
          pathParam({ name: 'repo', example: 'shields' }),
2 ✔
96
          pathParam({
2 ✔
97
            name: 'packageName',
2 ✔
98
            example: 'dayjs',
2 ✔
99
            description: packageNameDescription,
2 ✔
100
          }),
2 ✔
101
          queryParam({
2 ✔
102
            name: 'filename',
2 ✔
103
            example: 'badge-maker/package.json',
2 ✔
104
          }),
2 ✔
105
        ],
2 ✔
106
      },
2 ✔
107
    },
2 ✔
108
    '/github/package-json/dependency-version/{user}/{repo}/{packageName}/{branch}':
2 ✔
109
      {
2 ✔
110
        get: {
2 ✔
111
          summary: 'GitHub package.json prod dependency version (branch)',
2 ✔
112
          description: documentation,
2 ✔
113
          parameters: [
2 ✔
114
            pathParam({ name: 'user', example: 'badges' }),
2 ✔
115
            pathParam({ name: 'repo', example: 'shields' }),
2 ✔
116
            pathParam({
2 ✔
117
              name: 'packageName',
2 ✔
118
              example: 'dayjs',
2 ✔
119
              description: packageNameDescription,
2 ✔
120
            }),
2 ✔
121
            pathParam({ name: 'branch', example: 'master' }),
2 ✔
122
            queryParam({
2 ✔
123
              name: 'filename',
2 ✔
124
              example: 'badge-maker/package.json',
2 ✔
125
            }),
2 ✔
126
          ],
2 ✔
127
        },
2 ✔
128
      },
2 ✔
129
    '/github/package-json/dependency-version/{user}/{repo}/{kind}/{packageName}':
2 ✔
130
      {
2 ✔
131
        get: {
2 ✔
132
          summary: 'GitHub package.json dev/peer/optional dependency version',
2 ✔
133
          description: documentation,
2 ✔
134
          parameters: [
2 ✔
135
            pathParam({ name: 'user', example: 'gatsbyjs' }),
2 ✔
136
            pathParam({ name: 'repo', example: 'gatsby' }),
2 ✔
137
            pathParam({
2 ✔
138
              name: 'kind',
2 ✔
139
              example: 'dev',
2 ✔
140
              schema: { type: 'string', enum: this.getEnum('kind') },
2 ✔
141
            }),
2 ✔
142
            pathParam({
2 ✔
143
              name: 'packageName',
2 ✔
144
              example: 'cross-env',
2 ✔
145
              description: packageNameDescription,
2 ✔
146
            }),
2 ✔
147
            queryParam({
2 ✔
148
              name: 'filename',
2 ✔
149
              example: 'packages/gatsby-cli/package.json',
2 ✔
150
            }),
2 ✔
151
          ],
2 ✔
152
        },
2 ✔
153
      },
2 ✔
154
    '/github/package-json/dependency-version/{user}/{repo}/{kind}/{packageName}/{branch}':
2 ✔
155
      {
2 ✔
156
        get: {
2 ✔
157
          summary:
2 ✔
158
            'GitHub package.json dev/peer/optional dependency version (branch)',
2 ✔
159
          description: documentation,
2 ✔
160
          parameters: [
2 ✔
161
            pathParam({ name: 'user', example: 'gatsbyjs' }),
2 ✔
162
            pathParam({ name: 'repo', example: 'gatsby' }),
2 ✔
163
            pathParam({
2 ✔
164
              name: 'kind',
2 ✔
165
              example: 'dev',
2 ✔
166
              schema: { type: 'string', enum: this.getEnum('kind') },
2 ✔
167
            }),
2 ✔
168
            pathParam({
2 ✔
169
              name: 'packageName',
2 ✔
170
              example: 'cross-env',
2 ✔
171
              description: packageNameDescription,
2 ✔
172
            }),
2 ✔
173
            pathParam({ name: 'branch', example: 'master' }),
2 ✔
174
            queryParam({
2 ✔
175
              name: 'filename',
2 ✔
176
              example: 'packages/gatsby-cli/package.json',
2 ✔
177
            }),
2 ✔
178
          ],
2 ✔
179
        },
2 ✔
180
      },
2 ✔
181
  }
2 ✔
182

2 ✔
183
  static defaultBadgeData = { label: 'dependency' }
2 ✔
184

2 ✔
185
  static render({ dependency, range }) {
2 ✔
UNCOV
186
    return {
×
UNCOV
187
      label: dependency,
×
UNCOV
188
      message: range,
×
UNCOV
189
      color: 'blue',
×
UNCOV
190
    }
×
UNCOV
191
  }
×
192

2 ✔
193
  async handle(
2 ✔
UNCOV
194
    { user, repo, kind, branch = 'HEAD', scope, packageName },
×
UNCOV
195
    { filename = 'package.json' },
×
UNCOV
196
  ) {
×
UNCOV
197
    const {
×
UNCOV
198
      dependencies,
×
UNCOV
199
      devDependencies,
×
UNCOV
200
      peerDependencies,
×
UNCOV
201
      optionalDependencies,
×
UNCOV
202
    } = await fetchJsonFromRepo(this, {
×
UNCOV
203
      schema: isPackageJsonWithDependencies,
×
UNCOV
204
      user,
×
UNCOV
205
      repo,
×
UNCOV
206
      branch,
×
UNCOV
207
      filename,
×
UNCOV
208
    })
×
UNCOV
209

×
UNCOV
210
    const wantedDependency = scope ? `${scope}/${packageName}` : packageName
×
UNCOV
211
    const range = getDependencyVersion({
×
UNCOV
212
      kind,
×
UNCOV
213
      wantedDependency,
×
UNCOV
214
      dependencies,
×
UNCOV
215
      devDependencies,
×
UNCOV
216
      peerDependencies,
×
UNCOV
217
      optionalDependencies,
×
UNCOV
218
    })
×
UNCOV
219

×
UNCOV
220
    return this.constructor.render({
×
UNCOV
221
      dependency: wantedDependency,
×
UNCOV
222
      range,
×
UNCOV
223
    })
×
UNCOV
224
  }
×
225
}
2 ✔
226

2 ✔
227
// This must be exported after GithubPackageJsonVersion in order for the
2 ✔
228
// former to work correctly.
2 ✔
229
class DynamicGithubPackageJson extends ConditionalGithubAuthV3Service {
2 ✔
230
  static category = 'other'
2 ✔
231
  static route = {
2 ✔
232
    base: 'github/package-json',
2 ✔
233
    pattern: ':key/:user/:repo/:branch*',
2 ✔
234
  }
2 ✔
235

2 ✔
236
  static openApi = {
2 ✔
237
    '/github/package-json/{key}/{user}/{repo}': {
2 ✔
238
      get: {
2 ✔
239
        summary: 'GitHub package.json dynamic',
2 ✔
240
        description: documentation,
2 ✔
241
        parameters: pathParams(
2 ✔
242
          {
2 ✔
243
            name: 'key',
2 ✔
244
            example: 'keywords',
2 ✔
245
            description: 'any key in package.json',
2 ✔
246
          },
2 ✔
247
          { name: 'user', example: 'developit' },
2 ✔
248
          { name: 'repo', example: 'microbundle' },
2 ✔
249
        ),
2 ✔
250
      },
2 ✔
251
    },
2 ✔
252
    '/github/package-json/{key}/{user}/{repo}/{branch}': {
2 ✔
253
      get: {
2 ✔
254
        summary: 'GitHub package.json dynamic (branch)',
2 ✔
255
        description: documentation,
2 ✔
256
        parameters: pathParams(
2 ✔
257
          {
2 ✔
258
            name: 'key',
2 ✔
259
            example: 'keywords',
2 ✔
260
            description: 'any key in package.json',
2 ✔
261
          },
2 ✔
262
          { name: 'user', example: 'developit' },
2 ✔
263
          { name: 'repo', example: 'microbundle' },
2 ✔
264
          { name: 'branch', example: 'master' },
2 ✔
265
        ),
2 ✔
266
      },
2 ✔
267
    },
2 ✔
268
  }
2 ✔
269

2 ✔
270
  static defaultBadgeData = { label: 'package.json' }
2 ✔
271

2 ✔
272
  static render({ key, value, branch }) {
2 ✔
UNCOV
273
    return renderDynamicBadge({
×
UNCOV
274
      defaultLabel: key,
×
UNCOV
275
      tag: branch,
×
UNCOV
276
      value,
×
UNCOV
277
    })
×
UNCOV
278
  }
×
279

2 ✔
280
  async handle({ key, user, repo, branch }) {
2 ✔
UNCOV
281
    // Not sure `package-json/n` was ever advertised, but it was supported.
×
UNCOV
282
    if (key === 'n') {
×
UNCOV
283
      key = 'name'
×
UNCOV
284
    }
×
UNCOV
285
    const data = await fetchJsonFromRepo(this, {
×
UNCOV
286
      schema: Joi.object().required(),
×
UNCOV
287
      user,
×
UNCOV
288
      repo,
×
UNCOV
289
      branch,
×
UNCOV
290
      filename: 'package.json',
×
UNCOV
291
    })
×
UNCOV
292
    let value = transformAndValidate({ data, key })
×
UNCOV
293
    // Strip build metadata suffix from packageManager field (e.g. yarn@3.2.3+sha224.abc -> yarn@3.2.3)
×
UNCOV
294
    if (key === 'packageManager' && typeof value === 'string') {
×
UNCOV
295
      value = value.replace(/\+.*$/, '')
×
UNCOV
296
    }
×
UNCOV
297
    return this.constructor.render({ key, value, branch })
×
UNCOV
298
  }
×
299
}
2 ✔
300

2 ✔
301
export default [
2 ✔
302
  GithubPackageJsonVersion,
2 ✔
303
  GithubPackageJsonDependencyVersion,
2 ✔
304
  DynamicGithubPackageJson,
2 ✔
305
]
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