Skip to content

Commit

Permalink
test: trying auto push
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-Jyoti committed Apr 8, 2024
1 parent f666082 commit 26ae82a
Showing 1 changed file with 17 additions and 30 deletions.
47 changes: 17 additions & 30 deletions pr_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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()

0 comments on commit 26ae82a

Please sign in to comment.