mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 23:16:26 +00:00
feat(jsonnet-bundler)!: Use absolute import format for depName (#14525)
Use absolute import format for depName in jsonnet-bundler. Closes #13568 BREAKING CHANGE: `depName` now uses the "absolute import" format (e.g. `bar` → `github.com/foo/bar/baz-wow`)
This commit is contained in:
parent
deea75058a
commit
5e7844fb81
4 changed files with 43 additions and 16 deletions
|
@ -5,7 +5,7 @@ exports[`modules/manager/jsonnet-bundler/extract extractPackageFile() extracts d
|
|||
"deps": [
|
||||
{
|
||||
"currentValue": "v0.50.0",
|
||||
"depName": "prometheus-operator",
|
||||
"depName": "github.com/prometheus-operator/prometheus-operator/jsonnet/prometheus-operator",
|
||||
"managerData": {
|
||||
"subdir": "jsonnet/prometheus-operator",
|
||||
},
|
||||
|
@ -13,7 +13,7 @@ exports[`modules/manager/jsonnet-bundler/extract extractPackageFile() extracts d
|
|||
},
|
||||
{
|
||||
"currentValue": "v0.9.0",
|
||||
"depName": "kube-prometheus",
|
||||
"depName": "github.com/prometheus-operator/kube-prometheus/jsonnet/kube-prometheus",
|
||||
"managerData": {
|
||||
"subdir": "jsonnet/kube-prometheus",
|
||||
},
|
||||
|
@ -28,7 +28,7 @@ exports[`modules/manager/jsonnet-bundler/extract extractPackageFile() extracts d
|
|||
"deps": [
|
||||
{
|
||||
"currentValue": "v0.50.0",
|
||||
"depName": "prometheus-operator-mixin",
|
||||
"depName": "github.com/prometheus-operator/prometheus-operator/jsonnet/mixin",
|
||||
"managerData": {
|
||||
"subdir": "jsonnet/mixin",
|
||||
},
|
||||
|
|
|
@ -82,11 +82,11 @@ describe('modules/manager/jsonnet-bundler/artifacts', () => {
|
|||
packageFileName: 'jsonnetfile.json',
|
||||
updatedDeps: [
|
||||
{
|
||||
depName: 'foo',
|
||||
depName: 'github.com/foo/foo',
|
||||
packageName: 'https://github.com/foo/foo.git',
|
||||
},
|
||||
{
|
||||
depName: 'foo',
|
||||
depName: 'github.com/foo/foo',
|
||||
packageName: 'ssh://git@github.com/foo/foo.git',
|
||||
managerData: {
|
||||
subdir: 'bar',
|
||||
|
|
|
@ -9,6 +9,15 @@ const jsonnetfileNoDependencies = Fixtures.get(
|
|||
const jsonnetfileLocalDependencies = Fixtures.get(
|
||||
'jsonnetfile-local-dependencies.json'
|
||||
);
|
||||
const jsonnetfileEmptyGitSource = JSON.stringify({
|
||||
version: 1,
|
||||
dependencies: [
|
||||
{
|
||||
source: { git: {} },
|
||||
version: 'v0.50.0',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
describe('modules/manager/jsonnet-bundler/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
|
@ -36,18 +45,29 @@ describe('modules/manager/jsonnet-bundler/extract', () => {
|
|||
).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for dependencies with empty Git source', () => {
|
||||
expect(
|
||||
extractPackageFile(
|
||||
jsonnetfileEmptyGitSource,
|
||||
'jsonnetfile-empty-git-source.json'
|
||||
)
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it('extracts dependency', () => {
|
||||
const res = extractPackageFile(jsonnetfile, 'jsonnetfile.json');
|
||||
expect(res).toMatchSnapshot({
|
||||
deps: [
|
||||
{
|
||||
depName: 'prometheus-operator',
|
||||
depName:
|
||||
'github.com/prometheus-operator/prometheus-operator/jsonnet/prometheus-operator',
|
||||
packageName:
|
||||
'https://github.com/prometheus-operator/prometheus-operator.git',
|
||||
currentValue: 'v0.50.0',
|
||||
},
|
||||
{
|
||||
depName: 'kube-prometheus',
|
||||
depName:
|
||||
'github.com/prometheus-operator/kube-prometheus/jsonnet/kube-prometheus',
|
||||
packageName:
|
||||
'ssh://git@github.com/prometheus-operator/kube-prometheus.git',
|
||||
currentValue: 'v0.9.0',
|
||||
|
@ -61,7 +81,8 @@ describe('modules/manager/jsonnet-bundler/extract', () => {
|
|||
expect(res).toMatchSnapshot({
|
||||
deps: [
|
||||
{
|
||||
depName: 'prometheus-operator-mixin',
|
||||
depName:
|
||||
'github.com/prometheus-operator/prometheus-operator/jsonnet/mixin',
|
||||
packageName:
|
||||
'https://github.com/prometheus-operator/prometheus-operator',
|
||||
currentValue: 'v0.50.0',
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
import { join } from 'upath';
|
||||
import { logger } from '../../../logger';
|
||||
import { coerceArray } from '../../../util/array';
|
||||
import { regEx } from '../../../util/regex';
|
||||
import { parseUrl } from '../../../util/url';
|
||||
import type { PackageDependency, PackageFile } from '../types';
|
||||
import type { Dependency, JsonnetFile } from './types';
|
||||
|
||||
const gitUrl = regEx(
|
||||
/(ssh:\/\/git@|https:\/\/)([\w.]+)\/([\w:/\-~]*)\/(?<depName>[\w:/-]+)(\.git)?/
|
||||
);
|
||||
|
||||
export function extractPackageFile(
|
||||
content: string,
|
||||
packageFile: string
|
||||
|
@ -46,11 +43,20 @@ function extractDependency(dependency: Dependency): PackageDependency | null {
|
|||
return null;
|
||||
}
|
||||
|
||||
const match = gitUrl.exec(dependency.source.git.remote);
|
||||
const gitRemote = parseUrl(dependency.source.git.remote);
|
||||
if (gitRemote === null) {
|
||||
logger.debug({ dependency }, 'Invalid Git remote URL');
|
||||
return null;
|
||||
}
|
||||
|
||||
const depName = join(
|
||||
gitRemote.host,
|
||||
gitRemote.pathname.replace(/\.git$/, ''),
|
||||
dependency.source.git.subdir
|
||||
);
|
||||
|
||||
return {
|
||||
depName:
|
||||
dependency.name ?? match?.groups?.depName ?? dependency.source.git.remote,
|
||||
depName,
|
||||
packageName: dependency.source.git.remote,
|
||||
currentValue: dependency.version,
|
||||
managerData: { subdir: dependency.source.git.subdir },
|
||||
|
|
Loading…
Reference in a new issue