Skip to content

Commit fe0ea5a

Browse files
add special handling for DOIs to URL linter
Redirect targets of DOIs often block prgrammatic CI requests. This might help.
1 parent 9e8b8cb commit fe0ea5a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

planemo/lint.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Utilities to help linting various targets."""
22

33
import os
4+
import re
45
from typing import (
56
Any,
67
Dict,
@@ -134,7 +135,15 @@ def lint_urls(root, lint_ctx):
134135

135136
def validate_url(url, lint_ctx, user_agent=None):
136137
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://"):
138147
if user_agent:
139148
headers = {"User-Agent": user_agent, "Accept": "*/*"}
140149
else:

0 commit comments

Comments
 (0)