gitbeaker icon indicating copy to clipboard operation
gitbeaker copied to clipboard

Protected Tags Create typing is wrong

Open Dravere opened this issue 5 months ago • 0 comments

Description

  • Node.js version: n/a
  • Gitbeaker version: main branch
  • Gitbeaker release (cli, rest, core, requester-utils): core
  • OS & version: n/a

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

  • [x] I have checked that this is not a duplicate issue.
  • [x] I have read the documentation.

Dravere avatar Sep 25 '24 12:09 Dravere