Skip to content
Snippets Groups Projects
Commit 9dc3c4e3 authored by Florian Greinacher's avatar Florian Greinacher Committed by Rhys Arkins
Browse files

fix(manager): Fix extraction of gitlab-ci includes (#4557)

The extraction logic failed to extract the GitLab URI correctly
when the configured platform endpoint does not have a trailing
slash. This commit changes the logic to handle scenarios with
and without trailing slash

Fixes #4270
parent a07aa3b7
No related branches found
No related tags found
No related merge requests found
...@@ -37,7 +37,7 @@ export function extractPackageFile( ...@@ -37,7 +37,7 @@ export function extractPackageFile(
const dep = extractDepFromInclude(includeObj); const dep = extractDepFromInclude(includeObj);
if (dep) { if (dep) {
if (config.endpoint) { if (config.endpoint) {
dep.registryUrls = [config.endpoint.replace('/api/v4/', '')]; dep.registryUrls = [config.endpoint.replace(/\/api\/v4\/?/, '')];
} }
deps.push(dep); deps.push(dep);
} }
......
...@@ -7,26 +7,17 @@ Array [ ...@@ -7,26 +7,17 @@ Array [
"datasource": "gitlab", "datasource": "gitlab",
"depName": "mikebryant/include-source-example", "depName": "mikebryant/include-source-example",
"depType": "repository", "depType": "repository",
"registryUrls": Array [
"http://gitlab.test",
],
}, },
Object { Object {
"currentValue": "master", "currentValue": "master",
"datasource": "gitlab", "datasource": "gitlab",
"depName": "mikebryant/include-source-example2", "depName": "mikebryant/include-source-example2",
"depType": "repository", "depType": "repository",
"registryUrls": Array [
"http://gitlab.test",
],
}, },
Object { Object {
"datasource": "gitlab", "datasource": "gitlab",
"depName": "mikebryant/include-source-example3", "depName": "mikebryant/include-source-example3",
"depType": "repository", "depType": "repository",
"registryUrls": Array [
"http://gitlab.test",
],
"skipReason": "unknown-version", "skipReason": "unknown-version",
}, },
] ]
......
import fs from 'fs'; import fs from 'fs';
import { extractPackageFile } from '../../../lib/manager/gitlabci-include/extract'; import { extractPackageFile } from '../../../lib/manager/gitlabci-include/extract';
import { ExtractConfig } from '../../../lib/manager/common';
const yamlFile = fs.readFileSync( const yamlFile = fs.readFileSync(
'test/manager/gitlabci-include/_fixtures/gitlab-ci.yaml', 'test/manager/gitlabci-include/_fixtures/gitlab-ci.yaml',
...@@ -9,21 +8,27 @@ const yamlFile = fs.readFileSync( ...@@ -9,21 +8,27 @@ const yamlFile = fs.readFileSync(
describe('lib/manager/gitlabci-include/extract', () => { describe('lib/manager/gitlabci-include/extract', () => {
describe('extractPackageFile()', () => { describe('extractPackageFile()', () => {
let config: ExtractConfig;
beforeEach(() => {
config = {
endpoint: 'http://gitlab.test/api/v4/',
};
});
it('returns null for empty', () => { it('returns null for empty', () => {
expect( expect(
extractPackageFile('nothing here', '.gitlab-ci.yml', config) extractPackageFile('nothing here', '.gitlab-ci.yml', {})
).toBeNull(); ).toBeNull();
}); });
it('extracts multiple include blocks', () => { it('extracts multiple include blocks', () => {
const res = extractPackageFile(yamlFile, '.gitlab-ci.yml', config); const res = extractPackageFile(yamlFile, '.gitlab-ci.yml', {});
expect(res.deps).toMatchSnapshot(); expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(3); expect(res.deps).toHaveLength(3);
}); });
it('normalizes configured endpoints', () => {
const endpoints = [
'http://gitlab.test/api/v4',
'http://gitlab.test/api/v4/',
];
endpoints.forEach(endpoint => {
const res = extractPackageFile(yamlFile, '.gitlab-ci.yml', {
endpoint,
});
expect(res.deps[0].registryUrls[0]).toEqual('http://gitlab.test');
});
});
}); });
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment