Skip to content

Commit c1b1b79

Browse files
committed
Bugfix: Ignore the 'default_branch' option
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 situations. Signed-off-by: Marc Schöchlin <[email protected]>
1 parent 818090c commit c1b1b79

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

plugins/module_utils/github.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,12 @@ def request(
224224
error_data[key] = info[key]
225225

226226
error_data["response"] = response or "no response"
227-
error_data["body"] = body or "no body"
227+
error_data["response_body"] = body or "no body"
228+
error_data["request_url"] = url
229+
error_data["request_method"] = method
230+
if 'json' in kwargs:
231+
error_data["request_body"] = kwargs['json'] or 'no body'
232+
228233
self.save_error(f"request failed {error_msg}: {error_data}")
229234
elif status == 404 and ignore_missing:
230235
return None
@@ -1126,6 +1131,15 @@ def _manage_repository(self, state, current=None, check_mode=False, **kwargs):
11261131
owner = kwargs.pop('owner')
11271132
repo_name = kwargs.pop('name')
11281133
current_repo = current if current else self.get_repo(owner, repo_name, ignore_missing=True)
1134+
1135+
# When specifying a default branch on a repository which is still empty, the execution
1136+
# fails with the following error message:
1137+
# 'Cannot update default branch for an empty repository. Please init the repository and push first'
1138+
# Therefore we remove this option in that case.
1139+
if current_repo['size'] == 0:
1140+
del kwargs['default_branch']
1141+
1142+
11291143
if not current_repo:
11301144
changed = True
11311145
if not check_mode:

0 commit comments

Comments
 (0)