xanzy / go-gitlab

GitLab Go SDK
Apache License 2.0
2.37k stars 940 forks source link

Add support to Groups APIs for DefaultBranchDefaults #1971

Closed RicePatrick closed 1 month ago

RicePatrick commented 2 months ago

This Pull Request adds support for the new default_branch_protection_defaults attribute to the Group APIs. These were added in GitLab 17.0, replacing the default_branch_protection integer, so that attribute is now marked as deprecated as well.

Documentation: https://docs.gitlab.com/ee/api/groups.html#options-for-default_branch_protection_defaults

Note: The structure of the API requests is weird. Even though allowed_to_push and allowed_to_merge only expect 1 access level, they do in fact require an array of objects with "access_level" being the key.

Here is an example request and responss to show the API fingerprint, since I don't think it's exactly clear from the documentation how it's supposed to work ๐Ÿ˜† :

image

{"default_branch_protection_defaults":{"allowed_to_push":[{"access_level": 40}], "allow_force_push":false, "allowed_to_merge":[{"access_level":30}], "developer_can_initial_push": true}}
{"id":3,"web_url":"http://dcfd377d91d2/groups/test","name":"test","path":"test","description":"","visibility":"public","share_with_group_lock":false,"require_two_factor_authentication":false,"two_factor_grace_period":48,"project_creation_level":"developer","auto_devops_enabled":null,"subgroup_creation_level":"maintainer","emails_disabled":false,"emails_enabled":true,"mentions_disabled":null,"lfs_enabled":true,"math_rendering_limits_enabled":true,"lock_math_rendering_limits_enabled":false,"default_branch":null,"default_branch_protection":2,"default_branch_protection_defaults":{"allowed_to_push":[{"access_level":40}],"allow_force_push":false,"allowed_to_merge":[{"access_level":30}],"developer_can_initial_push":true},"avatar_url":null,"request_access_enabled":true,"full_name":"test","full_path":"test","created_at":"2024-07-12T18:58:09.554Z","parent_id":null,"organization_id":1,"shared_runners_setting":"enabled","ldap_cn":null,"ldap_access":null,"marked_for_deletion_on":null,"wiki_access_level":"enabled","repository_storage":null,"duo_features_enabled":true,"lock_duo_features_enabled":false,"shared_with_groups":[],"runners_token":"GR13489413zpxPbiz-s5TLjsMNi7x","enabled_git_access_protocol":"all","prevent_sharing_groups_outside_hierarchy":false,"projects":[],"shared_projects":[],"shared_runners_minutes_limit":null,"extra_shared_runners_minutes_limit":null,"prevent_forking_outside_group":false,"service_access_tokens_expiration_enforced":true,"membership_lock":false,"ip_restriction_ranges":null}
RicePatrick commented 2 months ago

@svanharmelen - This should be ready for review. Let me know what you think about the naming for GroupAccessLevel, or if there's a better struct already for that use-case. It's an odd structure, so I was having trouble naming it ๐Ÿ˜„

RicePatrick commented 2 months ago

Everything other than the deprecation notices has been fixed; will update Deprecation noticed in either direction on Monday and let you know!

RicePatrick commented 1 month ago

@svanharmelen - Documentation is updated and now shows the fields as Deprecated, so having them labelled as deprecated is correct: https://docs.gitlab.com/ee/api/groups.html#new-group

Reference from conversations with GitLab: https://gitlab.com/gitlab-org/gitlab/-/issues/462164#note_1999148308