-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 8921-postgres
- Loading branch information
Showing
4 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Joi from 'joi' | ||
import { ConditionalGithubAuthV3Service } from '../github/github-auth-service.js' | ||
import { fetchJsonFromRepo } from '../github/github-common-fetch.js' | ||
import { renderVersionBadge } from '../version.js' | ||
import { NotFound } from '../index.js' | ||
|
||
const vcpkgManifestSchema = Joi.object({ | ||
version: Joi.string().required(), | ||
}).required() | ||
|
||
export default class VcpkgVersion extends ConditionalGithubAuthV3Service { | ||
static category = 'version' | ||
|
||
static route = { base: 'vcpkg/v', pattern: ':portName' } | ||
|
||
static examples = [ | ||
{ | ||
title: 'Vcpkg', | ||
namedParams: { portName: 'entt' }, | ||
staticPreview: this.render({ version: '3.11.1' }), | ||
}, | ||
] | ||
|
||
static defaultBadgeData = { label: 'vcpkg' } | ||
|
||
static render({ version }) { | ||
return renderVersionBadge({ version }) | ||
} | ||
|
||
async handle({ portName }) { | ||
try { | ||
const { version } = await fetchJsonFromRepo(this, { | ||
schema: vcpkgManifestSchema, | ||
user: 'microsoft', | ||
repo: 'vcpkg', | ||
branch: 'master', | ||
filename: `ports/${portName}/vcpkg.json`, | ||
}) | ||
return this.constructor.render({ version }) | ||
} catch (error) { | ||
if (error instanceof NotFound) { | ||
throw new NotFound({ | ||
prettyMessage: 'port not found', | ||
}) | ||
} | ||
throw error | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { isSemver } from '../test-validators.js' | ||
import { createServiceTester } from '../tester.js' | ||
|
||
export const t = await createServiceTester() | ||
|
||
t.create('gets the port version of entt') | ||
.get('/entt.json') | ||
.expectBadge({ label: 'vcpkg', message: isSemver }) | ||
|
||
t.create('returns not found for invalid port') | ||
.get('/this-port-does-not-exist.json') | ||
.expectBadge({ | ||
label: 'vcpkg', | ||
color: 'red', | ||
message: 'port not found', | ||
}) |