Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- name: Install dependencies
run: |
uv sync --dev
uv sync --extra dev

- name: Check code formatting with black
run: |
Expand Down Expand Up @@ -67,12 +67,12 @@ jobs:

- name: Install dependencies
run: |
uv sync --dev
uv sync --extra dev

- name: Run tests with pytest
run: |
if [ -d "tests" ] && [ "$(ls -A tests 2>/dev/null)" ]; then
uv run pytest tests/ -v
uv run pytest tests/ -v --cov=github_pm --cov-report=term
else
echo "No tests directory or tests found, skipping pytest"
fi
Expand Down
55 changes: 54 additions & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ github_pm = "github_pm.cli:main"
dev = [
"black>=24.4.2",
"flake8>=7.3.0",
"httpx>=0.27.0",
"isort>=6.0.1",
"pytest>=8.0.0",
"pytest-asyncio>=0.23.0",
"pytest-cov>=5.0.0",
"tox>=4.23.2",
]

Expand All @@ -62,7 +65,7 @@ order_by_type = false

[tool.tox]
requires = ["tox>=4.23.2"]
env_list = ["format", "isort", "lint"]
env_list = ["format", "isort", "lint", "test", "coverage"]

[tool.tox.env.format]
description = "check code format"
Expand All @@ -81,3 +84,53 @@ description = "check code"
skip_install = true
deps = ["flake8"]
commands = [["flake8", { replace = "posargs", default = ["src", "tests"], extend = true}]]

[tool.tox.env.test]
description = "run tests"
deps = ["pytest>=8.0.0", "pytest-asyncio>=0.23.0", "httpx>=0.27.0"]
commands = [["pytest", { replace = "posargs", default = ["tests"], extend = true}]]

[tool.tox.env.coverage]
description = "run tests with coverage"
deps = ["pytest>=8.0.0", "pytest-asyncio>=0.23.0", "pytest-cov>=5.0.0", "httpx>=0.27.0"]
commands = [
["pytest", "--cov=github_pm", "--cov-report=term-missing", "--cov-report=html", { replace = "posargs", default = ["tests"], extend = true}],
]

[tool.pytest.ini_options]
asyncio_mode = "auto"
testpaths = ["tests"]
python_files = ["test_*.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]

[tool.coverage.run]
source = ["src"]
omit = [
"*/tests/*",
"*/test_*.py",
"*/__pycache__/*",
"*/__init__.py",
]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"raise AssertionError",
"raise NotImplementedError",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
"@abstractmethod",
"@abstractproperty",
"if False:",
"if 0:",
"class .*\\bProtocol\\):",
"@(abc\\.)?abstractmethod",
]
show_missing = true
precision = 2
skip_covered = false

[tool.coverage.html]
directory = "htmlcov"
28 changes: 24 additions & 4 deletions backend/src/github_pm/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from collections import defaultdict
from datetime import date
import time
from typing import Annotated, AsyncGenerator

from fastapi import APIRouter, Body, Depends, HTTPException, Path
from fastapi import APIRouter, Body, Depends, HTTPException, Path, Query
from github import Auth, Github, Repository
from github.GithubObject import NotSet
from pydantic import BaseModel, Field
Expand Down Expand Up @@ -52,7 +53,15 @@ async def get_project():
async def get_issues(
repo: Annotated[Repository, Depends(connection)],
milestone_number: Annotated[int, Path(title="Milestone")],
sort: Annotated[
str | None, Query(title="Sort", description="List of labels to sort by")
] = None,
):
if sort:
sort_by = [s.strip() for s in sort.split(",")]
else:
sort_by = []
sorted_issues = defaultdict(list)
start = time.time()
if milestone_number == 0:
milestone = "none"
Expand All @@ -62,11 +71,22 @@ async def get_issues(
f"[Milestone {milestone_number} found: {milestone.title}: {time.time() - start:.3f} seconds]"
)
issues = repo.get_issues(milestone=milestone, state="open")
simplified = [i.raw_data for i in issues]
for i in issues:
labels = set([label.name.lower() for label in i.labels])
for label in sort_by:
if label in labels:
sorted_issues[label].append(i.raw_data)
break
else:
sorted_issues["other"].append(i.raw_data)
all_issues = []
for label in sort_by:
all_issues.extend(sorted_issues[label])
all_issues.extend(sorted_issues["other"])
print(
f"[{issues.totalCount}({len(simplified)}) issues: {time.time() - start:.3f} seconds]"
f"[{issues.totalCount}({len(all_issues)}) issues: {time.time() - start:.3f} seconds]"
)
return simplified
return all_issues


@api_router.get("/comments/{issue_number}")
Expand Down
13 changes: 13 additions & 0 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Pytest configuration and fixtures.

ai-generated: Cursor
"""

from pathlib import Path
import sys

# Add src directory to Python path for imports
backend_dir = Path(__file__).parent.parent
src_dir = backend_dir / "src"
if str(src_dir) not in sys.path:
sys.path.insert(0, str(src_dir))
Loading