forked from stripe/stripe-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check and fix broken documentation links. (stripe#4626)
- Loading branch information
1 parent
a1dc061
commit 2a8842a
Showing
3 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/bin/python | ||
import re | ||
import glob | ||
import os | ||
import sys | ||
import urllib.request | ||
from urllib.error import HTTPError | ||
from urllib.error import URLError | ||
|
||
root_dir="docs" | ||
readme="README.md" | ||
|
||
def request(url): | ||
try: | ||
print("requesting... ---" + url + "--- ") | ||
response = urllib.request.urlopen(url) | ||
if(response): | ||
return response.getcode() == 200 | ||
else: | ||
print("No response\n") | ||
return False | ||
except HTTPError as e: | ||
print("HTTPError \n") | ||
return False | ||
except URLError as e: | ||
print("URLError\n") | ||
return False | ||
print("\n") | ||
return False | ||
|
||
def findStripeLinksInFile(filename): | ||
regexStripe = r'(https://stripe.com[^\\)|"|\\ |<]*)' | ||
regexGithub = r'(https://github.com[^\\)|"|\\ |<]*)' | ||
allUrls = [] | ||
isFile = os.path.isfile(filename) | ||
if(isFile): | ||
with open(filename) as file: | ||
for line in file: | ||
allUrls.extend(re.findall(regexStripe, line)) | ||
allUrls.extend(re.findall(regexGithub, line)) | ||
return allUrls | ||
|
||
|
||
def findStripeLinks(root_dir): | ||
urlSet=set() | ||
for filename in glob.iglob(root_dir + '**/**', recursive=True): | ||
urls = findStripeLinksInFile(filename) | ||
if(urls): | ||
for url in urls: | ||
urlSet.add(url) | ||
|
||
return urlSet | ||
|
||
##------ | ||
# Find the stripe links in the documentation directory | ||
urlSet = findStripeLinks(root_dir) | ||
# Find the stripe links in the Readme | ||
for urlLinkFromReadme in findStripeLinksInFile("README.md"): | ||
urlSet.add(urlLinkFromReadme) | ||
|
||
# For each link verify it does not 404 when requested. | ||
urlDNE = [] | ||
for url in urlSet: | ||
if(not request(url)): | ||
urlDNE.append(url) | ||
print(urlDNE) | ||
sys.exit(1) |