Repository: ansible-collections/community.general

Issue:
community.general.gitlab_branch: add option default (branch)
### Summary

Is it feasable to add the option `default: true/false`, so this branch would be either the default branch or not?

### Issue Type

Feature Idea

### Component Name

community.general.gitlab_branch

### Additional Information

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- name: Create branch branch2 from main
  community.general.gitlab_branch:
    api_url: https://gitlab.com
    api_token: secret_access_token
    project: "group1/project1"
    branch: branch2
    ref_branch: main
    state: present
    default: true

```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/gitlab_branch.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/gitlab_branch.py)

If these files are incorrect, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @Lunik @Shaps @dj-wasabi @lgatellier @marwatk @metanovii @nejch @paytroff @scodeman @sh0shin @suukit @waheedi @zanssa
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/plugins/modules/gitlab_project.py b/plugins/modules/gitlab_project.py
--- a/plugins/modules/gitlab_project.py
+++ b/plugins/modules/gitlab_project.py
@@ -175,8 +175,10 @@
     version_added: "4.2.0"
   default_branch:
     description:
-      - Default branch name for a new project.
-      - This option is only used on creation, not for updates. This is also only used if O(initialize_with_readme=true).
+      - The default branch name for this project.
+      - For project creation, this option requires O(initialize_with_readme=true).
+      - For project update, the branch must exist.
+      - Supports project's default branch update since community.general 8.0.0.
     type: str
     version_added: "4.2.0"
   builds_access_level:
@@ -355,7 +357,7 @@ def __init__(self, module, gitlab_instance):
     @param namespace Namespace Object (User or Group)
     @param options Options of the project
     '''
-    def create_or_update_project(self, project_name, namespace, options):
+    def create_or_update_project(self, module, project_name, namespace, options):
         changed = False
         project_options = {
             'name': project_name,
@@ -395,6 +397,8 @@ def create_or_update_project(self, project_name, namespace, options):
 
         # Because we have already call userExists in main()
         if self.project_object is None:
+            if options['default_branch'] and not options['initialize_with_readme']:
+                module.fail_json(msg="Param default_branch need param initialize_with_readme set to true")
             project_options.update({
                 'path': options['path'],
                 'import_url': options['import_url'],
@@ -416,6 +420,8 @@ def create_or_update_project(self, project_name, namespace, options):
 
             changed = True
         else:
+            if options['default_branch']:
+                project_options['default_branch'] = options['default_branch']
             changed, project = self.update_project(self.project_object, project_options)
 
         self.project_object = project
@@ -590,9 +596,6 @@ def main():
     security_and_compliance_access_level = module.params['security_and_compliance_access_level']
     topics = module.params['topics']
 
-    if default_branch and not initialize_with_readme:
-        module.fail_json(msg="Param default_branch need param initialize_with_readme set to true")
-
     gitlab_instance = gitlab_authentication(module)
 
     # Set project_path to project_name if it is empty.
@@ -636,7 +639,7 @@ def main():
 
     if state == 'present':
 
-        if gitlab_project.create_or_update_project(project_name, namespace, {
+        if gitlab_project.create_or_update_project(module, project_name, namespace, {
             "path": project_path,
             "description": project_description,
             "initialize_with_readme": initialize_with_readme,


Test patch: