2021-06-17 23:40:05 -06:00
|
|
|
import { GalaxyCollectionDatasource } from '../../datasource/galaxy-collection';
|
2021-04-09 09:02:57 -06:00
|
|
|
import type { PackageDependency } from '../types';
|
|
|
|
import { dependencyRegex, galaxyRegEx } from './util';
|
|
|
|
|
|
|
|
export function extractCollectionsMetaDataFile(
|
2023-11-07 08:50:29 -07:00
|
|
|
lines: string[],
|
2021-04-09 09:02:57 -06:00
|
|
|
): PackageDependency[] {
|
|
|
|
const deps: PackageDependency[] = [];
|
|
|
|
// in a galaxy.yml the dependency map is inside a `dependencies:` block
|
|
|
|
let foundDependencyBlock = false;
|
|
|
|
for (let lineNumber = 0; lineNumber < lines.length; lineNumber += 1) {
|
|
|
|
const line = lines[lineNumber];
|
|
|
|
|
|
|
|
if (dependencyRegex.exec(line)) {
|
|
|
|
foundDependencyBlock = true;
|
|
|
|
} else if (foundDependencyBlock) {
|
|
|
|
// expects a line like this ` ansible.windows: "1.4.0"`
|
|
|
|
const galaxyRegExResult = galaxyRegEx.exec(line);
|
2022-04-17 06:34:26 -06:00
|
|
|
if (galaxyRegExResult?.groups) {
|
2021-04-09 09:02:57 -06:00
|
|
|
const dep: PackageDependency = {
|
|
|
|
depType: 'galaxy-collection',
|
2021-06-17 23:40:05 -06:00
|
|
|
datasource: GalaxyCollectionDatasource.id,
|
2022-03-03 08:08:43 -07:00
|
|
|
depName: galaxyRegExResult.groups.packageName,
|
2021-04-09 09:02:57 -06:00
|
|
|
currentValue: galaxyRegExResult.groups.version,
|
|
|
|
};
|
|
|
|
deps.push(dep);
|
|
|
|
} else {
|
|
|
|
// if we can not match additional lines, the block has ended.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return deps;
|
|
|
|
}
|