Skip to content

Commit

Permalink
Update validate_markdown.py
Browse files Browse the repository at this point in the history
  • Loading branch information
0xldr authored Jan 25, 2024
1 parent 63a4db3 commit 53e8ec4
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions .github/scripts/validate_markdown.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import os
import re
import sys
import requests
from github import Github
from frontmatter import Frontmatter as fm

# Constants
URL_REGEX = re.compile(
r"(https?://(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?://(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})"
)
from web3 import Web3

# Environment variables
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
Expand Down Expand Up @@ -35,18 +31,26 @@ def validate_markdown(file_path):
errors.append('missing date')
if 'address' not in metadata:
errors.append('missing mainnet address')
elif not re.match(URL_REGEX, metadata['address']):
errors.append('invalid mainnet address')

# Additional validation logic goes here
elif not Web3.isAddress(metadata['address']):
errors.append('invalid address format')
elif not Web3.isChecksumAddress(metadata['address']):
errors.append('address is not checksummed')

return errors

# Variable to track if any file has errors
has_errors = False

# Iterate over modified files in the PR
for file in pr.get_files():
if file.filename.startswith('governance/votes/') and file.filename.endswith('.md'):
errors = validate_markdown(file.filename)
if errors:
has_errors = True # Set has_errors to True if any errors are found
print(f"Validation errors in {file.filename}:")
for error in errors:
print(f"- {error}")

# Exit with a non-zero status code if any errors were found
if has_errors:
sys.exit(1)

0 comments on commit 53e8ec4

Please sign in to comment.