Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rest_api spec being fetched from outdated link #85

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/pulp_docs/mkdocs_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from pulp_docs.constants import SECTION_REPO
from pulp_docs.navigation import get_navigation
from pulp_docs.repository import Repo, Repos, SubPackage
from pulp_docs.utils.general import get_git_ignored_files
from pulp_docs.utils.general import get_label

# the name of the docs in the source repositories
SRC_DOCS_DIRNAME = "staging_docs"
Expand Down Expand Up @@ -152,13 +152,11 @@ def _download_api_json(api_dir: Path, repo_name: str):
return

log.info(f"Downloading api.json for {repo_name}")
api_url_1 = "https://pulpproject.org/{repo_name}/api.json"
api_url_2 = "https://pulpproject.org/{repo_name}/_static/api.json"
response = httpx.get(api_url_1.format(repo_name=repo_name))
app_label = get_label(repo_name)
api_url = f"https://raw.githubusercontent.com/pulp/pulp-docs/docs-data/data/openapi_json/{app_label}-api.json"
response = httpx.get(api_url)
if response.is_error:
response = httpx.get(api_url_2.format(repo_name=repo_name))
if response.is_error:
raise Exception("Couldnt get rest api page")
raise Exception("Couldnt get rest api schema for {app_label}")

# Schema overrides for better display
json_file_content = response.json()
Expand Down
11 changes: 11 additions & 0 deletions src/pulp_docs/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
from pathlib import Path


def get_label(repo_name: str):
"""Get app_label from repo_name.

E.g: 'pulp_ostree' -> 'ostree'.
"""
if repo_name == "pulpcore":
return "core"
# E.g: "pulp-ostree" -> "pulp_ostree" -> ("", "pulp_", "ostree")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhh, that's a bit of a dangerous assumption.
I guess the only way to "know" is to look into the template config of the plugin.
Does this run with all the plugins checked out side by side?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's possible to get from there, I'll do that.

return repo_name.replace("-", "_").rpartition("pulp_")[2]


def get_git_ignored_files(repo_path: Path) -> t.List[str]:
"""Get list of ignored files as defined in the repo .gitignore"""
repo_gitignore = Path(repo_path / ".gitignore")
Expand Down