Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protected Tags Create typing is wrong #3629

Open
2 tasks done
Dravere opened this issue Sep 25, 2024 · 0 comments
Open
2 tasks done

Protected Tags Create typing is wrong #3629

Dravere opened this issue Sep 25, 2024 · 0 comments
Labels
type:bug Changes fix a minor bug

Comments

@Dravere
Copy link

Dravere commented Sep 25, 2024

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

  • I have checked that this is not a duplicate issue.
  • I have read the documentation.
@jdalrymple jdalrymple added the type:bug Changes fix a minor bug label Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Changes fix a minor bug
Projects
None yet
Development

No branches or pull requests

2 participants