• 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

50.0
/services/github/github-pull-requests.service.js
1
import gql from 'graphql-tag'
2 ✔
2
import Joi from 'joi'
2 ✔
3
import { pathParams, queryParam } from '../index.js'
2 ✔
4
import { metric } from '../text-formatters.js'
2 ✔
5
import { nonNegativeInteger } from '../validators.js'
2 ✔
6
import { GithubAuthV4Service } from './github-auth-service.js'
2 ✔
7
import { documentation, transformErrors } from './github-helpers.js'
2 ✔
8

2 ✔
9
const pullRequestCountSchema = Joi.object({
2 ✔
10
  data: Joi.object({
2 ✔
11
    repository: Joi.object({
2 ✔
12
      pullRequests: Joi.object({
2 ✔
13
        totalCount: nonNegativeInteger,
2 ✔
14
      }).required(),
2 ✔
15
    }).required(),
2 ✔
16
  }).required(),
2 ✔
17
}).required()
2 ✔
18

2 ✔
19
const pullRequestSearchSchema = Joi.object({
2 ✔
20
  data: Joi.object({
2 ✔
21
    repository: Joi.object({
2 ✔
22
      id: Joi.string().required(),
2 ✔
23
    }).required(),
2 ✔
24
    search: Joi.object({
2 ✔
25
      issueCount: nonNegativeInteger,
2 ✔
26
    }).required(),
2 ✔
27
  }).required(),
2 ✔
28
}).required()
2 ✔
29

2 ✔
30
const queryParamSchema = Joi.object({
2 ✔
31
  excludeDrafts: Joi.equal(''),
2 ✔
32
  onlyDrafts: Joi.equal(''),
2 ✔
33
})
2 ✔
34
  .oxor('excludeDrafts', 'onlyDrafts')
2 ✔
35
  .required()
2 ✔
36

2 ✔
37
const pullRequestVariants = [
2 ✔
38
  'issues-pr',
2 ✔
39
  'issues-pr-raw',
2 ✔
40
  'issues-pr-closed',
2 ✔
41
  'issues-pr-closed-raw',
2 ✔
42
]
2 ✔
43

2 ✔
44
const variantSummaries = {
2 ✔
45
  'issues-pr': 'GitHub Pull Requests',
2 ✔
46
  'issues-pr-raw': 'GitHub Pull Requests (raw)',
2 ✔
47
  'issues-pr-closed': 'GitHub Closed Pull Requests',
2 ✔
48
  'issues-pr-closed-raw': 'GitHub Closed Pull Requests (raw)',
2 ✔
49
}
2 ✔
50

2 ✔
51
function openApiRoute({ variant, label }) {
16 ✔
52
  return {
16 ✔
53
    get: {
16 ✔
54
      summary: `${variantSummaries[variant]}${label ? ' by label' : ''}`,
16 ✔
55
      description: documentation,
16 ✔
56
      parameters: [
16 ✔
57
        ...pathParams(
16 ✔
58
          { name: 'user', example: 'badges' },
16 ✔
59
          { name: 'repo', example: 'shields' },
16 ✔
60
          ...(label ? [{ name: 'label', example: 'service-badge' }] : []),
16 ✔
61
        ),
16 ✔
62
        queryParam({
16 ✔
63
          name: 'excludeDrafts',
16 ✔
64
          description: 'Exclude draft pull requests',
16 ✔
65
          example: null,
16 ✔
66
          schema: { type: 'boolean' },
16 ✔
67
        }),
16 ✔
68
        queryParam({
16 ✔
69
          name: 'onlyDrafts',
16 ✔
70
          description: 'Only include draft pull requests',
16 ✔
71
          example: null,
16 ✔
72
          schema: { type: 'boolean' },
16 ✔
73
        }),
16 ✔
74
      ],
16 ✔
75
    },
16 ✔
76
  }
16 ✔
77
}
16 ✔
78

2 ✔
79
const openApi = Object.fromEntries(
2 ✔
80
  pullRequestVariants.flatMap(variant => [
2 ✔
81
    [
8 ✔
82
      `/github/${variant}/{user}/{repo}`,
8 ✔
83
      openApiRoute({ variant, label: false }),
8 ✔
84
    ],
8 ✔
85
    [
8 ✔
86
      `/github/${variant}/{user}/{repo}/{label}`,
8 ✔
87
      openApiRoute({ variant, label: true }),
8 ✔
88
    ],
8 ✔
89
  ]),
2 ✔
90
)
2 ✔
91

2 ✔
92
export default class GithubPullRequests extends GithubAuthV4Service {
2 ✔
93
  static category = 'issue-tracking'
2 ✔
94
  static route = {
2 ✔
95
    base: 'github',
2 ✔
96
    pattern:
2 ✔
97
      ':variant(issues-pr|issues-pr-raw|issues-pr-closed|issues-pr-closed-raw)/:user/:repo/:label*',
2 ✔
98
    queryParamSchema,
2 ✔
99
  }
2 ✔
100

2 ✔
101
  static openApi = openApi
2 ✔
102

2 ✔
103
  static defaultBadgeData = {
2 ✔
104
    label: 'pull requests',
2 ✔
105
    color: 'informational',
2 ✔
106
  }
2 ✔
107

2 ✔
108
  static render({
2 ✔
UNCOV
109
    issueCount,
×
UNCOV
110
    label,
×
UNCOV
111
    raw,
×
UNCOV
112
    isClosed,
×
UNCOV
113
    excludeDrafts,
×
UNCOV
114
    onlyDrafts,
×
UNCOV
115
  }) {
×
UNCOV
116
    const state = isClosed ? 'closed' : 'open'
×
UNCOV
117
    const isGhLabelMultiWord = label && label.includes(' ')
×
UNCOV
118
    const labelText = label
×
UNCOV
119
      ? `${isGhLabelMultiWord ? `"${label}"` : label} `
×
UNCOV
120
      : ''
×
UNCOV
121
    let draftText = ''
×
UNCOV
122
    if (excludeDrafts) {
×
UNCOV
123
      draftText = 'non-draft '
×
UNCOV
124
    } else if (onlyDrafts) {
×
UNCOV
125
      draftText = 'draft '
×
UNCOV
126
    }
×
UNCOV
127

×
UNCOV
128
    return {
×
UNCOV
129
      label: `${raw ? `${state} ` : ''}${labelText}${draftText}pull requests`,
×
UNCOV
130
      message: `${metric(issueCount)}${raw ? '' : ` ${state}`}`,
×
UNCOV
131
      color: issueCount > 0 ? 'yellow' : 'brightgreen',
×
UNCOV
132
    }
×
UNCOV
133
  }
×
134

2 ✔
135
  async fetch({ user, repo, label, isClosed, excludeDrafts, onlyDrafts }) {
2 ✔
UNCOV
136
    if (!excludeDrafts && !onlyDrafts) {
×
UNCOV
137
      const {
×
UNCOV
138
        data: {
×
UNCOV
139
          repository: {
×
UNCOV
140
            pullRequests: { totalCount },
×
UNCOV
141
          },
×
UNCOV
142
        },
×
UNCOV
143
      } = await this._requestGraphql({
×
UNCOV
144
        query: gql`
×
UNCOV
145
          query (
×
UNCOV
146
            $user: String!
×
UNCOV
147
            $repo: String!
×
UNCOV
148
            $states: [PullRequestState!]
×
UNCOV
149
            $labels: [String!]
×
UNCOV
150
          ) {
×
UNCOV
151
            repository(owner: $user, name: $repo) {
×
UNCOV
152
              pullRequests(states: $states, labels: $labels) {
×
UNCOV
153
                totalCount
×
UNCOV
154
              }
×
UNCOV
155
            }
×
UNCOV
156
          }
×
UNCOV
157
        `,
×
UNCOV
158
        variables: {
×
UNCOV
159
          user,
×
UNCOV
160
          repo,
×
UNCOV
161
          states: isClosed ? ['MERGED', 'CLOSED'] : ['OPEN'],
×
UNCOV
162
          labels: label ? [label] : undefined,
×
UNCOV
163
        },
×
UNCOV
164
        schema: pullRequestCountSchema,
×
UNCOV
165
        transformErrors,
×
UNCOV
166
      })
×
UNCOV
167
      return totalCount
×
UNCOV
168
    }
×
UNCOV
169

×
UNCOV
170
    const searchQualifiers = [
×
UNCOV
171
      `repo:${user}/${repo}`,
×
UNCOV
172
      'is:pr',
×
UNCOV
173
      `is:${isClosed ? 'closed' : 'open'}`,
×
UNCOV
174
    ]
×
UNCOV
175
    if (label) {
×
UNCOV
176
      searchQualifiers.push(`label:"${label}"`)
×
UNCOV
177
    }
×
UNCOV
178
    if (excludeDrafts) {
×
UNCOV
179
      searchQualifiers.push('draft:false')
×
UNCOV
180
    }
×
UNCOV
181
    if (onlyDrafts) {
×
UNCOV
182
      searchQualifiers.push('draft:true')
×
UNCOV
183
    }
×
UNCOV
184

×
UNCOV
185
    const data = await this._requestGraphql({
×
UNCOV
186
      query: gql`
×
UNCOV
187
        query ($query: String!, $user: String!, $repo: String!) {
×
UNCOV
188
          repository(owner: $user, name: $repo) {
×
UNCOV
189
            id
×
UNCOV
190
          }
×
UNCOV
191
          search(query: $query, type: ISSUE) {
×
UNCOV
192
            issueCount
×
UNCOV
193
          }
×
UNCOV
194
        }
×
UNCOV
195
      `,
×
UNCOV
196
      variables: { query: searchQualifiers.join(' '), user, repo },
×
UNCOV
197
      schema: pullRequestSearchSchema,
×
UNCOV
198
      transformErrors,
×
UNCOV
199
    })
×
UNCOV
200

×
UNCOV
201
    return data.data.search.issueCount
×
UNCOV
202
  }
×
203

2 ✔
204
  async handle({ variant, user, repo, label }, queryParams) {
2 ✔
UNCOV
205
    const raw = variant.endsWith('-raw')
×
UNCOV
206
    const isClosed = variant.includes('-closed')
×
UNCOV
207
    const excludeDrafts = queryParams.excludeDrafts !== undefined
×
UNCOV
208
    const onlyDrafts = queryParams.onlyDrafts !== undefined
×
UNCOV
209
    const issueCount = await this.fetch({
×
UNCOV
210
      user,
×
UNCOV
211
      repo,
×
UNCOV
212
      label,
×
UNCOV
213
      isClosed,
×
UNCOV
214
      excludeDrafts,
×
UNCOV
215
      onlyDrafts,
×
UNCOV
216
    })
×
UNCOV
217
    return this.constructor.render({
×
UNCOV
218
      issueCount,
×
UNCOV
219
      label,
×
UNCOV
220
      raw,
×
UNCOV
221
      isClosed,
×
UNCOV
222
      excludeDrafts,
×
UNCOV
223
      onlyDrafts,
×
UNCOV
224
    })
×
UNCOV
225
  }
×
226
}
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