Skip to content

Commit

Permalink
feat(manager/cargo): Changes to support cargo repository source repla…
Browse files Browse the repository at this point in the history
…cement (#28759)
  • Loading branch information
thian002 authored May 1, 2024
1 parent 4ec9485 commit 3374bd1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/modules/manager/cargo/__fixtures__/Cargo.7.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "renovate-test"
version = "0.1.0"
authors = ["John Doe <john.doe@example.org>"]
edition = "2018"

[dependencies]
tokio = "0.2"

26 changes: 26 additions & 0 deletions lib/modules/manager/cargo/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const cargo4toml = Fixtures.get('Cargo.4.toml');
const cargo5toml = Fixtures.get('Cargo.5.toml');
const cargo6configtoml = Fixtures.get('cargo.6.config.toml');
const cargo6toml = Fixtures.get('Cargo.6.toml');
const cargo7toml = Fixtures.get('Cargo.7.toml');

const lockfileUpdateCargotoml = Fixtures.get('lockfile-update/Cargo.toml');

Expand Down Expand Up @@ -167,6 +168,31 @@ replace-with = "private-crates"`,
]);
});

it('extracts overridden source registry indexes from .cargo/config.toml', async () => {
mockReadLocalFile({
'.cargo/config.toml': codeBlock`[source.crates-io-replacement]
registry = "https://github.com/replacement/testregistry"
[source.crates-io]
replace-with = "crates-io-replacement"`,
});
const res = await extractPackageFile(cargo7toml, 'Cargo.toml', {
...config,
});
expect(res?.deps).toEqual([
{
currentValue: '0.2',
datasource: 'crate',
depName: 'tokio',
depType: 'dependencies',
managerData: {
nestedVersion: false,
},
registryUrls: ['https://github.com/replacement/testregistry'],
},
]);
});

it('extracts registries overridden to the default', async () => {
mockReadLocalFile({
'.cargo/config.toml': codeBlock`[source.mcorbin]
Expand Down
8 changes: 8 additions & 0 deletions lib/modules/manager/cargo/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ function resolveRegistryIndex(
);
}

const sourceRegistry = config.source?.[registryName]?.registry;
if (sourceRegistry) {
logger.debug(
`Replacing cargo source registry with ${sourceRegistry} for ${registryName}`,
);
return sourceRegistry;
}

const registryIndex = config.registries?.[registryName]?.index;
if (registryIndex) {
return registryIndex;
Expand Down
1 change: 1 addition & 0 deletions lib/modules/manager/cargo/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface CargoRegistry {

export interface CargoSource {
'replace-with'?: string;
registry?: string;
}

/**
Expand Down

0 comments on commit 3374bd1

Please sign in to comment.