Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions src/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,6 @@ async function createBranch(
return GitLabReferenceSchema.parse(await response.json());
}

async function getDefaultBranchRef(projectId: string): Promise<string> {
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,
Expand All @@ -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, {
Expand Down Expand Up @@ -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, {
Expand Down