mirror of
https://github.com/karma-riuk/crab.git
synced 2025-07-05 13:38:12 +02:00
made code cleaner
This commit is contained in:
35
handlers.py
35
handlers.py
@ -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:
|
||||||
"""
|
"""
|
||||||
|
@ -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()
|
||||||
|
Reference in New Issue
Block a user