File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 1
1
"""Utilities to help linting various targets."""
2
2
3
3
import os
4
+ import re
4
5
from typing import (
5
6
Any ,
6
7
Dict ,
@@ -134,7 +135,15 @@ def lint_urls(root, lint_ctx):
134
135
135
136
def validate_url (url , lint_ctx , user_agent = None ):
136
137
is_valid = True
137
- if url .startswith ("http://" ) or url .startswith ("https://" ):
138
+ if (match := re .match ("https?://doi.org/(.*)$" , url )) != None :
139
+ doi = match .group (1 )
140
+ xref_url = f"https://api.crossref.org/works/{ doi } "
141
+ try :
142
+ response = requests .get (xref_url , timeout = 5 )
143
+ except requests .RequestException :
144
+ is_valid = False
145
+ lint_ctx .error (f"Error '{ e } ' accessing { url } " )
146
+ elif url .startswith ("http://" ) or url .startswith ("https://" ):
138
147
if user_agent :
139
148
headers = {"User-Agent" : user_agent , "Accept" : "*/*" }
140
149
else :
You can’t perform that action at this time.
0 commit comments