Skip to content

Commit bdb5cab

Browse files
a-grealishparamt
authored andcommitted
Support for private repos
1 parent 0abea32 commit bdb5cab

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jobs:
1111
build:
1212
runs-on: ubuntu-latest
1313
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
1416
- name: Check URLs
1517
uses: paramt/url-checker@master
1618
with:
@@ -23,5 +25,3 @@ jobs:
2325

2426
### Sample Output
2527
[![Example](https://i.imgur.com/35zldHS.png)](https://github.com/paramt/url-checker/commit/093ef6cb5f7e9eff8300887f07eb0c3a55f4aa82/checks)
26-
27-
> Note: url-checker only works on public repositories

check_links.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,28 @@
1616
def remove_duplicates(urls):
1717
return list(set(urls))
1818

19+
20+
def get_test_from_file(file):
21+
# Assume the local file has been checked out in the action
22+
try:
23+
with open('./' + file) as f:
24+
text = f.readlines()
25+
except FileNotFoundError as e:
26+
print("Could not find file checked out locally, falling back to using public link")
27+
28+
# Fall-back to pulling from the public URL for backawards comaptibility
29+
try:
30+
filepath = "https://raw.githubusercontent.com/" + repo + "/master/" + file
31+
r = requests.get(filepath)
32+
r.raise_for_status()
33+
return r.text
34+
except requests.exceptions.HTTPError as err:
35+
print("Could not find file using fallback public link")
36+
37+
1938
for file in files:
20-
print(f"Collecting URLs from {file}")
21-
filepath = "https://raw.githubusercontent.com/" + repo + "/master/" + file
22-
text = requests.get(filepath).text
39+
40+
text = get_test_from_file(file)
2341

2442
extractor = URLExtract()
2543
file_links = extractor.find_urls(text)

0 commit comments

Comments
 (0)