Linkify changelog (#46)

This commit is contained in:
Dev Ojha
2021-03-23 13:59:51 -05:00
committed by GitHub
parent 666da1e3b2
commit fea21d919a
3 changed files with 58 additions and 7 deletions

View File

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