Skip to content

Commit 7b007f1

Browse files
committed
github-url added, github-project-folder github-files removed
1 parent a0ecf04 commit 7b007f1

File tree

6 files changed

+26
-45
lines changed

6 files changed

+26
-45
lines changed

src/codeplag/codeplagcli.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -321,25 +321,15 @@ def __add_check_path(self: Self, subparsers: argparse._SubParsersAction) -> None
321321
type=str,
322322
help=_("A regular expression to filter searching repositories on GitHub."),
323323
)
324-
check_github.add_argument(
325-
"-gf",
326-
"--github-files",
327-
metavar="GITHUB_FILE",
328-
type=GitHubContentUrl,
329-
help=_("URL to file in a GitHub repository."),
330-
nargs="+",
331-
action=CheckUniqueStore,
332-
default=[],
333-
)
334324
check_github.add_argument(
335325
"-gu", "--github-user", type=str, help=_("GitHub organization/user name.")
336326
)
337327
check_github.add_argument(
338-
"-gp",
339-
"--github-project-folders",
340-
metavar="GITHUB_PROJECT_FOLDER",
328+
"-gr",
329+
"--github-urls",
330+
metavar="GITHUB_URL",
341331
type=GitHubContentUrl,
342-
help=_("URL to a GitHub project folder."),
332+
help=_("URL to a GitHub file or folder"),
343333
nargs="+",
344334
action=CheckUniqueStore,
345335
default=[],
@@ -458,12 +448,12 @@ def validate_args(self: Self, parsed_args: argparse.Namespace) -> None:
458448
elif parsed_args.path_regexp and not (
459449
parsed_args.directories
460450
or parsed_args.github_user
461-
or parsed_args.github_project_folders
451+
or parsed_args.github_urls
462452
):
463453
self.error(
464454
_(
465455
"The'path-regexp' option requires the provided 'directories', "
466-
"'github-user', or 'github-project-folder' options."
456+
"'github-user', or 'github-urls' options."
467457
)
468458
)
469459
elif (

src/codeplag/utils.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515
from codeplag.handlers.settings import settings_modify, settings_show
1616
from codeplag.logger import codeplag_logger as logger
17-
from codeplag.types import ExitCode, ReportType
17+
from codeplag.types import ExitCode, ReportType, Extension
1818

1919

2020
class CodeplagEngine:
@@ -34,16 +34,18 @@ def __init__(self: Self, parsed_args: dict[str, Any]) -> None:
3434
self.first_root_path = parsed_args.pop("first_root_path", None)
3535
self.second_root_path = parsed_args.pop("second_root_path", None)
3636
else:
37-
self.github_files: list[str] = parsed_args.pop("github_files", [])
38-
self.github_project_folders: list[str] = parsed_args.pop("github_project_folders", [])
39-
self.github_user: str = parsed_args.pop("github_user", "") or ""
37+
files_extension: Extension = parsed_args.pop("extension")
38+
github_urls: list[str] = parsed_args.pop("github_urls", [])
39+
self.github_files: list[str] = list(filter(lambda url: '.' + files_extension in url, github_urls))
40+
self.github_project_folders: list[str] = list(filter(lambda url: '.' + files_extension not in url, github_urls))
41+
self.github_user: str = parsed_args.pop("github_user", "")
4042
ignore_threshold: bool = parsed_args.pop("ignore_threshold")
4143
if ignore_threshold:
4244
comparator_class = IgnoreThresholdWorksComparator
4345
else:
4446
comparator_class = WorksComparator
4547
self.comparator: WorksComparator = comparator_class(
46-
extension=parsed_args.pop("extension"),
48+
extension=files_extension,
4749
repo_regexp=parsed_args.pop("repo_regexp", None),
4850
path_regexp=parsed_args.pop("path_regexp", None),
4951
mode=parsed_args.pop("mode", DEFAULT_MODE),

test/auto/functional/test_check.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,10 @@ def test_check_util_version():
6060
True,
6161
),
6262
(
63-
["--github-files", *CPP_GITHUB_FILES],
63+
["--github-urls", *CPP_GITHUB_FILES, CPP_GITHUB_DIR],
6464
b"Getting works features from GitHub urls",
6565
True,
6666
),
67-
(
68-
["--github-project-folders", CPP_GITHUB_DIR],
69-
f"Getting works features from {CPP_GITHUB_DIR}".encode("utf-8"),
70-
True,
71-
),
7267
(
7368
["--github-user", "OSLL", "--repo-regexp", "code-plag"],
7469
f"Getting works features from {REPO_URL}".encode("utf-8"),
@@ -96,15 +91,10 @@ def test_compare_cpp_files(cmd: list[str], out: bytes, found_plag: bool):
9691
True,
9792
),
9893
(
99-
["--github-files", *PY_GITHUB_FILES],
94+
["--github-urls", *PY_GITHUB_FILES, PY_GITHUB_DIR],
10095
b"Getting works features from GitHub urls",
10196
False,
10297
),
103-
(
104-
["--github-project-folders", PY_GITHUB_DIR],
105-
f"Getting works features from {PY_GITHUB_DIR}".encode("utf-8"),
106-
False,
107-
),
10898
(
10999
["--github-user", "OSLL", "--repo-regexp", "code-plag"],
110100
f"Getting works features from {REPO_URL}".encode("utf-8"),
@@ -147,9 +137,8 @@ def test_check_short_output() -> None:
147137
"cmd",
148138
[
149139
["--files", *PY_FILES],
150-
["--github-files", *PY_GITHUB_FILES],
140+
["--github-urls", *PY_GITHUB_FILES, PY_GITHUB_DIR],
151141
["--directories", *PY_DIRS],
152-
["--github-project-folders", PY_GITHUB_DIR],
153142
],
154143
)
155144
def test_check_failed_when_repo_regexp_provided_without_required_args(
@@ -164,7 +153,7 @@ def test_check_failed_when_repo_regexp_provided_without_required_args(
164153
"cmd",
165154
[
166155
["--files", *PY_FILES],
167-
["--github-files", *PY_GITHUB_FILES],
156+
["--github-urls", *PY_GITHUB_FILES],
168157
],
169158
)
170159
def test_check_failed_when_path_regexp_provided_without_required_args(

test/auto/functional/test_mongo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def setup_module(mongo_connection: MongoDBConnection) -> Generator[None, None, N
8585
("--files", PY_SIM_FILES, "py", True),
8686
("--files", CPP_FILES, "cpp", False),
8787
("--files", CPP_SIM_FILES, "cpp", True),
88-
("--github-files", PY_GITHUB_FILES, "py", False),
89-
("--github-files", CPP_GITHUB_SIM_FILES, "cpp", True),
88+
("--github-urls", PY_GITHUB_FILES, "py", False),
89+
("--github-urls", CPP_GITHUB_SIM_FILES, "cpp", True),
9090
],
9191
)
9292
def test_correct_mongo_connection(
@@ -108,8 +108,8 @@ def test_correct_mongo_connection(
108108
("--files", PY_SIM_FILES, "py", True),
109109
("--files", CPP_FILES, "cpp", False),
110110
("--files", CPP_SIM_FILES, "cpp", True),
111-
("--github-files", PY_GITHUB_FILES, "py", False),
112-
("--github-files", CPP_GITHUB_SIM_FILES, "cpp", True),
111+
("--github-urls", PY_GITHUB_FILES, "py", False),
112+
("--github-urls", CPP_GITHUB_SIM_FILES, "cpp", True),
113113
],
114114
)
115115
def test_reading_metadata_and_reports_after_saving(
@@ -210,8 +210,8 @@ def test_saving_after_file_significant_change(
210210
("--files", PY_SIM_FILES, "py", True),
211211
("--files", CPP_FILES, "cpp", False),
212212
("--files", CPP_SIM_FILES, "cpp", True),
213-
("--github-files", PY_GITHUB_FILES, "py", False),
214-
("--github-files", CPP_GITHUB_SIM_FILES, "cpp", True),
213+
("--github-urls", PY_GITHUB_FILES, "py", False),
214+
("--github-urls", CPP_GITHUB_SIM_FILES, "cpp", True),
215215
],
216216
)
217217
def test_saving_metadata_and_reports(

test/auto/functional/test_stream_log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
def test_splitted_streams():
55
# Try to get a file that does not exist
66
github_file = "https://github.com/OSLL/code-plagiarism/blob/main/skfjkljflsd"
7-
result = run_check(["--github-files", github_file], extension="cpp")
7+
result = run_check(["--github-urls", github_file], extension="cpp")
88

99
stdout = result.cmd_res.stdout.decode("utf-8")
1010
stderr = result.cmd_res.stderr.decode("utf-8")

test/unit/codeplag/test_codeplagcli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ def test_file_path_bad(path: str):
6464
"check",
6565
"--extension",
6666
"py",
67-
"--github-project-folders",
67+
"--github-urls",
6868
"https://github.com/OSLL/code-plagiarism/tree/main/src",
6969
"https://github.com/OSLL/code-plagiarism/tree/main/src",
7070
],
7171
[
7272
"check",
7373
"--extension",
7474
"py",
75-
"--github-files",
75+
"--github-urls",
7676
"https://github.com/OSLL/code-plagiarism/blob/main/setup.py",
7777
"https://github.com/OSLL/code-plagiarism/blob/main/setup.py",
7878
],

0 commit comments

Comments
 (0)