Skip to content

Commit 0b35330

Browse files
authored
doc+fix: actualizes use case notebook and also fixes displaying suspect parts and getting commit info.
Refs: #207
1 parent 6e4569a commit 0b35330

File tree

8 files changed

+290
-288
lines changed

8 files changed

+290
-288
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
UTIL_VERSION := 0.5.8
1+
UTIL_VERSION := 0.5.9
22
UTIL_NAME := codeplag
33
PWD := $(shell pwd)
44

docs/notebooks/usecases.ipynb

Lines changed: 237 additions & 242 deletions
Large diffs are not rendered by default.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"clang~=14.0.6",
1818
"llvmlite~=0.42.0",
1919
"libclang~=14.0.6",
20-
"python-decouple~=3.6",
20+
"python-decouple~=3.8",
2121
"requests~=2.31.0",
2222
"typing-extensions~=4.3.0",
2323
"aiohttp~=3.9.3",

src/codeplag/display.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def print_suspect_parts(
123123
column = 1
124124

125125
if row in ROWS:
126-
print(red_bold(symbol))
126+
print(red_bold(symbol), end="")
127127

128128
column += 1
129129

src/webparsers/async_github_parser.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from uritemplate import variable
1313

1414
from webparsers.types import (
15-
Branch,
15+
BranchInfo,
1616
Commit,
1717
GitHubContentUrl,
1818
GitHubRepoUrl,
@@ -186,8 +186,8 @@ async def _get_branch_last_commit_info(
186186

187187
return response["commit"]
188188

189-
async def get_list_repo_branches(self: Self, owner: str, repo: str) -> list[Branch]:
190-
branches: list[Branch] = []
189+
async def get_list_repo_branches(self: Self, owner: str, repo: str) -> list[BranchInfo]:
190+
branches: list[BranchInfo] = []
191191
url_vars = {"per_page": 100, "page": 1, "username": owner, "repo": repo}
192192
while True:
193193
response = await self.send_get_request(self.BRANCH_GET, url_vars)
@@ -198,7 +198,7 @@ async def get_list_repo_branches(self: Self, owner: str, repo: str) -> list[Bran
198198
branch_name = branch_info["name"]
199199
commit_info = await self.send_get_request(branch_info["commit"]["url"])
200200
branches.append(
201-
Branch(
201+
BranchInfo(
202202
name=branch_name,
203203
last_commit=Commit(
204204
commit_info["sha"],
@@ -248,7 +248,7 @@ async def get_files_generator_from_sha_commit(
248248
self: Self,
249249
owner: str,
250250
repo: str,
251-
branch: Branch,
251+
branch: BranchInfo,
252252
sha: str,
253253
path: str = "",
254254
path_regexp: re.Pattern | None = None,
@@ -266,7 +266,7 @@ async def get_files_generator_from_sha_commit(
266266
async for file_gen in self.get_files_generator_from_sha_commit(
267267
owner=owner,
268268
repo=repo,
269-
branch=Branch(branch.name, commit_info),
269+
branch=BranchInfo(branch.name, commit_info),
270270
sha=node["sha"],
271271
path=current_path,
272272
path_regexp=path_regexp,
@@ -307,7 +307,7 @@ async def get_files_generator_from_repo_url(
307307
repo_url.owner, repo_url.repo, default_branch
308308
)
309309
branches = [
310-
Branch(
310+
BranchInfo(
311311
name=default_branch,
312312
last_commit=Commit(
313313
commit_info["sha"],
@@ -384,7 +384,7 @@ async def get_files_generator_from_dir_url(
384384
async for work_info in self.get_files_generator_from_sha_commit(
385385
owner=dir_url.owner,
386386
repo=dir_url.repo,
387-
branch=Branch(dir_url.branch, commit_info),
387+
branch=BranchInfo(dir_url.branch, commit_info),
388388
sha=node["sha"],
389389
path=current_path,
390390
path_regexp=path_regexp,

src/webparsers/github_parser.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing_extensions import Self
99

1010
from webparsers.types import (
11-
Branch,
11+
BranchInfo,
1212
Commit,
1313
Extensions,
1414
GitHubContentUrl,
@@ -189,7 +189,7 @@ def get_files_generator_from_sha_commit(
189189
self: Self,
190190
owner: str,
191191
repo: str,
192-
branch: Branch,
192+
branch: BranchInfo,
193193
sha: str,
194194
path: str = "",
195195
path_regexp: re.Pattern | None = None,
@@ -206,7 +206,7 @@ def get_files_generator_from_sha_commit(
206206
yield from self.get_files_generator_from_sha_commit(
207207
owner=owner,
208208
repo=repo,
209-
branch=Branch(branch.name, commit_info),
209+
branch=BranchInfo(branch.name, commit_info),
210210
sha=node["sha"],
211211
path=current_path,
212212
path_regexp=path_regexp,
@@ -223,8 +223,8 @@ def get_files_generator_from_sha_commit(
223223

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

226-
def get_list_repo_branches(self: Self, owner: str, repo: str) -> list[Branch]:
227-
branches: list[Branch] = []
226+
def get_list_repo_branches(self: Self, owner: str, repo: str) -> list[BranchInfo]:
227+
branches: list[BranchInfo] = []
228228
api_url: str = f"/repos/{owner}/{repo}/branches"
229229
params: dict[str, int] = {"per_page": 100, "page": 1}
230230
while True:
@@ -233,12 +233,14 @@ def get_list_repo_branches(self: Self, owner: str, repo: str) -> list[Branch]:
233233
cnt = 0 # noqa: SIM113
234234
for node in response_json:
235235
cnt += 1
236-
commit_info = node["commit"]
236+
branch_name = node["name"]
237+
last_commit_sha = node["commit"]["sha"]
238+
commit_info = self._get_branch_last_commit_info(owner, repo, branch_name)
237239
branches.append(
238-
Branch(
239-
name=node["name"],
240+
BranchInfo(
241+
name=branch_name,
240242
last_commit=Commit(
241-
commit_info["sha"],
243+
last_commit_sha,
242244
commit_info["commit"]["author"]["date"],
243245
),
244246
)
@@ -267,7 +269,7 @@ def get_files_generator_from_repo_url(
267269
repo_url.owner, repo_url.repo, default_branch
268270
)
269271
branches = [
270-
Branch(
272+
BranchInfo(
271273
name=default_branch,
272274
last_commit=Commit(
273275
commit_info["sha"],
@@ -331,7 +333,7 @@ def get_files_generator_from_dir_url(
331333
yield from self.get_files_generator_from_sha_commit(
332334
owner=dir_url.owner,
333335
repo=dir_url.repo,
334-
branch=Branch(dir_url.branch, commit_info),
336+
branch=BranchInfo(dir_url.branch, commit_info),
335337
sha=node["sha"],
336338
path=current_path,
337339
path_regexp=path_regexp,

src/webparsers/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Commit(NamedTuple):
7373
date: str # TODO: convert to datetime or another
7474

7575

76-
class Branch(NamedTuple):
76+
class BranchInfo(NamedTuple):
7777
name: str
7878
last_commit: Commit
7979

test/unit/webparsers/test_github_parser.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing_extensions import Self
1010

1111
from webparsers.github_parser import GitHubParser
12-
from webparsers.types import Branch, Commit, PullRequest, Repository, WorkInfo
12+
from webparsers.types import BranchInfo, Commit, PullRequest, Repository, WorkInfo
1313

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

23-
_BRANCH1: Final[Branch] = Branch("iss76", _COMMIT1)
24-
_BRANCH2: Final[Branch] = Branch("iss78", _COMMIT2)
23+
_BRANCH1: Final[BranchInfo] = BranchInfo("iss76", _COMMIT1)
24+
_BRANCH2: Final[BranchInfo] = BranchInfo("iss78", _COMMIT2)
2525

2626
_GET_FILE_CONTENT_RES: Final[list[WorkInfo]] = [
2727
WorkInfo(
@@ -801,12 +801,25 @@ def test_get_list_repo_branches(self: Self, mock_send_get_request: MagicMock) ->
801801
"name": "main",
802802
"commit": {
803803
"sha": "0928jlskdfj",
804-
"commit": {"author": {"date": _COMMIT_DATE}},
805804
},
806805
}
807806
_BRANCH_INFO2 = {
808807
"name": "iss76",
809-
"commit": {"sha": "kjsadfwi", "commit": {"author": {"date": _COMMIT_DATE}}},
808+
"commit": {
809+
"sha": "kjsadfwi",
810+
},
811+
}
812+
_COMMIT_INFO1 = {
813+
"commit": {
814+
"sha": "0928jlskdfj",
815+
"commit": {"author": {"date": _COMMIT_DATE}},
816+
}
817+
}
818+
_COMMIT_INFO2 = {
819+
"commit": {
820+
"sha": "kjsadfwi",
821+
"commit": {"author": {"date": _COMMIT_DATE}},
822+
},
810823
}
811824

812825
test_cases = [
@@ -817,29 +830,21 @@ def test_get_list_repo_branches(self: Self, mock_send_get_request: MagicMock) ->
817830
"/repos/OSLL/aido-auto-feedback/branches",
818831
params=_REQUEST_PARAMS_1,
819832
),
833+
call(
834+
"/repos/OSLL/aido-auto-feedback/branches/main",
835+
),
836+
call(
837+
"/repos/OSLL/aido-auto-feedback/branches/iss76",
838+
),
820839
],
821840
"send_se": [
822841
Response([_BRANCH_INFO1, _BRANCH_INFO2]),
842+
Response(_COMMIT_INFO1),
843+
Response(_COMMIT_INFO2),
823844
],
824845
"expected_result": [
825-
Branch("main", Commit("0928jlskdfj", "2022-12-29T10:10:41Z")),
826-
Branch("iss76", Commit("kjsadfwi", "2022-12-29T10:10:41Z")),
827-
],
828-
},
829-
{
830-
"arguments": {
831-
"owner": "moevm",
832-
"repo": "asm_web_debug",
833-
},
834-
"send_calls": [
835-
call("/repos/moevm/asm_web_debug/branches", params=_REQUEST_PARAMS_1),
836-
],
837-
"send_se": [
838-
Response([_BRANCH_INFO1, _BRANCH_INFO2]),
839-
],
840-
"expected_result": [
841-
Branch("main", Commit("0928jlskdfj", _COMMIT_DATE)),
842-
Branch("iss76", Commit("kjsadfwi", _COMMIT_DATE)),
846+
BranchInfo("main", Commit("0928jlskdfj", _COMMIT_DATE)),
847+
BranchInfo("iss76", Commit("kjsadfwi", _COMMIT_DATE)),
843848
],
844849
},
845850
]

0 commit comments

Comments
 (0)