Skip to content

Commit

Permalink
feat(terraform-module): always use 'source' as sourceUrl when availab…
Browse files Browse the repository at this point in the history
…le (#25008)

Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
  • Loading branch information
colinodell and secustor committed Oct 4, 2023
1 parent ecd6ac0 commit 3758782
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
@@ -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
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
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
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

0 comments on commit 3758782

Please sign in to comment.