Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions lib/modules/datasource/galaxy-collection/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,40 @@ describe('modules/datasource/galaxy-collection/index', () => {
expect(res?.releases).toHaveLength(3);
});
});

describe('constructBaseUrl', () => {
const galaxy_collection_datasource = new GalaxyCollectionDatasource();
it('returns ansible url with artifactory URL', () => {
expect(
galaxy_collection_datasource.constructBaseUrl(
'https://my.artifactory.local/artifactory/api/ansible/ansible-repo/',
'foo.bar',
),
).toBe(
'https://my.artifactory.local/artifactory/api/ansible/ansible-repo/api/v3/collections/foo/bar/',
);
});

it('returns galaxy url with automation hub URL', () => {
expect(
galaxy_collection_datasource.constructBaseUrl(
'https://my.automationhub.local/api/galaxy/content/community/',
'foo.bar',
),
).toBe(
'https://my.automationhub.local/api/galaxy/content/community/v3/plugin/ansible/content/community/collections/index/foo/bar/',
);
});

it('returns galaxy url with other url', () => {
expect(
galaxy_collection_datasource.constructBaseUrl(
'https://my.collectiondatasource.local/api/collection/content/community/',
'foo.bar',
),
).toBe(
'https://my.collectiondatasource.local/api/collection/content/community/v3/plugin/ansible/content/published/collections/index/foo/bar/',
);
});
});
});
39 changes: 24 additions & 15 deletions lib/modules/datasource/galaxy-collection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Datasource } from '../datasource';
import type { GetReleasesConfig, Release, ReleaseResult } from '../types';
import { GalaxyV3, GalaxyV3DetailedVersion, GalaxyV3Versions } from './schema';

const ansibleProtocolRegex = regEx(/^\S+\/api\/ansible\/.+/);
const repositoryRegex = regEx(
/^\S+\/api\/galaxy\/content\/(?<repository>[^/]+)/,
);
Expand Down Expand Up @@ -45,21 +46,7 @@ export class GalaxyCollectionDatasource extends Datasource {
packageName,
registryUrl,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
const [namespace, projectName] = packageName.split('.');

const repository =
repositoryRegex.exec(registryUrl!)?.groups?.repository ?? 'published';

const baseUrl = ensureTrailingSlash(
joinUrlParts(
registryUrl!,
'v3/plugin/ansible/content',
repository,
'collections/index',
namespace,
projectName,
),
);
const baseUrl = this.constructBaseUrl(registryUrl!, packageName);

const { val: baseProject, err: baseErr } = await this.http
.getJsonSafe(baseUrl, GalaxyV3)
Expand Down Expand Up @@ -118,6 +105,28 @@ export class GalaxyCollectionDatasource extends Datasource {
};
}

constructBaseUrl(registryUrl: string, packageName: string): string {
const [namespace, projectName] = packageName.split('.');
if (ansibleProtocolRegex.test(registryUrl)) {
return ensureTrailingSlash(
joinUrlParts(registryUrl, 'api/v3/collections', namespace, projectName),
);
} else {
const repository =
repositoryRegex.exec(registryUrl)?.groups?.repository ?? 'published';
return ensureTrailingSlash(
joinUrlParts(
registryUrl,
'v3/plugin/ansible/content',
repository,
'collections/index',
namespace,
projectName,
),
);
}
}

@cache({
namespace: `datasource-${GalaxyCollectionDatasource.id}`,
key: (_packageName: string, versionsUrl: string, basicRelease: Release) =>
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/datasource/galaxy-collection/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Set your own registries by:
- setting a `source` in your `requirements.yaml` file, _or_
- writing a `packageRule` to set a new `registryURLs`

Then you can use Renovate with a private automation hub.
Then you can use Renovate with a private automation hub or an ansible repository on artifactory.

```yaml title="Example config for requirements.yaml"
---
Expand All @@ -25,6 +25,7 @@ collections:
"https://hub.mydomain.com/api/galaxy/content/community/",
"https://hub.mydomain.com/api/galaxy/content/certified/",
"https://hub.mydomain.com/api/galaxy/content/myprivaterepo/"
"https://mydomain.com/artifactory/api/ansible/myrepository/"
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/galaxy-collection/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const GalaxyV3DetailedVersion = z
sha256: z.string(),
}),
metadata: z.object({
homepage: z.string(),
homepage: z.string().optional(),
repository: z.string(),
dependencies: z.record(z.string(), z.string()).optional(),
}),
Expand Down
Loading