From 1b023bfe5a9c46a564fabfa8ce0eaa0c56daf92c Mon Sep 17 00:00:00 2001 From: Rowena Date: Thu, 30 Jan 2025 11:07:06 +0100 Subject: [PATCH 1/5] fix(review-bot): update for new structure --- bin/check-review-dates.py | 57 ++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/bin/check-review-dates.py b/bin/check-review-dates.py index 17ff276ab7..e3e72afeba 100644 --- a/bin/check-review-dates.py +++ b/bin/check-review-dates.py @@ -4,6 +4,7 @@ from datetime import timedelta, date, datetime DEFAULT_VAL_FREQ = 6 +FILEPATH = "." def convert_to_date_and_delta(val_date, val_freq): "Converts validation date string to datetime and validation frequency string (months) to timedelta." @@ -15,6 +16,26 @@ def convert_to_date_and_delta(val_date, val_freq): # handles the case where validation format is incorrect return None, None +def get_prod_cat_ref(): + "Makes a dictionary where keys are product slugs and values are their category label and product label" + + product_categories = {} + + # Load the menu file + with open('menu/navigation.json', 'r') as file: + data = json.load(file) # Parse the JSON content into a Python dictionary or list + + for grouping in data: + for category in grouping["items"]: + category_label = category["label"] + for product in category["items"]: + product_label = product["label"] + product_slug = product["slug"] + + product_categories[product_slug] = [category_label, product_label] + + return(product_categories) + def needs_review(val_date, val_freq): "Returns true if doc needs to be reviewed, based on val date and frequency" val_date_conv, val_freq_conv = convert_to_date_and_delta(val_date, val_freq) @@ -60,32 +81,38 @@ def process_files(directory): docs_to_review.append(filepath) return docs_to_review -def get_doc_cat_name(filepath): - "Returns a document-to-review's category and tidied-up filepath, based on its raw filepath." +def get_doc_cat_name(filepath, prod_cat_ref): + "Returns a document-to-review's category and tidied-up filepath, based on its raw filepath and the prod_cat_ref dict." trimmed_filepath = filepath[2:-4] filepath_list = trimmed_filepath.split("/") - if filepath_list[0] == "tutorials": - category = filepath_list[0] - elif filepath_list[0] == "faq": - category = filepath_list[1] + if filepath_list[1] == "tutorials": + category_product = "Tutorials" + elif filepath_list[1] == "faq": + category_product = "FAQ" else: - category = ' '.join(filepath_list[0:2]) - - return category, trimmed_filepath + # catches everything in pages + category = prod_cat_ref.get(filepath_list[2], ["Unknown", "Unknown"])[0] + product = prod_cat_ref.get(filepath_list[2], ["Unknown", "Unknown"])[1] + category_product = category + ": " + product + + return category_product, trimmed_filepath def organize_docs_by_category(docs_to_review): "Organizes docs to review by category into a dictionary." print("Organizing docs by category") dict_by_cat = {} - + + # one shot: make a dict of all products and their categories, based on menu file + prod_cat_ref = get_prod_cat_ref() + for filepath in docs_to_review: - category, trimmed_filepath = get_doc_cat_name(filepath) + category_product, trimmed_filepath = get_doc_cat_name(filepath, prod_cat_ref) - if category not in dict_by_cat: - dict_by_cat[category] = [trimmed_filepath] + if category_product not in dict_by_cat: + dict_by_cat[category_product] = [trimmed_filepath] else: - dict_by_cat[category].append(trimmed_filepath) + dict_by_cat[category_product].append(trimmed_filepath) # sort the dictionary alphabetically by category dict_by_cat_sorted = {key: value for key, value in sorted(dict_by_cat.items())} @@ -116,7 +143,7 @@ def send_message(message): ) def main(): - docs_to_review = process_files(".") + docs_to_review = process_files(FILEPATH) docs_to_review_by_cat = organize_docs_by_category(docs_to_review) message = prep_message(docs_to_review_by_cat) if os.environ.get("DRY_RUN") != "true": From 9644b1a4ace9bb1e2413d3623f092577f4c4ab9a Mon Sep 17 00:00:00 2001 From: Rowena Date: Thu, 30 Jan 2025 11:18:11 +0100 Subject: [PATCH 2/5] fix(review-bot): review bot for new structure done --- bin/check-review-dates.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/check-review-dates.py b/bin/check-review-dates.py index e3e72afeba..f543a98a19 100644 --- a/bin/check-review-dates.py +++ b/bin/check-review-dates.py @@ -2,9 +2,10 @@ import logging from slack_sdk import WebClient from datetime import timedelta, date, datetime +import json DEFAULT_VAL_FREQ = 6 -FILEPATH = "." +FILEPATH = "./" ## for local testing use "../" def convert_to_date_and_delta(val_date, val_freq): "Converts validation date string to datetime and validation frequency string (months) to timedelta." @@ -22,7 +23,7 @@ def get_prod_cat_ref(): product_categories = {} # Load the menu file - with open('menu/navigation.json', 'r') as file: + with open(FILEPATH + 'menu/navigation.json', 'r') as file: data = json.load(file) # Parse the JSON content into a Python dictionary or list for grouping in data: From aa7d1e0cbaf1f332d9f4e519cb2bccaf0dd4fe24 Mon Sep 17 00:00:00 2001 From: Rowena Date: Thu, 30 Jan 2025 12:09:34 +0100 Subject: [PATCH 3/5] fix(review-bot): test --- bin/check-review-dates.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/check-review-dates.py b/bin/check-review-dates.py index f543a98a19..05801f3780 100644 --- a/bin/check-review-dates.py +++ b/bin/check-review-dates.py @@ -93,6 +93,8 @@ def get_doc_cat_name(filepath, prod_cat_ref): category_product = "FAQ" else: # catches everything in pages + print("Currently checking FILEPATH", filepath) + print("filepath_list is", filepath_list) category = prod_cat_ref.get(filepath_list[2], ["Unknown", "Unknown"])[0] product = prod_cat_ref.get(filepath_list[2], ["Unknown", "Unknown"])[1] category_product = category + ": " + product From c2b41f5fc7a508c96990ce0f93bdc7a7378496e0 Mon Sep 17 00:00:00 2001 From: Rowena Date: Thu, 30 Jan 2025 12:14:21 +0100 Subject: [PATCH 4/5] fix(bot): test --- bin/check-review-dates.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/check-review-dates.py b/bin/check-review-dates.py index 05801f3780..617a9478f6 100644 --- a/bin/check-review-dates.py +++ b/bin/check-review-dates.py @@ -87,16 +87,16 @@ def get_doc_cat_name(filepath, prod_cat_ref): trimmed_filepath = filepath[2:-4] filepath_list = trimmed_filepath.split("/") - if filepath_list[1] == "tutorials": + if filepath_list[0] == "tutorials": category_product = "Tutorials" - elif filepath_list[1] == "faq": + elif filepath_list[0] == "faq": category_product = "FAQ" else: # catches everything in pages print("Currently checking FILEPATH", filepath) print("filepath_list is", filepath_list) - category = prod_cat_ref.get(filepath_list[2], ["Unknown", "Unknown"])[0] - product = prod_cat_ref.get(filepath_list[2], ["Unknown", "Unknown"])[1] + category = prod_cat_ref.get(filepath_list[1], ["Unknown", "Unknown"])[0] + product = prod_cat_ref.get(filepath_list[1], ["Unknown", "Unknown"])[1] category_product = category + ": " + product return category_product, trimmed_filepath From 63fb3b820662682a61001551e7701bf32dd16c53 Mon Sep 17 00:00:00 2001 From: Rowena Date: Thu, 30 Jan 2025 12:20:59 +0100 Subject: [PATCH 5/5] fix(review-bot): final fix for indexes --- bin/check-review-dates.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bin/check-review-dates.py b/bin/check-review-dates.py index 617a9478f6..9285cfc57a 100644 --- a/bin/check-review-dates.py +++ b/bin/check-review-dates.py @@ -5,7 +5,7 @@ import json DEFAULT_VAL_FREQ = 6 -FILEPATH = "./" ## for local testing use "../" +FILEPATH = "./" ## for local testing use "../" and shift filepath_list[] indexes +1 def convert_to_date_and_delta(val_date, val_freq): "Converts validation date string to datetime and validation frequency string (months) to timedelta." @@ -93,8 +93,6 @@ def get_doc_cat_name(filepath, prod_cat_ref): category_product = "FAQ" else: # catches everything in pages - print("Currently checking FILEPATH", filepath) - print("filepath_list is", filepath_list) category = prod_cat_ref.get(filepath_list[1], ["Unknown", "Unknown"])[0] product = prod_cat_ref.get(filepath_list[1], ["Unknown", "Unknown"])[1] category_product = category + ": " + product @@ -128,7 +126,7 @@ def prep_message(docs_to_review_by_cat): message = ":wave: Hi doc team, here are some docs to review: \n \n" for key in docs_to_review_by_cat: - message += "*" + key.title() + "*" + "\n" + message += "*" + key + "*" + "\n" for doc in docs_to_review_by_cat[key]: message += doc + "\n" message += "\n"