From 37219012ac25c8ac30049be5302c35ed6d461430 Mon Sep 17 00:00:00 2001 From: Dylan Fontaine <10430358+dylf@users.noreply.github.com> Date: Fri, 24 May 2024 13:34:51 -0700 Subject: [PATCH] fix: remove job token --- README.md | 4 ++-- src/index.ts | 31 ++++++++++--------------------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 50683cf2..232428a9 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,8 @@ GLOBAL_AGENT_NO_PROXY # Like above but for no proxied requests GITLAB_HOST # optional, if you're using custom GitLab host, will fallback to `CI_SERVER_URL` if not provided -GITLAB_TOKEN # required, token with accessibility to push -GITLAB_TOKEN_TYPE # optional, type of the provided token in GITLAB_TOKEN. defaults to personal access token. can be `job` if you provide the Gitlab CI_JOB_TOKEN or `oauth` if you use Gitlab Oauth token +GITLAB_TOKEN # required, token with accessibility to push, package registries, and merge request APIs. Note the CI_JOB_TOKEN does not have sufficient permissons +GITLAB_TOKEN_TYPE # optional, type of the provided token in GITLAB_TOKEN. defaults to personal access token. Can be `oauth` if you use Gitlab Oauth (personal access) token.. GITLAB_CI_USER_NAME # optional, username with accessibility to push, used in pairs of the above token (if it was personal access token). If not set read it from the Gitlab API GITLAB_CI_USER_EMAIL # optional, default `gitlab[bot]@users.noreply.gitlab.com` GITLAB_COMMENT_TYPE # optional, type of the comment. defaults to `discussion`. can be set to `note` to not create a discussion instead of a thread diff --git a/src/index.ts b/src/index.ts index 2c740e55..c7ba59eb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,26 +28,15 @@ export const createApi = (gitlabToken?: string) => { const token = gitlabToken || env.GITLAB_TOKEN const host = env.GITLAB_HOST - // we cannot use { [tokenType]: token } now - // because it will break the type of the Gitlab constructor - switch (env.GITLAB_TOKEN_TYPE) { - case 'job': { - return new Gitlab({ - host, - jobToken: token, - }) - } - case 'oauth': { - return new Gitlab({ - host, - oauthToken: token, - }) - } - default: { - return new Gitlab({ - host, - token, - }) - } + if (env.GITLAB_TOKEN_TYPE === 'oauth') { + return new Gitlab({ + host, + oauthToken: token, + }) } + + return new Gitlab({ + host, + token, + }) }