diff --git a/src/config.py b/src/config.py index 7cbb72a..bd514fe 100644 --- a/src/config.py +++ b/src/config.py @@ -22,6 +22,7 @@ class Settings(BaseSettings): # Gitea gitea_url: str = "http://localhost:3000" + gitea_public_url: str = "" # external URL for clickable links in comments; falls back to gitea_url gitea_token: str = "" gitea_webhook_secret: str = "" gitea_owner: str = "admin" diff --git a/src/stage_engine.py b/src/stage_engine.py index 3068039..43d762f 100644 --- a/src/stage_engine.py +++ b/src/stage_engine.py @@ -296,7 +296,7 @@ def _build_analyst_ready_comment(repo: str, work_item_id: str, branch: str) -> s wt_dir = None owner = getattr(settings, "gitea_owner", "admin") - base = settings.gitea_url.rstrip("/") + base = (getattr(settings, "gitea_public_url", "") or settings.gitea_url).rstrip("/") links = [] for label, fname in candidates: if wt_dir and not os.path.isfile(os.path.join(wt_dir, fname)): diff --git a/tests/test_analyst_comment.py b/tests/test_analyst_comment.py index a4e5414..1002001 100644 --- a/tests/test_analyst_comment.py +++ b/tests/test_analyst_comment.py @@ -25,7 +25,9 @@ def test_analyst_comment_asks_approved_with_links(monkeypatch, tmp_path): # 04b-ui-test-cases.md intentionally absent -> must NOT be linked monkeypatch.setattr(SE, "get_worktree_path", lambda repo, branch: str(wt)) - monkeypatch.setattr(SE.settings, "gitea_url", "https://git.mva154.duckdns.org") + # public URL set -> links must be built from it (not gitea_url) + monkeypatch.setattr(SE.settings, "gitea_url", "http://localhost:3000") + monkeypatch.setattr(SE.settings, "gitea_public_url", "https://git.mva154.duckdns.org") monkeypatch.setattr(SE.settings, "gitea_owner", "admin") html = SE._build_analyst_ready_comment( @@ -45,3 +47,28 @@ def test_analyst_comment_asks_approved_with_links(monkeypatch, tmp_path): assert base + "04-test-plan.yaml" in html # the missing file is NOT invented assert "04b-ui-test-cases.md" not in html + # internal git url must NOT appear in clickable links + assert "localhost:3000" not in html + + +def test_analyst_comment_falls_back_to_gitea_url(monkeypatch, tmp_path): + """When gitea_public_url is empty, links fall back to gitea_url.""" + from src import stage_engine as SE + + wt = tmp_path / "wt" + docs = wt / "docs" / "work-items" / "ET-011" + docs.mkdir(parents=True) + (docs / "01-brd.md").write_text("x") + + monkeypatch.setattr(SE, "get_worktree_path", lambda repo, branch: str(wt)) + monkeypatch.setattr(SE.settings, "gitea_url", "http://localhost:3000") + monkeypatch.setattr(SE.settings, "gitea_public_url", "") + monkeypatch.setattr(SE.settings, "gitea_owner", "admin") + + html = SE._build_analyst_ready_comment( + "enduro-trails", "ET-011", "feature/ET-011-gpx-upload-feature" + ) + + base = ("http://localhost:3000/admin/enduro-trails/src/branch/" + "feature/ET-011-gpx-upload-feature/docs/work-items/ET-011/") + assert base + "01-brd.md" in html