从源代码中提取 # TODO 标签并将其转换为 Bitbucket / Github 上的问题

Sky*_*ght 5 ide tags github bitbucket todo

某些 IDE(例如 PyCharm)提供使用 # TODO 标签标记部分源代码的功能,并能在以后进一步定位所有标签。

在提交到 Butbucket 或 Github 后,有什么方法可以将它们转换为“问题”吗?

我发现在编写代码时动态创建 TODO 可能非常有用,这样其他贡献者就可以在在线存储库(例如 Bitbucket)上查看它们。

Bitbucket 和 Github 有很多插件或“服务”,但我在任何地方都找不到类似的功能。

小智 -2

这是一个相当简单的 python 脚本。它使用Githubpy与github进行交互。它会遍历当前的目录树并获取给定的文件(在本例中为 *.cpp 和 *.h)。然后它会遍历每个文件,找到任何 #TODO 并创建一个 github 问题。然后将该行更改为 TODO [GH]:

gh = GitHub(username=user, password=password)

path = '.'

configfiles = [os.path.join(dirpath, f)
    for dirpath, dirnames, files in os.walk(path)
    for extension in extensions
    for f in fnmatch.filter(files, ["*.cpp", "*.h")]

import fileinput
for fileName in configfiles:
    count = 0
    search = fileinput.input(fileName, inplace = 1)
    for line in search: #TODO [GH12]: to
        line = line.rstrip()  # remove '\n' at end of line
        if re.match("(.*)(\#)TODO:(.*)", line):
            todoInfo= re.sub("(.*)(\#)TODO:\s","", line)
            fileNameShort = re.sub("\.\/","", fileName)
            subject = fileNameShort+":"+str(count)+" " + todoInfo
            # make url that can link to specific place in file
            url = "https://github.com/"+projectAccount + "/" + project + "/blob/master/" + fileNameShort + "#L" + str(count)
            r = gh.repos(projectAccount)(project).issues.post(title=subject, body=url)
            line = re.sub("(\#)TODO:","#TODO [GH"+str(r.number)+"]:", line)
        print(line) #write line back to file
        count = count + 1
Run Code Online (Sandbox Code Playgroud)

您可以访问我的 github 上的 who 脚本。https://github.com/jmeed/todo2github