@@ -31,20 +31,28 @@ def run(self) -> List[nodes.Node]:
31
31
config = self .state .document .settings .env .config
32
32
try :
33
33
return compute_changelog (
34
- token = config .sphinx_github_changelog_token , options = self .options
34
+ token = config .sphinx_github_changelog_token ,
35
+ options = self .options ,
36
+ root_url = config .sphinx_github_changelog_root_repo ,
37
+ graphql_url = config .sphinx_github_changelog_graphql_url ,
35
38
)
36
39
except ChangelogError as exc :
37
40
raise self .error (str (exc ))
38
41
39
42
40
43
def compute_changelog (
41
- token : Optional [str ], options : Dict [str , str ]
44
+ token : Optional [str ],
45
+ options : Dict [str , str ],
46
+ root_url : Optional [str ] = None ,
47
+ graphql_url : Optional [str ] = None ,
42
48
) -> List [nodes .Node ]:
43
49
if not token :
44
50
return no_token (changelog_url = options .get ("changelog-url" ))
45
51
46
- owner_repo = extract_github_repo_name (url = options ["github" ])
47
- releases = extract_releases (owner_repo = owner_repo , token = token )
52
+ owner_repo = extract_github_repo_name (url = options ["github" ], root_url = root_url )
53
+ releases = extract_releases (
54
+ owner_repo = owner_repo , token = token , graphql_url = graphql_url
55
+ )
48
56
49
57
pypi_name = extract_pypi_package_name (url = options .get ("pypi" ))
50
58
@@ -72,14 +80,19 @@ def no_token(changelog_url: Optional[str]) -> List[nodes.Node]:
72
80
return result
73
81
74
82
75
- def extract_github_repo_name (url : str ) -> str :
83
+ def extract_github_repo_name (url : str , root_url : Optional [ str ] = None ) -> str :
76
84
stripped_url = url .rstrip ("/" )
77
- prefix , postfix = "https://github.com/" , "/releases"
85
+ prefix , postfix = (
86
+ root_url if root_url is not None else "https://github.com/" ,
87
+ "/releases" ,
88
+ )
89
+ if not prefix .endswith ("/" ):
90
+ prefix += "/"
78
91
url_is_correct = stripped_url .startswith (prefix ) and stripped_url .endswith (postfix )
79
92
if not url_is_correct :
80
93
raise ChangelogError (
81
94
"Changelog needs a Github releases URL "
82
- f"(https://github.com/ :owner/:repo/releases). Received { url } "
95
+ f"({ prefix } :owner/:repo/releases). Received { url } "
83
96
)
84
97
85
98
return stripped_url [len (prefix ) : - len (postfix )]
@@ -142,7 +155,9 @@ def node_for_release(
142
155
return section
143
156
144
157
145
- def extract_releases (owner_repo : str , token : str ) -> Iterable [Dict [str , Any ]]:
158
+ def extract_releases (
159
+ owner_repo : str , token : str , graphql_url : Optional [str ] = None
160
+ ) -> Iterable [Dict [str , Any ]]:
146
161
# Necessary for GraphQL
147
162
owner , repo = owner_repo .split ("/" )
148
163
query = """
@@ -161,7 +176,7 @@ def extract_releases(owner_repo: str, token: str) -> Iterable[Dict[str, Any]]:
161
176
)
162
177
full_query = {"query" : query .replace ("\n " , "" )}
163
178
164
- url = "https://api.github.com/graphql"
179
+ url = "https://api.github.com/graphql" if graphql_url is None else graphql_url
165
180
166
181
try :
167
182
result = github_call (url = url , query = full_query , token = token )
0 commit comments