You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.2 KiB

  1. import re
  2. import sys
  3. import fileinput
  4. import os
  5. # Set this to the name of the repo, if you don't want it to be read from the filesystem.
  6. # It assumes the changelog file is in the root of the repo.
  7. repo_name = ""
  8. # This script goes through the provided file, and replaces any " \#<number>",
  9. # with the valid mark down formatted link to it. e.g.
  10. # " [\#number](https://github.com/arkworks-rs/template/pull/<number>)
  11. # Note that if the number is for a an issue, github will auto-redirect you when you click the link.
  12. # It is safe to run the script multiple times in succession.
  13. #
  14. # Example usage $ python3 linkify_changelog.py ../CHANGELOG.md
  15. if len(sys.argv) < 2:
  16. print("Must include path to changelog as the first argument to the script")
  17. print("Example Usage: python3 linkify_changelog.py ../CHANGELOG.md")
  18. exit()
  19. changelog_path = sys.argv[1]
  20. if repo_name == "":
  21. path = os.path.abspath(changelog_path)
  22. components = path.split(os.path.sep)
  23. repo_name = components[-2]
  24. for line in fileinput.input(inplace=True):
  25. line = re.sub(r"\- #([0-9]*)", r"- [\\#\1](https://github.com/arkworks-rs/" + repo_name + r"/pull/\1)", line.rstrip())
  26. # edits the current file
  27. print(line)