Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add [FlakeHub] service #9554

Closed
wants to merge 11 commits into from
48 changes: 48 additions & 0 deletions services/flakehub/flakehub.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Joi from 'joi'
import { renderVersionBadge } from '../version.js'
import { BaseJsonService, NotFound, pathParams } from '../index.js'

const schema = Joi.object({
latest: Joi.string().required(),
}).required()

export default class FlakeHub extends BaseJsonService {
static category = 'version'
static route = { base: 'flake', pattern: ':org/:project' }
static openApi = {
'/flake/{org}/{project}': {
get: {
summary: 'FlakeHub flake version',
parameters: pathParams(
{
name: 'org',
example: 'DeterminateSystems',
},
{
name: 'project',
example: 'flake-schemas',
},
),
},
},
}

static defaultBadgeData = { label: 'FlakeHub', color: 'rgb(33,29,82)' }

async handle({ org, project }) {
const data = await this._requestJson({
schema,
url: `https://api.flakehub.com/f/${encodeURIComponent(
org,
)}/${encodeURIComponent(project)}/badge`,
})

// the upstream API indicates "not found"
// by returning a 200 OK with a null body
if (data === null) {
throw new NotFound()
}

return renderVersionBadge({ version: data.latest })
}
}
25 changes: 25 additions & 0 deletions services/flakehub/flakehub.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { isVPlusDottedVersionNClauses } from '../test-validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()

t.create('FlakeHub (valid)')
.get('/f/DeterminateSystems/nuenv/badge')
.expectBadge({
label: 'flakehub',
message: isVPlusDottedVersionNClauses,
})

t.create('FlakeHub (valid)')
.get('/f/DeterminateSystems/nuenv/badge')
.intercept(nock =>
nock('https://api.flakehub.com')
.get('/f/DeterminateSystems/nuenv/badge')
.reply(200, {
latest: '0.1.160',
}),
)
.expectBadge({ label: 'FlakeHub', message: '0.1.160' })

t.create('FlakeHub (not found)')
.get('/f/DeterminateSystems/flakehub-this-will-never-exist-we-promise')
.expectBadge({ label: 'FlakeHub', message: 'not found' })
Loading