jdalrymple / gitbeaker

🦊🧪 A comprehensive and typed Gitlab SDK for Node.js, Browsers, Deno and CLI
Other
1.57k stars 299 forks source link

Protected Tags Create typing is wrong #3629

Closed Dravere closed 1 month ago

Dravere commented 2 months ago

Description

Protecting tags generates a bad request error as the typing on the function is wrong.

Steps to reproduce

const gitlabApi = new Gitlab({
  host: 'https://some.gitlab.host',
  token: tokenValue
})

await gitlabApi.ProtectedTags.protect(projectId, "v*", {
  allowedToCreate: {
    groupId: GROUP_ID
  },
  createAccessLevel: AccessLevel.MAINTAINER
})

This is accepted by the typing but will throw a GitBeaker exception, since the server will response with a bad request.

Expected behaviour

It should create the protected tag.

Actual behaviour

The server responses with a HTTP status code 400 bad request.

Possible fixes

I can get it to work with this workaround:

const gitlabApi = new Gitlab({
  host: 'https://some.gitlab.host',
  token: tokenValue
})

await gitlabApi.ProtectedTags.protect(projectId, "v*", {
  allowedToCreate: [
    {
      groupId: GROUP_ID
    }
  ] as unknown as ProtectedTagAccessLevelEntity,
  createAccessLevel: AccessLevel.MAINTAINER
})

To me it seems the error is located on this line: https://github.com/jdalrymple/gitbeaker/blob/main/packages/core/src/resources/ProtectedTags.ts#L53

Instead of accepting a single entity it should accept an array of these entities:

allowedToCreate?: ProtectedTagAccessLevelEntity[];

The same will then also be true for this line (protect function instead of create): https://github.com/jdalrymple/gitbeaker/blob/main/packages/core/src/resources/ProtectedTags.ts#L79

The GitLab documentation also clearly states this has to be a list of entities: https://docs.gitlab.com/ee/api/protected_tags.html#protect-repository-tags

Also under 16.11: https://archives.docs.gitlab.com/16.11/ee/api/protected_tags.html#protect-repository-tags

Checklist

jdalrymple commented 1 month ago

:rocket: Issue was released in 40.6.0 :rocket: