Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions services/macports/macports-version.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Joi from 'joi'
import { renderVersionBadge } from '../version.js'
import { BaseJsonService, pathParams } from '../index.js'

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

export default class MacportsVersion extends BaseJsonService {
static category = 'version'

static route = {
base: 'macports/v',
pattern: ':portName',
}

static openApi = {
'/macports/v/{portName}': {
get: {
summary: 'MacPorts Version',
parameters: pathParams({
name: 'portName',
example: 'git',
}),
},
},
}

static defaultBadgeData = { label: 'macports' }

async fetch({ portName }) {
return this._requestJson({
schema,
url: `https://ports.macports.org/api/v1/ports/${portName}/`,
httpErrors: { 404: 'port not found' },
})
}

async handle({ portName }) {
const { version } = await this.fetch({ portName })
return renderVersionBadge({ version })
}
}
25 changes: 25 additions & 0 deletions services/macports/macports-version.tester.js

@PyvesB PyvesB Apr 26, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please switch to non-mocked tests, i.e. using real data and API calls? See https://github.com/badges/shields/blob/master/doc/service-tests.md for more information. :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @PyvesB , thanks for the feedback! I tried switching to live tests but ran into an issue — ports.macports.org appears to be unreachable from the GitHub Actions CI runners. Both the valid and not-found tests consistently time out when hitting the real API, even though the API itself works fine when accessed directly.

I've verified the service code is correct and the API returns the expected response format, so I belive it's purely a connectivity issue from the CI environment rather than a problem with the implementation.

I've reverted back to mocked tests for now. Happy to switch to live tests if there's a way to work around the connectivity issue, or if there's a preferred approach for services where the upstream API isn't accessible from CI. Let me know how you'd like to proceed! Really appreciate your review and guidance with this!

@PyvesB PyvesB May 11, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty odd. Perhaps we could still have a live test or two in addition to the mocked ones, but with .skipWhen(() => process.env.GITHUB_ACTIONS === 'true'), so that we they are still run when launched locally?

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { isVPlusDottedVersionAtLeastOne } from '../test-validators.js'
import { createServiceTester } from '../tester.js'

export const t = await createServiceTester()

t.create('version (valid)')
.get('/git.json')
.intercept(nock =>
nock('https://ports.macports.org')
.get('/api/v1/ports/git/')
.reply(200, { version: '2.47.1' }),
)
.expectBadge({
label: 'macports',
message: isVPlusDottedVersionAtLeastOne,
})

t.create('version (not found)')
.get('/not-a-real-port.json')
.intercept(nock =>
nock('https://ports.macports.org')
.get('/api/v1/ports/not-a-real-port/')
.reply(404),
)
.expectBadge({ label: 'macports', message: 'port not found' })
Loading