From 428b79a688145047b89dea656ea110c0fb6afda6 Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Tue, 1 Oct 2024 14:34:48 +0200 Subject: [PATCH] fix: support creating a repo with auto_init disabled and gh_pages_build_type disabled as well --- CHANGELOG.md | 1 + otterdog/models/repository.py | 4 ++++ otterdog/providers/github/rest/repo_client.py | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9824269..16ffc6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ ### Fixed +- Creating a repo with `auto_init: false` and `gh_pages_build_type: "disabled"` is now supported. - Avoided unnecessary GitHub API calls when getting the `default_branch` or `id` of a repository. - Detect errors during an automatic `apply` operation and add a corresponding comment to the pull request. - Support showing dialog windows when using operation `web-login`. diff --git a/otterdog/models/repository.py b/otterdog/models/repository.py index c9b236a..ec5b7b8 100644 --- a/otterdog/models/repository.py +++ b/otterdog/models/repository.py @@ -714,6 +714,10 @@ async def get_mapping_to_provider( if len(gh_pages_mapping) > 0: mapping["gh_pages"] = gh_pages_mapping + for prop in ["gh_pages_source_branch", "gh_pages_source_path"]: + if prop in mapping: + mapping.pop(prop) + # code scanning default setup code_scanning_mapping = {} if "code_scanning_default_setup_enabled" in data: diff --git a/otterdog/providers/github/rest/repo_client.py b/otterdog/providers/github/rest/repo_client.py index 81fed31..3c9e7c3 100644 --- a/otterdog/providers/github/rest/repo_client.py +++ b/otterdog/providers/github/rest/repo_client.py @@ -248,6 +248,14 @@ async def add_repo( # whether the repo should be initialized with an empty README data["auto_init"] = auto_init_repo + # if the repo does not get initialized and gh pages are disabled, + # do not try to update the config as it will fail + if auto_init_repo is False and "gh_pages" in update_data: + gh_pages = update_data.get("gh_pages", {}) + build_type = gh_pages.get("build_type") + if build_type == "disabled": + update_data.pop("gh_pages") + try: result = await self.requester.request_json("POST", f"/orgs/{org_id}/repos", data) print_debug(f"created repo with name '{repo_name}'")