Skip to content

Commit

Permalink
fix: usage of CI_JOB_TOKEN
Browse files Browse the repository at this point in the history
  • Loading branch information
jase88 committed Jul 31, 2023
1 parent 1827b8a commit dc8acd6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ npx publish-gitlab-release -v "1.2.3" [options]

Specifies the version name to be used for the Git tag and the Gitlab release. This option is required and should be used to define the version of the release.

#### `-t, --token` _(optional)_
#### `-t, --token` _(required)_

Gitlab API token. If provided, the tool will use this token to authenticate with Gitlab when creating the release. If not provided, the tool will attempt to use the environment variable `CI_JOB_TOKEN` within Gitlab pipelines.
Gitlab API token. Unfortunately the `CI_JOB_TOKEN` has not enough rights, so that a personal access token or a project access token is required. Go to your project settings and then _Access Tokens_. Create a token with the scope _api_.

#### `--ref` _(optional)_

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "publish-gitlab-release",
"version": "0.0.4",
"version": "0.0.5",
"description": "publish-gitlab-release is a command-line tool that automates the process of creating GitLab releases, including generating changelogs, adding comments to merge requests and linked issues, all while providing flexibility in versioning schemes.",
"license": "MIT",
"repository": "https://github.com/jase88/publish-gitlab-release",
Expand Down
14 changes: 9 additions & 5 deletions src/create-context-from-arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export function createContextFromArguments(): Context {
CI_SERVER_PROTOCOL,
CI_SERVER_HOST,
CI_SERVER_PORT,
CI_JOB_TOKEN,
CI_COMMIT_SHA,
} = env;

Expand Down Expand Up @@ -84,7 +83,7 @@ Description:
Options:
-v, --version <version> Specifies the version name to be used for the Git tag and the Gitlab release.
-t, --token <token> (Optional) Gitlab API token. If not provided, the tool will attempt to use the environment variable CI_JOB_TOKEN within Gitlab pipelines.
-t, --token <token> Gitlab API token. Personal or project access token.
--ref <ref> (Optional) Git ref that should be tagged. If not provided, the tool will use the given environment variable CI_COMMIT_SHA from Gitlab pipelines.
--host <host> (Optional) Gitlab URI. If not specified, the tool will default to gitlab.com.
--project <project_id> (Optional) Gitlab project ID. If not specified, the tool will use the given variable CI_PROJECT_ID from Gitlab pipelines.
Expand All @@ -98,12 +97,17 @@ Description:
? `${CI_SERVER_PROTOCOL}://${CI_SERVER_HOST}:${CI_SERVER_PORT}`
: 'gitlab.com';
const projectId = Number.parseInt(gitlabProjectId || CI_PROJECT_ID, 10);
const token = gitlabToken || CI_JOB_TOKEN;
const reference = gitReference || CI_COMMIT_SHA;

validateArguments({ version, token, projectId, ref: reference, host });
validateArguments({
version,
token: gitlabToken,
projectId,
ref: reference,
host,
});

const api = new Gitlab({ host, token });
const api = new Gitlab({ host, token: gitlabToken });

return { api, host, projectId, version, reference };
}

0 comments on commit dc8acd6

Please sign in to comment.