2018-06-03 15:00:58 +00:00
|
|
|
const versioning = require('../../versioning');
|
|
|
|
|
|
|
|
const { isPinnedVersion } = versioning('semver');
|
2018-06-01 15:12:08 +00:00
|
|
|
|
2018-04-27 17:54:44 +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';
|
|
|
|
}
|
|
|
|
}
|
2018-04-27 17:54:44 +00:00
|
|
|
deps.push({
|
|
|
|
lineNumber,
|
|
|
|
depName,
|
2018-06-01 15:12:08 +00:00
|
|
|
purl: repo ? 'pkg:github/' + repo : undefined,
|
2018-06-03 17:13:39 +00:00
|
|
|
versionScheme: 'semver',
|
2018-04-27 17:54:44 +00:00
|
|
|
currentVersion,
|
2018-06-01 15:12:08 +00:00
|
|
|
skipReason,
|
2018-04-27 17:54:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (err) /* istanbul ignore next */ {
|
|
|
|
logger.error(
|
|
|
|
{ err, message: err.message },
|
|
|
|
'Error extracting buildkite plugins'
|
|
|
|
);
|
|
|
|
}
|
2018-05-03 16:09:18 +00:00
|
|
|
if (!deps.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return { deps };
|
2018-04-27 17:54:44 +00:00
|
|
|
}
|