Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(manager): pass through UpdateArtifact generic type #18205

Merged
merged 3 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/modules/manager/flux/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import type { ExecOptions } from '../../../util/exec/types';
import { readLocalFile } from '../../../util/fs';
import type { UpdateArtifact, UpdateArtifactsResult } from '../types';
import { isSystemManifest } from './common';
import type { FluxManagerData } from './types';

export async function updateArtifacts({
packageFileName,
updatedDeps,
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
}: UpdateArtifact<FluxManagerData>): Promise<UpdateArtifactsResult[] | null> {
const systemDep = updatedDeps[0];
if (!isSystemManifest(packageFileName) || !systemDep?.newVersion) {
return null;
Expand Down
19 changes: 12 additions & 7 deletions lib/modules/manager/flux/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { GithubReleasesDatasource } from '../../datasource/github-releases';
import { HelmDatasource } from '../../datasource/helm';
import type { ExtractConfig, PackageDependency, PackageFile } from '../types';
import { isSystemManifest } from './common';
import type { FluxManifest, FluxResource, ResourceFluxManifest } from './types';
import type {
FluxManagerData,
FluxManifest,
FluxResource,
ResourceFluxManifest,
} from './types';

function readManifest(content: string, file: string): FluxManifest | null {
if (isSystemManifest(file)) {
Expand Down Expand Up @@ -68,14 +73,14 @@ function readManifest(content: string, file: string): FluxManifest | null {
function resolveManifest(
manifest: FluxManifest,
context: FluxManifest[]
): PackageDependency[] | null {
): PackageDependency<FluxManagerData>[] | null {
const resourceManifests = context.filter(
(manifest) => manifest.kind === 'resource'
) as ResourceFluxManifest[];
const repositories = resourceManifests.flatMap(
(manifest) => manifest.repositories
);
let res: PackageDependency[] | null = null;
let res: PackageDependency<FluxManagerData>[] | null = null;
switch (manifest.kind) {
case 'system':
res = [
Expand All @@ -91,7 +96,7 @@ function resolveManifest(
break;
case 'resource':
res = manifest.releases.map((release) => {
const dep: PackageDependency = {
const dep: PackageDependency<FluxManagerData> = {
depName: release.spec.chart.spec.chart,
currentValue: release.spec.chart.spec.version,
datasource: HelmDatasource.id,
Expand Down Expand Up @@ -122,7 +127,7 @@ function resolveManifest(
export function extractPackageFile(
content: string,
packageFile: string
): PackageFile | null {
): PackageFile<FluxManagerData> | null {
const manifest = readManifest(content, packageFile);
if (!manifest) {
return null;
Expand All @@ -134,9 +139,9 @@ export function extractPackageFile(
export async function extractAllPackageFiles(
_config: ExtractConfig,
packageFiles: string[]
): Promise<PackageFile[] | null> {
): Promise<PackageFile<FluxManagerData>[] | null> {
const manifests: FluxManifest[] = [];
const results: PackageFile[] = [];
const results: PackageFile<FluxManagerData>[] = [];

for (const file of packageFiles) {
const content = await readLocalFile(file, 'utf8');
Expand Down
4 changes: 4 additions & 0 deletions lib/modules/manager/flux/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export type FluxManagerData = {
components: string;
};

export interface KubernetesResource {
apiVersion: string;
metadata: {
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ export interface UpdateArtifactsResult {
file?: FileChange;
}

export interface UpdateArtifact {
export interface UpdateArtifact<T = Record<string, unknown>> {
packageFileName: string;
updatedDeps: PackageDependency[];
updatedDeps: PackageDependency<T>[];
newPackageFileContent: string;
config: UpdateArtifactsConfig;
}
Expand Down