mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
Check links to ref in :calls: sections
This commit is contained in:
@@ -12,31 +12,33 @@ import glob
|
||||
|
||||
def parseReference():
|
||||
badlyNamedUrls = {
|
||||
"/gitignore/templates/C GET": "/gitignore/templates/:name GET",
|
||||
"/notifications/threads/1/subscription DELETE": "/notifications/threads/:id/subscription DELETE",
|
||||
"/notifications/threads/1/subscription GET": "/notifications/threads/:id/subscription GET",
|
||||
"/notifications/threads/1/subscription PUT": "/notifications/threads/:id/subscription PUT",
|
||||
("/gitignore/templates/C", "GET"): ("/gitignore/templates/:name", "GET"),
|
||||
("/notifications/threads/1/subscription", "DELETE"): ("/notifications/threads/:id/subscription", "DELETE"),
|
||||
("/notifications/threads/1/subscription", "GET"): ("/notifications/threads/:id/subscription", "GET"),
|
||||
("/notifications/threads/1/subscription", "PUT"): ("/notifications/threads/:id/subscription", "PUT"),
|
||||
}
|
||||
undocumentedUrls = [
|
||||
"/hooks GET", # Mentioned somewhere
|
||||
"/hub POST", # Described in content/v3/repos/hooks.md
|
||||
("/hooks", "GET"), # Mentioned somewhere
|
||||
("/hub", "POST"), # Described in content/v3/repos/hooks.md
|
||||
]
|
||||
uninterestingUrls = [
|
||||
"/markdown/raw POST", # Job is done by /markdown => useless in PyGithub
|
||||
"/repos/octocat/Hello-World/git/refs/heads/feature-a DELETE", # Example of DELETE /repos/:owner/:repo/git/refs/:ref
|
||||
"/repos/octocat/Hello-World/git/refs/tags/v1.0 DELETE", # Example of DELETE /repos/:owner/:repo/git/refs/:ref
|
||||
"/repos/:owner/:repo/git/trees/:sha?recursive=1 GET", # Example of GET /repos/:owner/:repo/git/trees/:sha
|
||||
"/repos/:owner/:repo/git/refs/heads/skunkworkz/featureA GET", # Example of GET /repos/:owner/:repo/git/refs
|
||||
"/repos/:owner/:repo/git/refs/tags GET", # Example of GET /repos/:owner/:repo/git/refs
|
||||
("/markdown/raw", "POST"), # Job is done by /markdown => useless in PyGithub
|
||||
("/repos/octocat/Hello-World/git/refs/heads/feature-a", "DELETE"), # Example of DELETE /repos/:owner/:repo/git/refs/:ref
|
||||
("/repos/octocat/Hello-World/git/refs/tags/v1.0", "DELETE"), # Example of DELETE /repos/:owner/:repo/git/refs/:ref
|
||||
("/repos/:owner/:repo/git/trees/:sha?recursive=1", "GET"), # Example of GET /repos/:owner/:repo/git/trees/:sha
|
||||
("/repos/:owner/:repo/git/refs/heads/skunkworkz/featureA", "GET"), # Example of GET /repos/:owner/:repo/git/refs
|
||||
("/repos/:owner/:repo/git/refs/tags", "GET"), # Example of GET /repos/:owner/:repo/git/refs
|
||||
]
|
||||
|
||||
urls = set()
|
||||
urls = dict()
|
||||
|
||||
for root, _, filenames in os.walk('developer.github.com'):
|
||||
for filename in fnmatch.filter(filenames, '*.md'):
|
||||
filename = os.path.join(root, filename)
|
||||
with open(filename) as f:
|
||||
for line in f:
|
||||
if line.startswith("#"):
|
||||
section = ("-".join(line.rstrip().split(" ")[1:])) ### @todo anchor-ify (lowercase, only a-z, etc.)
|
||||
if line.startswith(" "):
|
||||
line = line[4:]
|
||||
if line.startswith("\t"):
|
||||
@@ -44,22 +46,23 @@ def parseReference():
|
||||
for v in ["GET", "PATCH", "DELETE", "POST", "PUT"]:
|
||||
if line.startswith(v + " /"):
|
||||
verb, url = line.strip().split(" ")
|
||||
url = url + " " + verb
|
||||
url = (url, verb)
|
||||
if url in badlyNamedUrls:
|
||||
url = badlyNamedUrls[url]
|
||||
urls.add(url)
|
||||
docUrl = "http://developer.github.com/" + filename[29:-3] ### @todo + "#" + section
|
||||
urls[url] = docUrl
|
||||
|
||||
for url in undocumentedUrls:
|
||||
urls.add(url)
|
||||
urls[url] = "http://developer.github.com/"
|
||||
|
||||
for url in uninterestingUrls:
|
||||
urls.remove(url)
|
||||
del urls[url]
|
||||
|
||||
return urls
|
||||
|
||||
|
||||
def parseLibrary():
|
||||
urls = set()
|
||||
urls = dict()
|
||||
|
||||
for filename in glob.glob("github/*.py"):
|
||||
with open(filename) as f:
|
||||
@@ -67,8 +70,9 @@ def parseLibrary():
|
||||
if line.startswith(" :calls:"):
|
||||
line = line[17:-3]
|
||||
for part in line.split("`_ or `"):
|
||||
verb, url, _ = part.split(" ")
|
||||
urls.add(url + " " + verb)
|
||||
verb, apiUrl, docUrl = part.split(" ")
|
||||
docUrl = docUrl[1:-1]
|
||||
urls[(apiUrl, verb)] = docUrl
|
||||
|
||||
return urls
|
||||
|
||||
@@ -76,15 +80,19 @@ def parseLibrary():
|
||||
def printUrls(title, urls):
|
||||
if len(urls) > 0:
|
||||
print len(urls), "URLs", title + ":"
|
||||
print " ", "\n ".join(sorted(urls))
|
||||
print " ", "\n ".join(url + " (" + verb + ")" for url, verb in sorted(urls))
|
||||
print
|
||||
|
||||
|
||||
def main():
|
||||
ref = parseReference()
|
||||
lib = parseLibrary()
|
||||
printUrls("in Github API v3, but not implemented in PyGithub", ref - lib)
|
||||
printUrls("called by PyGithub but not existing in Github API v3", lib - ref)
|
||||
printUrls("in Github API v3, but not implemented in PyGithub", set(ref) - set(lib))
|
||||
printUrls("called by PyGithub but not existing in Github API v3", set(lib) - set(ref))
|
||||
for key in set(lib) & set(ref):
|
||||
(url, verb) = key
|
||||
if lib[key] != ref[key]:
|
||||
print "sed -i \"s@:calls: ." + verb + " " + url + " ." + lib[key] + ".._" + "@:calls: \\`" + verb + " " + url + " \\<" + ref[key] + "\\>\\`_@\" github/*.py"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user