From a04193380d1ea9c2e6bb72112affd51e1928f249 Mon Sep 17 00:00:00 2001 From: Bob Merkus Date: Wed, 9 Apr 2025 14:12:01 +0200 Subject: [PATCH 1/2] fix: use default HEAD as ref --- src/gitlab/index.ts | 22 +++------------------- src/gitlab/schemas.ts | 1 + 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/gitlab/index.ts b/src/gitlab/index.ts index 3c96461ca8..06ac9d8675 100644 --- a/src/gitlab/index.ts +++ b/src/gitlab/index.ts @@ -111,24 +111,6 @@ async function createBranch( return GitLabReferenceSchema.parse(await response.json()); } -async function getDefaultBranchRef(projectId: string): Promise { - const response = await fetch( - `${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}`, - { - headers: { - "Authorization": `Bearer ${GITLAB_PERSONAL_ACCESS_TOKEN}` - } - } - ); - - if (!response.ok) { - throw new Error(`GitLab API error: ${response.statusText}`); - } - - const project = GitLabRepositorySchema.parse(await response.json()); - return project.default_branch; -} - async function getFileContents( projectId: string, filePath: string, @@ -138,6 +120,8 @@ async function getFileContents( let url = `${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}/repository/files/${encodedPath}`; if (ref) { url += `?ref=${encodeURIComponent(ref)}`; + } else { + url += '?ref=HEAD'; } const response = await fetch(url, { @@ -444,7 +428,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { const args = CreateBranchSchema.parse(request.params.arguments); let ref = args.ref; if (!ref) { - ref = await getDefaultBranchRef(args.project_id); + ref = "HEAD"; } const branch = await createBranch(args.project_id, { diff --git a/src/gitlab/schemas.ts b/src/gitlab/schemas.ts index af93380dd0..21d5390ee2 100644 --- a/src/gitlab/schemas.ts +++ b/src/gitlab/schemas.ts @@ -262,6 +262,7 @@ export const CreateRepositorySchema = z.object({ }); export const GetFileContentsSchema = ProjectParamsSchema.extend({ + project_id: z.string().describe("Project ID or URL-encoded path"), file_path: z.string().describe("Path to the file or directory"), ref: z.string().optional().describe("Branch/tag/commit to get contents from") }); From f221e958d3773204a483e509095255f234d33ed9 Mon Sep 17 00:00:00 2001 From: Bob Date: Sat, 19 Apr 2025 21:56:43 +0200 Subject: [PATCH 2/2] fix: remove duplicated project_id from schema --- src/gitlab/schemas.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gitlab/schemas.ts b/src/gitlab/schemas.ts index 21d5390ee2..af93380dd0 100644 --- a/src/gitlab/schemas.ts +++ b/src/gitlab/schemas.ts @@ -262,7 +262,6 @@ export const CreateRepositorySchema = z.object({ }); export const GetFileContentsSchema = ProjectParamsSchema.extend({ - project_id: z.string().describe("Project ID or URL-encoded path"), file_path: z.string().describe("Path to the file or directory"), ref: z.string().optional().describe("Branch/tag/commit to get contents from") });