@@ -44,7 +44,7 @@ def download_file_from_github(
44
44
tag : str , path : str , output_file : Path , github_token : str | None = None , timeout : int = 60
45
45
) -> bool :
46
46
"""
47
- Downloads a file from GitHub repository of Apache Airflow
47
+ Downloads a file from the GitHub repository of Apache Airflow using the GitHub API.
48
48
49
49
:param tag: tag to download from
50
50
:param path: path of the file relative to the repository root
@@ -55,21 +55,21 @@ def download_file_from_github(
55
55
"""
56
56
import requests
57
57
58
- url = f"https://raw.githubusercontent .com/apache/airflow/{ tag } /{ path } "
58
+ url = f"https://api.github .com/repos/ apache/airflow/contents /{ path } ?ref= { tag } "
59
59
get_console ().print (f"[info]Downloading { url } to { output_file } " )
60
60
if not get_dry_run ():
61
+ headers = {"Accept" : "application/vnd.github.v3.raw" }
62
+ if github_token :
63
+ headers ["Authorization" ] = f"Bearer { github_token } "
64
+ headers ["X-GitHub-Api-Version" ] = "2022-11-28"
61
65
try :
62
- # add github token to the request if provided
63
- headers = {}
64
- if github_token :
65
- headers ["Authorization" ] = f"Bearer { github_token } "
66
- headers ["X-GitHub-Api-Version" ] = "2022-11-28"
67
66
response = requests .get (url , headers = headers , timeout = timeout )
68
67
if response .status_code == 403 :
69
68
get_console ().print (
70
- f"[error]The { url } is not accessible.This may be caused by either of:\n "
71
- f" 1. network issues or VPN settings\n "
72
- f" 2. Github rate limit"
69
+ f"[error]Access denied to { url } . This may be caused by:\n "
70
+ f" 1. Network issues or VPN settings\n "
71
+ f" 2. GitHub API rate limiting\n "
72
+ f" 3. Invalid or missing GitHub token"
73
73
)
74
74
return False
75
75
if response .status_code == 404 :
0 commit comments