renovate/lib/manager/buildkite/extract.ts

79 lines
2.9 KiB
TypeScript
Raw Normal View History

import { logger } from '../../logger';
import { isVersion } from '../../versioning/semver';
import { PackageFile, PackageDependency } from '../common';
import { DATASOURCE_GITHUB_TAGS } from '../../constants/data-binary-source';
2018-06-01 15:12:08 +00:00
export function extractPackageFile(content: string): PackageFile | null {
const deps: PackageDependency[] = [];
try {
const lines = content.split('\n');
let isPluginsSection = false;
let pluginsIndent = '';
for (let lineNumber = 1; lineNumber <= lines.length; lineNumber += 1) {
const lineIdx = lineNumber - 1;
const line = lines[lineIdx];
const pluginsSection = /^(?<pluginsIndent>\s*)(-?\s*)plugins:/.exec(line);
if (pluginsSection) {
logger.trace(`Matched plugins on line ${lineNumber}`);
isPluginsSection = true;
pluginsIndent = pluginsSection.groups.pluginsIndent;
} else if (isPluginsSection) {
logger.debug(`serviceImageLine: "${line}"`);
const { currentIndent } = /^(?<currentIndent>\s*)/.exec(line).groups;
const depLineMatch = /^\s+(?:-\s+)?(?<depName>[^#]+)#(?<currentValue>[^:]+)/.exec(
line
);
if (currentIndent.length <= pluginsIndent.length) {
isPluginsSection = false;
pluginsIndent = '';
} else if (depLineMatch) {
const { depName, currentValue } = depLineMatch.groups;
logger.trace('depLineMatch');
let skipReason: string;
let repo: string;
2018-06-01 15:12:08 +00:00
if (depName.startsWith('https://') || depName.startsWith('git@')) {
2018-09-20 10:13:18 +00:00
logger.debug({ dependency: depName }, 'Skipping git plugin');
2018-06-01 15:12:08 +00:00
skipReason = 'git-plugin';
} else if (!isVersion(currentValue)) {
2018-06-01 15:12:08 +00:00
logger.debug(
{ currentValue },
2018-06-01 15:12:08 +00:00
'Skipping non-pinned current version'
);
skipReason = 'invalid-version';
} else {
const splitName = depName.split('/');
if (splitName.length === 1) {
repo = `buildkite-plugins/${depName}-buildkite-plugin`;
} else if (splitName.length === 2) {
repo = `${depName}-buildkite-plugin`;
} else {
logger.warn(
2018-09-20 10:13:18 +00:00
{ dependency: depName },
2018-06-01 15:12:08 +00:00
'Something is wrong with buildkite plugin name'
);
skipReason = 'unknown';
}
}
const dep: PackageDependency = {
2019-07-22 07:05:53 +00:00
managerData: { lineNumber },
depName,
currentValue,
2018-06-01 15:12:08 +00:00
skipReason,
};
if (repo) {
dep.datasource = DATASOURCE_GITHUB_TAGS;
dep.lookupName = repo;
}
deps.push(dep);
}
}
}
} catch (err) /* istanbul ignore next */ {
2019-07-02 05:08:48 +00:00
logger.warn({ err }, 'Error extracting buildkite plugins');
}
if (!deps.length) {
return null;
}
return { deps };
}