Skip to content

Commit 611e262

Browse files
ShahanaFarooquimadelinevibes
authored andcommitted
script: Update sync RPC documentation script to check if the page was renderable for Readme
- ReadMe API v2 now requires category.uri instead of category.id. - ReadMe v2 page responses include a renderable field indicating whether the document is MDX-compatible and can be rendered successfully. The script now checks this field and prints detailed compilation errors if rendering fails.
1 parent 3e841b3 commit 611e262

File tree

1 file changed

+48
-13
lines changed

1 file changed

+48
-13
lines changed

.github/scripts/sync-rpc-cmds.py

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
# readme url
99
URL = "https://api.readme.com/v2/branches/stable"
10-
# category id for API reference
11-
CATEGORY_ID = "685ce4df1df887006ff221c5"
1210
CATEGORY_SLUG = "JSON-RPC API Reference"
1311

1412

@@ -26,39 +24,76 @@ def getListOfRPCDocs(headers):
2624
return []
2725

2826

27+
def check_renderable(response, action, title):
28+
try:
29+
data = response.json()
30+
except Exception:
31+
print("Non-JSON response:")
32+
print(response.text)
33+
return False
34+
35+
renderable = data.get("renderable")
36+
if renderable is None:
37+
# Some endpoints don’t include renderable (e.g. DELETE)
38+
return True
39+
40+
if not renderable.get("status", False):
41+
print(f"\n❌ RENDER FAILED for {action.value.upper()} '{title}'")
42+
print("Error :", renderable.get("error"))
43+
print("Message:", renderable.get("message"))
44+
return False
45+
46+
return True
47+
48+
2949
def publishDoc(action, title, body, order, headers):
3050
payload = {
3151
"title": title,
3252
"type": "basic",
33-
"body": body,
53+
"content": {
54+
"body": body,
55+
},
3456
"category": {
35-
"id": CATEGORY_ID
57+
"uri": f"/branches/1/categories/reference/{CATEGORY_SLUG}"
3658
},
3759
"hidden": False,
3860
"order": order,
3961
}
62+
4063
if action == Action.ADD:
41-
# create doc
42-
payload['slug'] = title
64+
payload["slug"] = title
4365
response = requests.post(URL + "/reference", json=payload, headers=headers)
4466
if response.status_code != 201:
67+
print("❌ HTTP ERROR:", response.status_code)
4568
print(response.text)
46-
else:
47-
print("Created ", title)
69+
return
70+
71+
if not check_renderable(response, action, title):
72+
raise RuntimeError(f"Renderable check failed for {title}")
73+
74+
print("✅ Created", title)
75+
4876
elif action == Action.UPDATE:
49-
# update doc
5077
response = requests.patch(f"{URL}/reference/{title}", json=payload, headers=headers)
5178
if response.status_code != 200:
79+
print("❌ HTTP ERROR:", response.status_code)
5280
print(response.text)
53-
else:
54-
print("Updated ", title)
81+
return
82+
83+
if not check_renderable(response, action, title):
84+
raise RuntimeError(f"Renderable check failed for {title}")
85+
86+
print("✅ Updated", title)
87+
5588
elif action == Action.DELETE:
56-
# delete doc
5789
response = requests.delete(f"{URL}/reference/{title}", headers=headers)
90+
5891
if response.status_code != 204:
92+
print("❌ DELETE FAILED:", title)
5993
print(response.text)
6094
else:
61-
print("Deleted ", title)
95+
print("🗑️ Deleted", title)
96+
6297
else:
6398
print("Invalid action")
6499

0 commit comments

Comments
 (0)