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]:
raise GradleAggregateReportNotFound("Gradle does not generate a single coverage report file")
class NoTestsFoundError(Exception):
pass
class HandlerException(Exception):
reason_for_failure = "Generic handler expection (this shouldn't appear)"
class FailedToCompileError(Exception):
pass
class NoTestsFoundError(HandlerException):
reason_for_failure = "No tests found"
class FailedToTestError(Exception):
pass
class FailedToCompileError(HandlerException):
reason_for_failure = "Failed to compile"
class NoTestResultsToExtractError(Exception):
pass
class FailedToTestError(HandlerException):
reason_for_failure = "Failed to test"
class CantExecJacoco(Exception):
pass
class NoTestResultsToExtractError(HandlerException):
reason_for_failure = "Failed to extract test results"
class NoCoverageReportFound(Exception):
pass
class CantExecJacoco(HandlerException):
reason_for_failure = "Couldn't execute jacoco"
class FileNotCovered(Exception):
pass
class NoCoverageReportFound(HandlerException):
reason_for_failure = "No coverage report was found"
class GradleAggregateReportNotFound(Exception):
pass
class FileNotCovered(HandlerException):
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:
"""

View File

@ -8,7 +8,7 @@ from tqdm import tqdm
from datetime import datetime
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
@ -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()])),
]
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:
try:
for message, action in steps:
pbar.set_postfix({"doing": message, "started at": datetime.now().strftime("%d/%m, %H:%M:%S")})
action()
pbar.update(1)
except tuple(error_map) as e:
except HandlerException as 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
finally:
build_handler.clean_repo()