From b2fa1031d4dfe64aee3b34ff8c1a0c53b3484972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Sch=C3=B6chlin?= Date: Wed, 20 Nov 2024 11:11:06 +0100 Subject: [PATCH] Bugfix: Ignore the 'default_branch' option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When specifying a default branch on a repository which is still empty, the execution fails with the following error message: 'Cannot update default branch for an empty repository. Please init the repository and push first' This change avoids that users have to debug this problem and/or create new repositories in three steps (1. ‘create repo PR’, 2. add branch , 3. ‘set default branch’ PR). Secondly this change adds a bit more detailed error-debug-output to simplify debugging sitations. Signed-off-by: Marc Schöchlin --- plugins/module_utils/github.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/github.py b/plugins/module_utils/github.py index 1178751..4dd106d 100644 --- a/plugins/module_utils/github.py +++ b/plugins/module_utils/github.py @@ -224,7 +224,12 @@ def request( error_data[key] = info[key] error_data["response"] = response or "no response" - error_data["body"] = body or "no body" + error_data["response_body"] = body or "no body" + error_data["request_url"] = url + error_data["request_method"] = method + if 'json' in kwargs: + error_data["request_body"] = kwargs['json'] or 'no body' + self.save_error(f"request failed {error_msg}: {error_data}") elif status == 404 and ignore_missing: return None @@ -1126,6 +1131,15 @@ def _manage_repository(self, state, current=None, check_mode=False, **kwargs): owner = kwargs.pop('owner') repo_name = kwargs.pop('name') current_repo = current if current else self.get_repo(owner, repo_name, ignore_missing=True) + + # When specifying a default branch on a repository which is still empty, the execution + # fails with the following error message: + # 'Cannot update default branch for an empty repository. Please init the repository and push first' + # Therefore we remove this option in that case. + if current_repo['size'] == 0: + del kwargs['default_branch'] + + if not current_repo: changed = True if not check_mode: