async function deleteOldBuilds(storageMethod, maxAgeInDays, skipBranches, onlyBranches) {
  if (!maxAgeInDays || !Number.isInteger(maxAgeInDays) || maxAgeInDays <= 0) {
    throw new Error('Invalid range');
  }

  const DAY_IN_MS = 24 * 60 * 60 * 1000;
  const cutoffTime = new Date(Date.now() - maxAgeInDays * DAY_IN_MS);
  const oldBuilds = (await storageMethod.findBuildsBeforeTimestamp(cutoffTime)).filter(
    ({branch}) => {
      if (Array.isArray(skipBranches) && skipBranches.includes(branch)) {
        return false;
      }
      if (Array.isArray(onlyBranches) && !onlyBranches.includes(branch)) return false;

      return true;
    }
  );

  for (const {projectId, id} of oldBuilds) {
    await storageMethod.deleteBuild(projectId, id);
  }
}
@param {LHCI.ServerCommand.StorageMethod} storageMethod
@param {number} maxAgeInDays
@param {string[] | null} skipBranches
@param {string[] | null} onlyBranches
@return {Promise<void>}