mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-03 11:03:39 +00:00
6293edc19a
Co-Authored-By: Michael Kriese <michael.kriese@visualon.de>
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import is from '@sindresorhus/is';
|
|
import yaml from 'js-yaml';
|
|
import { logger } from '../../logger';
|
|
import { PackageDependency, ExtractConfig, PackageFile } from '../common';
|
|
import * as datasourceGitlabTags from '../../datasource/gitlab-tags';
|
|
|
|
function extractDepFromInclude(includeObj: {
|
|
file: any;
|
|
project: string;
|
|
ref: string;
|
|
}): PackageDependency | null {
|
|
if (!includeObj.file || !includeObj.project) {
|
|
return null;
|
|
}
|
|
const dep: PackageDependency = {
|
|
datasource: datasourceGitlabTags.id,
|
|
depName: includeObj.project,
|
|
depType: 'repository',
|
|
};
|
|
if (!includeObj.ref) {
|
|
dep.skipReason = 'unknown-version';
|
|
return dep;
|
|
}
|
|
dep.currentValue = includeObj.ref;
|
|
return dep;
|
|
}
|
|
|
|
export function extractPackageFile(
|
|
content: string,
|
|
_packageFile: string,
|
|
config: ExtractConfig
|
|
): PackageFile | null {
|
|
const deps: PackageDependency[] = [];
|
|
try {
|
|
const doc = yaml.safeLoad(content, { json: true });
|
|
if (doc.include && is.array(doc.include)) {
|
|
for (const includeObj of doc.include) {
|
|
const dep = extractDepFromInclude(includeObj);
|
|
if (dep) {
|
|
if (config.endpoint) {
|
|
dep.registryUrls = [config.endpoint.replace(/\/api\/v4\/?/, '')];
|
|
}
|
|
deps.push(dep);
|
|
}
|
|
}
|
|
}
|
|
} catch (err) /* istanbul ignore next */ {
|
|
if (err.stack && err.stack.startsWith('YAMLException:')) {
|
|
logger.debug({ err });
|
|
logger.debug('YAML exception extracting GitLab CI includes');
|
|
} else {
|
|
logger.warn({ err }, 'Error extracting GitLab CI includes');
|
|
}
|
|
}
|
|
|
|
if (!deps.length) {
|
|
return null;
|
|
}
|
|
return { deps };
|
|
}
|