Skip to content

Commit a041933

Browse files
committed
fix: use default HEAD as ref
1 parent e8f0b15 commit a041933

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

src/gitlab/index.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,6 @@ async function createBranch(
111111
return GitLabReferenceSchema.parse(await response.json());
112112
}
113113

114-
async function getDefaultBranchRef(projectId: string): Promise<string> {
115-
const response = await fetch(
116-
`${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}`,
117-
{
118-
headers: {
119-
"Authorization": `Bearer ${GITLAB_PERSONAL_ACCESS_TOKEN}`
120-
}
121-
}
122-
);
123-
124-
if (!response.ok) {
125-
throw new Error(`GitLab API error: ${response.statusText}`);
126-
}
127-
128-
const project = GitLabRepositorySchema.parse(await response.json());
129-
return project.default_branch;
130-
}
131-
132114
async function getFileContents(
133115
projectId: string,
134116
filePath: string,
@@ -138,6 +120,8 @@ async function getFileContents(
138120
let url = `${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}/repository/files/${encodedPath}`;
139121
if (ref) {
140122
url += `?ref=${encodeURIComponent(ref)}`;
123+
} else {
124+
url += '?ref=HEAD';
141125
}
142126

143127
const response = await fetch(url, {
@@ -444,7 +428,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
444428
const args = CreateBranchSchema.parse(request.params.arguments);
445429
let ref = args.ref;
446430
if (!ref) {
447-
ref = await getDefaultBranchRef(args.project_id);
431+
ref = "HEAD";
448432
}
449433

450434
const branch = await createBranch(args.project_id, {

src/gitlab/schemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ export const CreateRepositorySchema = z.object({
262262
});
263263

264264
export const GetFileContentsSchema = ProjectParamsSchema.extend({
265+
project_id: z.string().describe("Project ID or URL-encoded path"),
265266
file_path: z.string().describe("Path to the file or directory"),
266267
ref: z.string().optional().describe("Branch/tag/commit to get contents from")
267268
});

0 commit comments

Comments
 (0)