Title: gitlab.projects.create from template creates project with unprotected main branch · Issue #3037 · python-gitlab/python-gitlab · GitHub
Open Graph Title: gitlab.projects.create from template creates project with unprotected main branch · Issue #3037 · python-gitlab/python-gitlab
X Title: gitlab.projects.create from template creates project with unprotected main branch · Issue #3037 · python-gitlab/python-gitlab
Description: Description of the problem, including code/CLI snippet I am trying to create projects in subgroups by a python script using python-gitlab. The projects are created from a template. The template project has a single branch main that is th...
Open Graph Description: Description of the problem, including code/CLI snippet I am trying to create projects in subgroups by a python script using python-gitlab. The projects are created from a template. The template pro...
X Description: Description of the problem, including code/CLI snippet I am trying to create projects in subgroups by a python script using python-gitlab. The projects are created from a template. The template pro...
Opengraph URL: https://github.com/python-gitlab/python-gitlab/issues/3037
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"gitlab.projects.create from template creates project with unprotected main branch","articleBody":"## Description of the problem, including code/CLI snippet\r\n\r\nI am trying to create projects in subgroups by a python script using `python-gitlab`. The projects are created from a template. The template project has a single branch `main` that is the default and protected:\r\n\r\n\r\n\r\nAnd *Settings* -\u003e * Repository* - \u003e *Protected branches* looks like this:\r\n\r\n\r\nThe creation of the project is done by \r\n\r\n\tproject = gitlab.projects.create({\r\n\t\t'name': projectname,\r\n\t\t'description' : projectdescription,\r\n\t\t'namespace_id': subgroup.id,\r\n\t\t'use_custom_template': True,\r\n\t\t'group_with_project_templates_id': group_with_project_templates_id,\r\n\t\t'template_project_id': template_project_id,\r\n ... some more preferences\r\n\t})\r\n\r\nAs a result I get a new project. The result of a `print(project)` gives\r\n\r\n\t\u003cclass 'gitlab.v4.objects.projects.Project'\u003e =\u003e {'id': 44638, 'description': None, 'name': '[NAME]', 'name_with_namespace': '[VALUE]', 'path': '[VALUE]', 'path_with_namespace': '[VALUE]', 'created_at': '2024-11-14T15:09:25.753Z', 'default_branch': 'main', 'tag_list': [], 'topics': [], 'ssh_url_to_repo': 'git@[VALUE].git', 'http_url_to_repo': '[VALUE].git', 'web_url': '[URL]', 'readme_url': None, 'forks_count': 0, 'avatar_url': None, 'star_count': 0, 'last_activity_at': '2024-11-14T15:09:25.717Z', 'namespace': {'id': 63056, 'name': '[VALUE]', 'path': '[VALUE]', 'kind': 'group', 'full_path': '[VALUE]', 'parent_id': 62984, 'avatar_url': None, 'web_url': '[VALUE]'}, '_links': {'self': 'https://gitlab.dlr.de/api/v4/projects/44638', 'issues': 'https://gitlab.dlr.de/api/v4/projects/44638/issues', 'merge_requests': 'https://gitlab.dlr.de/api/v4/projects/44638/merge_requests', 'repo_branches': 'https://gitlab.dlr.de/api/v4/projects/44638/repository/branches', 'labels': 'https://gitlab.dlr.de/api/v4/projects/44638/labels', 'events': 'https://gitlab.dlr.de/api/v4/projects/44638/events', 'members': 'https://gitlab.dlr.de/api/v4/projects/44638/members', 'cluster_agents': 'https://gitlab.dlr.de/api/v4/projects/44638/cluster_agents'}, 'packages_enabled': True, 'empty_repo': True, 'archived': False, 'visibility': 'private', 'resolve_outdated_diff_discussions': False, 'container_expiration_policy': {'cadence': '1d', 'enabled': False, 'keep_n': 10, 'older_than': '90d', 'name_regex': '.*', 'name_regex_keep': None, 'next_run_at': '2024-11-15T15:09:25.765Z'}, 'repository_object_format': 'sha1', 'issues_enabled': False, 'merge_requests_enabled': True, 'wiki_enabled': False, 'jobs_enabled': False, 'snippets_enabled': False, 'container_registry_enabled': False, 'service_desk_enabled': False, 'can_create_merge_request_in': True, 'issues_access_level': 'disabled', 'repository_access_level': 'enabled', 'merge_requests_access_level': 'enabled', 'forking_access_level': 'enabled', 'wiki_access_level': 'disabled', 'builds_access_level': 'disabled', 'snippets_access_level': 'disabled', 'pages_access_level': 'disabled', 'analytics_access_level': 'enabled', 'container_registry_access_level': 'disabled', 'security_and_compliance_access_level': 'private', 'releases_access_level': 'enabled', 'environments_access_level': 'enabled', 'feature_flags_access_level': 'enabled', 'infrastructure_access_level': 'enabled', 'monitor_access_level': 'enabled', 'model_experiments_access_level': 'enabled', 'model_registry_access_level': 'enabled', 'emails_disabled': False, 'emails_enabled': True, 'shared_runners_enabled': True, 'lfs_enabled': True, 'creator_id': 13620, 'import_url': None, 'import_type': 'gitlab_custom_project_template', 'import_status': 'scheduled', 'import_error': None, 'description_html': '', 'updated_at': '2024-11-14T15:05:14.750Z', 'ci_default_git_depth': 20, 'ci_forward_deployment_enabled': True, 'ci_forward_deployment_rollback_allowed': True, 'ci_job_token_scope_enabled': False, 'ci_separated_caches': True, 'ci_allow_fork_pipelines_to_run_in_parent_project': True, 'ci_id_token_sub_claim_components': ['project_path', 'ref_type', 'ref'], 'build_git_strategy': 'fetch', 'keep_latest_artifact': True, 'restrict_user_defined_variables': False, 'ci_pipeline_variables_minimum_override_role': 'maintainer', 'runners_token': None, 'runner_token_expiration_interval': None, 'group_runners_enabled': True, 'auto_cancel_pending_pipelines': 'enabled', 'build_timeout': 3600, 'auto_devops_enabled': False, 'auto_devops_deploy_strategy': 'continuous', 'ci_push_repository_for_job_token_allowed': False, 'ci_config_path': None, 'public_jobs': True, 'shared_with_groups': [], 'only_allow_merge_if_pipeline_succeeds': False, 'allow_merge_on_skipped_pipeline': None, 'request_access_enabled': True, 'only_allow_merge_if_all_discussions_are_resolved': False, 'remove_source_branch_after_merge': True, 'printing_merge_request_link_enabled': True, 'merge_method': 'merge', 'squash_option': 'default_off', 'enforce_auth_checks_on_uploads': True, 'suggestion_commit_message': None, 'merge_commit_template': None, 'squash_commit_template': None, 'issue_branch_template': None, 'warn_about_potentially_unwanted_characters': True, 'autoclose_referenced_issues': True, 'approvals_before_merge': 0, 'mirror': False, 'external_authorization_classification_label': None, 'marked_for_deletion_at': None, 'marked_for_deletion_on': None, 'requirements_enabled': False, 'requirements_access_level': 'enabled', 'security_and_compliance_enabled': True, 'pre_receive_secret_detection_enabled': False, 'compliance_frameworks': [], 'merge_requests_template': None, 'ci_restrict_pipeline_cancellation_role': 'developer', 'merge_pipelines_enabled': False, 'merge_trains_enabled': False, 'merge_trains_skip_train_allowed': False, 'allow_pipeline_trigger_approve_deployment': False}\r\n\r\nHowever, the `main` branch of the project is not protected all of a sudden. If I call\r\n\r\n\tprint(project.branches.get(project.default_branch))\r\n\r\nI get\r\n\r\n\t\u003cclass 'gitlab.v4.objects.branches.ProjectBranch'\u003e =\u003e {'name': 'main', 'commit': {'id': 'c9c61bb46e2040b904ab9cc5c6f14e969b551503', 'short_id': 'c9c61bb4', 'created_at': '2024-11-13T15:24:00.000+00:00', 'parent_ids': ['d3f2686c9750ec7c49a7f1467dd0f6bf734ba378'], 'title': 'Update README.md', 'message': 'Update README.md', 'author_name': '[MYNAME]', 'author_email': '[MYMAIL]', 'authored_date': '2024-11-13T15:24:00.000+00:00', 'committer_name': '[MYNAME]', 'committer_email': '[MYMAIL]', 'committed_date': '2024-11-13T15:24:00.000+00:00', 'trailers': {}, 'extended_trailers': {}, 'web_url': '[COMMITID]'}, 'merged': False, 'protected': False, 'developers_can_push': False, 'developers_can_merge': False, 'can_push': True, 'default': True, 'web_url': '[URL]/-/tree/main'}\r\n\r\nwith my main problem being: `'protected': False`\r\n\r\n## Expected Behavior\r\n\r\nI would expect the `main` branch of the newly created project to be protected.\r\n\r\n## Actual Behavior\r\n\r\nThe `main` branch of the newly created project is not protected. A quick look in the newly created project *Settings* -\u003e * Repository* - \u003e *Protected branches* confirms that there are no protected branches:\r\n\r\n\r\n\r\n\r\n## Specifications\r\n\r\n - python-gitlab version: 5.0.0-pyhff2d567_0\r\n - Gitlab server version (or gitlab.com): GitLab Enterprise Edition [v17.3.6-ee](https://gitlab.com/gitlab-org/gitlab/-/tags/v17.3.6-ee)\r\n\r\nIs this the desired behavior? If so, how can I protect the `main` branch after project creation? I can add them manually in *Settings* -\u003e * Repository* - \u003e *Protected branches* but I would like to do that via the script. Unfortunately, I can't seem to figure out out to protect a branch after it was created from the `python-gitlab` api.","author":{"url":"https://github.com/raedma","@type":"Person","name":"raedma"},"datePublished":"2024-11-14T15:37:10.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/3037/python-gitlab/issues/3037"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f6583bd3-ae15-b157-2517-04f257c74160 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9376:2294D5:3E1D8F6:54BE0F7:69739FEB |
| html-safe-nonce | 2bd39ef224127742b2e6ceba730b2e65dc81b7d93231ff49ed40c36f79a760ac |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Mzc2OjIyOTRENTozRTFEOEY2OjU0QkUwRjc6Njk3MzlGRUIiLCJ2aXNpdG9yX2lkIjoiODk3ODIyNjkxODk1OTg0OTQ1MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 13fb73da1a2afd4565d21cfde649e97d631cc8f2a82cc3b2b7b5cc594465d359 |
| hovercard-subject-tag | issue:2659214352 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-gitlab/python-gitlab/3037/issue_layout |
| twitter:image | https://opengraph.githubassets.com/be009805d4e9ce6259baca56c5be7a556dfca500f596335cff84517e24ccdeb1/python-gitlab/python-gitlab/issues/3037 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/be009805d4e9ce6259baca56c5be7a556dfca500f596335cff84517e24ccdeb1/python-gitlab/python-gitlab/issues/3037 |
| og:image:alt | Description of the problem, including code/CLI snippet I am trying to create projects in subgroups by a python script using python-gitlab. The projects are created from a template. The template pro... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | raedma |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3e9aa9d0c22a21b13b378b4acd09f5dd4876a884425aacd32a9f473b84c8762d |
| turbo-cache-control | no-preview |
| go-import | github.com/python-gitlab/python-gitlab git https://github.com/python-gitlab/python-gitlab.git |
| octolytics-dimension-user_id | 28886265 |
| octolytics-dimension-user_login | python-gitlab |
| octolytics-dimension-repository_id | 8077625 |
| octolytics-dimension-repository_nwo | python-gitlab/python-gitlab |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 8077625 |
| octolytics-dimension-repository_network_root_nwo | python-gitlab/python-gitlab |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ae4dbd3ac4179af799d71b75a60b0075ccccc5f6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width