-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
feat: add [MacPortsVersion] badge #11807
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
Open
Shaz666
wants to merge
4
commits into
badges:master
Choose a base branch
from
Shaz666:feat/macports-version-badge
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e82906f
feat: Shaz666 add MacPorts version badge Closes #9588
Shaz666 2bbf696
refactor(macports): switch to non-mocked service tests
Shaz666 7f4fbb2
fix(macports): mock not-found test; MacPorts API times out for invali…
Shaz666 ae17fac
revert(macports): restore mocked tests; ports.macports.org unreachabl…
Shaz666 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,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 }) | ||
| } | ||
| } |
This file contains hidden or 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,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' }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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. :)
There was a problem hiding this comment.
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!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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?