jdalrymple / gitbeaker

🦊πŸ§ͺ A comprehensive and typed Gitlab SDK for Node.js, Browsers, Deno and CLI
Other
1.55k stars 294 forks source link

`Groups.show("")` returns `GroupSchema[]`, not `ExpandedGroupSchema` #3603

Closed ryan-williams closed 2 months ago

ryan-williams commented 3 months ago

Steps to reproduce

Attempting to fetch top-level GitLab groups:

const gl = new Gitlab({ token: "" })
await gl.Groups.allSubgroups("")  // ❌ throws `GitbeakerRequestError: Not Found`

This seems to correspond to the underlying GL REST API: /groups/:id/subgroups requires an :id.

This works:

await gl.Groups.show("", {page: 1, perPage: 5, topLevelOnly: true})  // 🚨 returns GroupSchema[], not ExpandedGroupSchema
5 top-level groups returned ``` [ { id: 7891903, web_url: 'https://gitlab.com/groups/xn--tg8h', name: '🌍', path: 'xn--tg8h', description: '🌍 all geo matters', 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: [Array], allow_force_push: false, allowed_to_merge: [Array] }, avatar_url: null, request_access_enabled: true, full_name: '🌍', full_path: 'xn--tg8h', created_at: '2020-05-09T10:54:58.236Z', parent_id: null, organization_id: 1, shared_runners_setting: 'enabled', ldap_cn: null, ldap_access: null, wiki_access_level: 'enabled' }, { id: 7892291, web_url: 'https://gitlab.com/groups/xn--1g8h', name: 'πŸŒ•', path: 'xn--1g8h', 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: [Array], allow_force_push: false, allowed_to_merge: [Array] }, avatar_url: null, request_access_enabled: true, full_name: 'πŸŒ•', full_path: 'xn--1g8h', created_at: '2020-05-09T12:22:29.200Z', parent_id: null, organization_id: 1, shared_runners_setting: 'enabled', ldap_cn: null, ldap_access: null, wiki_access_level: 'enabled' }, { id: 12161090, web_url: 'https://gitlab.com/groups/stxnelessi', name: '🍷', path: 'stxnelessi', 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: [Array], allow_force_push: false, allowed_to_merge: [Array] }, avatar_url: null, request_access_enabled: true, full_name: '🍷', full_path: 'stxnelessi', created_at: '2021-05-23T09:24:42.900Z', parent_id: null, organization_id: 1, shared_runners_setting: 'enabled', ldap_cn: null, ldap_access: null, wiki_access_level: 'enabled' }, { id: 84541626, web_url: 'https://gitlab.com/groups/eleph9nt', name: '🐘', path: 'eleph9nt', 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: [Array], allow_force_push: false, allowed_to_merge: [Array] }, avatar_url: null, request_access_enabled: true, full_name: '🐘', full_path: 'eleph9nt', created_at: '2024-03-23T11:19:19.505Z', parent_id: null, organization_id: 1, shared_runners_setting: 'enabled', ldap_cn: null, ldap_access: null, wiki_access_level: 'enabled' }, { id: 80003608, web_url: 'https://gitlab.com/groups/siontian', name: '🐣', path: 'siontian', 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: [Array], allow_force_push: false, allowed_to_merge: [Array] }, avatar_url: null, request_access_enabled: true, full_name: '🐣', full_path: 'siontian', created_at: '2023-12-23T05:32:52.973Z', parent_id: null, organization_id: 1, shared_runners_setting: 'enabled', ldap_cn: null, ldap_access: null, wiki_access_level: 'enabled' } ] ```

corresponding to e.g.:

curl 'https://gitlab.com/api/v4/groups?page=1&per_page=5&top_level_only=true'

However, the GitBeaker type definitions think it returns an ExpandedGroupSchema, when in this case (quertying the root group) it actually returns a GroupSchema[] (similar to allSubgroups).

Groups.show also doesn't take pagination params, according to GitBeaker types, but they are passed through and take effect, in this case. This inconsistency previously confused me re: GitBeaker pagination semantics in general, leading to #3602.

Expected behaviour There should be a way to query for top-level groups, with matching type definitions.

Actual behaviour There is only a hack for querying top-level groups (with incorrect type defs).

Possible fixes

Checklist

ryan-williams commented 2 months ago

j/w if the comment above was meant for https://github.com/jdalrymple/gitbeaker/issues/3607? I don't see any commits or PRs that appear to address this issue. Thanks!

jdalrymple commented 2 months ago

Im blind haha, disregard my excitment

jdalrymple commented 2 months ago

Okay, following up on this.

You have seemed to have found a hack.

The typing for the .show method is correct, and while the typing will give you an error when you dont pass a variable (the id) the underlying API apparently allows this behaviour as it defaults to /groups as opposed to /groups/undefined. There is nothing wrong with the pagination in the case, since you are not using the method that returns paginated results (as the typing does indicate). For such results use the .all method. Check the docs for more information.