Skip to content

Commit

Permalink
feat(mix): handle hex package aliases (#32984)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <rhys@arkins.net>
Co-authored-by: Michael Kriese <michael.kriese@gmx.de>
  • Loading branch information
3 people authored Dec 10, 2024
1 parent df8bbff commit 2b7ab40
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/modules/manager/mix/__fixtures__/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ defmodule MyProject.MixProject do
optional: true},
{:hammer_backend_redis, "~> 6.1"},
{:public, "== 1.6.14"},
{:gun, "~> 2.0.0", hex: "grpc_gun"},
{:another_gun, "~> 1.0.0", hex: :gun_atom},
]
end
end
4 changes: 3 additions & 1 deletion lib/modules/manager/mix/__fixtures__/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
"mason": {:hex, :mason, "1.1.0", "344dbbf6610d205760ec37e2848bff2aab5a2de182bb5cdaa72cc2fd19d74535", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "19c205c8de0e2e5817f2250100281c58e717cb11ff1bb410bf661ee78c24e79b"},
"hammer_backend_redis": {:hex, :hammer_backend_redis, "6.1.5", "344dbbf6610d205760ec37e2848bff2aab5a2de182bb5cdaa72cc2fd19d74535", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "19c205c8de0e2e5817f2250100281c58e717cb11ff1bb410bf661ee78c24e79b"},
"public": {:hex, :public, "1.6.14", "344dbbf6610d205760ec37e2848bff2aab5a2de182bb5cdaa72cc2fd19d74535", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "19c205c8de0e2e5817f2250100281c58e717cb11ff1bb410bf661ee78c24e79b"},
"a_transient_dependency": {:hex, :a_transient_dependency, "1.6.14", "344dbbf6610d205760ec37e2848bff2aab5a2de182bb5cdaa72cc2fd19d74535", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "19c205c8de0e2e5817f2250100281c58e717cb11ff1bb410bf661ee78c24e79b"}
"a_transient_dependency": {:hex, :a_transient_dependency, "1.6.14", "344dbbf6610d205760ec37e2848bff2aab5a2de182bb5cdaa72cc2fd19d74535", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "19c205c8de0e2e5817f2250100281c58e717cb11ff1bb410bf661ee78c24e79b"},
"gun": {:hex, :grpc_gun, "2.0.0", "f99678a2ab975e74372a756c86ec30a8384d3ac8a8b86c7ed6243ef4e61d2729", [:rebar3], [{:cowlib, "~> 2.8.0", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "03dbbca1a9c604a0267a40ea1d69986225091acb822de0b2dbea21d5815e410b"},
"another_gun": {:hex, :gun_atom, "1.0.0", "344dbbf6610d205760ec37e2848bff2aab5a2de182bb5cdaa72cc2fd19d74535", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "19c205c8de0e2e5817f2250100281c58e717cb11ff1bb410bf661ee78c24e79b"}
}
26 changes: 26 additions & 0 deletions lib/modules/manager/mix/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ describe('modules/manager/mix/extract', () => {
depName: 'public',
packageName: 'public',
},
{
currentValue: '~> 2.0.0',
datasource: 'hex',
depName: 'gun',
packageName: 'grpc_gun',
},
{
currentValue: '~> 1.0.0',
datasource: 'hex',
depName: 'another_gun',
packageName: 'gun_atom',
},
]);
});

Expand Down Expand Up @@ -188,6 +200,20 @@ describe('modules/manager/mix/extract', () => {
packageName: 'public',
lockedVersion: '1.6.14',
},
{
currentValue: '~> 2.0.0',
datasource: 'hex',
depName: 'gun',
packageName: 'grpc_gun',
lockedVersion: '2.0.0',
},
{
currentValue: '~> 1.0.0',
datasource: 'hex',
depName: 'another_gun',
packageName: 'gun_atom',
lockedVersion: '1.0.0',
},
]);
});
});
Expand Down
11 changes: 10 additions & 1 deletion lib/modules/manager/mix/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const commentMatchRegExp = regEx(/#.*$/);
const lockedVersionRegExp = regEx(
/^\s+"(?<app>\w+)".*?"(?<lockedVersion>\d+\.\d+\.\d+)"/,
);
const hexRegexp = regEx(/hex:\s*(?:"(?<strValue>[^"]+)"|:(?<atomValue>\w+))/);

export async function extractPackageFile(
content: string,
Expand All @@ -44,6 +45,8 @@ export async function extractPackageFile(
const ref = refRegexp.exec(opts)?.groups?.value;
const branchOrTag = branchOrTagRegexp.exec(opts)?.groups?.value;
const organization = organizationRegexp.exec(opts)?.groups?.value;
const hexGroups = hexRegexp.exec(opts)?.groups;
const hex = hexGroups?.strValue ?? hexGroups?.atomValue;

let dep: PackageDependency;

Expand All @@ -60,8 +63,14 @@ export async function extractPackageFile(
depName: app,
currentValue: requirement,
datasource: HexDatasource.id,
packageName: organization ? `${app}:${organization}` : app,
};
if (organization) {
dep.packageName = `${app}:${organization}`;
} else if (hex) {
dep.packageName = hex;
} else {
dep.packageName = app;
}
if (requirement?.startsWith('==')) {
dep.currentVersion = requirement.replace(regEx(/^==\s*/), '');
}
Expand Down

0 comments on commit 2b7ab40

Please sign in to comment.