Add release path module

This commit is contained in:
C-3PO 2018-06-22 18:16:59 +02:00
parent ee3fd0a60f
commit 620cb8bb1d
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -40,13 +40,35 @@ function getFroms({ product, to: releaseTo}: {product: string, to: number}) {
}
}
/** Checks whether there is a valid path between our current release and the release we want to update to, and returns true or false.
/**
* Checks whether there is a valid path between our current release and the release we want to update to, and returns an array with
* the release path, or an empty array if no path exists.
* E.g. for `{ from: 21, to: 24 }`, it returns [[21, 22], [22, 23], [23, 24]].
* Does not actually look at the manifest.xml file but theorizes on possible patches based on the usually created patches, allowing
* us to find release pathes for products that have not been released yet.
*/
export default function findReleasePath({ product, from, to}: {product: string, from: number, to: number}) {
//TODO: need to recursively get froms until path is found
//TODO: need to ignore patches that we know are bugged (i.e. missing from CDN)
return getFroms({ product, to }).includes(from);
//TODO: we also need to return the release path, e.g. [[3, 4], [4, 5], [5, 6]]
export default function findReleasePath({ product, from, to}: {product: string, from: number, to: number}): Array<[number, number]> {
//We assume that "from < to" is true for all patches
const froms = getFroms({ product, to });
//If we can patch, return immediately
if (froms.includes(from)) {
return [[from, to]];
}
//Otherwise, check all froms recursively, by checking interim releases
const smallerFroms = froms.filter((num) => num > from);
//Always prefer shortest release paths (e.g. 1->3 vs. 1->2->3) by ensuring we check smallest froms first
smallerFroms.sort();
for (let i = 0, il = smallerFroms.length; i < il; i += 1) {
const interim = smallerFroms[i];
const releasePath = findReleasePath({ product, from, to: interim} );
if (releasePath.length > 0) {
return [...releasePath, [interim, to]];
}
}
return [];
}