renovate/lib/manager/buildkite/extract.js

74 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-06-03 15:00:58 +00:00
const versioning = require('../../versioning');
const { isPinnedVersion } = versioning('semver');
2018-06-01 15:12:08 +00:00
module.exports = {
extractDependencies,
};
function extractDependencies(content) {
logger.debug('buildkite.extractDependencies()');
logger.trace({ content });
const deps = [];
try {
const lines = content.split('\n');
for (let lineNumber = 0; lineNumber < lines.length; lineNumber += 1) {
const line = lines[lineNumber];
const plugins = line.match(/^\s*-?\s*plugins:\s*$/);
if (plugins) {
logger.trace(`Matched plugins on line ${lineNumber}`);
const depLine = lines[lineNumber + 1];
logger.debug(`serviceImageLine: "${depLine}"`);
const depLineMatch = depLine.match(/^\s+([^#]+)#([^:]+):/);
if (depLineMatch) {
logger.trace('depLineMatch');
lineNumber += 1;
const [, depName, currentVersion] = depLineMatch;
2018-06-01 15:12:08 +00:00
let skipReason;
let repo;
if (depName.startsWith('https://') || depName.startsWith('git@')) {
logger.debug({ depName }, 'Skipping git plugin');
skipReason = 'git-plugin';
} else if (!isPinnedVersion(currentVersion)) {
logger.debug(
{ currentVersion },
'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(
{ depName },
'Something is wrong with buildkite plugin name'
);
skipReason = 'unknown';
}
}
deps.push({
lineNumber,
depName,
2018-06-01 15:12:08 +00:00
purl: repo ? 'pkg:github/' + repo : undefined,
versionScheme: 'semver',
currentVersion,
2018-06-01 15:12:08 +00:00
skipReason,
});
}
}
}
} catch (err) /* istanbul ignore next */ {
logger.error(
{ err, message: err.message },
'Error extracting buildkite plugins'
);
}
if (!deps.length) {
return null;
}
return { deps };
}