Skip to content

Commit 1f46c3f

Browse files
authored
fix(bot): fix review bot (#5691)
* fix(bot): fix review bot * fix(syntax): fix syntax * Update bin/check-review-dates.py * Apply suggestions from code review * Delete menu/navigation.json
1 parent 16d9095 commit 1f46c3f

File tree

4 files changed

+55
-19
lines changed

4 files changed

+55
-19
lines changed

bin/check-review-dates.py

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import logging
33
from slack_sdk import WebClient
44
from datetime import timedelta, date, datetime
5-
import json
5+
import re
6+
import ast
67

78
DEFAULT_VAL_FREQ = 6
89
FILEPATH = "./" ## for local testing use "../" and shift filepath_list[] indexes +1
@@ -22,18 +23,53 @@ def get_prod_cat_ref():
2223

2324
product_categories = {}
2425

25-
# Load the menu file
26-
with open(FILEPATH + 'menu/navigation.json', 'r') as file:
27-
data = json.load(file) # Parse the JSON content into a Python dictionary or list
28-
29-
for grouping in data:
30-
for category in grouping["items"]:
31-
category_label = category["label"]
32-
for product in category["items"]:
33-
product_label = product["label"]
34-
product_slug = product["slug"]
35-
36-
product_categories[product_slug] = [category_label, product_label]
26+
# Read the menu file
27+
with open(FILEPATH + "menu/navigation.ts", "r", encoding="utf-8") as f:
28+
js = f.read()
29+
30+
# remove all lines up to "export default"
31+
js = re.sub(r"^import .*", "", js, flags=re.M) # remove import lines
32+
js = re.sub(r"//.*", "", js) # strip line comments
33+
js = re.sub(r"/\*.*?\*/", "", js, flags=re.S) # strip block comments
34+
js = js.replace("export default", "").strip() # strip "export default" and cleanup
35+
36+
# Convert items - [accountMenu, billingMenu] → ['account', 'billing']
37+
js = re.sub(r"\b([a-zA-Z0-9_]+)Menu\b(?!')", r"'\1'", js)
38+
39+
# Convert icons - OrganizationDashboardCategoryIcon → 'OrganizationDashboardCategory'
40+
js = re.sub(r"\b([A-Z][A-Za-z0-9]+)Icon\b(?!')", r"'\1'", js)
41+
42+
# Normalize JS → Python syntax ---
43+
js = re.sub(r"(\w+):", r"'\1':", js) # quote keys
44+
js = js.replace("null", "None") # replace nulls with Nones
45+
js = re.sub(r",(\s*[}\]])", r"\1", js) # remove trailing commas
46+
47+
# Convert the js string now containing Python literal syntax, into an actual Python object.
48+
data = ast.literal_eval(js)
49+
50+
# Helper function
51+
def camel_to_kebab(name: str) -> str:
52+
"""Convert camelCase or PascalCase to kebab-case."""
53+
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1-\2', name)
54+
s2 = re.sub('([a-z0-9])([A-Z])', r'\1-\2', s1)
55+
return s2.lower()
56+
57+
# Helper function
58+
def prettify_label(slug: str) -> str:
59+
"""Convert kebab-case to title case."""
60+
return slug.replace("-", " ").title()
61+
62+
# Walk structure and make new dict
63+
64+
product_categories = {}
65+
66+
for section in data:
67+
for category in section["items"]:
68+
category_label = category["label"]
69+
for item in category["items"]:
70+
key = camel_to_kebab(item).lower().replace("_", "-")
71+
label = prettify_label(key)
72+
product_categories[key] = [category_label, label]
3773

3874
return(product_categories)
3975

menu/navigation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { partnerSpaceMenu } from "../pages/partner-space/menu"
5151
import { publicGatewaysMenu } from "../pages/public-gateways/menu"
5252
import { queuesMenu } from "../pages/queues/menu"
5353
import { scalewayCliMenu } from "../pages/scaleway-cli/menu"
54-
import { scalewySdkMenu } from "../pages/scaleway-sdk/menu"
54+
import { scalewaySdkMenu } from "../pages/scaleway-sdk/menu"
5555
import { secretManagerMenu } from "../pages/secret-manager/menu"
5656
import { serverlessContainersMenu } from "../pages/serverless-containers/menu"
5757
import { serverlessFunctionsMenu } from "../pages/serverless-functions/menu"
@@ -61,7 +61,7 @@ import { terraformMenu } from "../pages/terraform/menu"
6161
import { topicsAndEventsMenu } from "../pages/topics-and-events/menu"
6262
import { transactionalEmailMenu } from "../pages/transactional-email/menu"
6363
import { vpcMenu } from "../pages/vpc/menu"
64-
import { webHostingMenu } from "../pages/webhosting/menu"
64+
import { webhostingMenu } from "../pages/webhosting/menu"
6565

6666
export default [
6767
{
@@ -162,7 +162,7 @@ export default [
162162
icon: 'DevToolsCategoryIcon',
163163
items: [
164164
scalewayCliMenu,
165-
scalewySdkMenu,
165+
scalewaySdkMenu,
166166
terraformMenu,
167167
],
168168
label: 'Developer Tools',
@@ -173,7 +173,7 @@ export default [
173173
items: [
174174
domainsAndDnsMenu,
175175
transactionalEmailMenu,
176-
webHostingMenu,
176+
webhostingMenu,
177177
],
178178
label: 'Domains & Web Hosting',
179179
category: 'domains-and-web-hosting',

pages/scaleway-sdk/menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const scalewySdkMenu = {
1+
export const scalewaySdkMenu = {
22
items: [
33
{
44
label: 'Python SDK quickstart',

pages/webhosting/menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const webHostingMenu = {
1+
export const webhostingMenu = {
22
items: [
33
{
44
label: 'Overview',

0 commit comments

Comments
 (0)