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:
Maxime Brunet 2022-10-12 23:53:02 -07:00 committed by Rhys Arkins
parent deea75058a
commit 5e7844fb81
4 changed files with 43 additions and 16 deletions

View file

@ -5,7 +5,7 @@ exports[`modules/manager/jsonnet-bundler/extract extractPackageFile() extracts d
"deps": [ "deps": [
{ {
"currentValue": "v0.50.0", "currentValue": "v0.50.0",
"depName": "prometheus-operator", "depName": "github.com/prometheus-operator/prometheus-operator/jsonnet/prometheus-operator",
"managerData": { "managerData": {
"subdir": "jsonnet/prometheus-operator", "subdir": "jsonnet/prometheus-operator",
}, },
@ -13,7 +13,7 @@ exports[`modules/manager/jsonnet-bundler/extract extractPackageFile() extracts d
}, },
{ {
"currentValue": "v0.9.0", "currentValue": "v0.9.0",
"depName": "kube-prometheus", "depName": "github.com/prometheus-operator/kube-prometheus/jsonnet/kube-prometheus",
"managerData": { "managerData": {
"subdir": "jsonnet/kube-prometheus", "subdir": "jsonnet/kube-prometheus",
}, },
@ -28,7 +28,7 @@ exports[`modules/manager/jsonnet-bundler/extract extractPackageFile() extracts d
"deps": [ "deps": [
{ {
"currentValue": "v0.50.0", "currentValue": "v0.50.0",
"depName": "prometheus-operator-mixin", "depName": "github.com/prometheus-operator/prometheus-operator/jsonnet/mixin",
"managerData": { "managerData": {
"subdir": "jsonnet/mixin", "subdir": "jsonnet/mixin",
}, },

View file

@ -82,11 +82,11 @@ describe('modules/manager/jsonnet-bundler/artifacts', () => {
packageFileName: 'jsonnetfile.json', packageFileName: 'jsonnetfile.json',
updatedDeps: [ updatedDeps: [
{ {
depName: 'foo', depName: 'github.com/foo/foo',
packageName: 'https://github.com/foo/foo.git', packageName: 'https://github.com/foo/foo.git',
}, },
{ {
depName: 'foo', depName: 'github.com/foo/foo',
packageName: 'ssh://git@github.com/foo/foo.git', packageName: 'ssh://git@github.com/foo/foo.git',
managerData: { managerData: {
subdir: 'bar', subdir: 'bar',

View file

@ -9,6 +9,15 @@ const jsonnetfileNoDependencies = Fixtures.get(
const jsonnetfileLocalDependencies = Fixtures.get( const jsonnetfileLocalDependencies = Fixtures.get(
'jsonnetfile-local-dependencies.json' 'jsonnetfile-local-dependencies.json'
); );
const jsonnetfileEmptyGitSource = JSON.stringify({
version: 1,
dependencies: [
{
source: { git: {} },
version: 'v0.50.0',
},
],
});
describe('modules/manager/jsonnet-bundler/extract', () => { describe('modules/manager/jsonnet-bundler/extract', () => {
describe('extractPackageFile()', () => { describe('extractPackageFile()', () => {
@ -36,18 +45,29 @@ describe('modules/manager/jsonnet-bundler/extract', () => {
).toBeNull(); ).toBeNull();
}); });
it('returns null for dependencies with empty Git source', () => {
expect(
extractPackageFile(
jsonnetfileEmptyGitSource,
'jsonnetfile-empty-git-source.json'
)
).toBeNull();
});
it('extracts dependency', () => { it('extracts dependency', () => {
const res = extractPackageFile(jsonnetfile, 'jsonnetfile.json'); const res = extractPackageFile(jsonnetfile, 'jsonnetfile.json');
expect(res).toMatchSnapshot({ expect(res).toMatchSnapshot({
deps: [ deps: [
{ {
depName: 'prometheus-operator', depName:
'github.com/prometheus-operator/prometheus-operator/jsonnet/prometheus-operator',
packageName: packageName:
'https://github.com/prometheus-operator/prometheus-operator.git', 'https://github.com/prometheus-operator/prometheus-operator.git',
currentValue: 'v0.50.0', currentValue: 'v0.50.0',
}, },
{ {
depName: 'kube-prometheus', depName:
'github.com/prometheus-operator/kube-prometheus/jsonnet/kube-prometheus',
packageName: packageName:
'ssh://git@github.com/prometheus-operator/kube-prometheus.git', 'ssh://git@github.com/prometheus-operator/kube-prometheus.git',
currentValue: 'v0.9.0', currentValue: 'v0.9.0',
@ -61,7 +81,8 @@ describe('modules/manager/jsonnet-bundler/extract', () => {
expect(res).toMatchSnapshot({ expect(res).toMatchSnapshot({
deps: [ deps: [
{ {
depName: 'prometheus-operator-mixin', depName:
'github.com/prometheus-operator/prometheus-operator/jsonnet/mixin',
packageName: packageName:
'https://github.com/prometheus-operator/prometheus-operator', 'https://github.com/prometheus-operator/prometheus-operator',
currentValue: 'v0.50.0', currentValue: 'v0.50.0',

View file

@ -1,13 +1,10 @@
import { join } from 'upath';
import { logger } from '../../../logger'; import { logger } from '../../../logger';
import { coerceArray } from '../../../util/array'; import { coerceArray } from '../../../util/array';
import { regEx } from '../../../util/regex'; import { parseUrl } from '../../../util/url';
import type { PackageDependency, PackageFile } from '../types'; import type { PackageDependency, PackageFile } from '../types';
import type { Dependency, JsonnetFile } from './types'; import type { Dependency, JsonnetFile } from './types';
const gitUrl = regEx(
/(ssh:\/\/git@|https:\/\/)([\w.]+)\/([\w:/\-~]*)\/(?<depName>[\w:/-]+)(\.git)?/
);
export function extractPackageFile( export function extractPackageFile(
content: string, content: string,
packageFile: string packageFile: string
@ -46,11 +43,20 @@ function extractDependency(dependency: Dependency): PackageDependency | null {
return 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 { return {
depName: depName,
dependency.name ?? match?.groups?.depName ?? dependency.source.git.remote,
packageName: dependency.source.git.remote, packageName: dependency.source.git.remote,
currentValue: dependency.version, currentValue: dependency.version,
managerData: { subdir: dependency.source.git.subdir }, managerData: { subdir: dependency.source.git.subdir },