reformat_readme.py 660 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env python3
  2. """
  3. This script turns readme shorthand pull request references (i.e. dylanaraps/neofetch#1946) into full
  4. GitHub pull request links.
  5. """
  6. import re
  7. from pathlib import Path
  8. RE_SHORTHAND = re.compile(r"""[a-z0-9]+?/[a-z0-9]+?#[0-9]+""")
  9. def reformat_readme():
  10. readme = Path('README.md').read_text()
  11. for shorthand in RE_SHORTHAND.findall(readme):
  12. user, pull = shorthand.split('/')
  13. repo, pull = pull.split('#')
  14. readme = readme.replace(shorthand, f'[{user}#{pull}](https://github.com/{user}/{repo}/pull/{pull})')
  15. Path('README.md').write_text(readme)
  16. if __name__ == '__main__':
  17. reformat_readme()