-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
/
touchup_gh_issues.py
executable file
·44 lines (35 loc) · 1.04 KB
/
touchup_gh_issues.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
from collections import OrderedDict
import sys
import re
"""
Reads in stdin, replace all occurences of '#num' or 'GH #num' with
links to github issue. dumps the issue anchors before the next
section header
"""
pat = "((?:\s*GH\s*)?)#(\d{3,4})([^_]|$)?"
rep_pat = r"\1GH\2_\3"
anchor_pat = ".. _GH{id}: https://github.com/pandas-dev/pandas/issues/{id}"
section_pat = "^pandas\s[\d\.]+\s*$"
def main():
issues = OrderedDict()
while True:
line = sys.stdin.readline()
if not line:
break
if re.search(section_pat, line):
for id in issues:
print(anchor_pat.format(id=id).rstrip())
if issues:
print("\n")
issues = OrderedDict()
for m in re.finditer(pat, line):
id = m.group(2)
if id not in issues:
issues[id] = True
print(re.sub(pat, rep_pat, line).rstrip())
pass
if __name__ == "__main__":
main()