optimized getting reading directories, started work on dir tree in file view
This commit is contained in:
@@ -4,7 +4,7 @@ from textual.widgets import Input, Select, TextArea, LoadingIndicator, Static, D
|
||||
from textual.containers import VerticalGroup, Vertical, HorizontalGroup, Right
|
||||
from textual import work
|
||||
|
||||
from widgets import Navbar
|
||||
from widgets import Navbar, RepoDirectoryTree
|
||||
|
||||
from datetime import datetime
|
||||
from human_readable import time_delta
|
||||
@@ -180,7 +180,10 @@ class RepoViewScreen(Screen):
|
||||
|
||||
# get files in dir
|
||||
files_response = requests.get(
|
||||
self.app.GITEA_HOST + f"api/v1/repos/{self.owner_name}/{self.repo_name}/contents/{path}"
|
||||
self.app.GITEA_HOST + f"api/v1/repos/{self.owner_name}/{self.repo_name}/contents-ext/{path}",
|
||||
params={
|
||||
"includes": "commit_metadata,commit_message"
|
||||
}
|
||||
)
|
||||
|
||||
if not files_response.ok:
|
||||
@@ -212,32 +215,6 @@ class RepoViewScreen(Screen):
|
||||
print("Getting root commits...")
|
||||
|
||||
rows = []
|
||||
commit_page_number = 1
|
||||
page_size = 50
|
||||
commit_data = {}
|
||||
|
||||
# loop over all the root commits until we get em' all
|
||||
while True:
|
||||
commits = requests.get(
|
||||
self.app.GITEA_HOST + f"api/v1/repos/{self.owner_name}/{self.repo_name}/commits",
|
||||
params={
|
||||
"path": path,
|
||||
"verification": False,
|
||||
"files": False,
|
||||
"stat": False,
|
||||
"page": commit_page_number,
|
||||
"limit": page_size,
|
||||
}
|
||||
).json()
|
||||
|
||||
|
||||
commit_data.update({commit["sha"]: commit for commit in commits})
|
||||
|
||||
if len(commits) == page_size: # we reached end of the page
|
||||
commit_page_number += 1
|
||||
print("Next page...")
|
||||
else:
|
||||
break
|
||||
|
||||
|
||||
found_readme = False
|
||||
@@ -251,14 +228,12 @@ class RepoViewScreen(Screen):
|
||||
""
|
||||
))
|
||||
|
||||
for file in files_response.json():
|
||||
commit = commit_data[file["last_commit_sha"]]
|
||||
|
||||
commit_created_at = datetime.fromisoformat(commit["created"]).replace(tzinfo=None)
|
||||
for file in files_response.json()["dir_contents"]:
|
||||
commit_created_at = datetime.fromisoformat(file["last_committer_date"]).replace(tzinfo=None)
|
||||
|
||||
rows.append((
|
||||
f"[cyan]{self.get_icon_from_name_and_type(file["name"], file["type"] != "file")}[/] [@click=screen.view_file('{self.current_dir}/{file["name"]}','{file["type"]}')]{file["name"]}[/]",
|
||||
f"[d]{commit["commit"]["message"]}[/]",
|
||||
f"[d]{file["last_commit_message"]}[/]",
|
||||
f"[d]Updated {time_delta(datetime.now() - commit_created_at)} ago[/]"
|
||||
))
|
||||
|
||||
@@ -342,6 +317,7 @@ class RepoViewScreen(Screen):
|
||||
yield table
|
||||
|
||||
with Vertical(id="file-screen"):
|
||||
yield RepoDirectoryTree(self.owner_name, self.repo_name, ".")
|
||||
with HorizontalGroup(id="file-commit"):
|
||||
yield Static("[b]Person[/] [r]aaaaabbbbb[/] [d]some commit message[/d]")
|
||||
with Right():
|
||||
|
||||
Reference in New Issue
Block a user