Skip to content

Commit 0f86b30

Browse files
authored
Merge pull request #1335 from BobMerkus/fix/gitlab-get-file-contents
fix: use default HEAD as ref
2 parents 790403a + d6a06c6 commit 0f86b30

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-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, {

0 commit comments

Comments
 (0)