Skip to content

Commit

Permalink
refactor(workers/repository): Extract processUpdateArtifactResults me…
Browse files Browse the repository at this point in the history
…thod (#27324)
  • Loading branch information
not7cd committed Feb 17, 2024
1 parent 75d2d37 commit f9dc713
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions lib/workers/repository/update/branch/get-updated.ts
Expand Up @@ -6,6 +6,7 @@ import { get } from '../../../../modules/manager';
import type {
ArtifactError,
PackageDependency,
UpdateArtifactsResult,
} from '../../../../modules/manager/types';
import { getFile } from '../../../../util/git';
import type { FileAddition, FileChange } from '../../../../util/git/types';
Expand Down Expand Up @@ -299,16 +300,11 @@ export async function getUpdatedPackageFiles(
newPackageFileContent: packageFile.contents!.toString(),
config,
});
if (is.nonEmptyArray(results)) {
for (const res of results) {
const { file, artifactError } = res;
if (file) {
updatedArtifacts.push(file);
} else if (artifactError) {
artifactErrors.push(artifactError);
}
}
}
processUpdateArtifactResults(
results,
updatedArtifacts,
artifactErrors,
);
}
}
}
Expand All @@ -334,17 +330,13 @@ export async function getUpdatedPackageFiles(
newPackageFileContent: packageFile.contents!.toString(),
config,
});
processUpdateArtifactResults(
results,
updatedArtifacts,
artifactErrors,
);
if (is.nonEmptyArray(results)) {
updatedPackageFiles.push(packageFile);
for (const res of results) {
const { file, artifactError } = res;
// istanbul ignore else
if (file) {
updatedArtifacts.push(file);
} else if (artifactError) {
artifactErrors.push(artifactError);
}
}
}
}
}
Expand All @@ -367,16 +359,11 @@ export async function getUpdatedPackageFiles(
newPackageFileContent: packageFileContents!,
config,
});
if (is.nonEmptyArray(results)) {
for (const res of results) {
const { file, artifactError } = res;
if (file) {
updatedArtifacts.push(file);
} else if (artifactError) {
artifactErrors.push(artifactError);
}
}
}
processUpdateArtifactResults(
results,
updatedArtifacts,
artifactErrors,
);
}
}
}
Expand All @@ -389,3 +376,21 @@ export async function getUpdatedPackageFiles(
artifactErrors,
};
}

function processUpdateArtifactResults(
results: UpdateArtifactsResult[] | null,
updatedArtifacts: FileChange[],
artifactErrors: ArtifactError[],
): void {
if (is.nonEmptyArray(results)) {
for (const res of results) {
const { file, artifactError } = res;
// istanbul ignore else
if (file) {
updatedArtifacts.push(file);
} else if (artifactError) {
artifactErrors.push(artifactError);
}
}
}
}

0 comments on commit f9dc713

Please sign in to comment.