From 4a15c7c7bf59a8b76136ddb550b042a443dbf16d Mon Sep 17 00:00:00 2001 From: iwakitakuma33 Date: Mon, 9 Jun 2025 10:17:19 +0900 Subject: [PATCH] FEAT: private token auth issue: #88 --- index.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/index.ts b/index.ts index 5132f7b..b23a089 100644 --- a/index.ts +++ b/index.ts @@ -203,6 +203,7 @@ const server = new Server( ); const GITLAB_PERSONAL_ACCESS_TOKEN = process.env.GITLAB_PERSONAL_ACCESS_TOKEN; +const IS_OLD = process.env.GITLAB_IS_OLD === "true"; const GITLAB_READ_ONLY_MODE = process.env.GITLAB_READ_ONLY_MODE === "true"; const USE_GITLAB_WIKI = process.env.USE_GITLAB_WIKI === "true"; const USE_MILESTONE = process.env.USE_MILESTONE === "true"; @@ -245,11 +246,15 @@ httpsAgent = httpsAgent || new HttpsAgent(sslOptions); httpAgent = httpAgent || new Agent(); // Modify DEFAULT_HEADERS to include agent configuration -const DEFAULT_HEADERS = { +const DEFAULT_HEADERS: Record = { Accept: "application/json", "Content-Type": "application/json", - Authorization: `Bearer ${GITLAB_PERSONAL_ACCESS_TOKEN}`, }; +if (IS_OLD) { + DEFAULT_HEADERS["Private-Token"] = `Bearer ${GITLAB_PERSONAL_ACCESS_TOKEN}`; +} else { + DEFAULT_HEADERS["Authorization"] = `Bearer ${GITLAB_PERSONAL_ACCESS_TOKEN}`; +} // Create a default fetch configuration object that includes proxy agents if set const DEFAULT_FETCH_CONFIG = { @@ -2730,15 +2735,20 @@ async function getRepositoryTree(options: GetRepositoryTreeOptions): Promise = { + "Content-Type": "application/json", + }; + if (IS_OLD) { + headers["Private-Token"] = `Bearer ${GITLAB_PERSONAL_ACCESS_TOKEN}`; + } else { + headers["Authorization"] = `Bearer ${GITLAB_PERSONAL_ACCESS_TOKEN}`; + } const response = await fetch( `${GITLAB_API_URL}/projects/${encodeURIComponent( options.project_id )}/repository/tree?${queryParams.toString()}`, { - headers: { - Authorization: `Bearer ${GITLAB_PERSONAL_ACCESS_TOKEN}`, - "Content-Type": "application/json", - }, + headers, } );