Skip to content

Commit 0a81ce1

Browse files
authored
Merge pull request #76 from GitHubSecurityLab/p--fix-gh-list-dir
P fix list_directory_from_gh in case no directory is returned from API
2 parents 8374841 + 6a9f6df commit 0a81ce1

3 files changed

Lines changed: 407 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ Issues = "https://github.com/GitHubSecurityLab/seclab-taskflows/issues"
3535
[tool.hatch.version]
3636
path = "src/seclab_taskflows/__about__.py"
3737

38+
[tool.hatch.envs.hatch-test]
39+
extra-dependencies = [
40+
"pytest-asyncio==1.3.0",
41+
]
42+
3843
[tool.hatch.envs.types]
3944
extra-dependencies = [
4045
"mypy>=1.0.0",
@@ -120,3 +125,8 @@ ignore = [
120125
"S101", # Use of assert (standard in pytest)
121126
"SLF001", # Private member accessed (tests legitimately access module internals)
122127
]
128+
129+
[tool.pytest.ini_options]
130+
markers = [
131+
"xdist_group: Group tests to run on the same xdist worker",
132+
]

src/seclab_taskflows/mcp_servers/gh_file_viewer.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
from sqlalchemy.orm import DeclarativeBase, mapped_column, Mapped
1111
from sqlalchemy import create_engine
12+
import sqlalchemy.exc
1213
from sqlalchemy.orm import Session
1314
from typing import Optional
1415
from pathlib import Path
@@ -53,7 +54,11 @@ def __repr__(self):
5354
SEARCH_RESULT_DIR = mcp_data_dir("seclab-taskflows", "gh_file_viewer", "SEARCH_RESULTS_DIR")
5455

5556
engine = create_engine(f"sqlite:///{os.path.abspath(SEARCH_RESULT_DIR)}/search_result.db", echo=False)
56-
Base.metadata.create_all(engine, tables=[SearchResults.__table__])
57+
58+
try:
59+
Base.metadata.create_all(engine, tables=[SearchResults.__table__])
60+
except sqlalchemy.exc.OperationalError as e:
61+
logging.exception(f"Database/Tables already exist(s)") # only log here, as this error likely only happens in test
5762

5863

5964
async def call_api(url: str, params: dict) -> str:
@@ -283,10 +288,13 @@ async def list_directory_from_gh(
283288
r = await call_api(url=f"https://api.github.com/repos/{owner}/{repo}/contents/{path}", params={})
284289
if isinstance(r, str):
285290
return r
286-
if not r.json():
291+
data = r.json()
292+
if not data:
287293
return json.dumps([], indent=2)
294+
if not isinstance(data, list):
295+
return f"Path '{path}' is not a directory."
288296

289-
content = [item["path"] for item in r.json()]
297+
content = [item["path"] for item in data]
290298
return json.dumps(content, indent=2)
291299

292300

0 commit comments

Comments
 (0)