-
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
f55a91f
147ee07
85e33b0
3195049
2874401
ce84524
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ const Categories = [ | |
'ci', | ||
'custom', | ||
'dart', | ||
'devbox', | ||
'docker', | ||
'dotnet', | ||
'elixir', | ||
|
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" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`modules/datasource/nixhub/index processes real data 1`] = ` | ||
{ | ||
"homepage": "https://www.nixhub.io", | ||
"registryUrl": "https://www.nixhub.io", | ||
"releases": [ | ||
{ | ||
"version": "20.10.0", | ||
}, | ||
{ | ||
"version": "20.11.0", | ||
}, | ||
{ | ||
"version": "20.11.1", | ||
}, | ||
{ | ||
"version": "20.12.2", | ||
}, | ||
{ | ||
"version": "21.0.0", | ||
}, | ||
{ | ||
"version": "21.1.0", | ||
}, | ||
{ | ||
"version": "21.2.0", | ||
}, | ||
{ | ||
"version": "21.3.0", | ||
}, | ||
{ | ||
"version": "21.4.0", | ||
}, | ||
{ | ||
"version": "21.5.0", | ||
}, | ||
{ | ||
"version": "21.6.0", | ||
}, | ||
{ | ||
"version": "21.6.1", | ||
}, | ||
{ | ||
"version": "21.6.2", | ||
}, | ||
{ | ||
"version": "21.7.0", | ||
}, | ||
{ | ||
"version": "21.7.1", | ||
}, | ||
{ | ||
"version": "21.7.2", | ||
}, | ||
{ | ||
"version": "21.7.3", | ||
}, | ||
{ | ||
"version": "22.0.0", | ||
}, | ||
{ | ||
"version": "22.2.0", | ||
}, | ||
], | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const defaultRegistryUrl = 'https://search.devbox.sh/v2/'; | ||
|
||
export const datasource = 'nixhub'; | ||
|
||
export const nixhubPackageMap = { | ||
nodejs: 'node', | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
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 `/packages/${packageName}?_data=routes/_nixhub.packages.$pkg._index`; | ||
} | ||
|
||
describe('modules/datasource/nixhub/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).toMatchSnapshot(); | ||
burritobill marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(res?.releases).toHaveLength(19); | ||
}); | ||
}); |
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 nixhubVersioning from '../../versioning/nixhub'; | ||
import { Datasource } from '../datasource'; | ||
import type { GetReleasesConfig, ReleaseResult } from '../types'; | ||
import { datasource, defaultRegistryUrl } from './common'; | ||
import type { NixhubResponse } from './types'; | ||
|
||
export class NixhubDatasource extends Datasource { | ||
static readonly id = datasource; | ||
|
||
constructor() { | ||
super(datasource); | ||
} | ||
|
||
override readonly customRegistrySupport = true; | ||
override readonly releaseTimestampSupport = true; | ||
|
||
override readonly registryStrategy = 'first'; | ||
|
||
override readonly defaultVersioning = nixhubVersioning.id; | ||
|
||
override readonly defaultRegistryUrls = [defaultRegistryUrl]; | ||
|
||
async getReleases({ | ||
registryUrl, | ||
packageName, | ||
}: GetReleasesConfig): Promise<ReleaseResult | null> { | ||
const res: ReleaseResult = { | ||
homepage: 'https://www.nixhub.io', | ||
releases: [], | ||
}; | ||
|
||
logger.trace({ registryUrl, packageName }, 'fetching nixhub release'); | ||
|
||
const nixhubPkgUrl = joinUrlParts(registryUrl!, `/pkg?name=${packageName}`); | ||
|
||
try { | ||
const response = await this.http.getJson<NixhubResponse>(nixhubPkgUrl); | ||
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); | ||
Check failure on line 50 in lib/modules/datasource/nixhub/index.ts GitHub Actions / test (2/16)modules/datasource/nixhub/index › returns null for 404
Check failure on line 50 in lib/modules/datasource/nixhub/index.ts GitHub Actions / test (2/16)modules/datasource/nixhub/index › returns null for empty result
Check failure on line 50 in lib/modules/datasource/nixhub/index.ts GitHub Actions / test (2/16)modules/datasource/nixhub/index › returns null for empty 200 OK
Check failure on line 50 in lib/modules/datasource/nixhub/index.ts GitHub Actions / test (2/16)modules/datasource/nixhub/index › processes real data
|
||
} | ||
} | ||
this.handleGenericErrors(err); | ||
} | ||
return res.releases.length ? res : null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export interface NixhubRelease { | ||
version: string; | ||
last_updated: string; | ||
} | ||
|
||
export interface NixhubResponse { | ||
name: string; | ||
summary: string; | ||
homepage_url: string; | ||
license: string; | ||
releases: NixhubRelease[]; | ||
} |
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