mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-23 10:46:30 +01:00
Read GitHub repo from checkout origin
feedback_inbox and app_errors guessed kuhyx/<folder> for a task's repo, which filed cleanup-plate under kuhyx/cleanup-plate (real: Sepci0/cleanup-plate) and showed phantom repos on the board. Both now read the GitHub owner/name from ~/src/<folder>'s origin remote (https or ssh forms) and fall back to the guess only when there is no checkout or its origin is not on GitHub. app-errors 0.1.2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWZfgt44aEKxvGBJkwP
This commit is contained in:
parent
efa1c2ab05
commit
f05845e2f7
@ -26,7 +26,7 @@ The ingest skips `kartka` in RTDB, because kartka still runs its own ingest.
|
|||||||
`ui.snackbar`, `perf.slow`, ...), `error`, `stack` (list of frames), plus these
|
`ui.snackbar`, `perf.slow`, ...), `error`, `stack` (list of frames), plus these
|
||||||
optional fields:
|
optional fields:
|
||||||
|
|
||||||
- `repo` (`owner/name`, default `kuhyx/<app>`)
|
- `repo` (`owner/name`; default: the `origin` of `~/src/<app>` when it is on GitHub, else `kuhyx/<app>`)
|
||||||
- `mark` (the substring that marks the app's own frames: `package:todo/`,
|
- `mark` (the substring that marks the app's own frames: `package:todo/`,
|
||||||
`leetcode_guard/`, `res://`)
|
`leetcode_guard/`, `res://`)
|
||||||
- `route`
|
- `route`
|
||||||
|
|||||||
@ -13,11 +13,12 @@ its ``kartka`` adapter, and two readers of ``/kartka/errors`` would race.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
import functools
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from app_errors import spool, store
|
from app_errors import origin, spool, store
|
||||||
from app_errors.rtdb import RtdbError
|
from app_errors.rtdb import RtdbError
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -34,6 +35,8 @@ class Paths:
|
|||||||
state: Path
|
state: Path
|
||||||
reports: Path
|
reports: Path
|
||||||
spool: Path
|
spool: Path
|
||||||
|
#: Checkouts: ``<src_root>/<app>``'s origin names the repo of a report without one.
|
||||||
|
src_root: Path
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
@ -45,12 +48,13 @@ class Summary:
|
|||||||
|
|
||||||
|
|
||||||
def default_paths() -> Paths:
|
def default_paths() -> Paths:
|
||||||
"""Return the paths under ``$XDG_STATE_HOME`` (default ``~/.local/state``)."""
|
"""Return the state paths (``$XDG_STATE_HOME``, default ``~/.local/state``) and ``~/src``."""
|
||||||
base = Path(os.environ.get("XDG_STATE_HOME") or Path.home() / ".local" / "state")
|
base = Path(os.environ.get("XDG_STATE_HOME") or Path.home() / ".local" / "state")
|
||||||
return Paths(
|
return Paths(
|
||||||
base / "app-errors-ingest" / "state.json",
|
base / "app-errors-ingest" / "state.json",
|
||||||
base / "app-errors",
|
base / "app-errors",
|
||||||
base / "app-errors-spool",
|
base / "app-errors-spool",
|
||||||
|
Path.home() / "src",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -75,6 +79,7 @@ def _rtdb_entries(
|
|||||||
def run(paths: Paths, db: Rtdb | None, *, keep: bool = False) -> Summary:
|
def run(paths: Paths, db: Rtdb | None, *, keep: bool = False) -> Summary:
|
||||||
"""Ingest everything once; RTDB failures are returned, the spool still goes in."""
|
"""Ingest everything once; RTDB failures are returned, the spool still goes in."""
|
||||||
state = store.load(paths.state)
|
state = store.load(paths.state)
|
||||||
|
repo_of = functools.partial(origin.repo_slug, paths.src_root, owner=store.OWNER)
|
||||||
merged = 0
|
merged = 0
|
||||||
rtdb_error = None
|
rtdb_error = None
|
||||||
deletes: dict[str, dict[str, object]] = {}
|
deletes: dict[str, dict[str, object]] = {}
|
||||||
@ -83,8 +88,9 @@ def run(paths: Paths, db: Rtdb | None, *, keep: bool = False) -> Summary:
|
|||||||
found, deletes = _rtdb_entries(db)
|
found, deletes = _rtdb_entries(db)
|
||||||
except RtdbError as e:
|
except RtdbError as e:
|
||||||
found, rtdb_error = [], str(e)
|
found, rtdb_error = [], str(e)
|
||||||
merged += sum(store.merge(state, app, key, entry) for app, key, entry in found)
|
merged += sum(store.merge(state, a, k, e, repo_of=repo_of) for a, k, e in found)
|
||||||
merged += sum(store.merge(state, line.app, line.id, line.entry) for line in spool.drain(paths.spool))
|
lines = spool.drain(paths.spool)
|
||||||
|
merged += sum(store.merge(state, ln.app, ln.id, ln.entry, repo_of=repo_of) for ln in lines)
|
||||||
store.save(paths.state, state)
|
store.save(paths.state, state)
|
||||||
store.write_reports(paths.reports, state)
|
store.write_reports(paths.reports, state)
|
||||||
if db is not None and not keep:
|
if db is not None and not keep:
|
||||||
|
|||||||
61
app_errors/app_errors/origin.py
Normal file
61
app_errors/app_errors/origin.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# Copyright (c) 2026 Krzysztof Rudnicki
|
||||||
|
"""Which GitHub repo a local checkout is, read from its ``origin`` remote.
|
||||||
|
|
||||||
|
A folder name says nothing about the owner: ``~/src/cleanup-plate`` is
|
||||||
|
``Sepci0/cleanup-plate`` and ``~/src/todo`` is ``kuhyx/todo-app``. Guessing
|
||||||
|
``<owner>/<folder>`` filed tasks and error tickets under repos that do not exist, so the guess is
|
||||||
|
only the fallback for a folder with no checkout or no GitHub origin.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
GIT_TIMEOUT = 5.0
|
||||||
|
# https://[user@]github.com/o/n[.git], ssh://git@github.com[:port]/o/n[.git]
|
||||||
|
# and git@github.com:o/n[.git]. Other hosts (a local mirror, a gitea) are not
|
||||||
|
# the GitHub slug the board works with, so they fall back to the guess.
|
||||||
|
_GITHUB = re.compile(
|
||||||
|
r"^(?:https?://(?:[^@/]+@)?github\.com/|ssh://git@github\.com(?::\d+)?/"
|
||||||
|
r"|git@github\.com:)(?P<slug>[^/\s]+/[^/\s]+?)(?:\.git)?/?$"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def slug_from_url(url: str) -> str | None:
|
||||||
|
"""Return ``owner/name`` of a GitHub remote URL, or None for any other URL."""
|
||||||
|
match = _GITHUB.match(url.strip())
|
||||||
|
return match["slug"] if match else None
|
||||||
|
|
||||||
|
|
||||||
|
def origin_slug(checkout: Path) -> str | None:
|
||||||
|
"""Return the GitHub ``owner/name`` of ``checkout``'s origin, or None.
|
||||||
|
|
||||||
|
None when ``checkout`` is not a git checkout (a ``.git`` dir, or file for a
|
||||||
|
worktree), has no ``origin``, git is missing or hangs, or origin is not
|
||||||
|
GitHub. Checking ``.git`` first keeps git from walking up to a parent repo.
|
||||||
|
"""
|
||||||
|
git = shutil.which("git")
|
||||||
|
if git is None or not (checkout / ".git").exists():
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
out = subprocess.run(
|
||||||
|
[git, "-C", str(checkout), "remote", "get-url", "origin"],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=False,
|
||||||
|
timeout=GIT_TIMEOUT,
|
||||||
|
)
|
||||||
|
except OSError, subprocess.SubprocessError:
|
||||||
|
return None
|
||||||
|
return None if out.returncode else slug_from_url(out.stdout)
|
||||||
|
|
||||||
|
|
||||||
|
def repo_slug(src_root: Path, folder: str, owner: str) -> str:
|
||||||
|
"""Return the slug of ``src_root/folder``'s origin, else ``owner/folder``."""
|
||||||
|
return origin_slug(src_root / folder) or f"{owner}/{folder}"
|
||||||
@ -24,13 +24,20 @@ from typing import TYPE_CHECKING, NotRequired, TypedDict, cast
|
|||||||
from app_errors.signature import SLOW_KIND, mark_of, signature, strings, top_frame
|
from app_errors.signature import SLOW_KIND, mark_of, signature, strings, top_frame
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import Mapping
|
from collections.abc import Callable, Mapping
|
||||||
|
|
||||||
#: Entry ids remembered for dedup (oldest dropped first).
|
#: Entry ids remembered for dedup (oldest dropped first).
|
||||||
MAX_SEEN = 5000
|
MAX_SEEN = 5000
|
||||||
#: An app name the board accepts (the contract's ``app`` pattern).
|
#: An app name the board accepts (the contract's ``app`` pattern).
|
||||||
APP_NAME = re.compile(r"^[a-z0-9][a-z0-9_-]*$")
|
APP_NAME = re.compile(r"^[a-z0-9][a-z0-9_-]*$")
|
||||||
_REPO = re.compile(r"^[^/\s]+/[^/\s]+$")
|
_REPO = re.compile(r"^[^/\s]+/[^/\s]+$")
|
||||||
|
#: The owner guessed for an app whose report names no repo and has no checkout.
|
||||||
|
OWNER = "kuhyx"
|
||||||
|
|
||||||
|
|
||||||
|
def guess_repo(app: str) -> str:
|
||||||
|
"""Return ``OWNER/app``: the fallback when nothing better names the repo."""
|
||||||
|
return f"{OWNER}/{app}"
|
||||||
|
|
||||||
|
|
||||||
class Resolved(TypedDict):
|
class Resolved(TypedDict):
|
||||||
@ -109,8 +116,18 @@ def _reopens(resolved: Resolved, at: str, build: int) -> bool:
|
|||||||
return at > resolved["at"]
|
return at > resolved["at"]
|
||||||
|
|
||||||
|
|
||||||
def merge(state: State, app: str, entry_id: str, raw: object) -> bool:
|
def merge(
|
||||||
"""Count one report ``raw`` of ``app`` under its signature; False when seen or not a report."""
|
state: State,
|
||||||
|
app: str,
|
||||||
|
entry_id: str,
|
||||||
|
raw: object,
|
||||||
|
*,
|
||||||
|
repo_of: Callable[[str], str] = guess_repo,
|
||||||
|
) -> bool:
|
||||||
|
"""Count one report ``raw`` of ``app`` under its signature; False when seen or not a report.
|
||||||
|
|
||||||
|
A new record takes the report's ``repo``, else ``repo_of(app)``.
|
||||||
|
"""
|
||||||
if not isinstance(raw, dict):
|
if not isinstance(raw, dict):
|
||||||
return False
|
return False
|
||||||
entry = cast("Mapping[str, object]", raw)
|
entry = cast("Mapping[str, object]", raw)
|
||||||
@ -131,7 +148,7 @@ def merge(state: State, app: str, entry_id: str, raw: object) -> bool:
|
|||||||
repo = _str(entry.get("repo"))
|
repo = _str(entry.get("repo"))
|
||||||
rec = recs[sig.id] = {
|
rec = recs[sig.id] = {
|
||||||
"signature": sig.id,
|
"signature": sig.id,
|
||||||
"repo": repo if repo and _REPO.match(repo) else f"kuhyx/{app}",
|
"repo": repo if repo and _REPO.match(repo) else repo_of(app),
|
||||||
"kind": kind,
|
"kind": kind,
|
||||||
"message": sig.message,
|
"message": sig.message,
|
||||||
"top_frame": top_frame(strings(entry.get("stack")), mark_of(entry, app)),
|
"top_frame": top_frame(strings(entry.get("stack")), mark_of(entry, app)),
|
||||||
|
|||||||
20
app_errors/app_errors/tests/checkout.py
Normal file
20
app_errors/app_errors/tests/checkout.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
"""A real git checkout in a temp dir, built without kuhy's git config."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
GIT = shutil.which("git") or "git"
|
||||||
|
|
||||||
|
|
||||||
|
def make_checkout(path: Path, origin: str | None) -> Path:
|
||||||
|
"""Init a repo at ``path`` with remote ``origin`` (none when None)."""
|
||||||
|
env = {"PATH": os.environ["PATH"], "HOME": str(path.parent), "GIT_CONFIG_NOSYSTEM": "1"}
|
||||||
|
path.mkdir(parents=True)
|
||||||
|
subprocess.run([GIT, "init", "-q", str(path)], check=True, env=env)
|
||||||
|
if origin is not None:
|
||||||
|
subprocess.run([GIT, "-C", str(path), "remote", "add", "origin", origin], check=True, env=env)
|
||||||
|
return path
|
||||||
@ -9,6 +9,7 @@ import pytest
|
|||||||
|
|
||||||
from app_errors import cli, ingest, spool
|
from app_errors import cli, ingest, spool
|
||||||
from app_errors.rtdb import RtdbError
|
from app_errors.rtdb import RtdbError
|
||||||
|
from app_errors.tests.checkout import make_checkout
|
||||||
|
|
||||||
|
|
||||||
class FakeRtdb:
|
class FakeRtdb:
|
||||||
@ -64,6 +65,7 @@ def dirs(tmp_path: Path) -> ingest.Paths:
|
|||||||
state=tmp_path / "ingest" / "state.json",
|
state=tmp_path / "ingest" / "state.json",
|
||||||
reports=tmp_path / "app-errors",
|
reports=tmp_path / "app-errors",
|
||||||
spool=tmp_path / "app-errors-spool",
|
spool=tmp_path / "app-errors-spool",
|
||||||
|
src_root=tmp_path / "src",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -105,6 +107,18 @@ def test_rtdb_down_still_ingests_spool(dirs: ingest.Paths) -> None:
|
|||||||
assert list(dirs.spool.glob("*")) == [] # the spool is consumed
|
assert list(dirs.spool.glob("*")) == [] # the spool is consumed
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_without_repo_takes_the_checkouts_origin(dirs: ingest.Paths) -> None:
|
||||||
|
# Regression: a report with no repo was filed under a guessed kuhyx/<app>;
|
||||||
|
# the checkout's origin names the real one (here Sepci0/cleanup-plate).
|
||||||
|
make_checkout(dirs.src_root / "cleanup-plate", "git@github.com:Sepci0/cleanup-plate.git")
|
||||||
|
spool.append(dirs.spool, "cleanup-plate", {"at": "2026-11-17T10:00:00Z", "kind": "k", "error": "e"})
|
||||||
|
spool.append(dirs.spool, "kartka", {"at": "2026-11-17T10:00:00Z", "kind": "k", "error": "e"})
|
||||||
|
assert ingest.run(dirs, None).merged == 2
|
||||||
|
repos = {app: json.loads((dirs.reports / f"{app}.json").read_text())["errors"][0]["repo"]
|
||||||
|
for app in ("cleanup-plate", "kartka")} # fmt: skip
|
||||||
|
assert repos == {"cleanup-plate": "Sepci0/cleanup-plate", "kartka": "kuhyx/kartka"}
|
||||||
|
|
||||||
|
|
||||||
def test_no_rtdb_at_all(dirs: ingest.Paths) -> None:
|
def test_no_rtdb_at_all(dirs: ingest.Paths) -> None:
|
||||||
assert ingest.run(dirs, None).merged == 0
|
assert ingest.run(dirs, None).merged == 0
|
||||||
|
|
||||||
|
|||||||
74
app_errors/app_errors/tests/test_origin.py
Normal file
74
app_errors/app_errors/tests/test_origin.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
"""Origin lookup: every remote URL form, and every way a checkout has none."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from app_errors import origin as _origin
|
||||||
|
from app_errors.origin import origin_slug, repo_slug, slug_from_url
|
||||||
|
from app_errors.tests.checkout import make_checkout
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"url",
|
||||||
|
[
|
||||||
|
"https://github.com/Sepci0/cleanup-plate",
|
||||||
|
"https://github.com/Sepci0/cleanup-plate.git",
|
||||||
|
"https://github.com/Sepci0/cleanup-plate/\n",
|
||||||
|
"https://kuhy@github.com/Sepci0/cleanup-plate.git",
|
||||||
|
"git@github.com:Sepci0/cleanup-plate.git",
|
||||||
|
"ssh://git@github.com/Sepci0/cleanup-plate",
|
||||||
|
"ssh://git@github.com:22/Sepci0/cleanup-plate.git",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_github_urls_give_the_slug(url: str) -> None:
|
||||||
|
assert slug_from_url(url) == "Sepci0/cleanup-plate"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"url",
|
||||||
|
[
|
||||||
|
"/home/someone/mirror/cleanup-plate",
|
||||||
|
"file:///srv/git/cleanup-plate.git",
|
||||||
|
"https://gitea.example.org/Sepci0/cleanup-plate.git",
|
||||||
|
"https://github.com/Sepci0",
|
||||||
|
"https://github.com/Sepci0/cleanup-plate/extra",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_other_urls_give_none(url: str) -> None:
|
||||||
|
assert slug_from_url(url) is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_checkout_origin_is_read(tmp_path: Path) -> None:
|
||||||
|
repo = make_checkout(tmp_path / "todo", "https://github.com/kuhyx/todo-app.git")
|
||||||
|
assert origin_slug(repo) == "kuhyx/todo-app"
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_checkout_or_no_origin_is_none(tmp_path: Path) -> None:
|
||||||
|
(tmp_path / "plain").mkdir()
|
||||||
|
assert origin_slug(tmp_path / "missing") is None
|
||||||
|
assert origin_slug(tmp_path / "plain") is None
|
||||||
|
assert origin_slug(make_checkout(tmp_path / "bare", None)) is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_missing_or_hung_git_is_none(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
|
repo = make_checkout(tmp_path / "todo", "https://github.com/kuhyx/todo-app")
|
||||||
|
|
||||||
|
def hang(*args: object, **kwargs: object) -> None:
|
||||||
|
raise subprocess.TimeoutExpired("git", _origin.GIT_TIMEOUT)
|
||||||
|
|
||||||
|
monkeypatch.setattr(subprocess, "run", hang)
|
||||||
|
assert origin_slug(repo) is None
|
||||||
|
monkeypatch.setattr(shutil, "which", lambda _: None)
|
||||||
|
assert origin_slug(repo) is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_repo_slug_falls_back_to_the_owner_guess(tmp_path: Path) -> None:
|
||||||
|
make_checkout(tmp_path / "todo", "git@github.com:kuhyx/todo-app.git")
|
||||||
|
assert repo_slug(tmp_path, "todo", "kuhyx") == "kuhyx/todo-app"
|
||||||
|
assert repo_slug(tmp_path, "museum", "kuhyx") == "kuhyx/museum"
|
||||||
@ -118,7 +118,7 @@ class _PatchFails:
|
|||||||
|
|
||||||
|
|
||||||
def test_delete_failure_is_reported_after_save(tmp_path: Path) -> None:
|
def test_delete_failure_is_reported_after_save(tmp_path: Path) -> None:
|
||||||
paths = ingest.Paths(tmp_path / "s.json", tmp_path / "r", tmp_path / "sp")
|
paths = ingest.Paths(tmp_path / "s.json", tmp_path / "r", tmp_path / "sp", tmp_path / "src")
|
||||||
summary = ingest.run(paths, _PatchFails())
|
summary = ingest.run(paths, _PatchFails())
|
||||||
assert summary == ingest.Summary(1, "patch down")
|
assert summary == ingest.Summary(1, "patch down")
|
||||||
assert (tmp_path / "r" / "todo.json").exists()
|
assert (tmp_path / "r" / "todo.json").exists()
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "app-errors"
|
name = "app-errors"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
description = "Shared app error and slow-wait ingest: RTDB and local spool reports become todoImplementer error tickets"
|
description = "Shared app error and slow-wait ingest: RTDB and local spool reports become todoImplementer error tickets"
|
||||||
requires-python = ">=3.14"
|
requires-python = ">=3.14"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
@ -8,7 +8,7 @@ resolution-markers = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "app-errors"
|
name = "app-errors"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
source = { virtual = "." }
|
source = { virtual = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "crdt-sync" },
|
{ name = "crdt-sync" },
|
||||||
|
|||||||
@ -6,7 +6,9 @@ kuhy saves with F12 is never forgotten.
|
|||||||
A game saves `~/data/<repo>_binaries/feedback/<stamp>/` (`report.json`,
|
A game saves `~/data/<repo>_binaries/feedback/<stamp>/` (`report.json`,
|
||||||
screenshots, logs) and appends a ready-to-run Claude prompt to
|
screenshots, logs) and appends a ready-to-run Claude prompt to
|
||||||
`feedback-<date>.md` beside it. This package imports each complete bundle once
|
`feedback-<date>.md` beside it. This package imports each complete bundle once
|
||||||
as a task in the todo app for `kuhyx/<repo>`.
|
as a task in the todo app for the GitHub repo named by the `origin` of
|
||||||
|
`~/src/<repo>` (`kuhyx/<repo>` only when there is no such checkout or it is not
|
||||||
|
on GitHub).
|
||||||
|
|
||||||
## Task shape
|
## Task shape
|
||||||
|
|
||||||
|
|||||||
@ -42,7 +42,7 @@ def _run(wait: float, client: TodoClient | None) -> int:
|
|||||||
fcntl.flock(lock, fcntl.LOCK_EX)
|
fcntl.flock(lock, fcntl.LOCK_EX)
|
||||||
results = run_settled(
|
results = run_settled(
|
||||||
paths.data_root,
|
paths.data_root,
|
||||||
Importer(todo, OWNER),
|
Importer(todo, OWNER, paths.src_root),
|
||||||
Waiter(wait, time.time, time.sleep),
|
Waiter(wait, time.time, time.sleep),
|
||||||
)
|
)
|
||||||
failed = 0
|
failed = 0
|
||||||
|
|||||||
@ -24,6 +24,7 @@ from feedback_inbox._entry import (
|
|||||||
note_from_entry,
|
note_from_entry,
|
||||||
read_report,
|
read_report,
|
||||||
)
|
)
|
||||||
|
from feedback_inbox._origin import repo_slug
|
||||||
from feedback_inbox._todo import TodoError
|
from feedback_inbox._todo import TodoError
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -122,10 +123,11 @@ def _read_marker(bundle: Path) -> dict[str, object] | None:
|
|||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class Importer:
|
class Importer:
|
||||||
"""Who files the tasks (``client``) under which GitHub owner."""
|
"""Who files the tasks (``client``), where checkouts live, the fallback owner."""
|
||||||
|
|
||||||
client: TodoClient
|
client: TodoClient
|
||||||
owner: str
|
owner: str
|
||||||
|
src_root: Path
|
||||||
settle: float = SETTLE_SECONDS
|
settle: float = SETTLE_SECONDS
|
||||||
|
|
||||||
def import_bundle(self, feedback_dir: Path, bundle: Path, now: float) -> Result:
|
def import_bundle(self, feedback_dir: Path, bundle: Path, now: float) -> Result:
|
||||||
@ -140,7 +142,8 @@ class Importer:
|
|||||||
return Result(bundle, Outcome.PENDING, detail="report.json settling")
|
return Result(bundle, Outcome.PENDING, detail="report.json settling")
|
||||||
repo = repo_name(feedback_dir)
|
repo = repo_name(feedback_dir)
|
||||||
draft = build_task(repo, bundle.name, entry, read_report(report_path))
|
draft = build_task(repo, bundle.name, entry, read_report(report_path))
|
||||||
return self._file(bundle, f"{self.owner}/{repo}", draft)
|
slug = repo_slug(self.src_root, repo, self.owner)
|
||||||
|
return self._file(bundle, slug, draft)
|
||||||
|
|
||||||
def _file(self, bundle: Path, repo: str, draft: TaskDraft) -> Result:
|
def _file(self, bundle: Path, repo: str, draft: TaskDraft) -> Result:
|
||||||
"""Create the task, write the marker, then fix the title."""
|
"""Create the task, write the marker, then fix the title."""
|
||||||
|
|||||||
61
feedback_inbox/feedback_inbox/_origin.py
Normal file
61
feedback_inbox/feedback_inbox/_origin.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# Copyright (c) 2026 Krzysztof Rudnicki
|
||||||
|
"""Which GitHub repo a local checkout is, read from its ``origin`` remote.
|
||||||
|
|
||||||
|
A folder name says nothing about the owner: ``~/src/cleanup-plate`` is
|
||||||
|
``Sepci0/cleanup-plate`` and ``~/src/todo`` is ``kuhyx/todo-app``. Guessing
|
||||||
|
``<owner>/<folder>`` filed tasks under repos that do not exist, so the guess is
|
||||||
|
only the fallback for a folder with no checkout or no GitHub origin.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
GIT_TIMEOUT = 5.0
|
||||||
|
# https://[user@]github.com/o/n[.git], ssh://git@github.com[:port]/o/n[.git]
|
||||||
|
# and git@github.com:o/n[.git]. Other hosts (a local mirror, a gitea) are not
|
||||||
|
# the GitHub slug the board works with, so they fall back to the guess.
|
||||||
|
_GITHUB = re.compile(
|
||||||
|
r"^(?:https?://(?:[^@/]+@)?github\.com/|ssh://git@github\.com(?::\d+)?/"
|
||||||
|
r"|git@github\.com:)(?P<slug>[^/\s]+/[^/\s]+?)(?:\.git)?/?$"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def slug_from_url(url: str) -> str | None:
|
||||||
|
"""Return ``owner/name`` of a GitHub remote URL, or None for any other URL."""
|
||||||
|
match = _GITHUB.match(url.strip())
|
||||||
|
return match["slug"] if match else None
|
||||||
|
|
||||||
|
|
||||||
|
def origin_slug(checkout: Path) -> str | None:
|
||||||
|
"""Return the GitHub ``owner/name`` of ``checkout``'s origin, or None.
|
||||||
|
|
||||||
|
None when ``checkout`` is not a git checkout (a ``.git`` dir, or file for a
|
||||||
|
worktree), has no ``origin``, git is missing or hangs, or origin is not
|
||||||
|
GitHub. Checking ``.git`` first keeps git from walking up to a parent repo.
|
||||||
|
"""
|
||||||
|
git = shutil.which("git")
|
||||||
|
if git is None or not (checkout / ".git").exists():
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
out = subprocess.run(
|
||||||
|
[git, "-C", str(checkout), "remote", "get-url", "origin"],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=False,
|
||||||
|
timeout=GIT_TIMEOUT,
|
||||||
|
)
|
||||||
|
except OSError, subprocess.SubprocessError:
|
||||||
|
return None
|
||||||
|
return None if out.returncode else slug_from_url(out.stdout)
|
||||||
|
|
||||||
|
|
||||||
|
def repo_slug(src_root: Path, folder: str, owner: str) -> str:
|
||||||
|
"""Return the slug of ``src_root/folder``'s origin, else ``owner/folder``."""
|
||||||
|
return origin_slug(src_root / folder) or f"{owner}/{folder}"
|
||||||
@ -24,6 +24,8 @@ class Paths:
|
|||||||
lock_file: Path
|
lock_file: Path
|
||||||
unit_dir: Path
|
unit_dir: Path
|
||||||
mcp_url: str
|
mcp_url: str
|
||||||
|
# Game checkouts: ``<src_root>/<repo>``'s origin names the GitHub repo.
|
||||||
|
src_root: Path
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def under(cls, root: Path) -> Paths:
|
def under(cls, root: Path) -> Paths:
|
||||||
@ -34,6 +36,7 @@ class Paths:
|
|||||||
lock_file=root / "state" / "lock",
|
lock_file=root / "state" / "lock",
|
||||||
unit_dir=root / "units",
|
unit_dir=root / "units",
|
||||||
mcp_url=DEAD_URL,
|
mcp_url=DEAD_URL,
|
||||||
|
src_root=root / "src",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -48,4 +51,5 @@ def resolve_paths(given: Paths | None = None) -> Paths:
|
|||||||
lock_file=home / ".local" / "share" / "feedback-inbox" / "lock",
|
lock_file=home / ".local" / "share" / "feedback-inbox" / "lock",
|
||||||
unit_dir=home / ".config" / "systemd" / "user",
|
unit_dir=home / ".config" / "systemd" / "user",
|
||||||
mcp_url=MCP_URL,
|
mcp_url=MCP_URL,
|
||||||
|
src_root=home / "src",
|
||||||
)
|
)
|
||||||
|
|||||||
@ -16,7 +16,12 @@ from feedback_inbox._inbox import (
|
|||||||
run_once,
|
run_once,
|
||||||
run_settled,
|
run_settled,
|
||||||
)
|
)
|
||||||
from feedback_inbox.tests.test_support import STAMP, FakeTodo, make_bundle
|
from feedback_inbox.tests.test_support import (
|
||||||
|
STAMP,
|
||||||
|
FakeTodo,
|
||||||
|
make_bundle,
|
||||||
|
make_checkout,
|
||||||
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -29,7 +34,21 @@ MANUAL = "MANUAL WORK REQUIRED: "
|
|||||||
|
|
||||||
|
|
||||||
def _run(paths: Paths, todo: FakeTodo) -> list[Outcome]:
|
def _run(paths: Paths, todo: FakeTodo) -> list[Outcome]:
|
||||||
return [r.outcome for r in run_once(paths.data_root, Importer(todo, OWNER), NOW)]
|
return [
|
||||||
|
r.outcome
|
||||||
|
for r in run_once(paths.data_root, Importer(todo, OWNER, paths.src_root), NOW)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_task_goes_to_the_checkouts_origin_not_a_guessed_owner(paths: Paths) -> None:
|
||||||
|
# Regression: the board showed a phantom kuhyx/cleanup-plate; the real
|
||||||
|
# repo is the origin of the checkout, Sepci0/cleanup-plate.
|
||||||
|
origin = "https://github.com/Sepci0/cleanup-plate"
|
||||||
|
make_checkout(paths.src_root / "cleanup-plate", origin)
|
||||||
|
make_bundle(paths.data_root)
|
||||||
|
todo = FakeTodo()
|
||||||
|
assert _run(paths, todo) == [Outcome.IMPORTED]
|
||||||
|
assert [repo for repo, _, _ in todo.calls] == ["Sepci0/cleanup-plate"]
|
||||||
|
|
||||||
|
|
||||||
def test_complete_bundle_becomes_one_task(paths: Paths) -> None:
|
def test_complete_bundle_becomes_one_task(paths: Paths) -> None:
|
||||||
@ -64,7 +83,7 @@ def test_incomplete_bundles_wait(paths: Paths) -> None:
|
|||||||
todo = FakeTodo()
|
todo = FakeTodo()
|
||||||
assert _run(paths, todo) == [Outcome.PENDING] * 3
|
assert _run(paths, todo) == [Outcome.PENDING] * 3
|
||||||
assert todo.calls == []
|
assert todo.calls == []
|
||||||
later = run_once(paths.data_root, Importer(todo, OWNER), NOW + 10)
|
later = run_once(paths.data_root, Importer(todo, OWNER, paths.src_root), NOW + 10)
|
||||||
assert [r.outcome for r in later] == [
|
assert [r.outcome for r in later] == [
|
||||||
Outcome.PENDING,
|
Outcome.PENDING,
|
||||||
Outcome.PENDING,
|
Outcome.PENDING,
|
||||||
@ -126,7 +145,7 @@ def test_title_uses_first_line_and_caps_length() -> None:
|
|||||||
def test_todo_failure_leaves_no_marker(paths: Paths) -> None:
|
def test_todo_failure_leaves_no_marker(paths: Paths) -> None:
|
||||||
bundle = make_bundle(paths.data_root)
|
bundle = make_bundle(paths.data_root)
|
||||||
todo = FakeTodo(fail=True)
|
todo = FakeTodo(fail=True)
|
||||||
results = run_once(paths.data_root, Importer(todo, OWNER), NOW)
|
results = run_once(paths.data_root, Importer(todo, OWNER, paths.src_root), NOW)
|
||||||
assert [r.outcome for r in results] == [Outcome.FAILED]
|
assert [r.outcome for r in results] == [Outcome.FAILED]
|
||||||
assert "todo down" in results[0].detail
|
assert "todo down" in results[0].detail
|
||||||
assert not (bundle / MARKER).exists()
|
assert not (bundle / MARKER).exists()
|
||||||
@ -135,7 +154,9 @@ def test_todo_failure_leaves_no_marker(paths: Paths) -> None:
|
|||||||
|
|
||||||
def test_merge_is_flagged_but_marked(paths: Paths) -> None:
|
def test_merge_is_flagged_but_marked(paths: Paths) -> None:
|
||||||
make_bundle(paths.data_root)
|
make_bundle(paths.data_root)
|
||||||
results = run_once(paths.data_root, Importer(FakeTodo(merged=True), OWNER), NOW)
|
results = run_once(
|
||||||
|
paths.data_root, Importer(FakeTodo(merged=True), OWNER, paths.src_root), NOW
|
||||||
|
)
|
||||||
assert results[0].outcome is Outcome.IMPORTED
|
assert results[0].outcome is Outcome.IMPORTED
|
||||||
assert "merged" in results[0].detail
|
assert "merged" in results[0].detail
|
||||||
|
|
||||||
@ -143,12 +164,16 @@ def test_merge_is_flagged_but_marked(paths: Paths) -> None:
|
|||||||
def test_marker_write_failure_is_reported(paths: Paths) -> None:
|
def test_marker_write_failure_is_reported(paths: Paths) -> None:
|
||||||
bundle = make_bundle(paths.data_root)
|
bundle = make_bundle(paths.data_root)
|
||||||
(bundle / MARKER).mkdir()
|
(bundle / MARKER).mkdir()
|
||||||
results = run_once(paths.data_root, Importer(FakeTodo(), OWNER), NOW)
|
results = run_once(
|
||||||
|
paths.data_root, Importer(FakeTodo(), OWNER, paths.src_root), NOW
|
||||||
|
)
|
||||||
assert results[0].outcome is Outcome.SKIPPED
|
assert results[0].outcome is Outcome.SKIPPED
|
||||||
(bundle / MARKER).rmdir()
|
(bundle / MARKER).rmdir()
|
||||||
bundle.chmod(0o500)
|
bundle.chmod(0o500)
|
||||||
try:
|
try:
|
||||||
results = run_once(paths.data_root, Importer(FakeTodo(), OWNER), NOW)
|
results = run_once(
|
||||||
|
paths.data_root, Importer(FakeTodo(), OWNER, paths.src_root), NOW
|
||||||
|
)
|
||||||
finally:
|
finally:
|
||||||
bundle.chmod(0o700)
|
bundle.chmod(0o700)
|
||||||
assert results[0].outcome is Outcome.FAILED
|
assert results[0].outcome is Outcome.FAILED
|
||||||
@ -166,7 +191,9 @@ def test_run_settled_waits_then_gives_up(paths: Paths, tmp_path: Path) -> None:
|
|||||||
|
|
||||||
todo = FakeTodo()
|
todo = FakeTodo()
|
||||||
results = run_settled(
|
results = run_settled(
|
||||||
paths.data_root, Importer(todo, OWNER), Waiter(5.0, lambda: clock[0], sleep)
|
paths.data_root,
|
||||||
|
Importer(todo, OWNER, paths.src_root),
|
||||||
|
Waiter(5.0, lambda: clock[0], sleep),
|
||||||
)
|
)
|
||||||
assert [r.outcome for r in results] == [Outcome.IMPORTED]
|
assert [r.outcome for r in results] == [Outcome.IMPORTED]
|
||||||
assert slept == [1.0, 1.0]
|
assert slept == [1.0, 1.0]
|
||||||
@ -176,7 +203,9 @@ def test_run_settled_waits_then_gives_up(paths: Paths, tmp_path: Path) -> None:
|
|||||||
make_bundle(other, report=None)
|
make_bundle(other, report=None)
|
||||||
slept.clear()
|
slept.clear()
|
||||||
results = run_settled(
|
results = run_settled(
|
||||||
other, Importer(todo, OWNER), Waiter(3.0, lambda: clock[0], sleep)
|
other,
|
||||||
|
Importer(todo, OWNER, paths.src_root),
|
||||||
|
Waiter(3.0, lambda: clock[0], sleep),
|
||||||
)
|
)
|
||||||
assert [r.outcome for r in results] == [Outcome.PENDING]
|
assert [r.outcome for r in results] == [Outcome.PENDING]
|
||||||
assert slept == [1.0, 1.0, 1.0]
|
assert slept == [1.0, 1.0, 1.0]
|
||||||
|
|||||||
@ -28,7 +28,10 @@ MANUAL = "MANUAL WORK REQUIRED: "
|
|||||||
|
|
||||||
|
|
||||||
def _run(paths: Paths, todo: FakeTodo) -> list[Outcome]:
|
def _run(paths: Paths, todo: FakeTodo) -> list[Outcome]:
|
||||||
return [r.outcome for r in run_once(paths.data_root, Importer(todo, OWNER), NOW)]
|
return [
|
||||||
|
r.outcome
|
||||||
|
for r in run_once(paths.data_root, Importer(todo, OWNER, paths.src_root), NOW)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def _marker(bundle: Path) -> dict[str, object]:
|
def _marker(bundle: Path) -> dict[str, object]:
|
||||||
@ -63,7 +66,7 @@ def test_failed_update_keeps_marker_and_retries_without_a_second_task(
|
|||||||
) -> None:
|
) -> None:
|
||||||
bundle = make_bundle(paths.data_root)
|
bundle = make_bundle(paths.data_root)
|
||||||
todo = FakeTodo(fail_update=True)
|
todo = FakeTodo(fail_update=True)
|
||||||
results = run_once(paths.data_root, Importer(todo, OWNER), NOW)
|
results = run_once(paths.data_root, Importer(todo, OWNER, paths.src_root), NOW)
|
||||||
assert [r.outcome for r in results] == [Outcome.FAILED]
|
assert [r.outcome for r in results] == [Outcome.FAILED]
|
||||||
assert "update refused" in results[0].detail
|
assert "update refused" in results[0].detail
|
||||||
assert "format" not in _marker(bundle)
|
assert "format" not in _marker(bundle)
|
||||||
@ -138,7 +141,9 @@ def test_repair_reports_an_unwritable_marker(paths: Paths) -> None:
|
|||||||
)
|
)
|
||||||
bundle.chmod(0o500)
|
bundle.chmod(0o500)
|
||||||
try:
|
try:
|
||||||
results = run_once(paths.data_root, Importer(FakeTodo(), OWNER), NOW)
|
results = run_once(
|
||||||
|
paths.data_root, Importer(FakeTodo(), OWNER, paths.src_root), NOW
|
||||||
|
)
|
||||||
finally:
|
finally:
|
||||||
bundle.chmod(0o700)
|
bundle.chmod(0o700)
|
||||||
assert results[0].outcome is Outcome.FAILED
|
assert results[0].outcome is Outcome.FAILED
|
||||||
|
|||||||
80
feedback_inbox/feedback_inbox/tests/test_origin.py
Normal file
80
feedback_inbox/feedback_inbox/tests/test_origin.py
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
# Copyright (c) 2026 Krzysztof Rudnicki
|
||||||
|
"""Origin lookup: every remote URL form, and every way a checkout has none."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from feedback_inbox import _origin
|
||||||
|
from feedback_inbox._origin import origin_slug, repo_slug, slug_from_url
|
||||||
|
from feedback_inbox.tests.test_support import make_checkout
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"url",
|
||||||
|
[
|
||||||
|
"https://github.com/Sepci0/cleanup-plate",
|
||||||
|
"https://github.com/Sepci0/cleanup-plate.git",
|
||||||
|
"https://github.com/Sepci0/cleanup-plate/\n",
|
||||||
|
"https://kuhy@github.com/Sepci0/cleanup-plate.git",
|
||||||
|
"git@github.com:Sepci0/cleanup-plate.git",
|
||||||
|
"ssh://git@github.com/Sepci0/cleanup-plate",
|
||||||
|
"ssh://git@github.com:22/Sepci0/cleanup-plate.git",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_github_urls_give_the_slug(url: str) -> None:
|
||||||
|
assert slug_from_url(url) == "Sepci0/cleanup-plate"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"url",
|
||||||
|
[
|
||||||
|
"/home/someone/mirror/cleanup-plate",
|
||||||
|
"file:///srv/git/cleanup-plate.git",
|
||||||
|
"https://gitea.example.org/Sepci0/cleanup-plate.git",
|
||||||
|
"https://github.com/Sepci0",
|
||||||
|
"https://github.com/Sepci0/cleanup-plate/extra",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_other_urls_give_none(url: str) -> None:
|
||||||
|
assert slug_from_url(url) is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_checkout_origin_is_read(tmp_path: Path) -> None:
|
||||||
|
repo = make_checkout(tmp_path / "todo", "https://github.com/kuhyx/todo-app.git")
|
||||||
|
assert origin_slug(repo) == "kuhyx/todo-app"
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_checkout_or_no_origin_is_none(tmp_path: Path) -> None:
|
||||||
|
(tmp_path / "plain").mkdir()
|
||||||
|
assert origin_slug(tmp_path / "missing") is None
|
||||||
|
assert origin_slug(tmp_path / "plain") is None
|
||||||
|
assert origin_slug(make_checkout(tmp_path / "bare", None)) is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_missing_or_hung_git_is_none(
|
||||||
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||||
|
) -> None:
|
||||||
|
repo = make_checkout(tmp_path / "todo", "https://github.com/kuhyx/todo-app")
|
||||||
|
|
||||||
|
def hang(*args: object, **kwargs: object) -> None:
|
||||||
|
msg = "git"
|
||||||
|
raise subprocess.TimeoutExpired(msg, _origin.GIT_TIMEOUT)
|
||||||
|
|
||||||
|
monkeypatch.setattr(_origin.subprocess, "run", hang)
|
||||||
|
assert origin_slug(repo) is None
|
||||||
|
monkeypatch.setattr(_origin.shutil, "which", lambda _: None)
|
||||||
|
assert origin_slug(repo) is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_repo_slug_falls_back_to_the_owner_guess(tmp_path: Path) -> None:
|
||||||
|
make_checkout(tmp_path / "todo", "git@github.com:kuhyx/todo-app.git")
|
||||||
|
assert repo_slug(tmp_path, "todo", "kuhyx") == "kuhyx/todo-app"
|
||||||
|
assert repo_slug(tmp_path, "museum", "kuhyx") == "kuhyx/museum"
|
||||||
@ -6,6 +6,8 @@ from __future__ import annotations
|
|||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from feedback_inbox._todo import TaskRef, TodoError
|
from feedback_inbox._todo import TaskRef, TodoError
|
||||||
@ -93,3 +95,21 @@ class FakeTodo:
|
|||||||
raise TodoError(msg)
|
raise TodoError(msg)
|
||||||
self.updated.append(task_id)
|
self.updated.append(task_id)
|
||||||
self.stored[task_id] = f"{title}\n\n{body}"
|
self.stored[task_id] = f"{title}\n\n{body}"
|
||||||
|
|
||||||
|
|
||||||
|
GIT = shutil.which("git") or "git"
|
||||||
|
|
||||||
|
|
||||||
|
def make_checkout(path: Path, origin: str | None) -> Path:
|
||||||
|
"""A real git repo at ``path`` (origin ``origin`` unless None), no real config."""
|
||||||
|
env = {
|
||||||
|
"PATH": os.environ["PATH"],
|
||||||
|
"HOME": str(path.parent),
|
||||||
|
"GIT_CONFIG_NOSYSTEM": "1",
|
||||||
|
}
|
||||||
|
path.mkdir(parents=True)
|
||||||
|
subprocess.run([GIT, "init", "-q", str(path)], check=True, env=env)
|
||||||
|
if origin is not None:
|
||||||
|
git = [GIT, "-C", str(path), "remote", "add", "origin", origin]
|
||||||
|
subprocess.run(git, check=True, env=env)
|
||||||
|
return path
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user