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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@ Issues and pull requests are welcome. See
organisation-wide rules; setup, test and lint commands are in this README. Commits carry DCO
sign-off.

## Licensing

The code in this repository is Apache-2.0 and needs no licence key to build, test or run.
Licence tokens are an **optional** identity source: with `LICENSE_INTROSPECT_URL` unset (the
default), a `Bearer` licence cannot be introspected, and callers authenticate through the
platform's mesh-forwarded identity instead. With the URL set, every licence token is
introspected against the licences service, and an unreachable service yields no identity
(401) — never an admission.

The licensing stack is public too — [`licenses`](https://github.com/nonagenticai/licenses)
(entitlements, plans and tokens) and
[`license-authz`](https://github.com/nonagenticai/license-authz) (the Envoy `ext_authz`
enforcement point). Neither is required to run this code.

## License

Apache-2.0 — see [`LICENSE`](LICENSE) and [`NOTICE`](NOTICE).
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ include = ["src"]
python-version = "3.14"

[tool.ty.rules]
unresolved-import = "ignore"
unresolved-attribute = "ignore"
import-not-found = "ignore"
missing-attribute = "ignore"

[tool.pytest.ini_options]
asyncio_mode = "auto"
Expand Down
4 changes: 2 additions & 2 deletions src/db/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from __future__ import annotations

import asyncio
from collections.abc import AsyncIterator
from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager

from psycopg import AsyncConnection
Expand Down Expand Up @@ -73,7 +73,7 @@ async def get_pool() -> AsyncConnectionPool:


@asynccontextmanager
async def get_connection() -> AsyncIterator[AsyncConnection]:
async def get_connection() -> AsyncGenerator[AsyncConnection]:
"""Yield a pooled connection; the block is one transaction (commit on exit)."""
pool = await get_pool()
async with pool.connection() as conn:
Expand Down
4 changes: 2 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging
import os
from collections.abc import AsyncIterator
from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager
from typing import Any

Expand Down Expand Up @@ -84,7 +84,7 @@ def get_security_client() -> Any:


@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
async def lifespan(app: FastAPI) -> AsyncGenerator[None]:
"""Application startup / shutdown events."""
global _db_engine, _db_session_factory, _workspaces_client, _security_client # noqa: PLW0603

Expand Down
2 changes: 1 addition & 1 deletion src/routers/github_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def _lookup() -> _PrivateFlag:
return CloneTokenResponse(
token=token,
expires_at=expires_at,
visibility=visibility, # type: ignore[invalid-argument-type] # ty: ignore[invalid-argument-type]
visibility=visibility,
source=source,
reason=reason,
private=private,
Expand Down
4 changes: 2 additions & 2 deletions src/routers/github_issue_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from __future__ import annotations

import logging
from collections.abc import AsyncIterator
from collections.abc import AsyncGenerator
from contextlib import AsyncExitStack, asynccontextmanager

from coding_client.auth.tenant import require_tenant
Expand Down Expand Up @@ -60,7 +60,7 @@ async def _github(
repo: str | None = None,
tenant_id: str | None = None,
permissions: dict[str, str] | None = None,
) -> AsyncIterator[GitHubService]:
) -> AsyncGenerator[GitHubService]:
"""Open a GitHubService on the App-first credential ladder.

This used to read the platform PAT setting directly (since removed, 2026-09-30).
Expand Down
40 changes: 22 additions & 18 deletions src/services/github/github_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@
HAS_AIOHTTP = True
except ImportError:
HAS_AIOHTTP = False
aiohttp = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment]
# `Any`, not `module | None`: placeholder for an absent optional dependency.
# HAS_AIOHTTP gates the use, so the union case is not a real state.
aiohttp: Any = None

try:
from github import Github, GithubException, RateLimitExceededException
from github.Repository import Repository

HAS_GITHUB = True
except ImportError:
# `Any`, not `type[X] | None`: placeholders for an absent optional dependency.
# Keeping the real classes in the union turns every downstream call and
# attribute access into a union-case error. HAS_GITHUB gates the use.
HAS_GITHUB = False
Github = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment]
GithubException = Exception # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment]
RateLimitExceededException = Exception # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment]
Repository = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment]
Github: Any = None
GithubException: Any = Exception
RateLimitExceededException: Any = Exception
Repository: Any = None
from coding_client.models.github import PRFileChange, PullRequest
from pydantic import BaseModel

Expand Down Expand Up @@ -1451,19 +1456,18 @@ def _shape() -> dict[str, Any]:
raw_files = list(comparison.files or [])
if len(raw_files) >= GITHUB_COMPARE_FILES_CAP:
raise CompareFilesTruncatedError(len(raw_files))
files = sorted(
(
{
"filename": f.filename,
"status": f.status,
"previous_filename": (
f.previous_filename if f.status == "renamed" else None
),
}
for f in raw_files
),
key=lambda item: item["filename"],
)
# Sort the raw files by filename (a plain `str`) rather than sorting
# the shaped dicts: the shaped values are `str | None`
# (previous_filename), so a dict-key sort hands `sorted` a union it
# cannot prove is ordered.
files = [
{
"filename": f.filename,
"status": f.status,
"previous_filename": (f.previous_filename if f.status == "renamed" else None),
}
for f in sorted(raw_files, key=lambda f: f.filename)
]
status = comparison.status
return {
"status": status,
Expand Down
8 changes: 5 additions & 3 deletions src/services/github/secure_token_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
except ImportError:
logger.warning("cryptography module not available - GitHub token encryption disabled")
CRYPTOGRAPHY_AVAILABLE = False
Fernet = None # type: ignore[assignment] # ty: ignore[invalid-assignment]
hashes = None # type: ignore[assignment] # ty: ignore[invalid-assignment]
PBKDF2HMAC = None # type: ignore[assignment] # ty: ignore[invalid-assignment]
# `Any`, not `type[X] | None`: placeholders for an absent optional dependency.
# CRYPTOGRAPHY_AVAILABLE gates the use, so the union case is not a real state.
Fernet: Any = None
hashes: Any = None
PBKDF2HMAC: Any = None


class TokenStatus(StrEnum):
Expand Down
21 changes: 14 additions & 7 deletions src/services/github_app_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@

HAS_GITHUB = True
except ImportError: # pragma: no cover - exercised only when PyGithub absent
Auth = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment]
GithubIntegration = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment]
# `Any`, not `type[X] | None`: placeholders for an absent optional dependency.
# HAS_GITHUB gates the use, so the union case is not a real state.
Auth: Any = None
GithubIntegration: Any = None
HAS_GITHUB = False

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -587,10 +589,13 @@ def _assert_minted_repo_owner(payload: object, expected_owner: str, owner: str,
repos = body.get("repositories")
seen: list[str] = []
if isinstance(repos, list):
for r in repos:
r = r if isinstance(r, dict) else {}
o = r.get("owner") if isinstance(r.get("owner"), dict) else {}
seen.append(f"{o.get('login') or '?'}/{r.get('name') or '?'}")
for entry in repos:
repo_dict = cast("dict[str, Any]", entry) if isinstance(entry, dict) else {}
owner_value = repo_dict.get("owner")
owner_dict = (
cast("dict[str, Any]", owner_value) if isinstance(owner_value, dict) else {}
)
seen.append(f"{owner_dict.get('login') or '?'}/{repo_dict.get('name') or '?'}")
want = f"{expected_owner.strip().lower()}/{repo.strip().lower()}"
if [x.lower() for x in seen] != [want]:
logger.error(
Expand Down Expand Up @@ -658,7 +663,9 @@ def mint_public_repo_token(
)


def get_repo_visibility(owner: str, repo: str, token: str | None = None) -> str:
def get_repo_visibility(
owner: str, repo: str, token: str | None = None
) -> Literal["public", "private"]:
"""Return ``"public"`` or ``"private"`` for ``owner/repo``.

coding-github is the only coding-* service with egress to api.github.com, so
Expand Down
11 changes: 7 additions & 4 deletions src/services/github_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@

HAS_GITHUB = True
except ImportError:
# `Any`, not `type[X] | None`: placeholders for an absent optional dependency.
# Keeping the real classes in the union turns every downstream call and
# attribute access into a union-case error. HAS_GITHUB gates the use.
HAS_GITHUB = False
Auth = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment]
Github = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment]
GithubException = Exception # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment]
Repository = None # type: ignore[invalid-assignment] # ty: ignore[invalid-assignment]
Auth: Any = None
Github: Any = None
GithubException: Any = Exception
Repository: Any = None

FixValidator = None # Stub for patching in tests

Expand Down
11 changes: 7 additions & 4 deletions src/services/github_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import logging
import os
from typing import TYPE_CHECKING, NamedTuple
from typing import TYPE_CHECKING, Any, NamedTuple
from urllib.parse import urlparse

if TYPE_CHECKING:
Expand All @@ -19,10 +19,13 @@

HAS_GITHUB = True
except ImportError:
# `Any`, not `type[X] | None`: these are placeholders for an absent optional
# dependency, so keeping the real classes in the union makes every call and
# attribute access downstream a union-case error. HAS_GITHUB gates the use.
HAS_GITHUB = False
Auth = None # type: ignore[assignment] # ty: ignore[invalid-assignment]
Github = None # type: ignore[assignment] # ty: ignore[invalid-assignment]
GithubException = Exception # type: ignore[assignment] # ty: ignore[invalid-assignment]
Auth: Any = None
Github: Any = None
GithubException: Any = Exception

from coding_client.exceptions.api_exceptions import NotFoundException, ValidationException
from coding_client.models.container import GitHubRepoRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def extract_change_metadata(self, changes: list[FileChange]) -> dict[str, Any]:

# Analyze file types
for change in changes:
file_type = change.file_type.value if change.file_type else "unknown"
file_type = change.file_type.value
metadata["file_types"][file_type] = metadata["file_types"].get(file_type, 0) + 1

# Analyze change distribution
Expand Down
2 changes: 1 addition & 1 deletion src/utils/github_error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def sync_wrapper(*args: Any, **kwargs: Any) -> T:
import inspect

if inspect.iscoroutinefunction(func):
return async_wrapper # type: ignore[return-value] # ty: ignore[invalid-return-type]
return async_wrapper # type: ignore[return-value] # ty: ignore[invalid-explicit-return]
return sync_wrapper

return decorator
Loading