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