made code cleaner

This commit is contained in:
Karma Riuk
2025-03-18 11:48:36 +01:00
parent 6a857b2a9d
commit dfbc6f5afa
2 changed files with 22 additions and 30 deletions

View File

@ -274,29 +274,32 @@ class GradleHandler(BuildHandler):
def get_jacoco_report_paths(self) -> Iterable[str]: def get_jacoco_report_paths(self) -> Iterable[str]:
raise GradleAggregateReportNotFound("Gradle does not generate a single coverage report file") raise GradleAggregateReportNotFound("Gradle does not generate a single coverage report file")
class NoTestsFoundError(Exception): class HandlerException(Exception):
pass reason_for_failure = "Generic handler expection (this shouldn't appear)"
class FailedToCompileError(Exception): class NoTestsFoundError(HandlerException):
pass reason_for_failure = "No tests found"
class FailedToTestError(Exception): class FailedToCompileError(HandlerException):
pass reason_for_failure = "Failed to compile"
class NoTestResultsToExtractError(Exception): class FailedToTestError(HandlerException):
pass reason_for_failure = "Failed to test"
class CantExecJacoco(Exception): class NoTestResultsToExtractError(HandlerException):
pass reason_for_failure = "Failed to extract test results"
class NoCoverageReportFound(Exception): class CantExecJacoco(HandlerException):
pass reason_for_failure = "Couldn't execute jacoco"
class FileNotCovered(Exception): class NoCoverageReportFound(HandlerException):
pass reason_for_failure = "No coverage report was found"
class GradleAggregateReportNotFound(Exception): class FileNotCovered(HandlerException):
pass reason_for_failure = "Files from the PR were not covered"
class GradleAggregateReportNotFound(HandlerException):
reason_for_failure = "Couldn't find the aggregate report (with gradle it's messy)"
def merge_download_lines(lines: list) -> list: def merge_download_lines(lines: list) -> list:
""" """

View File

@ -8,7 +8,7 @@ from tqdm import tqdm
from datetime import datetime from datetime import datetime
from dataset import Dataset, DatasetEntry, FileData, Metadata from dataset import Dataset, DatasetEntry, FileData, Metadata
from handlers import CantExecJacoco, FailedToCompileError, FailedToTestError, FileNotCovered, GradleAggregateReportNotFound, NoCoverageReportFound, NoTestsFoundError, NoTestResultsToExtractError, get_build_handler from handlers import FileNotCovered, HandlerException, get_build_handler
from utils import has_only_1_comment, move_github_logging_to_file, clone from utils import has_only_1_comment, move_github_logging_to_file, clone
@ -154,26 +154,15 @@ def process_pull(repo: Repository, pr: PullRequest, dataset: Dataset, repos_dir:
("Checking coverage...", lambda: _check_coverage([file.filename for file in pr.get_files()])), ("Checking coverage...", lambda: _check_coverage([file.filename for file in pr.get_files()])),
] ]
error_map = {
NoTestsFoundError: "No tests found",
FailedToCompileError: "Failed to compile",
FailedToTestError: "Failed to test",
NoTestResultsToExtractError: "Failed to extract test results",
CantExecJacoco: "Couldn't execute jacoco",
NoCoverageReportFound: "No coverage report was found",
FileNotCovered: "Files from the PR were not covered",
GradleAggregateReportNotFound: "Couldn't find the aggregate report (with gradle it's messy)",
}
with build_handler, tqdm(total=len(steps), desc="Processing PR", leave=False) as pbar: with build_handler, tqdm(total=len(steps), desc="Processing PR", leave=False) as pbar:
try: try:
for message, action in steps: for message, action in steps:
pbar.set_postfix({"doing": message, "started at": datetime.now().strftime("%d/%m, %H:%M:%S")}) pbar.set_postfix({"doing": message, "started at": datetime.now().strftime("%d/%m, %H:%M:%S")})
action() action()
pbar.update(1) pbar.update(1)
except tuple(error_map) as e: except HandlerException as e:
entry.metadata.last_cmd_error_msg = str(e) entry.metadata.last_cmd_error_msg = str(e)
entry.metadata.reason_for_failure = error_map[type(e)] entry.metadata.reason_for_failure = e.reason_for_failure
entry.metadata.successful = False entry.metadata.successful = False
finally: finally:
build_handler.clean_repo() build_handler.clean_repo()