mirror of
https://github.com/public-apis/public-apis.git
synced 2025-05-10 15:46:48 +02:00
Check links on PRs and Update main build script
This commit is contained in:
parent
2ceb3025ba
commit
21eb114d6d
2 changed files with 58 additions and 54 deletions
|
@ -1,45 +1,55 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
FORMAT_FILE=../README.md
|
FORMAT_FILE=../README.md
|
||||||
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
|
|
||||||
echo "running on $TRAVIS_BRANCH branch"
|
|
||||||
LINK_FILE=../README.md
|
|
||||||
else
|
|
||||||
echo "running on Pull Request #$TRAVIS_PULL_REQUEST"
|
|
||||||
DIFF_URL="https://patch-diff.githubusercontent.com/raw/toddmotto/public-apis/pull/$TRAVIS_PULL_REQUEST.diff"
|
|
||||||
curl $DIFF_URL > diff.txt
|
|
||||||
echo "------- BEGIN DIFF -------"
|
|
||||||
cat diff.txt
|
|
||||||
echo "-------- END DIFF --------"
|
|
||||||
cat diff.txt | egrep "\+" > additions.txt
|
|
||||||
echo "------ BEGIN ADDITIONS -----"
|
|
||||||
cat additions.txt
|
|
||||||
echo "------- END ADDITIONS ------"
|
|
||||||
LINK_FILE=additions.txt
|
|
||||||
|
|
||||||
echo "checking if /json was changed..."
|
|
||||||
if egrep "\+{3}\s.\/json\/" diff.txt > json.txt; then
|
|
||||||
echo "JSON files are auto-generated! Please do not update these files:"
|
|
||||||
cat json.txt
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo "/json check passed!"
|
|
||||||
rm json.txt
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "running format validation..."
|
echo "running format validation..."
|
||||||
./validate_format.py $FORMAT_FILE
|
./validate_format.py $FORMAT_FILE
|
||||||
if [[ $? != 0 ]]; then
|
if [[ $? != 0 ]]; then
|
||||||
echo "format validation failed!"
|
echo "format validation failed!"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
fi
|
||||||
echo "format validation passed!"
|
echo "format validation passed!"
|
||||||
./build.sh && ./deploy.sh
|
./build.sh
|
||||||
if [[ $? != 0 ]]; then
|
if [[ $? != 0 ]]; then
|
||||||
echo "JSON build and deploy failed!"
|
echo "JSON build failed!"
|
||||||
else
|
else
|
||||||
echo "JSON build and deploy success!"
|
echo "JSON build success!"
|
||||||
fi
|
fi
|
||||||
|
if [ "$TRAVIS_BRANCH" == "master" ]
|
||||||
|
then
|
||||||
|
echo "Master build - deploying JSON"
|
||||||
|
./deploy.sh
|
||||||
|
fi
|
||||||
|
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
|
||||||
|
echo "running on $TRAVIS_BRANCH branch - skipping Pull Request logic"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
echo "running on Pull Request #$TRAVIS_PULL_REQUEST"
|
||||||
|
DIFF_URL="https://patch-diff.githubusercontent.com/raw/toddmotto/public-apis/pull/$TRAVIS_PULL_REQUEST.diff"
|
||||||
|
curl $DIFF_URL > diff.txt
|
||||||
|
echo "------- BEGIN DIFF -------"
|
||||||
|
cat diff.txt
|
||||||
|
echo "-------- END DIFF --------"
|
||||||
|
cat diff.txt | egrep "\+" > additions.txt
|
||||||
|
echo "------ BEGIN ADDITIONS -----"
|
||||||
|
cat additions.txt
|
||||||
|
echo "------- END ADDITIONS ------"
|
||||||
|
LINK_FILE=additions.txt
|
||||||
|
|
||||||
|
echo "checking if /json was changed..."
|
||||||
|
if egrep "\+{3}\s.\/json\/" diff.txt > json.txt; then
|
||||||
|
echo "JSON files are auto-generated! Please do not update these files:"
|
||||||
|
cat json.txt
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "/json check passed!"
|
||||||
|
rm json.txt
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "running link validation..."
|
||||||
|
./validate_links.py $LINK_FILE
|
||||||
|
if [[ $? != 0 ]]; then
|
||||||
|
echo "link validation failed!"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "link validation passed!"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,32 +1,26 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import httplib2
|
import httplib2
|
||||||
import json
|
import re
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def parse_links(filename):
|
def parse_links(filename):
|
||||||
"""Returns a list of links from JSON object"""
|
"""Returns a list of URLs from text file"""
|
||||||
data = json.load(open(filename))
|
with open(filename) as fp:
|
||||||
links = []
|
data = fp.read()
|
||||||
for entry in data['entries']:
|
raw_links = re.findall( \
|
||||||
link = entry['Link']
|
'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', \
|
||||||
https = True if link.startswith('https') else False
|
data)
|
||||||
x = {
|
links = [raw_link.replace(')', '') for raw_link in raw_links]
|
||||||
'link': link,
|
|
||||||
'https': https,
|
|
||||||
}
|
|
||||||
links.append(x)
|
|
||||||
return links
|
return links
|
||||||
|
|
||||||
|
|
||||||
def validate_links(links):
|
def validate_links(links):
|
||||||
"""Checks each entry in JSON file for live link"""
|
"""Checks each entry in JSON file for live link"""
|
||||||
print('Validating {} links...'.format(len(links)))
|
print('Validating {} links...'.format(len(links)))
|
||||||
errors = []
|
errors = []
|
||||||
for each in links:
|
for link in links:
|
||||||
link = each['link']
|
|
||||||
h = httplib2.Http(disable_ssl_certificate_validation=True, timeout=5)
|
h = httplib2.Http(disable_ssl_certificate_validation=True, timeout=5)
|
||||||
try:
|
try:
|
||||||
resp = h.request(link, 'HEAD')
|
resp = h.request(link, 'HEAD')
|
||||||
|
@ -43,7 +37,7 @@ def validate_links(links):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
num_args = len(sys.argv)
|
num_args = len(sys.argv)
|
||||||
if num_args < 2:
|
if num_args < 2:
|
||||||
print("No .json file passed")
|
print("No .md file passed")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
errors = validate_links(parse_links(sys.argv[1]))
|
errors = validate_links(parse_links(sys.argv[1]))
|
||||||
if len(errors) > 0:
|
if len(errors) > 0:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue