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

feat(devbox): Add devbox manager and nixhub datasource and versioning #30002

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions lib/constants/category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Categories = [
'ci',
'custom',
'dart',
'devbox',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
'devbox',

It does not need its own category, otherwise category concept is meaningless if we make it 1:1

'docker',
'dotnet',
'elixir',
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/datasource/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { JavaVersionDatasource } from './java-version';
import { JenkinsPluginsDatasource } from './jenkins-plugins';
import { KubernetesApiDatasource } from './kubernetes-api';
import { MavenDatasource } from './maven';
import { NixhubDatasource } from './nixhub';
import { NodeVersionDatasource } from './node-version';
import { NpmDatasource } from './npm';
import { NugetDatasource } from './nuget';
Expand Down Expand Up @@ -115,6 +116,7 @@ api.set(JavaVersionDatasource.id, new JavaVersionDatasource());
api.set(JenkinsPluginsDatasource.id, new JenkinsPluginsDatasource());
api.set(KubernetesApiDatasource.id, new KubernetesApiDatasource());
api.set(MavenDatasource.id, new MavenDatasource());
api.set(NixhubDatasource.id, new NixhubDatasource());
api.set(NodeVersionDatasource.id, new NodeVersionDatasource());
api.set(NpmDatasource.id, new NpmDatasource());
api.set(NugetDatasource.id, new NugetDatasource());
Expand Down
84 changes: 84 additions & 0 deletions lib/modules/datasource/nixhub/__fixtures__/releases.json
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"
}
]
}
67 changes: 67 additions & 0 deletions lib/modules/datasource/nixhub/__snapshots__/index.spec.ts.snap
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",
},
],
}
`;
7 changes: 7 additions & 0 deletions lib/modules/datasource/nixhub/common.ts
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',
};
84 changes: 84 additions & 0 deletions lib/modules/datasource/nixhub/index.spec.ts
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);
});
});
57 changes: 57 additions & 0 deletions lib/modules/datasource/nixhub/index.ts
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 = {

Check warning on line 31 in lib/modules/datasource/nixhub/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/datasource/nixhub/index.ts#L31

Added line #L31 was not covered by tests
homepage: 'https://www.nixhub.io',
releases: [],
};

logger.trace({ registryUrl, packageName }, 'fetching nixhub release');

Check warning on line 36 in lib/modules/datasource/nixhub/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/datasource/nixhub/index.ts#L36

Added line #L36 was not covered by tests

const nixhubPkgUrl = joinUrlParts(registryUrl!, `/pkg?name=${packageName}`);

Check warning on line 38 in lib/modules/datasource/nixhub/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/datasource/nixhub/index.ts#L38

Added line #L38 was not covered by tests

try {
const response = await this.http.getJson<NixhubResponse>(nixhubPkgUrl);
res.releases = response?.body?.releases.map((release) => ({

Check warning on line 42 in lib/modules/datasource/nixhub/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/datasource/nixhub/index.ts#L40-L42

Added lines #L40 - L42 were not covered by tests
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

View workflow job for this annotation

GitHub Actions / test (2/16)

modules/datasource/nixhub/index › returns null for 404

external-host-error at NixhubDatasource.getReleases (lib/modules/datasource/nixhub/index.ts:50:17) at getRegistryReleases (lib/modules/datasource/index.ts:77:15) at fetchReleases (lib/modules/datasource/index.ts:289:15) at getPkgReleases (lib/modules/datasource/index.ts:381:31) at Object.<anonymous> (lib/modules/datasource/nixhub/index.spec.ts:32:7)

Check failure on line 50 in lib/modules/datasource/nixhub/index.ts

View workflow job for this annotation

GitHub Actions / test (2/16)

modules/datasource/nixhub/index › returns null for empty result

external-host-error at NixhubDatasource.getReleases (lib/modules/datasource/nixhub/index.ts:50:17) at getRegistryReleases (lib/modules/datasource/index.ts:77:15) at fetchReleases (lib/modules/datasource/index.ts:289:15) at getPkgReleases (lib/modules/datasource/index.ts:381:31) at Object.<anonymous> (lib/modules/datasource/nixhub/index.spec.ts:42:7)

Check failure on line 50 in lib/modules/datasource/nixhub/index.ts

View workflow job for this annotation

GitHub Actions / test (2/16)

modules/datasource/nixhub/index › returns null for empty 200 OK

external-host-error at NixhubDatasource.getReleases (lib/modules/datasource/nixhub/index.ts:50:17) at getRegistryReleases (lib/modules/datasource/index.ts:77:15) at fetchReleases (lib/modules/datasource/index.ts:289:15) at getPkgReleases (lib/modules/datasource/index.ts:381:31) at Object.<anonymous> (lib/modules/datasource/nixhub/index.spec.ts:55:7)

Check failure on line 50 in lib/modules/datasource/nixhub/index.ts

View workflow job for this annotation

GitHub Actions / test (2/16)

modules/datasource/nixhub/index › processes real data

external-host-error at NixhubDatasource.getReleases (lib/modules/datasource/nixhub/index.ts:50:17) at getRegistryReleases (lib/modules/datasource/index.ts:77:15) at fetchReleases (lib/modules/datasource/index.ts:289:15) at getPkgReleases (lib/modules/datasource/index.ts:381:31) at Object.<anonymous> (lib/modules/datasource/nixhub/index.spec.ts:77:17)

Check warning on line 50 in lib/modules/datasource/nixhub/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/datasource/nixhub/index.ts#L50

Added line #L50 was not covered by tests
}
}
this.handleGenericErrors(err);

Check warning on line 53 in lib/modules/datasource/nixhub/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/datasource/nixhub/index.ts#L53

Added line #L53 was not covered by tests
}
return res.releases.length ? res : null;
}
}
12 changes: 12 additions & 0 deletions lib/modules/datasource/nixhub/types.ts
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[];
}
2 changes: 2 additions & 0 deletions lib/modules/manager/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as conan from './conan';
import * as cpanfile from './cpanfile';
import * as crossplane from './crossplane';
import * as depsEdn from './deps-edn';
import * as devbox from './devbox';
import * as devContainer from './devcontainer';
import * as dockerCompose from './docker-compose';
import * as dockerfile from './dockerfile';
Expand Down Expand Up @@ -121,6 +122,7 @@ api.set('conan', conan);
api.set('cpanfile', cpanfile);
api.set('crossplane', crossplane);
api.set('deps-edn', depsEdn);
api.set('devbox', devbox);
api.set('devcontainer', devContainer);
api.set('docker-compose', dockerCompose);
api.set('dockerfile', dockerfile);
Expand Down
Loading
Loading