Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(terraform-module): always use 'source' as sourceUrl when available #25008

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"modules": [
{
"versions": [
{
"version": "0.0.2",
"submodules": [],
"root": {
"dependencies": [],
"providers": [
{
"name": "local",
"version": ""
}
]
}
},
{
"version": "0.0.1",
"submodules": [],
"root": {
"dependencies": [],
"providers": [
{
"name": "local",
"version": ""
}
]
}
}
],
"source": "https://gitlab.com/renovate-issue-25003/mymodule"
}
]
}
29 changes: 29 additions & 0 deletions lib/modules/datasource/terraform-module/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { TerraformModuleDatasource } from '.';

const consulData = Fixtures.get('registry-consul.json');
const consulVersionsData = Fixtures.get('registry-consul-versions.json');
const versionsDataWithSourceUrl = Fixtures.get(
'registry-versions-with-source.json'
);
const serviceDiscoveryResult = Fixtures.get('service-discovery.json');
const serviceDiscoveryCustomResult = Fixtures.get(
'service-custom-discovery.json'
Expand Down Expand Up @@ -176,6 +179,32 @@ describe('modules/datasource/terraform-module/index', () => {
});
});

it('processes real data from third party including source url', async () => {
httpMock
.scope('https://terraform.company.com')
.get('/v1/modules/renovate-issue-25003/mymodule/local/versions')
.reply(200, versionsDataWithSourceUrl)
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryResult);
const res = await getPkgReleases({
datasource,
packageName: 'renovate-issue-25003/mymodule/local',
registryUrls: ['https://terraform.company.com'],
});
expect(res).toEqual({
registryUrl: 'https://terraform.company.com',
releases: [
{
version: '0.0.1',
},
{
version: '0.0.2',
},
],
sourceUrl: 'https://gitlab.com/renovate-issue-25003/mymodule',
});
});

it('processes with registry in name', async () => {
httpMock
.scope(baseUrl)
Expand Down
7 changes: 7 additions & 0 deletions lib/modules/datasource/terraform-module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { logger } from '../../../logger';
import { cache } from '../../../util/cache/package/decorator';
import { regEx } from '../../../util/regex';
import { coerceString } from '../../../util/string';
import { validateUrl } from '../../../util/url';
import * as hashicorpVersioning from '../../versioning/hashicorp';
import type { GetReleasesConfig, ReleaseResult } from '../types';
import { TerraformDatasource } from './base';
Expand Down Expand Up @@ -159,6 +160,12 @@ export class TerraformModuleDatasource extends TerraformDatasource {
version,
})),
};

// Add the source URL if given
if (validateUrl(res.modules[0].source)) {
dep.sourceUrl = res.modules[0].source;
}

return dep;
}

Expand Down
3 changes: 3 additions & 0 deletions lib/modules/datasource/terraform-module/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export interface TerraformModuleVersions {

export interface TerraformModuleVersionsModules {
versions: TerraformModuleVersionsModuleVersion[];
// 'source' is not part of the base spec but GitLab supports it:
// https://docs.gitlab.com/ee/api/packages/terraform-modules.html#list-available-versions-for-a-specific-module
source?: string;
}

export interface TerraformModuleVersionsModuleVersion {
Expand Down