hyfetch/merging/reformat_readme.py
2022-07-31 16:03:26 -04:00

21 lines
613 B
Python

#!/usr/bin/env python3
"""
This script turns readme shorthand pull request references (i.e. dylanaraps/neofetch#1946) into full
GitHub pull request links.
"""
import re
from pathlib import Path
RE_SHORTHAND = re.compile(r"""[a-z0-9]+?/[a-z0-9]+?#[0-9]+""")
if __name__ == '__main__':
readme = Path('README.md').read_text()
for shorthand in RE_SHORTHAND.findall(readme):
user, pull = shorthand.split('/')
repo, pull = pull.split('#')
readme = readme.replace(shorthand, f'[{user}#{pull}](https://github.com/{user}/{repo}/pull/{pull})')
Path('README.md').write_text(readme)