-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
feat(devbox): Add devbox manager and nixhub datasource and versioning #30002
Draft
burritobill
wants to merge
6
commits into
renovatebot:main
Choose a base branch
from
jay-aye-see-kay:add-devbox
base: main
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.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f55a91f
it's pretty jank but this will update a devbox package
jay-aye-see-kay 147ee07
Add tests, nixhub versioning and support for all packages variations
burritobill 85e33b0
Fix tests and use nixhub package validation
burritobill 3195049
Remove nixhub packageName matching
burritobill 2874401
Update nixhub api url
burritobill ce84524
Addressing code review feedback
burritobill 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 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 |
---|---|---|
|
@@ -8,6 +8,7 @@ const Categories = [ | |
'ci', | ||
'custom', | ||
'dart', | ||
'devbox', | ||
'docker', | ||
'dotnet', | ||
'elixir', | ||
|
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,84 @@ | ||
{ | ||
"name": "nodejs", | ||
"summary": "Event-driven I/O framework for the V8 JavaScript engine", | ||
"homepage_url": "https://nodejs.org", | ||
"license": "MIT", | ||
"releases": [ | ||
{ | ||
"version": "22.2.0", | ||
"last_updated": "2024-05-22T06:18:38Z" | ||
}, | ||
{ | ||
"version": "22.0.0", | ||
"last_updated": "2024-05-12T16:19:40Z" | ||
}, | ||
{ | ||
"version": "21.7.3", | ||
"last_updated": "2024-04-19T21:36:04Z" | ||
}, | ||
{ | ||
"version": "21.7.2", | ||
"last_updated": "2024-04-05T14:44:07Z" | ||
}, | ||
{ | ||
"version": "21.7.1", | ||
"last_updated": "2024-04-02T02:53:36Z" | ||
}, | ||
{ | ||
"version": "21.7.0", | ||
"last_updated": "2024-03-08T13:51:52Z" | ||
}, | ||
{ | ||
"version": "21.6.2", | ||
"last_updated": "2024-02-24T23:06:34Z" | ||
}, | ||
{ | ||
"version": "21.6.1", | ||
"last_updated": "2024-02-10T18:15:24Z" | ||
}, | ||
{ | ||
"version": "21.6.0", | ||
"last_updated": "2024-01-17T15:31:30Z" | ||
}, | ||
{ | ||
"version": "21.5.0", | ||
"last_updated": "2024-01-14T03:55:27Z" | ||
}, | ||
{ | ||
"version": "21.4.0", | ||
"last_updated": "2023-12-18T02:58:18Z" | ||
}, | ||
{ | ||
"version": "21.3.0", | ||
"last_updated": "2023-12-13T22:54:10Z" | ||
}, | ||
{ | ||
"version": "21.2.0", | ||
"last_updated": "2023-11-17T14:14:56Z" | ||
}, | ||
{ | ||
"version": "21.1.0", | ||
"last_updated": "2023-10-25T20:49:13Z" | ||
}, | ||
{ | ||
"version": "21.0.0", | ||
"last_updated": "2023-10-21T11:05:41Z" | ||
}, | ||
{ | ||
"version": "20.12.2", | ||
"last_updated": "2024-05-22T06:18:38Z" | ||
}, | ||
{ | ||
"version": "20.11.1", | ||
"last_updated": "2024-04-02T02:53:36Z" | ||
}, | ||
{ | ||
"version": "20.11.0", | ||
"last_updated": "2024-02-10T18:15:24Z" | ||
}, | ||
{ | ||
"version": "20.10.0", | ||
"last_updated": "2024-01-14T03:55:27Z" | ||
} | ||
] | ||
} |
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,3 @@ | ||
export const defaultRegistryUrl = 'https://search.devbox.sh/v2/'; | ||
|
||
export const datasource = 'devbox'; |
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,88 @@ | ||
import { getPkgReleases } from '..'; | ||
import { Fixtures } from '../../../../test/fixtures'; | ||
import * as httpMock from '../../../../test/http-mock'; | ||
import { EXTERNAL_HOST_ERROR } from '../../../constants/error-messages'; | ||
import { datasource, defaultRegistryUrl } from './common'; | ||
|
||
const packageName = 'nodejs'; | ||
|
||
function getPath(packageName: string): string { | ||
return `/pkg?name=${packageName}`; | ||
} | ||
|
||
describe('modules/datasource/devbox/index', () => { | ||
describe('getReleases', () => { | ||
it('throws for error', async () => { | ||
httpMock | ||
.scope(defaultRegistryUrl) | ||
.get(getPath(packageName)) | ||
.replyWithError('error'); | ||
await expect( | ||
getPkgReleases({ | ||
datasource, | ||
packageName, | ||
}), | ||
).rejects.toThrow(EXTERNAL_HOST_ERROR); | ||
}); | ||
}); | ||
|
||
it('returns null for 404', async () => { | ||
httpMock.scope(defaultRegistryUrl).get(getPath(packageName)).reply(404); | ||
expect( | ||
await getPkgReleases({ | ||
datasource, | ||
packageName, | ||
}), | ||
).toBeNull(); | ||
}); | ||
|
||
it('returns null for empty result', async () => { | ||
httpMock.scope(defaultRegistryUrl).get(getPath(packageName)).reply(200, {}); | ||
expect( | ||
await getPkgReleases({ | ||
datasource, | ||
packageName, | ||
}), | ||
).toBeNull(); | ||
}); | ||
|
||
it('returns null for empty 200 OK', async () => { | ||
httpMock | ||
.scope(defaultRegistryUrl) | ||
.get(getPath(packageName)) | ||
.reply(200, { versions: [] }); | ||
expect( | ||
await getPkgReleases({ | ||
datasource, | ||
packageName, | ||
}), | ||
).toBeNull(); | ||
}); | ||
|
||
it('throws for 5xx', async () => { | ||
httpMock.scope(defaultRegistryUrl).get(getPath(packageName)).reply(502); | ||
await expect( | ||
getPkgReleases({ | ||
datasource, | ||
packageName, | ||
}), | ||
).rejects.toThrow(EXTERNAL_HOST_ERROR); | ||
}); | ||
|
||
it('processes real data', async () => { | ||
httpMock | ||
.scope(defaultRegistryUrl) | ||
.get(getPath(packageName)) | ||
.reply(200, Fixtures.get('releases.json')); | ||
const res = await getPkgReleases({ | ||
datasource, | ||
packageName, | ||
}); | ||
expect(res?.homepage).toBe('https://nodejs.org'); | ||
expect(res?.releases[0]).toStrictEqual({ | ||
version: '20.10.0', | ||
releaseTimestamp: '2024-01-14T03:55:27.000Z', | ||
}); | ||
expect(res?.releases).toHaveLength(19); | ||
}); | ||
}); |
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,57 @@ | ||
import { logger } from '../../../logger'; | ||
import { ExternalHostError } from '../../../types/errors/external-host-error'; | ||
import { HttpError } from '../../../util/http'; | ||
import { joinUrlParts } from '../../../util/url'; | ||
import * as devboxVersioning from '../../versioning/devbox'; | ||
import { Datasource } from '../datasource'; | ||
import type { GetReleasesConfig, ReleaseResult } from '../types'; | ||
import { datasource, defaultRegistryUrl } from './common'; | ||
import type { DevboxResponse } from './types'; | ||
|
||
export class DevboxDatasource extends Datasource { | ||
static readonly id = datasource; | ||
|
||
constructor() { | ||
super(datasource); | ||
} | ||
|
||
override readonly customRegistrySupport = true; | ||
override readonly releaseTimestampSupport = true; | ||
|
||
override readonly registryStrategy = 'first'; | ||
|
||
override readonly defaultVersioning = devboxVersioning.id; | ||
|
||
override readonly defaultRegistryUrls = [defaultRegistryUrl]; | ||
|
||
async getReleases({ | ||
registryUrl, | ||
packageName, | ||
}: GetReleasesConfig): Promise<ReleaseResult | null> { | ||
const res: ReleaseResult = { | ||
releases: [], | ||
}; | ||
|
||
logger.trace({ registryUrl, packageName }, 'fetching devbox release'); | ||
|
||
const devboxPkgUrl = joinUrlParts(registryUrl!, `/pkg?name=${packageName}`); | ||
|
||
try { | ||
const response = await this.http.getJson<DevboxResponse>(devboxPkgUrl); | ||
res.homepage = response?.body?.homepage_url; | ||
res.releases = response?.body?.releases.map((release) => ({ | ||
version: release.version, | ||
releaseTimestamp: release.last_updated, | ||
})); | ||
} catch (err) { | ||
// istanbul ignore else: not testable with nock | ||
if (err instanceof HttpError) { | ||
if (err.response?.statusCode !== 404) { | ||
throw new ExternalHostError(err); | ||
} | ||
} | ||
this.handleGenericErrors(err); | ||
} | ||
return res.releases.length ? res : null; | ||
} | ||
} |
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,12 @@ | ||
export interface DevboxRelease { | ||
version: string; | ||
last_updated: string; | ||
} | ||
|
||
export interface DevboxResponse { | ||
name: string; | ||
summary: string; | ||
homepage_url: string; | ||
license: string; | ||
releases: DevboxRelease[]; | ||
} |
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
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.
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.
It does not need its own category, otherwise category concept is meaningless if we make it 1:1