Return the expected GitHub Pages URL and update README. GitHub often requires Pages to be enabled manually from repository Settings > Pages. If Pages already exists, this function best-effort updates it/enforces HTTPS without printing raw API errors.
(owner: str, branch: str = "")
| 3182 | return generated |
| 3183 | |
| 3184 | def ensure_github_pages(owner: str, branch: str = "") -> str: |
| 3185 | """Return the expected GitHub Pages URL and update README. |
| 3186 | GitHub often requires Pages to be enabled manually from repository Settings > Pages. |
| 3187 | If Pages already exists, this function best-effort updates it/enforces HTTPS without printing raw API errors. |
| 3188 | """ |
| 3189 | ensure_repo_scope() |
| 3190 | branch = branch or current_branch() or get_default_branch(owner) or "main" |
| 3191 | pages_url = expected_pages_url(owner) |
| 3192 | |
| 3193 | rc, out = run_rc(["gh", "api", f"repos/{owner}/{REPO_NAME}/pages", "--jq", ".html_url"], capture=True) |
| 3194 | known = (out or "").strip() if rc == 0 else "" |
| 3195 | if known.startswith("http"): |
| 3196 | pages_url = known |
| 3197 | # Best-effort update existing Pages settings and enforce HTTPS. Ignore failures. |
| 3198 | run_rc([ |
| 3199 | "gh", "api", "-X", "PUT", f"repos/{owner}/{REPO_NAME}/pages", |
| 3200 | "-f", f"source[branch]={branch}", |
| 3201 | "-f", "source[path]=/", |
| 3202 | "-F", "https_enforced=true" |
| 3203 | ], capture=True) |
| 3204 | print(f"[✓] GitHub Pages URL: {pages_url}") |
| 3205 | else: |
| 3206 | print("[!] GitHub Pages is not enabled yet or GitHub has not published it yet.") |
| 3207 | print(" Enable it manually in repository Settings > Pages.") |
| 3208 | print(f" Expected website link after setup: {pages_url}") |
| 3209 | |
| 3210 | commit_readme_with_pages_url(owner, pages_url) |
| 3211 | print(" It can take a little time for GitHub Pages to finish publishing after a push.") |
| 3212 | return pages_url |
| 3213 | |
| 3214 | def publish_static_website(enable_pages: bool = True) -> str: |
| 3215 | print("\n=== Build / Publish Emergency Website ===") |
no test coverage detected