Skip to content

Commit 722d21f

Browse files
committed
Improve openapi_json fallback fetching
As a fallback we tried fetching from some git remote, but we didnt' have a guarantee that this was associated with the pulp-docs official remote git url. This applies a more robust approach explicit fetching from that url.
1 parent 0733a9c commit 722d21f

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/pulp_docs/plugin.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,13 @@ def log_pulp_config(
307307
log.info(display_str)
308308

309309

310+
def get_pulpdocs_git_url(config: PulpDocsPluginConfig):
311+
for component in config.components:
312+
if component.path == "pulp-docs":
313+
return component.git_url
314+
raise RuntimeError("Did pulp-docs changed it's name or was removed from mkdocs.yml?")
315+
316+
310317
class PulpDocsPlugin(BasePlugin[PulpDocsPluginConfig]):
311318
def on_config(self, config: MkDocsConfig) -> MkDocsConfig | None:
312319
# mkdocs may default to the installation dir
@@ -320,14 +327,15 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig | None:
320327

321328
self.mkdocs_yml_dir = Path(config.docs_dir).parent
322329
self.find_path = ctx_path.get() or [str(Path().cwd().parent)]
323-
self.config.components = load_components(self.find_path, self.config, self.draft)
330+
self.loaded_components = load_components(self.find_path, self.config, self.draft)
331+
self.pulpdocs_git_url = get_pulpdocs_git_url(self.config)
324332

325333
mkdocs_file = self.mkdocs_yml_dir / "mkdocs.yml"
326-
log_pulp_config(mkdocs_file, self.find_path, self.config.components, config.site_dir)
334+
log_pulp_config(mkdocs_file, self.find_path, self.loaded_components, config.site_dir)
327335

328336
mkdocstrings_config = config.plugins["mkdocstrings"].config
329337
components_var = []
330-
for component in self.config.components:
338+
for component in self.loaded_components:
331339
components_var.append(get_component_data(component))
332340
config.watch.append(str(component.component_dir / "docs"))
333341
component_dir = str(component.component_dir.resolve())
@@ -350,8 +358,8 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig | None:
350358
return config
351359

352360
def on_files(self, files: Files, /, *, config: MkDocsConfig) -> Files | None:
353-
log.info(f"Loading Pulp components: {self.config.components}")
354-
pulp_docs_component = [c for c in self.config.components if c.path == "pulp-docs"]
361+
log.info(f"Loading Pulp components: {self.loaded_components}")
362+
pulp_docs_component = [c for c in self.loaded_components if c.path == "pulp-docs"]
355363
if pulp_docs_component:
356364
pulp_docs_git = Repo(pulp_docs_component[0].repository_dir)
357365
else:
@@ -360,7 +368,7 @@ def on_files(self, files: Files, /, *, config: MkDocsConfig) -> Files | None:
360368

361369
user_nav: dict[str, t.Any] = {}
362370
dev_nav: dict[str, t.Any] = {}
363-
for component in self.config.components:
371+
for component in self.loaded_components:
364372
component_dir = component.component_dir
365373

366374
log.info(f"Fetching docs from '{component.title}'.")
@@ -493,10 +501,10 @@ def get_openapi_spec(self, component, pulp_docs_git: Repo):
493501
f"docs-data:data/openapi_json/{component.rest_api}-api.json"
494502
)
495503
except GitCommandError:
496-
# Try again on the first remote.
497-
remote = pulp_docs_git.remotes[0]
504+
# Not found locally. Try again fetching from the official remote url
505+
pulp_docs_git.git.fetch(self.pulpdocs_git_url, "docs-data")
498506
api_json = pulp_docs_git.git.show(
499-
f"{remote}/docs-data:data/openapi_json/{component.rest_api}-api.json"
507+
f"FETCH_HEAD:data/openapi_json/{component.rest_api}-api.json"
500508
)
501509
# fix the logo url for restapi page, which is defined in the openapi spec file
502510
api_json = api_json.replace(

0 commit comments

Comments
 (0)