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

feat: correctly handle new field minUpgradeFormatScore #89

Merged
merged 1 commit into from
Oct 28, 2024
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
36 changes: 24 additions & 12 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "dotenv/config";

import { HTTPError } from "ky";
import fs from "node:fs";
import { MergedCustomFormatResource } from "./src/__generated__/mergedTypes";
import { configureRadarrApi, configureSonarrApi, getArrApi, unsetApi } from "./src/api";
Expand Down Expand Up @@ -211,19 +212,30 @@ const pipeline = async (value: ConfigArrInstance, arrType: ArrType) => {
} catch (error: any) {
let message;

if (error.response) {
logger.info(error.response);
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
message = `Failed creating QualityProfile (${element.name}): Data ${JSON.stringify(error.response.data)}`;
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
logger.info(error.request);
logger.debug(`Error creating QualityProfile: ${error?.name}`);

if (error instanceof HTTPError) {
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
const errorJson = await error.response.json();
logger.error(errorJson, `Failed creating QualityProfile (${element.name})`);
message = `Failed creating QualityProfile (${element.name}): Data ${JSON.stringify(errorJson)}`;
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
const errorJson = await error.request.json();
logger.error(errorJson, `Failed creating QualityProfile (${element.name}) during request (probably some connection errors)`);
message = `Failed creating QualityProfile (${element.name}): Data ${JSON.stringify(errorJson)}`;
} else {
// Something happened in setting up the request that triggered an Error
logger.error("Error", error.message);
}
} else {
// Something happened in setting up the request that triggered an Error
logger.info("Error", error.message);
message = `An not expected error happened. Feel free to open an issue with details to improve handling.`;
logger.error(message);
throw error;
}

throw new Error(message);
Expand Down
2 changes: 2 additions & 0 deletions src/__generated__/ky-client.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/__generated__/radarr/data-contracts.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/quality-profiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,16 @@ describe("QualityProfiles", async () => {
expect(result[2].name).toBe("WEB 1080p");
expect(result[2].allowed).toBe(true);
});

test("calculateQualityProfilesDiff - should diff if minUpgradeFormatScore is different", async ({}) => {
// TODO
});

test("calculateQualityProfilesDiff - should not diff if minUpgradeFormatScore is equal", async ({}) => {
// TODO
});

test("calculateQualityProfilesDiff - should not diff if minUpgradeFormatScore is not configured", async ({}) => {
// TODO
});
});
14 changes: 14 additions & 0 deletions src/quality-profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ export const calculateQualityProfilesDiff = async (
minFormatScore: value.min_format_score,
upgradeAllowed: value.upgrade.allowed,
formatItems: customFormatsMapped,
// required since sonarr 4.0.10 (radarr also)
minUpgradeFormatScore: value.upgrade.min_format_score ?? 1,
});
continue;
}
Expand Down Expand Up @@ -409,6 +411,18 @@ export const calculateQualityProfilesDiff = async (

changeList.push(`Upgrade until score diff: server: ${serverMatch.cutoffFormatScore} - expected: ${value.upgrade.until_score}`);
}

const configMinUpgradeFormatScore = value.upgrade.min_format_score ?? 1;

// if not configured ignore
if (value.upgrade.min_format_score != null && serverMatch.minUpgradeFormatScore !== configMinUpgradeFormatScore) {
updatedServerObject.minUpgradeFormatScore = configMinUpgradeFormatScore;
diffExist = true;

changeList.push(
`Min upgrade format score diff: server: ${serverMatch.cutoffFormatScore} - expected: ${configMinUpgradeFormatScore}`,
);
}
}

// CFs matching
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export type ConfigQualityProfile = {
allowed: boolean;
until_quality: string;
until_score: number;
min_format_score?: number; // default 1
};
min_format_score: number;
score_set: keyof TrashScores;
Expand Down