forked from Aditya-Jyoti/Introduce-Yourself
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr_check.py
62 lines (51 loc) · 2.13 KB
/
pr_check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import sys
import re
def check_introduction_file(introduction_file):
"""
Check if the contents of the introduction.md file follow the specified pattern.
Args:
introduction_file (str): Path to the introduction.md file.
"""
if not os.path.exists(introduction_file):
print(f"Error: '{introduction_file}' does not exist.")
sys.exit(1)
# Read the contents of the introduction.md file
with open(introduction_file, "r") as file:
introduction_content = file.read()
# Define the pattern to match
pattern = r"""
^---\n # Start of YAML front matter
name:\s*(.*?)\n # Capture group for the name field
interests:\s*(.*?)\n # Capture group for the interests field
description:\s*(.*?)\n # Capture group for the description field
github:\s*(.*?)\n # Capture group for the github field
image:\s*(.*?)\n # Capture group for the image field
---$ # End of YAML front matter
"""
# Compile the regex pattern
regex = re.compile(pattern, re.MULTILINE | re.DOTALL | re.VERBOSE)
# Match the pattern against the introduction content
match = regex.match(introduction_content)
# Check if the pattern matches
if match:
print("Success: Introduction file follows the specified pattern.")
else:
print("Error: Introduction file does not follow the specified pattern.")
sys.exit(1)
def validate_pr():
introductions_folder = os.listdir("src/content/introductions")
for folder in introductions_folder:
introduction_md_path = f"src/content/introductions/{folder}/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(0)
if __name__ == "__main__":
validate_pr()