@zereight/mcp-gitlab 2.2.3 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ko.md +15 -7
- package/README.md +15 -7
- package/README.pt-BR.md +15 -7
- package/README.zh-CN.md +15 -7
- package/build/config.js +15 -1
- package/build/index.js +2 -1
- package/build/personal-access-token.js +75 -0
- package/package.json +1 -1
package/README.ko.md
CHANGED
|
@@ -12,10 +12,16 @@
|
|
|
12
12
|
|
|
13
13
|
`zereight-mcp-gitlab` 바이너리를 먼저 설치하세요. `npm install -g @zereight/mcp-gitlab`, 또는 Homebrew `brew tap zereight/gitlab-mcp https://github.com/zereight/gitlab-mcp` 다음 `brew install zereight/gitlab-mcp/zereight-mcp-gitlab`.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
토큰을 화면에 표시하지 않고 읽은 다음 export 하세요. 셸 기록에는 변수 이름만 남습니다.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
read -rs GITLAB_PERSONAL_ACCESS_TOKEN && export GITLAB_PERSONAL_ACCESS_TOKEN
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| 클라이언트 | 설치 |
|
|
22
|
+
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
23
|
+
| Claude Code | `claude mcp add gitlab --transport stdio --scope local --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
24
|
+
| Codex | `codex mcp add gitlab --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
19
25
|
| Cursor | [Cursor 설정 가이드](./docs/clients/cursor.md) |
|
|
20
26
|
| VS Code | [VS Code 설정 가이드](./docs/clients/vscode.md) |
|
|
21
27
|
| JSON 클라이언트 | [JSON 기반 MCP 클라이언트 설정 가이드](./docs/clients/json-clients.md) |
|
|
@@ -84,7 +90,7 @@ GitLab은 [공식 MCP 서버](https://docs.gitlab.com/user/model_context_protoco
|
|
|
84
90
|
|
|
85
91
|
**로컬/데스크톱 사용**(가장 일반적):
|
|
86
92
|
|
|
87
|
-
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN`) — 가장 단순한 설정
|
|
93
|
+
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN` 또는 `GITLAB_PERSONAL_ACCESS_TOKEN_FILE`) — 가장 단순한 설정
|
|
88
94
|
2. **OAuth2 — 로컬 브라우저** (`GITLAB_USE_OAUTH`) — 더 나은 보안을 위해 권장
|
|
89
95
|
|
|
90
96
|
**서버/원격 배포**:
|
|
@@ -132,7 +138,7 @@ command = lib.getExe inputs.gitlab-mcp.packages.${system}.default;
|
|
|
132
138
|
|
|
133
139
|
예시는 기존 `mcp-gitlab`보다 충돌 가능성이 낮은 `zereight-mcp-gitlab` 별칭을 사용합니다. MCP 클라이언트가 찾지 못하면 `which zereight-mcp-gitlab`의 절대 경로를 사용하세요.
|
|
134
140
|
|
|
135
|
-
전역 설치를 쓰지 않으려면 `npx -y @zereight/mcp-gitlab@2.2.
|
|
141
|
+
전역 설치를 쓰지 않으려면 `npx -y @zereight/mcp-gitlab@2.2.3`처럼 직전 안정 버전(문서가 권장하는 버전)으로 고정하세요. 항상 최신 버전을 원하면 `npx -y @zereight/mcp-gitlab@latest`를 사용하세요. 새 버전이 나오면 서버가 시작 시 stderr로 알려줍니다(`GITLAB_DISABLE_VERSION_CHECK=true`로 비활성화 가능).
|
|
136
142
|
|
|
137
143
|
#### CLI 인자 사용하기(환경 변수 문제가 있는 클라이언트용)
|
|
138
144
|
|
|
@@ -198,10 +204,12 @@ CLI 인자는 환경 변수보다 우선합니다.
|
|
|
198
204
|
|
|
199
205
|
- sse
|
|
200
206
|
|
|
207
|
+
변수 이름만 넘기세요. Docker 클라이언트는 export한 `GITLAB_PERSONAL_ACCESS_TOKEN` 값을 컨테이너로 복사합니다.
|
|
208
|
+
|
|
201
209
|
```shell
|
|
202
210
|
docker run -i --rm \
|
|
203
211
|
-e HOST=0.0.0.0 \
|
|
204
|
-
-e GITLAB_PERSONAL_ACCESS_TOKEN
|
|
212
|
+
-e GITLAB_PERSONAL_ACCESS_TOKEN \
|
|
205
213
|
-e GITLAB_API_URL="https://gitlab.com/api/v4" \
|
|
206
214
|
-e GITLAB_PERMISSION_MODE=readonly \
|
|
207
215
|
-e GITLAB_TOOLSETS=core,wiki,milestones,pipelines \
|
package/README.md
CHANGED
|
@@ -17,10 +17,16 @@ Install `@zereight/mcp-gitlab` with the recommended local personal-access-token
|
|
|
17
17
|
|
|
18
18
|
Install the `zereight-mcp-gitlab` binary first with `npm install -g @zereight/mcp-gitlab`, or Homebrew `brew tap zereight/gitlab-mcp https://github.com/zereight/gitlab-mcp` and `brew install zereight/gitlab-mcp/zereight-mcp-gitlab`.
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
Read the token without echo, then export it. The shell history keeps the variable name.
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
read -rs GITLAB_PERSONAL_ACCESS_TOKEN && export GITLAB_PERSONAL_ACCESS_TOKEN
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
| Client | Install |
|
|
27
|
+
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
28
|
+
| Claude Code | `claude mcp add gitlab --transport stdio --scope local --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
29
|
+
| Codex | `codex mcp add gitlab --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
24
30
|
| Cursor | [Cursor setup guide](./docs/clients/cursor.md) |
|
|
25
31
|
| VS Code | [VS Code setup guide](./docs/clients/vscode.md) |
|
|
26
32
|
| JSON clients | [JSON-based MCP clients setup guide](./docs/clients/json-clients.md) |
|
|
@@ -89,7 +95,7 @@ The server supports four authentication methods:
|
|
|
89
95
|
|
|
90
96
|
**For local/desktop use** (most common):
|
|
91
97
|
|
|
92
|
-
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN`) — simplest setup
|
|
98
|
+
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN` or `GITLAB_PERSONAL_ACCESS_TOKEN_FILE`) — simplest setup
|
|
93
99
|
2. **OAuth2 — Local Browser** (`GITLAB_USE_OAUTH`) — recommended for better security
|
|
94
100
|
|
|
95
101
|
**For server/remote deployments**:
|
|
@@ -137,7 +143,7 @@ The store path is pinned by your lock file; update it with `nix flake update git
|
|
|
137
143
|
|
|
138
144
|
The examples use `zereight-mcp-gitlab`, a less collision-prone alias for the legacy `mcp-gitlab` binary. If your MCP client cannot find it, use the absolute path from `which zereight-mcp-gitlab`.
|
|
139
145
|
|
|
140
|
-
No global install? Pin `npx` to the previous stable release (the version these docs recommend), for example `npx -y @zereight/mcp-gitlab@2.2.
|
|
146
|
+
No global install? Pin `npx` to the previous stable release (the version these docs recommend), for example `npx -y @zereight/mcp-gitlab@2.2.3`. If you always want the newest release, use `npx -y @zereight/mcp-gitlab@latest` instead. The server prints a notice to stderr on startup when a newer version is available (disable with `GITLAB_DISABLE_VERSION_CHECK=true`).
|
|
141
147
|
|
|
142
148
|
#### Using CLI Arguments (for clients with env var issues)
|
|
143
149
|
|
|
@@ -204,10 +210,12 @@ The same binary is also a `gh`-style GitLab CLI (`tool <name>` or curated forms
|
|
|
204
210
|
|
|
205
211
|
- sse
|
|
206
212
|
|
|
213
|
+
Pass the variable name only. The Docker client copies the exported `GITLAB_PERSONAL_ACCESS_TOKEN` into the container.
|
|
214
|
+
|
|
207
215
|
```shell
|
|
208
216
|
docker run -i --rm \
|
|
209
217
|
-e HOST=0.0.0.0 \
|
|
210
|
-
-e GITLAB_PERSONAL_ACCESS_TOKEN
|
|
218
|
+
-e GITLAB_PERSONAL_ACCESS_TOKEN \
|
|
211
219
|
-e GITLAB_API_URL="https://gitlab.com/api/v4" \
|
|
212
220
|
-e GITLAB_PERMISSION_MODE=readonly \
|
|
213
221
|
-e GITLAB_TOOLSETS=core,wiki,milestones,pipelines \
|
package/README.pt-BR.md
CHANGED
|
@@ -12,10 +12,16 @@ Instalação local recomendada com PAT para `@zereight/mcp-gitlab`. Os argumento
|
|
|
12
12
|
|
|
13
13
|
Instale o binário `zereight-mcp-gitlab` antes. `npm install -g @zereight/mcp-gitlab`, ou Homebrew `brew tap zereight/gitlab-mcp https://github.com/zereight/gitlab-mcp` e `brew install zereight/gitlab-mcp/zereight-mcp-gitlab`.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
Leia o token sem eco e exporte. O histórico do shell fica só com o nome da variável.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
read -rs GITLAB_PERSONAL_ACCESS_TOKEN && export GITLAB_PERSONAL_ACCESS_TOKEN
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| Cliente | Instalação |
|
|
22
|
+
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
23
|
+
| Claude Code | `claude mcp add gitlab --transport stdio --scope local --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
24
|
+
| Codex | `codex mcp add gitlab --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
19
25
|
| Cursor | [Guia de configuração do Cursor](./docs/clients/cursor.md) |
|
|
20
26
|
| VS Code | [Guia de configuração do VS Code](./docs/clients/vscode.md) |
|
|
21
27
|
| Clientes JSON | [Guia para clientes MCP baseados em JSON](./docs/clients/json-clients.md) |
|
|
@@ -84,7 +90,7 @@ O servidor suporta quatro métodos de autenticação.
|
|
|
84
90
|
|
|
85
91
|
**Para uso local/desktop** (mais comum):
|
|
86
92
|
|
|
87
|
-
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN`) — configuração mais simples
|
|
93
|
+
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN` ou `GITLAB_PERSONAL_ACCESS_TOKEN_FILE`) — configuração mais simples
|
|
88
94
|
2. **OAuth2 — navegador local** (`GITLAB_USE_OAUTH`) — recomendado para maior segurança
|
|
89
95
|
|
|
90
96
|
**Para implantações em servidor/remotas**:
|
|
@@ -132,7 +138,7 @@ O caminho no store é fixado pelo seu lock file; atualize-o com `nix flake updat
|
|
|
132
138
|
|
|
133
139
|
Os exemplos usam `zereight-mcp-gitlab`, um alias com menor chance de conflito que o binário legado `mcp-gitlab`. Se o seu cliente MCP não o encontrar, use o caminho absoluto retornado por `which zereight-mcp-gitlab`.
|
|
134
140
|
|
|
135
|
-
Não quer instalar globalmente? Fixe o `npx` na versão estável anterior (a versão recomendada por esta documentação), por exemplo `npx -y @zereight/mcp-gitlab@2.2.
|
|
141
|
+
Não quer instalar globalmente? Fixe o `npx` na versão estável anterior (a versão recomendada por esta documentação), por exemplo `npx -y @zereight/mcp-gitlab@2.2.3`. Se quiser sempre a versão mais recente, use `npx -y @zereight/mcp-gitlab@latest`. O servidor exibe um aviso no stderr durante a inicialização quando existe uma versão mais nova disponível (desative com `GITLAB_DISABLE_VERSION_CHECK=true`).
|
|
136
142
|
|
|
137
143
|
#### Usando argumentos de CLI (para clientes com problemas com variáveis de ambiente)
|
|
138
144
|
|
|
@@ -198,10 +204,12 @@ O mesmo binário também é uma CLI do GitLab no estilo `gh` (`tool <name>` ou f
|
|
|
198
204
|
|
|
199
205
|
- sse
|
|
200
206
|
|
|
207
|
+
Passe só o nome da variável. O cliente Docker copia o `GITLAB_PERSONAL_ACCESS_TOKEN` exportado para o contêiner.
|
|
208
|
+
|
|
201
209
|
```shell
|
|
202
210
|
docker run -i --rm \
|
|
203
211
|
-e HOST=0.0.0.0 \
|
|
204
|
-
-e GITLAB_PERSONAL_ACCESS_TOKEN
|
|
212
|
+
-e GITLAB_PERSONAL_ACCESS_TOKEN \
|
|
205
213
|
-e GITLAB_API_URL="https://gitlab.com/api/v4" \
|
|
206
214
|
-e GITLAB_PERMISSION_MODE=readonly \
|
|
207
215
|
-e GITLAB_TOOLSETS=core,wiki,milestones,pipelines \
|
package/README.zh-CN.md
CHANGED
|
@@ -12,10 +12,16 @@
|
|
|
12
12
|
|
|
13
13
|
先安装 `zereight-mcp-gitlab` 二进制。`npm install -g @zereight/mcp-gitlab`,或 Homebrew `brew tap zereight/gitlab-mcp https://github.com/zereight/gitlab-mcp` 然后 `brew install zereight/gitlab-mcp/zereight-mcp-gitlab`。
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
先不回显地读取令牌,再 export。shell 历史里只保留变量名。
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
read -rs GITLAB_PERSONAL_ACCESS_TOKEN && export GITLAB_PERSONAL_ACCESS_TOKEN
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| 客户端 | 安装 |
|
|
22
|
+
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
23
|
+
| Claude Code | `claude mcp add gitlab --transport stdio --scope local --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
24
|
+
| Codex | `codex mcp add gitlab --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
19
25
|
| Cursor | [Cursor 设置指南](./docs/clients/cursor.md) |
|
|
20
26
|
| VS Code | [VS Code 设置指南](./docs/clients/vscode.md) |
|
|
21
27
|
| JSON 客户端 | [基于 JSON 的 MCP 客户端设置指南](./docs/clients/json-clients.md) |
|
|
@@ -84,7 +90,7 @@ GitLab 还提供[官方 MCP 服务器](https://docs.gitlab.com/user/model_contex
|
|
|
84
90
|
|
|
85
91
|
**本地/桌面使用**(最常见):
|
|
86
92
|
|
|
87
|
-
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN`) — 最简单的设置
|
|
93
|
+
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN` 或 `GITLAB_PERSONAL_ACCESS_TOKEN_FILE`) — 最简单的设置
|
|
88
94
|
2. **OAuth2 — 本地浏览器** (`GITLAB_USE_OAUTH`) — 推荐用于更好的安全性
|
|
89
95
|
|
|
90
96
|
**服务器/远程部署**:
|
|
@@ -132,7 +138,7 @@ command = lib.getExe inputs.gitlab-mcp.packages.${system}.default;
|
|
|
132
138
|
|
|
133
139
|
示例使用 `zereight-mcp-gitlab`,这是比旧的 `mcp-gitlab` 更不容易冲突的别名。如果 MCP 客户端找不到它,请使用 `which zereight-mcp-gitlab` 输出的绝对路径。
|
|
134
140
|
|
|
135
|
-
如果不想全局安装,请将 `npx` 固定到上一个稳定版本(即文档推荐的版本),例如 `npx -y @zereight/mcp-gitlab@2.2.
|
|
141
|
+
如果不想全局安装,请将 `npx` 固定到上一个稳定版本(即文档推荐的版本),例如 `npx -y @zereight/mcp-gitlab@2.2.3`。如果始终想使用最新版本,请改用 `npx -y @zereight/mcp-gitlab@latest`。有新版本发布时,服务器会在启动时通过 stderr 提示(可用 `GITLAB_DISABLE_VERSION_CHECK=true` 关闭)。
|
|
136
142
|
|
|
137
143
|
#### 使用 CLI 参数(适用于环境变量有问题的客户端)
|
|
138
144
|
|
|
@@ -197,10 +203,12 @@ CLI 参数优先于环境变量。
|
|
|
197
203
|
|
|
198
204
|
- sse
|
|
199
205
|
|
|
206
|
+
只传变量名。Docker 客户端把已 export 的 `GITLAB_PERSONAL_ACCESS_TOKEN` 复制进容器。
|
|
207
|
+
|
|
200
208
|
```shell
|
|
201
209
|
docker run -i --rm \
|
|
202
210
|
-e HOST=0.0.0.0 \
|
|
203
|
-
-e GITLAB_PERSONAL_ACCESS_TOKEN
|
|
211
|
+
-e GITLAB_PERSONAL_ACCESS_TOKEN \
|
|
204
212
|
-e GITLAB_API_URL="https://gitlab.com/api/v4" \
|
|
205
213
|
-e GITLAB_PERMISSION_MODE=readonly \
|
|
206
214
|
-e GITLAB_TOOLSETS=core,wiki,milestones,pipelines \
|
package/build/config.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { parseCliArgs } from "./cli-boolean-flags.js";
|
|
2
2
|
import { deprecatedEnvInputFromSources } from "./deprecated-env.js";
|
|
3
|
+
import { readPersonalAccessTokenFile, resolvePersonalAccessToken, } from "./personal-access-token.js";
|
|
3
4
|
import { parseToolProfile } from "./tools/tool-profile.js";
|
|
4
5
|
import { parseCompactToolAllowlist } from "./utils/compact-tool-allowlist.js";
|
|
6
|
+
import { createLogger, flushStartupLogs } from "./utils/logger.js";
|
|
5
7
|
// Parse CLI arguments before anything else
|
|
6
8
|
export const cliArgs = parseCliArgs(process.argv.slice(2));
|
|
7
9
|
export function getConfig(cliKey, envKey, defaultValue) {
|
|
@@ -10,7 +12,19 @@ export function getConfig(cliKey, envKey, defaultValue) {
|
|
|
10
12
|
// ---------------------------------------------------------------------------
|
|
11
13
|
// Authentication
|
|
12
14
|
// ---------------------------------------------------------------------------
|
|
13
|
-
|
|
15
|
+
function warnIgnoredPersonalAccessTokenFile(message) {
|
|
16
|
+
const startupLogger = createLogger();
|
|
17
|
+
startupLogger.warn(message);
|
|
18
|
+
flushStartupLogs(startupLogger);
|
|
19
|
+
}
|
|
20
|
+
// Read once at module load. Later auth checks use this constant and do not reopen the file.
|
|
21
|
+
export const GITLAB_PERSONAL_ACCESS_TOKEN = resolvePersonalAccessToken({
|
|
22
|
+
cliToken: cliArgs.token,
|
|
23
|
+
envToken: process.env.GITLAB_PERSONAL_ACCESS_TOKEN,
|
|
24
|
+
filePath: process.env.GITLAB_PERSONAL_ACCESS_TOKEN_FILE,
|
|
25
|
+
readFile: readPersonalAccessTokenFile,
|
|
26
|
+
warn: warnIgnoredPersonalAccessTokenFile,
|
|
27
|
+
});
|
|
14
28
|
export const GITLAB_JOB_TOKEN = getConfig("job-token", "GITLAB_JOB_TOKEN");
|
|
15
29
|
export const GITLAB_AUTH_COOKIE_PATH = getConfig("cookie-path", "GITLAB_AUTH_COOKIE_PATH");
|
|
16
30
|
export const USE_OAUTH = getConfig("use-oauth", "GITLAB_USE_OAUTH") === "true";
|
package/build/index.js
CHANGED
|
@@ -743,7 +743,8 @@ function validateConfiguration() {
|
|
|
743
743
|
// Validate auth configuration
|
|
744
744
|
const remoteAuth = getConfig("remote-auth", "REMOTE_AUTHORIZATION") === "true";
|
|
745
745
|
const useOAuth = getConfig("use-oauth", "GITLAB_USE_OAUTH") === "true";
|
|
746
|
-
|
|
746
|
+
// getConfig() would ignore GITLAB_PERSONAL_ACCESS_TOKEN_FILE.
|
|
747
|
+
const hasToken = !!GITLAB_PERSONAL_ACCESS_TOKEN;
|
|
747
748
|
const hasJobToken = !!getConfig("job-token", "GITLAB_JOB_TOKEN");
|
|
748
749
|
const hasCookie = !!getConfig("cookie-path", "GITLAB_AUTH_COOKIE_PATH");
|
|
749
750
|
const mcpOAuth = getConfig("mcp-oauth", "GITLAB_MCP_OAUTH") === "true";
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
const EMPTY_FILE_CODE = "EMPTY";
|
|
3
|
+
export class PersonalAccessTokenFileError extends Error {
|
|
4
|
+
code;
|
|
5
|
+
filePath;
|
|
6
|
+
constructor(filePath, code) {
|
|
7
|
+
super(`Cannot load GITLAB_PERSONAL_ACCESS_TOKEN_FILE at ${filePath} (${code})`);
|
|
8
|
+
this.name = "PersonalAccessTokenFileError";
|
|
9
|
+
this.filePath = filePath;
|
|
10
|
+
this.code = code;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function presentInlineToken(value) {
|
|
14
|
+
if (value === undefined || value.length === 0) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function configuredFilePath(filePath) {
|
|
20
|
+
if (filePath === undefined) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const trimmed = filePath.trim();
|
|
24
|
+
if (trimmed.length === 0) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return trimmed;
|
|
28
|
+
}
|
|
29
|
+
function errnoCode(error) {
|
|
30
|
+
if (typeof error !== "object" || error === null || !("code" in error)) {
|
|
31
|
+
return "EIO";
|
|
32
|
+
}
|
|
33
|
+
const code = error.code;
|
|
34
|
+
if (typeof code !== "string" || code.length === 0) {
|
|
35
|
+
return "EIO";
|
|
36
|
+
}
|
|
37
|
+
return code;
|
|
38
|
+
}
|
|
39
|
+
export function readPersonalAccessTokenFile(filePath) {
|
|
40
|
+
return readFileSync(filePath, { encoding: "utf8" });
|
|
41
|
+
}
|
|
42
|
+
function ignoredFileWarning(filePath) {
|
|
43
|
+
return `Ignoring GITLAB_PERSONAL_ACCESS_TOKEN_FILE at ${filePath} because an inline personal access token is set`;
|
|
44
|
+
}
|
|
45
|
+
function readTokenFile(source, filePath) {
|
|
46
|
+
try {
|
|
47
|
+
return source.readFile(filePath);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
throw new PersonalAccessTokenFileError(filePath, errnoCode(error));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolve the personal access token once.
|
|
55
|
+
* `--token` wins, then a non-empty GITLAB_PERSONAL_ACCESS_TOKEN, then the file.
|
|
56
|
+
* Job tokens, OAuth, cookies, and remote authorization are not inputs.
|
|
57
|
+
*/
|
|
58
|
+
export function resolvePersonalAccessToken(source) {
|
|
59
|
+
const inline = presentInlineToken(source.cliToken) ?? presentInlineToken(source.envToken);
|
|
60
|
+
const filePath = configuredFilePath(source.filePath);
|
|
61
|
+
if (inline !== undefined) {
|
|
62
|
+
if (filePath !== undefined) {
|
|
63
|
+
source.warn(ignoredFileWarning(filePath));
|
|
64
|
+
}
|
|
65
|
+
return inline;
|
|
66
|
+
}
|
|
67
|
+
if (filePath === undefined) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
const token = readTokenFile(source, filePath).trim();
|
|
71
|
+
if (token.length === 0) {
|
|
72
|
+
throw new PersonalAccessTokenFileError(filePath, EMPTY_FILE_CODE);
|
|
73
|
+
}
|
|
74
|
+
return token;
|
|
75
|
+
}
|
package/package.json
CHANGED