fix: use default HEAD as ref
This commit is contained in:
parent
e8f0b15f41
commit
a04193380d
2 changed files with 4 additions and 19 deletions
|
|
@ -111,24 +111,6 @@ async function createBranch(
|
||||||
return GitLabReferenceSchema.parse(await response.json());
|
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(
|
async function getFileContents(
|
||||||
projectId: string,
|
projectId: string,
|
||||||
filePath: string,
|
filePath: string,
|
||||||
|
|
@ -138,6 +120,8 @@ async function getFileContents(
|
||||||
let url = `${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}/repository/files/${encodedPath}`;
|
let url = `${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}/repository/files/${encodedPath}`;
|
||||||
if (ref) {
|
if (ref) {
|
||||||
url += `?ref=${encodeURIComponent(ref)}`;
|
url += `?ref=${encodeURIComponent(ref)}`;
|
||||||
|
} else {
|
||||||
|
url += '?ref=HEAD';
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
|
|
@ -444,7 +428,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
||||||
const args = CreateBranchSchema.parse(request.params.arguments);
|
const args = CreateBranchSchema.parse(request.params.arguments);
|
||||||
let ref = args.ref;
|
let ref = args.ref;
|
||||||
if (!ref) {
|
if (!ref) {
|
||||||
ref = await getDefaultBranchRef(args.project_id);
|
ref = "HEAD";
|
||||||
}
|
}
|
||||||
|
|
||||||
const branch = await createBranch(args.project_id, {
|
const branch = await createBranch(args.project_id, {
|
||||||
|
|
|
||||||
|
|
@ -262,6 +262,7 @@ export const CreateRepositorySchema = z.object({
|
||||||
});
|
});
|
||||||
|
|
||||||
export const GetFileContentsSchema = ProjectParamsSchema.extend({
|
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"),
|
file_path: z.string().describe("Path to the file or directory"),
|
||||||
ref: z.string().optional().describe("Branch/tag/commit to get contents from")
|
ref: z.string().optional().describe("Branch/tag/commit to get contents from")
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue