Skip to content

Commit

Permalink
feat(manager/pub): extract hosted url from pubspec file (#27748)
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh committed Mar 6, 2024
1 parent 8b44771 commit 8dc8175
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lib/modules/manager/pub/extract.spec.ts
Expand Up @@ -42,7 +42,13 @@ describe('modules/manager/pub/extract', () => {
dependencies:
meta: 'something'
foo: 1.0.0
transmogrify:
hosted:
name: transmogrify
url: https://some-package-server.com
version: ^1.4.0
bar:
hosted: 'some-url'
version: 1.1.0
baz:
non-sense: true
Expand All @@ -68,12 +74,20 @@ describe('modules/manager/pub/extract', () => {
datasource: dartDatasource,
skipReason,
},
{
currentValue: '^1.4.0',
depName: 'transmogrify',
depType: dependenciesDepType,
datasource: dartDatasource,
registryUrls: ['https://some-package-server.com'],
},
{
currentValue: '1.1.0',
depName: 'bar',
depType: dependenciesDepType,
datasource: dartDatasource,
skipReason,
registryUrls: ['some-url'],
},
{
currentValue: '',
Expand Down
10 changes: 10 additions & 0 deletions lib/modules/manager/pub/extract.ts
Expand Up @@ -31,10 +31,19 @@ function extractFromSection(

let currentValue = sectionContent[depName];
let skipReason: SkipReason | undefined;
let registryUrls: string[] | undefined;

if (!is.string(currentValue)) {
const version = currentValue.version;
const path = currentValue.path;
const hosted = currentValue.hosted;

if (is.string(hosted)) {
registryUrls = [hosted];
} else if (is.string(hosted?.url)) {
registryUrls = [hosted.url];
}

if (version) {
currentValue = version;
} else if (path) {
Expand All @@ -50,6 +59,7 @@ function extractFromSection(
depType: sectionKey,
currentValue,
datasource: DartDatasource.id,
...(registryUrls && { registryUrls }),
skipReason,
});
}
Expand Down
9 changes: 8 additions & 1 deletion lib/modules/manager/pub/schema.ts
Expand Up @@ -5,7 +5,14 @@ const PubspecDependencySchema = LooseRecord(
z.string(),
z.union([
z.string(),
z.object({ version: z.string().optional(), path: z.string().optional() }),
z.object({
version: z.string().optional(),
path: z.string().optional(),
hosted: z.union([
z.string().optional(),
z.object({ name: z.string().optional(), url: z.string().optional() }),
]),
}),
]),
);

Expand Down

0 comments on commit 8dc8175

Please sign in to comment.