Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(changes): look a change up by the forge ref that listings print (#3904)
Raghav Chamadiyafd19875a1f79
diff --git a/packages/core/src/repowise/core/persistence/crud/changes.py b/packages/core/src/repowise/core/persistence/crud/changes.pyindex 68e3419ba..d5f93f005 100644--- a/packages/core/src/repowise/core/persistence/crud/changes.py+++ b/packages/core/src/repowise/core/persistence/crud/changes.py@@ -204,7 +204,7 @@ async def keep_evidence_if_unchanged(async def get_change(session: AsyncSession, repository_id: str, ref: str) -> Change | None:- """A change by its id, or the newest change that landed a commit (a sha of 7+ hex)."""+ """A change by its id or forge ref, or the newest change that landed a commit (a sha of 7+ hex)."""found = await find_changes(session, repository_id, ref, limit=1)return found[0] if found else None@@ -212,7 +212,8 @@ async def get_change(session: AsyncSession, repository_id: str, ref: str) -> Chaasync def find_changes(session: AsyncSession, repository_id: str, ref: str, *, limit: int = 2) -> list[Change]:- """Changes *ref* names, newest first: the one with that id, else up to+ """Changes *ref* names, newest first: the one with that id, else the one+ with that forge ref (``#12``, ``!7``, as listings print it), else up to*limit* that landed a commit starting with *ref* (7+ hex). More than onemeans a short sha is ambiguous."""@@ -223,6 +224,16 @@ async def find_changes().scalar_one_or_none()if row is not None:return [row]+ by_forge_ref = (+ await session.execute(+ select(Change)+ .where(Change.repository_id == repository_id, Change.forge_ref == ref)+ .order_by(Change.merged_at.desc().nulls_last())+ .limit(1)+ )+ ).scalar_one_or_none()+ if by_forge_ref is not None:+ return [by_forge_ref]if len(ref) < 7 or any(c not in "0123456789abcdef" for c in ref.lower()):return []sha = escape_like(ref.lower())diff --git a/tests/unit/core/test_changes.py b/tests/unit/core/test_changes.pyindex 4596dfa72..6462b8e26 100644--- a/tests/unit/core/test_changes.py+++ b/tests/unit/core/test_changes.py@@ -407,6 +407,9 @@ async def test_refresh_rebuilds_then_extends(tmp_path, history):assert (row.provenance, row.provenance_agent, row.provenance_known) == ("agent", 1, 1)assert (await get_change(session, repo_id, shas["f1"][:10])).change_id == "pr-13"assert (await get_change(session, repo_id, "pr-7")).approvals == 1+ # The forge ref is what `changes list` prints, so `show` takes it too.+ assert (await get_change(session, repo_id, "#13")).change_id == "pr-13"+ assert await get_change(session, repo_id, "#999") is Nonenewer = r.commit("z.py", "chore: z (#40)")async with get_session(factory) as session: