Skip to content

Commit

Permalink
doc+fix: actualizes use case notebook and also fixes displaying suspe…
Browse files Browse the repository at this point in the history
…ct parts and getting commit info.

Refs: #207
  • Loading branch information
Artanias authored Dec 31, 2024
1 parent 6e4569a commit 0b35330
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 288 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
UTIL_VERSION := 0.5.8
UTIL_VERSION := 0.5.9
UTIL_NAME := codeplag
PWD := $(shell pwd)

Expand Down
479 changes: 237 additions & 242 deletions docs/notebooks/usecases.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"clang~=14.0.6",
"llvmlite~=0.42.0",
"libclang~=14.0.6",
"python-decouple~=3.6",
"python-decouple~=3.8",
"requests~=2.31.0",
"typing-extensions~=4.3.0",
"aiohttp~=3.9.3",
Expand Down
2 changes: 1 addition & 1 deletion src/codeplag/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def print_suspect_parts(
column = 1

if row in ROWS:
print(red_bold(symbol))
print(red_bold(symbol), end="")

column += 1

Expand Down
16 changes: 8 additions & 8 deletions src/webparsers/async_github_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from uritemplate import variable

from webparsers.types import (
Branch,
BranchInfo,
Commit,
GitHubContentUrl,
GitHubRepoUrl,
Expand Down Expand Up @@ -186,8 +186,8 @@ async def _get_branch_last_commit_info(

return response["commit"]

async def get_list_repo_branches(self: Self, owner: str, repo: str) -> list[Branch]:
branches: list[Branch] = []
async def get_list_repo_branches(self: Self, owner: str, repo: str) -> list[BranchInfo]:
branches: list[BranchInfo] = []
url_vars = {"per_page": 100, "page": 1, "username": owner, "repo": repo}
while True:
response = await self.send_get_request(self.BRANCH_GET, url_vars)
Expand All @@ -198,7 +198,7 @@ async def get_list_repo_branches(self: Self, owner: str, repo: str) -> list[Bran
branch_name = branch_info["name"]
commit_info = await self.send_get_request(branch_info["commit"]["url"])
branches.append(
Branch(
BranchInfo(
name=branch_name,
last_commit=Commit(
commit_info["sha"],
Expand Down Expand Up @@ -248,7 +248,7 @@ async def get_files_generator_from_sha_commit(
self: Self,
owner: str,
repo: str,
branch: Branch,
branch: BranchInfo,
sha: str,
path: str = "",
path_regexp: re.Pattern | None = None,
Expand All @@ -266,7 +266,7 @@ async def get_files_generator_from_sha_commit(
async for file_gen in self.get_files_generator_from_sha_commit(
owner=owner,
repo=repo,
branch=Branch(branch.name, commit_info),
branch=BranchInfo(branch.name, commit_info),
sha=node["sha"],
path=current_path,
path_regexp=path_regexp,
Expand Down Expand Up @@ -307,7 +307,7 @@ async def get_files_generator_from_repo_url(
repo_url.owner, repo_url.repo, default_branch
)
branches = [
Branch(
BranchInfo(
name=default_branch,
last_commit=Commit(
commit_info["sha"],
Expand Down Expand Up @@ -384,7 +384,7 @@ async def get_files_generator_from_dir_url(
async for work_info in self.get_files_generator_from_sha_commit(
owner=dir_url.owner,
repo=dir_url.repo,
branch=Branch(dir_url.branch, commit_info),
branch=BranchInfo(dir_url.branch, commit_info),
sha=node["sha"],
path=current_path,
path_regexp=path_regexp,
Expand Down
24 changes: 13 additions & 11 deletions src/webparsers/github_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing_extensions import Self

from webparsers.types import (
Branch,
BranchInfo,
Commit,
Extensions,
GitHubContentUrl,
Expand Down Expand Up @@ -189,7 +189,7 @@ def get_files_generator_from_sha_commit(
self: Self,
owner: str,
repo: str,
branch: Branch,
branch: BranchInfo,
sha: str,
path: str = "",
path_regexp: re.Pattern | None = None,
Expand All @@ -206,7 +206,7 @@ def get_files_generator_from_sha_commit(
yield from self.get_files_generator_from_sha_commit(
owner=owner,
repo=repo,
branch=Branch(branch.name, commit_info),
branch=BranchInfo(branch.name, commit_info),
sha=node["sha"],
path=current_path,
path_regexp=path_regexp,
Expand All @@ -223,8 +223,8 @@ def get_files_generator_from_sha_commit(

yield self.get_file_content_by_sha(owner, repo, node["sha"], commit_info, full_link)

def get_list_repo_branches(self: Self, owner: str, repo: str) -> list[Branch]:
branches: list[Branch] = []
def get_list_repo_branches(self: Self, owner: str, repo: str) -> list[BranchInfo]:
branches: list[BranchInfo] = []
api_url: str = f"/repos/{owner}/{repo}/branches"
params: dict[str, int] = {"per_page": 100, "page": 1}
while True:
Expand All @@ -233,12 +233,14 @@ def get_list_repo_branches(self: Self, owner: str, repo: str) -> list[Branch]:
cnt = 0 # noqa: SIM113
for node in response_json:
cnt += 1
commit_info = node["commit"]
branch_name = node["name"]
last_commit_sha = node["commit"]["sha"]
commit_info = self._get_branch_last_commit_info(owner, repo, branch_name)
branches.append(
Branch(
name=node["name"],
BranchInfo(
name=branch_name,
last_commit=Commit(
commit_info["sha"],
last_commit_sha,
commit_info["commit"]["author"]["date"],
),
)
Expand Down Expand Up @@ -267,7 +269,7 @@ def get_files_generator_from_repo_url(
repo_url.owner, repo_url.repo, default_branch
)
branches = [
Branch(
BranchInfo(
name=default_branch,
last_commit=Commit(
commit_info["sha"],
Expand Down Expand Up @@ -331,7 +333,7 @@ def get_files_generator_from_dir_url(
yield from self.get_files_generator_from_sha_commit(
owner=dir_url.owner,
repo=dir_url.repo,
branch=Branch(dir_url.branch, commit_info),
branch=BranchInfo(dir_url.branch, commit_info),
sha=node["sha"],
path=current_path,
path_regexp=path_regexp,
Expand Down
2 changes: 1 addition & 1 deletion src/webparsers/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Commit(NamedTuple):
date: str # TODO: convert to datetime or another


class Branch(NamedTuple):
class BranchInfo(NamedTuple):
name: str
last_commit: Commit

Expand Down
51 changes: 28 additions & 23 deletions test/unit/webparsers/test_github_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing_extensions import Self

from webparsers.github_parser import GitHubParser
from webparsers.types import Branch, Commit, PullRequest, Repository, WorkInfo
from webparsers.types import BranchInfo, Commit, PullRequest, Repository, WorkInfo

_REQUEST_PARAMS_1 = {"per_page": 100, "page": 1}
_REQUEST_PARAMS_3 = {"per_page": 100, "page": 3}
Expand All @@ -20,8 +20,8 @@
_COMMIT1_RESP = [{"sha": _COMMIT1.sha, "commit": {"author": {"date": _COMMIT1.date}}}]
_COMMIT2_RESP = [{"sha": _COMMIT2.sha, "commit": {"author": {"date": _COMMIT2.date}}}]

_BRANCH1: Final[Branch] = Branch("iss76", _COMMIT1)
_BRANCH2: Final[Branch] = Branch("iss78", _COMMIT2)
_BRANCH1: Final[BranchInfo] = BranchInfo("iss76", _COMMIT1)
_BRANCH2: Final[BranchInfo] = BranchInfo("iss78", _COMMIT2)

_GET_FILE_CONTENT_RES: Final[list[WorkInfo]] = [
WorkInfo(
Expand Down Expand Up @@ -801,12 +801,25 @@ def test_get_list_repo_branches(self: Self, mock_send_get_request: MagicMock) ->
"name": "main",
"commit": {
"sha": "0928jlskdfj",
"commit": {"author": {"date": _COMMIT_DATE}},
},
}
_BRANCH_INFO2 = {
"name": "iss76",
"commit": {"sha": "kjsadfwi", "commit": {"author": {"date": _COMMIT_DATE}}},
"commit": {
"sha": "kjsadfwi",
},
}
_COMMIT_INFO1 = {
"commit": {
"sha": "0928jlskdfj",
"commit": {"author": {"date": _COMMIT_DATE}},
}
}
_COMMIT_INFO2 = {
"commit": {
"sha": "kjsadfwi",
"commit": {"author": {"date": _COMMIT_DATE}},
},
}

test_cases = [
Expand All @@ -817,29 +830,21 @@ def test_get_list_repo_branches(self: Self, mock_send_get_request: MagicMock) ->
"/repos/OSLL/aido-auto-feedback/branches",
params=_REQUEST_PARAMS_1,
),
call(
"/repos/OSLL/aido-auto-feedback/branches/main",
),
call(
"/repos/OSLL/aido-auto-feedback/branches/iss76",
),
],
"send_se": [
Response([_BRANCH_INFO1, _BRANCH_INFO2]),
Response(_COMMIT_INFO1),
Response(_COMMIT_INFO2),
],
"expected_result": [
Branch("main", Commit("0928jlskdfj", "2022-12-29T10:10:41Z")),
Branch("iss76", Commit("kjsadfwi", "2022-12-29T10:10:41Z")),
],
},
{
"arguments": {
"owner": "moevm",
"repo": "asm_web_debug",
},
"send_calls": [
call("/repos/moevm/asm_web_debug/branches", params=_REQUEST_PARAMS_1),
],
"send_se": [
Response([_BRANCH_INFO1, _BRANCH_INFO2]),
],
"expected_result": [
Branch("main", Commit("0928jlskdfj", _COMMIT_DATE)),
Branch("iss76", Commit("kjsadfwi", _COMMIT_DATE)),
BranchInfo("main", Commit("0928jlskdfj", _COMMIT_DATE)),
BranchInfo("iss76", Commit("kjsadfwi", _COMMIT_DATE)),
],
},
]
Expand Down

0 comments on commit 0b35330

Please sign in to comment.