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
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ name: CI
on:
push:
branches: [main]
# Run on every pull request, not just those targeting main. Restricting
# this to `branches: [main]` meant a stacked PR (one branch based on
# another) got no test run at all — it looked reviewed and green when
# nothing had actually executed.
pull_request:
branches: [main]

jobs:
test:
Expand Down
25 changes: 10 additions & 15 deletions openfoia/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

from __future__ import annotations

import contextlib
import logging
from dataclasses import dataclass
from datetime import datetime
from typing import Any

from .models import Agency, Request, RequestStatus
from .models import utcnow as _utcnow

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -318,10 +319,8 @@ async def _search_agencies(self, params: dict[str, Any]) -> dict[str, Any]:
if level and level != "all":
from .models import AgencyLevel

try:
with contextlib.suppress(ValueError):
agencies = agencies.filter(Agency.level == AgencyLevel(level))
except ValueError:
pass

results = agencies.limit(20).all()
return {
Expand Down Expand Up @@ -385,6 +384,7 @@ async def _draft_request(self, params: dict[str, Any]) -> dict[str, Any]:
"""

import uuid

from .models import DeliveryMethod, User

request_id = str(uuid.uuid4())
Expand All @@ -399,9 +399,7 @@ async def _draft_request(self, params: dict[str, Any]) -> dict[str, Any]:

user = self.db.query(User).first()
if user and agency:
from datetime import datetime as dt

req_num = f"REQ-{dt.utcnow().strftime('%Y%m%d')}-{uuid.uuid4().hex[:6].upper()}"
req_num = f"REQ-{_utcnow().strftime('%Y%m%d')}-{uuid.uuid4().hex[:6].upper()}"
new_req = Request(
id=request_id,
request_number=req_num,
Expand Down Expand Up @@ -432,7 +430,7 @@ async def _send_request(self, params: dict[str, Any]) -> dict[str, Any]:
return {"error": f"Request not found: {request_id}"}

request.status = RequestStatus.SENT
request.sent_at = datetime.utcnow()
request.sent_at = _utcnow()

# Auto-set due date (20 business days per FOIA statute)
if not request.due_date:
Expand Down Expand Up @@ -506,10 +504,8 @@ async def _list_requests(self, params: dict[str, Any]) -> dict[str, Any]:

status_filter = params.get("status")
if status_filter and status_filter != "all":
try:
with contextlib.suppress(ValueError):
query = query.filter(Request.status == RequestStatus(status_filter))
except ValueError:
pass

agency_id = params.get("agency_id")
if agency_id:
Expand Down Expand Up @@ -541,6 +537,7 @@ async def _process_document(self, params: dict[str, Any]) -> dict[str, Any]:
database, where it becomes visible in reports and exports.
"""
from pathlib import Path

from .db import get_data_dir

doc_path = params.get("document_path", "")
Expand Down Expand Up @@ -604,7 +601,7 @@ async def _extract_entities(self, params: dict[str, Any]) -> dict[str, Any]:

async def _build_entity_graph(self, params: dict[str, Any]) -> dict[str, Any]:
"""Build entity graph."""
from .models import Entity, Document, entity_links
from .models import Document, Entity, entity_links

query = self.db.query(Entity)
request_ids = params.get("request_ids")
Expand Down Expand Up @@ -639,10 +636,8 @@ async def _search_entities(self, params: dict[str, Any]) -> dict[str, Any]:
if entity_type and entity_type != "all":
from .models import EntityType

try:
with contextlib.suppress(ValueError):
query = query.filter(Entity.entity_type == EntityType(entity_type))
except ValueError:
pass

results = query.limit(50).all()

Expand Down
9 changes: 5 additions & 4 deletions openfoia/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
RequestStatus,
User,
)
from .models import utcnow as _utcnow


def _sandbox_env() -> SandboxedEnvironment:
Expand Down Expand Up @@ -71,7 +72,7 @@ def render(
context = {
"participant": participant,
"agency": agency,
"date": datetime.utcnow().strftime("%B %d, %Y"),
"date": _utcnow().strftime("%B %d, %Y"),
"custom": custom_params or {},
}

Expand Down Expand Up @@ -167,7 +168,7 @@ async def generate_request(
)

# Generate request number
request_number = f"REQ-{datetime.utcnow().strftime('%Y%m%d')}-{uuid4().hex[:6].upper()}"
request_number = f"REQ-{_utcnow().strftime('%Y%m%d')}-{uuid4().hex[:6].upper()}"

# Determine delivery method
if agency.foia_email and template.recommended_method == DeliveryMethod.EMAIL:
Expand Down Expand Up @@ -211,7 +212,7 @@ async def schedule_staggered_send(
2. Overwhelming agency systems
3. Making it easy to identify and block
"""
start = start_time or datetime.utcnow()
start = start_time or _utcnow()
schedule = []

# Distribute evenly with some randomness
Expand Down Expand Up @@ -307,7 +308,7 @@ async def generate_progress_report(self, campaign: Campaign) -> str:
- **Active:** {"Yes" if stats["is_active"] else "No"}

---
*Generated: {datetime.utcnow().strftime("%Y-%m-%d %H:%M UTC")}*
*Generated: {_utcnow().strftime("%Y-%m-%d %H:%M UTC")}*
""".strip()


Expand Down
Loading
Loading