Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
24 changes: 6 additions & 18 deletions src/codeplag/codeplagcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,25 +321,15 @@ def __add_check_path(self: Self, subparsers: argparse._SubParsersAction) -> None
type=str,
help=_("A regular expression to filter searching repositories on GitHub."),
)
check_github.add_argument(
"-gf",
"--github-files",
metavar="GITHUB_FILE",
type=GitHubContentUrl,
help=_("URL to file in a GitHub repository."),
nargs="+",
action=CheckUniqueStore,
default=[],
)
check_github.add_argument(
"-gu", "--github-user", type=str, help=_("GitHub organization/user name.")
)
check_github.add_argument(
"-gp",
"--github-project-folders",
metavar="GITHUB_PROJECT_FOLDER",
"-gr",
"--github-urls",
metavar="GITHUB_URL",
type=GitHubContentUrl,
help=_("URL to a GitHub project folder."),
help=_("URL to a GitHub file or folder"),
nargs="+",
action=CheckUniqueStore,
default=[],
Expand Down Expand Up @@ -456,14 +446,12 @@ def validate_args(self: Self, parsed_args: argparse.Namespace) -> None:
_("The'repo-regexp' option requires the provided 'github-user' option.")
)
elif parsed_args.path_regexp and not (
parsed_args.directories
or parsed_args.github_user
or parsed_args.github_project_folders
parsed_args.directories or parsed_args.github_user or parsed_args.github_urls
):
self.error(
_(
"The'path-regexp' option requires the provided 'directories', "
"'github-user', or 'github-project-folder' options."
"'github-user', or 'github-urls' options."
)
)
elif (
Expand Down
16 changes: 11 additions & 5 deletions src/codeplag/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from codeplag.handlers.settings import settings_modify, settings_show
from codeplag.logger import codeplag_logger as logger
from codeplag.types import ExitCode, ReportType
from codeplag.types import ExitCode, Extension, ReportType


class CodeplagEngine:
Expand All @@ -34,16 +34,22 @@ def __init__(self: Self, parsed_args: dict[str, Any]) -> None:
self.first_root_path = parsed_args.pop("first_root_path", None)
self.second_root_path = parsed_args.pop("second_root_path", None)
else:
self.github_files: list[str] = parsed_args.pop("github_files", [])
self.github_project_folders: list[str] = parsed_args.pop("github_project_folders", [])
self.github_user: str = parsed_args.pop("github_user", "") or ""
files_extension: Extension = parsed_args.pop("extension")
github_urls: list[str] = parsed_args.pop("github_urls", [])
self.github_files: list[str] = list(
filter(lambda url: "." + files_extension in url, github_urls)
)
self.github_project_folders: list[str] = list(
filter(lambda url: "." + files_extension not in url, github_urls)
)
self.github_user: str = parsed_args.pop("github_user", "")
ignore_threshold: bool = parsed_args.pop("ignore_threshold")
if ignore_threshold:
comparator_class = IgnoreThresholdWorksComparator
else:
comparator_class = WorksComparator
self.comparator: WorksComparator = comparator_class(
extension=parsed_args.pop("extension"),
extension=files_extension,
repo_regexp=parsed_args.pop("repo_regexp", None),
path_regexp=parsed_args.pop("path_regexp", None),
mode=parsed_args.pop("mode", DEFAULT_MODE),
Expand Down
19 changes: 4 additions & 15 deletions test/auto/functional/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,10 @@ def test_check_util_version():
True,
),
(
["--github-files", *CPP_GITHUB_FILES],
["--github-urls", *CPP_GITHUB_FILES, CPP_GITHUB_DIR],
b"Getting works features from GitHub urls",
True,
),
(
["--github-project-folders", CPP_GITHUB_DIR],
f"Getting works features from {CPP_GITHUB_DIR}".encode("utf-8"),
True,
),
(
["--github-user", "OSLL", "--repo-regexp", "code-plag"],
f"Getting works features from {REPO_URL}".encode("utf-8"),
Expand Down Expand Up @@ -96,15 +91,10 @@ def test_compare_cpp_files(cmd: list[str], out: bytes, found_plag: bool):
True,
),
(
["--github-files", *PY_GITHUB_FILES],
["--github-urls", *PY_GITHUB_FILES, PY_GITHUB_DIR],
b"Getting works features from GitHub urls",
False,
),
(
["--github-project-folders", PY_GITHUB_DIR],
f"Getting works features from {PY_GITHUB_DIR}".encode("utf-8"),
False,
),
(
["--github-user", "OSLL", "--repo-regexp", "code-plag"],
f"Getting works features from {REPO_URL}".encode("utf-8"),
Expand Down Expand Up @@ -147,9 +137,8 @@ def test_check_short_output() -> None:
"cmd",
[
["--files", *PY_FILES],
["--github-files", *PY_GITHUB_FILES],
["--github-urls", *PY_GITHUB_FILES, PY_GITHUB_DIR],
["--directories", *PY_DIRS],
["--github-project-folders", PY_GITHUB_DIR],
],
)
def test_check_failed_when_repo_regexp_provided_without_required_args(
Expand All @@ -164,7 +153,7 @@ def test_check_failed_when_repo_regexp_provided_without_required_args(
"cmd",
[
["--files", *PY_FILES],
["--github-files", *PY_GITHUB_FILES],
["--github-urls", *PY_GITHUB_FILES],
],
)
def test_check_failed_when_path_regexp_provided_without_required_args(
Expand Down
12 changes: 6 additions & 6 deletions test/auto/functional/test_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def setup_module(mongo_connection: MongoDBConnection) -> Generator[None, None, N
("--files", PY_SIM_FILES, "py", True),
("--files", CPP_FILES, "cpp", False),
("--files", CPP_SIM_FILES, "cpp", True),
("--github-files", PY_GITHUB_FILES, "py", False),
("--github-files", CPP_GITHUB_SIM_FILES, "cpp", True),
("--github-urls", PY_GITHUB_FILES, "py", False),
("--github-urls", CPP_GITHUB_SIM_FILES, "cpp", True),
],
)
def test_correct_mongo_connection(
Expand All @@ -108,8 +108,8 @@ def test_correct_mongo_connection(
("--files", PY_SIM_FILES, "py", True),
("--files", CPP_FILES, "cpp", False),
("--files", CPP_SIM_FILES, "cpp", True),
("--github-files", PY_GITHUB_FILES, "py", False),
("--github-files", CPP_GITHUB_SIM_FILES, "cpp", True),
("--github-urls", PY_GITHUB_FILES, "py", False),
("--github-urls", CPP_GITHUB_SIM_FILES, "cpp", True),
],
)
def test_reading_metadata_and_reports_after_saving(
Expand Down Expand Up @@ -210,8 +210,8 @@ def test_saving_after_file_significant_change(
("--files", PY_SIM_FILES, "py", True),
("--files", CPP_FILES, "cpp", False),
("--files", CPP_SIM_FILES, "cpp", True),
("--github-files", PY_GITHUB_FILES, "py", False),
("--github-files", CPP_GITHUB_SIM_FILES, "cpp", True),
("--github-urls", PY_GITHUB_FILES, "py", False),
("--github-urls", CPP_GITHUB_SIM_FILES, "cpp", True),
],
)
def test_saving_metadata_and_reports(
Expand Down
2 changes: 1 addition & 1 deletion test/auto/functional/test_stream_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def test_splitted_streams():
# Try to get a file that does not exist
github_file = "https://github.com/OSLL/code-plagiarism/blob/main/skfjkljflsd"
result = run_check(["--github-files", github_file], extension="cpp")
result = run_check(["--github-urls", github_file], extension="cpp")

stdout = result.cmd_res.stdout.decode("utf-8")
stderr = result.cmd_res.stderr.decode("utf-8")
Expand Down
4 changes: 2 additions & 2 deletions test/unit/codeplag/test_codeplagcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ def test_file_path_bad(path: str):
"check",
"--extension",
"py",
"--github-project-folders",
"--github-urls",
"https://github.com/OSLL/code-plagiarism/tree/main/src",
"https://github.com/OSLL/code-plagiarism/tree/main/src",
],
[
"check",
"--extension",
"py",
"--github-files",
"--github-urls",
"https://github.com/OSLL/code-plagiarism/blob/main/setup.py",
"https://github.com/OSLL/code-plagiarism/blob/main/setup.py",
],
Expand Down
Loading