Skip to content

Commit

Permalink
Merge branch 'master' into feat/9410/python-versions-toml
Browse files Browse the repository at this point in the history
  • Loading branch information
jNullj committed Sep 5, 2023
2 parents b3de30f + 6e793f1 commit 4e86c49
Show file tree
Hide file tree
Showing 54 changed files with 1,025 additions and 496 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test-bug-run-badge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ jobs:
steps:
- name: Test badge test run conditions
id: testCondition
env:
ISSUE_BODY: '${{ github.event.issue.body }}'
run: |
product=$(echo "${{ github.event.issue.body }}" | grep -A2 "Are you experiencing an issue with.*" | tail -n 1)
link=$(echo "${{ github.event.issue.body }}" | grep -A2 "Link to the badge.*" | tail -n 1)
product=$(echo "$ISSUE_BODY" | grep -A2 "Are you experiencing an issue with.*" | tail -n 1)
link=$(echo "$ISSUE_BODY" | grep -A2 "Link to the badge.*" | tail -n 1)
if [[ "$product" == "shields.io" && "$link" == "https://img.shields.io"* ]]; then
echo "runNext=true" >> "$GITHUB_OUTPUT"
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ Note: this changelog is for the shields.io server. The changelog for the badge-m

---

## server-2023-09-04

- Fix [testspace] badges [#9525](https://github.com/badges/shields/issues/9525)
- fix rSt code example [#9528](https://github.com/badges/shields/issues/9528)
- Add dynamic TOML support via [DynamicToml] Service [#9517](https://github.com/badges/shields/issues/9517)
- cache [pypi] downloads for longer [#9522](https://github.com/badges/shields/issues/9522)
- [twitter] --> x [#9496](https://github.com/badges/shields/issues/9496)
- [bundlejs] add badge for the npm package size [#9055](https://github.com/badges/shields/issues/9055)
- Switch [OpenCollective] badges to use GraphQL and auth [#9387](https://github.com/badges/shields/issues/9387)
- [Pulsar] Add Pulsar Badges for Stargazers & Downloads [#8767](https://github.com/badges/shields/issues/8767)
- Add [CurseForge] badges [#9252](https://github.com/badges/shields/issues/9252)
- deploy on node 18 [#9385](https://github.com/badges/shields/issues/9385)
- allow calling [github] without auth [#9427](https://github.com/badges/shields/issues/9427)
- Dependency updates

## server-2023-08-01

- Convert `examples` arrays to `openApi` objects (part 1) [#9320](https://github.com/badges/shields/issues/9320)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ You can read a [tutorial on how to add a badge][tutorial].

[![GitHub issues by-label](https://img.shields.io/github/issues/badges/shields/good%20first%20issue)](https://github.com/badges/shields/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)

If you intend on reporting or contributing a fix related to security vulnerabilities, please first refer to our [security policy][security].

[service-tests]: https://github.com/badges/shields/blob/master/doc/service-tests.md
[tutorial]: https://github.com/badges/shields/blob/master/doc/TUTORIAL.md
[contributing]: https://github.com/badges/shields/blob/master/CONTRIBUTING.md
[security]: https://github.com/badges/shields/blob/master/SECURITY.md

## Development

Expand Down
21 changes: 21 additions & 0 deletions core/base-service/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from './errors.js'
import { validateExample, transformExample } from './examples.js'
import { fetch } from './got.js'
import { getEnum } from './openapi.js'
import {
makeFullUrl,
assertValidRoute,
Expand Down Expand Up @@ -102,6 +103,26 @@ class BaseService {
throw new Error(`Route not defined for ${this.name}`)
}

/**
* Extract an array of allowed values from this service's route pattern
* for a given route parameter
*
* @param {string} param The name of a param in this service's route pattern
* @returns {string[]} Array of allowed values for this param
*/
static getEnum(param) {
if (!('pattern' in this.route)) {
throw new Error('getEnum() requires route to have a .pattern property')
}
const enumeration = getEnum(this.route.pattern, param)
if (!Array.isArray(enumeration)) {
throw new Error(
`Could not extract enum for param ${param} from pattern ${this.route.pattern}`,
)
}
return enumeration
}

/**
* Configuration for the authentication helper that prepares credentials
* for upstream requests.
Expand Down
41 changes: 41 additions & 0 deletions core/base-service/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ describe('BaseService', function () {
).to.not.contain('service_response_bytes_bucket')
})
})

describe('auth', function () {
class AuthService extends DummyService {
static auth = {
Expand Down Expand Up @@ -592,4 +593,44 @@ describe('BaseService', function () {
})
})
})

describe('getEnum', function () {
class EnumService extends DummyService {
static route = {
base: 'foo',
pattern: ':namedParamA/:namedParamB(this|that)',
queryParamSchema,
}
}

it('returns an array of allowed values', async function () {
expect(EnumService.getEnum('namedParamB')).to.deep.equal(['this', 'that'])
})

it('throws if param name is invalid', async function () {
expect(() => EnumService.getEnum('notAValidParam')).to.throw(
'Could not extract enum for param notAValidParam from pattern :namedParamA/:namedParamB(this|that)',
)
})

it('throws if param name is not an enum', async function () {
expect(() => EnumService.getEnum('namedParamA')).to.throw(
'Could not extract enum for param namedParamA from pattern :namedParamA/:namedParamB(this|that)',
)
})

it('throws if route does not have a pattern', async function () {
class FormatService extends DummyService {
static route = {
base: 'foo',
format: '([^/]+?)',
queryParamSchema,
}
}

expect(() => FormatService.getEnum('notAValidParam')).to.throw(
'getEnum() requires route to have a .pattern property',
)
})
})
})
2 changes: 2 additions & 0 deletions core/base-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import BaseJsonService from './base-json.js'
import BaseGraphqlService from './base-graphql.js'
import BaseStaticService from './base-static.js'
import BaseSvgScrapingService from './base-svg-scraping.js'
import BaseTomlService from './base-toml.js'
import BaseXmlService from './base-xml.js'
import BaseYamlService from './base-yaml.js'
import deprecatedService from './deprecated-service.js'
Expand All @@ -23,6 +24,7 @@ export {
BaseGraphqlService,
BaseStaticService,
BaseSvgScrapingService,
BaseTomlService,
BaseXmlService,
BaseYamlService,
deprecatedService,
Expand Down
11 changes: 9 additions & 2 deletions core/base-service/openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function getCodeSamples(altText) {
{
lang: 'reStructuredText',
label: 'rSt',
source: `.. image:: $url\n: alt: ${altText}`,
source: `.. image:: $url\n :alt: ${altText}`,
},
{
lang: 'AsciiDoc',
Expand Down Expand Up @@ -466,4 +466,11 @@ function queryParams(...params) {
* @property {boolean} allowEmptyValue If true, allows the ability to pass an empty value to this parameter
*/

export { category2openapi, pathParam, pathParams, queryParam, queryParams }
export {
category2openapi,
getEnum,
pathParam,
pathParams,
queryParam,
queryParams,
}
8 changes: 4 additions & 4 deletions core/base-service/openapi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const expected = {
{
lang: 'reStructuredText',
label: 'rSt',
source: '.. image:: $url\n: alt: OpenApiService Summary',
source: '.. image:: $url\n :alt: OpenApiService Summary',
},
{
lang: 'AsciiDoc',
Expand Down Expand Up @@ -248,7 +248,7 @@ const expected = {
lang: 'reStructuredText',
label: 'rSt',
source:
'.. image:: $url\n: alt: OpenApiService Summary (with Tag)',
'.. image:: $url\n :alt: OpenApiService Summary (with Tag)',
},
{
lang: 'AsciiDoc',
Expand Down Expand Up @@ -301,7 +301,7 @@ const expected = {
{
lang: 'reStructuredText',
label: 'rSt',
source: '.. image:: $url\n: alt: LegacyService Title (with Tag)',
source: '.. image:: $url\n :alt: LegacyService Title (with Tag)',
},
{
lang: 'AsciiDoc',
Expand Down Expand Up @@ -347,7 +347,7 @@ const expected = {
{
lang: 'reStructuredText',
label: 'rSt',
source: '.. image:: $url\n: alt: LegacyService Title (with Tag)',
source: '.. image:: $url\n :alt: LegacyService Title (with Tag)',
},
{
lang: 'AsciiDoc',
Expand Down
2 changes: 2 additions & 0 deletions doc/TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ Other classes implement useful behavior on top of [BaseService].
implements methods for performing requests to an XML API and schema validation.
- [BaseYamlService](https://contributing.shields.io/module-core_base-service_base-yaml-BaseYamlService.html)
implements methods for performing requests to a YAML API and schema validation.
- [BaseTomlService](https://contributing.shields.io/module-core_base-service_base-toml-BaseTomlService.html)
implements methods for performing requests to a TOML API and schema validation.
- [BaseSvgScrapingService](https://contributing.shields.io/module-core_base-service_base-svg-scraping-BaseSvgScrapingService.html)
implements methods for retrieving information from existing third-party badges.
- [BaseGraphqlService](https://contributing.shields.io/module-core_base-service_base-graphql-BaseGraphqlService.html)
Expand Down

0 comments on commit 4e86c49

Please sign in to comment.