Skip to content

Commit

Permalink
Add changelog links fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Apr 13, 2018
1 parent ffd704b commit 96e09c6
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tools/fix_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3

import argparse
import re
import sys
from pathlib import Path


PATTERN = re.compile("\(#(\d+)\)")


def get_root(script_path):
folder = script_path.absolute().parent
while not (folder / '.git').exists():
folder = folder.parent
if folder == folder.anchor:
raise RuntimeError("git repo not found")
return folder


def main(argv):
parser = argparse.ArgumentParser(description='Expand github links.')
parser.add_argument('filename', default='CHANGES.rst', nargs='?',
help="filename to proess")
args = parser.parse_args()
here = Path(argv[0])
root = get_root(here)
fname = root / args.filename

content = fname.read_text()
new = PATTERN.sub(
r'(`#\1 <https://github.com/aio-libs/aiohttp/pull/\1>`_)',
content)

fname.write_text(new)
print(f"Fixed links in {fname}")
return 0


if __name__ == '__main__':
sys.exit(main(sys.argv))

0 comments on commit 96e09c6

Please sign in to comment.