GRM-36: fix: use correct Gitea 1.26 wiki API endpoints
Updated sync_wiki.py to use correct Gitea 1.26 wiki API: POST /wiki/new for create, PATCH /wiki/page/{sub_url} for update, GET /wiki/pages returns sub_url. Tests updated to match.
Closes GRM-36
This commit is contained in:
+15
-9
@@ -6,6 +6,12 @@ map file paths to wiki page titles, and creates/updates wiki pages via the
|
|||||||
Gitea API. Pages that exist in the wiki but not in the mapping are left
|
Gitea API. Pages that exist in the wiki but not in the mapping are left
|
||||||
untouched (not deleted).
|
untouched (not deleted).
|
||||||
|
|
||||||
|
Gitea 1.26 wiki API endpoints:
|
||||||
|
- Create: POST /repos/{owner}/{repo}/wiki/new {title, content, message}
|
||||||
|
- Update: PATCH /repos/{owner}/{repo}/wiki/page/{sub_url} {title, content, message}
|
||||||
|
- List: GET /repos/{owner}/{repo}/wiki/pages → [{title, sub_url, ...}]
|
||||||
|
- Delete: DELETE /repos/{owner}/{repo}/wiki/page/{sub_url}
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
REPO_TOKEN=<token> python3 scripts/sync_wiki.py [--dry-run] [--repo owner/repo]
|
REPO_TOKEN=<token> python3 scripts/sync_wiki.py [--dry-run] [--repo owner/repo]
|
||||||
"""
|
"""
|
||||||
@@ -44,12 +50,12 @@ def read_doc_content(file_path: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def list_wiki_pages(client: GiteaClient) -> dict[str, str]:
|
def list_wiki_pages(client: GiteaClient) -> dict[str, str]:
|
||||||
"""List existing wiki pages, returning {title: page_name}."""
|
"""List existing wiki pages, returning {title: sub_url}."""
|
||||||
try:
|
try:
|
||||||
pages = client._request("GET", "/wiki/pages").json()
|
pages = client._request("GET", "/wiki/pages").json()
|
||||||
except APIError:
|
except APIError:
|
||||||
return {}
|
return {}
|
||||||
return {page.get("title", ""): page.get("page_name", page.get("title", "")) for page in pages}
|
return {page.get("title", ""): page.get("sub_url", page.get("title", "")) for page in pages}
|
||||||
|
|
||||||
|
|
||||||
def sync_page(
|
def sync_page(
|
||||||
@@ -68,19 +74,19 @@ def sync_page(
|
|||||||
return "skipped"
|
return "skipped"
|
||||||
|
|
||||||
if page_title in existing_pages:
|
if page_title in existing_pages:
|
||||||
# Update existing page
|
# Update existing page via PATCH
|
||||||
page_name = existing_pages[page_title]
|
sub_url = existing_pages[page_title]
|
||||||
client._request(
|
client._request(
|
||||||
"PUT",
|
"PATCH",
|
||||||
f"/wiki/page/{page_name}",
|
f"/wiki/page/{sub_url}",
|
||||||
json={"content": content, "message": f"Sync from docs/ — update {page_title}"},
|
json={"title": page_title, "content": content, "message": f"Sync from docs/ — update {page_title}"},
|
||||||
)
|
)
|
||||||
return "updated"
|
return "updated"
|
||||||
|
|
||||||
# Create new page
|
# Create new page via POST /wiki/new
|
||||||
client._request(
|
client._request(
|
||||||
"POST",
|
"POST",
|
||||||
"/wiki/page",
|
"/wiki/new",
|
||||||
json={"title": page_title, "content": content, "message": f"Sync from docs/ — create {page_title}"},
|
json={"title": page_title, "content": content, "message": f"Sync from docs/ — create {page_title}"},
|
||||||
)
|
)
|
||||||
return "created"
|
return "created"
|
||||||
|
|||||||
@@ -57,11 +57,11 @@ class TestListWikiPages:
|
|||||||
def test_returns_page_dict(self) -> None:
|
def test_returns_page_dict(self) -> None:
|
||||||
client = MagicMock()
|
client = MagicMock()
|
||||||
client._request.return_value.json.return_value = [
|
client._request.return_value.json.return_value = [
|
||||||
{"title": "Home", "page_name": "Home"},
|
{"title": "Home", "sub_url": "Home"},
|
||||||
{"title": "Getting-Started", "page_name": "Getting-Started"},
|
{"title": "Getting-Started", "sub_url": "Getting-Started.-"},
|
||||||
]
|
]
|
||||||
result = list_wiki_pages(client)
|
result = list_wiki_pages(client)
|
||||||
assert result == {"Home": "Home", "Getting-Started": "Getting-Started"}
|
assert result == {"Home": "Home", "Getting-Started": "Getting-Started.-"}
|
||||||
|
|
||||||
|
|
||||||
class TestSyncPage:
|
class TestSyncPage:
|
||||||
@@ -78,16 +78,17 @@ class TestSyncPage:
|
|||||||
client._request.assert_called_once()
|
client._request.assert_called_once()
|
||||||
call_args = client._request.call_args
|
call_args = client._request.call_args
|
||||||
assert call_args.args[0] == "POST"
|
assert call_args.args[0] == "POST"
|
||||||
assert call_args.args[1] == "/wiki/page"
|
assert call_args.args[1] == "/wiki/new"
|
||||||
|
|
||||||
def test_updates_existing_page(self) -> None:
|
def test_updates_existing_page(self) -> None:
|
||||||
client = MagicMock()
|
client = MagicMock()
|
||||||
existing = {"Existing-Page": "Existing-Page"}
|
existing = {"Existing-Page": "Existing-Page.-"}
|
||||||
result = sync_page(client, "Existing-Page", "# Updated", existing, dry_run=False)
|
result = sync_page(client, "Existing-Page", "# Updated", existing, dry_run=False)
|
||||||
assert result == "updated"
|
assert result == "updated"
|
||||||
client._request.assert_called_once()
|
client._request.assert_called_once()
|
||||||
call_args = client._request.call_args
|
call_args = client._request.call_args
|
||||||
assert call_args.args[0] == "PUT"
|
assert call_args.args[0] == "PATCH"
|
||||||
|
assert "/wiki/page/Existing-Page.-" in call_args.args[1]
|
||||||
|
|
||||||
|
|
||||||
class TestMain:
|
class TestMain:
|
||||||
|
|||||||
Reference in New Issue
Block a user