From 26ae82ab5d1908985f34fe77f762e778bf539e37 Mon Sep 17 00:00:00 2001 From: Aditya Jyoti Date: Mon, 8 Apr 2024 18:22:36 +0530 Subject: [PATCH] test: trying auto push --- pr_check.py | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/pr_check.py b/pr_check.py index 937c333..1f369c8 100644 --- a/pr_check.py +++ b/pr_check.py @@ -2,6 +2,7 @@ import sys import re + def check_introduction_file(introduction_file): """ Check if the contents of the introduction.md file follow the specified pattern. @@ -14,7 +15,7 @@ def check_introduction_file(introduction_file): sys.exit(1) # Read the contents of the introduction.md file - with open(introduction_file, 'r') as file: + with open(introduction_file, "r") as file: introduction_content = file.read() # Define the pattern to match @@ -36,45 +37,31 @@ def check_introduction_file(introduction_file): # Check if the pattern matches if match: print("Success: Introduction file follows the specified pattern.") - # Extract captured groups for further processing if needed - name, interests, description, github, image = match.groups() - print("Name:", name) - print("Interests:", interests) - print("Description:", description) - print("GitHub:", github) - print("Image:", image) else: print("Error: Introduction file does not follow the specified pattern.") sys.exit(1) + def validate_pr(directory="."): introductions_folder = os.path.join(directory, "src", "content", "introductions") - try: - before_folders = set(os.listdir(introductions_folder)) - - os.system(f'git checkout origin/main -- {introductions_folder}') - - after_folders = set(os.listdir(introductions_folder)) - added_folders = after_folders - before_folders - - except Exception as e: - print(f"Error: Unable to retrieve folder information: {e}") - sys.exit(1) - - if added_folders: - for folder in added_folders: - folder_path = os.path.join(introductions_folder, folder) - introduction_md_path = os.path.join(folder_path, "introduction.md") - if os.path.exists(introduction_md_path): - print(f"Success: '{folder}' folder was added in 'src/content/introductions' and contains 'introduction.md'.") - check_introduction_file(introduction_md_path) - else: - print(f"Error: '{folder}' folder was added in 'src/content/introductions' but does not contain 'introduction.md'.") - sys.exit(1) + for folder in introductions_folder: + folder_path = os.path.join(introductions_folder, folder) + introduction_md_path = os.path.join(folder_path, "introduction.md") + if os.path.exists(introduction_md_path): + print( + f"Success: '{folder}' folder was added in 'src/content/introductions' and contains 'introduction.md'." + ) + check_introduction_file(introduction_md_path) + else: + print( + f"Error: '{folder}' folder was added in 'src/content/introductions' but does not contain 'introduction.md'." + ) + sys.exit(1) else: print("Error: No folders were added in 'src/content/introductions'.") sys.exit(1) + if __name__ == "__main__": validate_pr()