Skip to content
Draft
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
13 changes: 12 additions & 1 deletion issue_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
from dotenv import load_dotenv

load_dotenv()
client = AsyncOpenAI(api_key=os.getenv("OPENAI_API_KEY"))

def get_openai_client():
"""Get OpenAI client, initialized lazily."""
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
return None
return AsyncOpenAI(api_key=api_key)


async def ai_select_labels(title: str, description: str, available_labels: List[str]) -> List[str]:
Expand All @@ -18,6 +24,11 @@ async def ai_select_labels(title: str, description: str, available_labels: List[
if not available_labels:
return []

client = get_openai_client()
if not client:
print("OpenAI API key not set, skipping AI label selection", flush=True)
return []

try:
response = await client.chat.completions.create(
model="gpt-4o",
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ httpx==0.25.2
openai==1.3.7
requests==2.31.0
anthropic==0.39.0
pytest==7.4.3

57 changes: 57 additions & 0 deletions test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
Simple tests for the OMI GitHub Issues Integration
"""
import pytest
from fastapi.testclient import TestClient
from main import app

client = TestClient(app)


def test_health_endpoint():
"""Test the health check endpoint"""
response = client.get("/health")
assert response.status_code == 200
data = response.json()
assert data["status"] == "healthy"
assert data["service"] == "omi-github-issues"


def test_root_endpoint():
"""Test the root endpoint without uid"""
response = client.get("/")
assert response.status_code == 200
data = response.json()
assert data["app"] == "OMI GitHub Issues Integration"
assert data["version"] == "2.0.0"
assert data["status"] == "active"


def test_omi_tools_manifest():
"""Test the OMI tools manifest endpoint"""
response = client.get("/.well-known/omi-tools.json")
assert response.status_code == 200
data = response.json()
assert "tools" in data
assert len(data["tools"]) > 0

# Verify key tools exist
tool_names = [tool["name"] for tool in data["tools"]]
assert "create_issue" in tool_names
assert "list_repos" in tool_names
assert "list_issues" in tool_names
assert "code_feature" in tool_names


def test_setup_completed_endpoint():
"""Test setup check endpoint"""
response = client.get("/setup-completed?uid=test-user")
assert response.status_code == 200
data = response.json()
assert "is_setup_completed" in data
# Should be False for non-existent user
assert data["is_setup_completed"] is False


if __name__ == "__main__":
pytest.main([__file__, "-v"])