UNPKG

@therealchristhomas/gitlab-mcp-server

Version:
76 lines (75 loc) 3.21 kB
import { z } from "zod"; import { gitlabGet, gitlabPost, gitlabPut, encodeProjectId, buildSearchParams } from "../utils/gitlab-client.js"; import { GitLabMergeRequestSchema, GitLabCommentSchema } from "../types/index.js"; export async function listMergeRequests(projectId, options = {}) { if (!projectId?.trim()) { throw new Error("Project ID is required"); } const endpoint = `/projects/${encodeProjectId(projectId)}/merge_requests`; const params = buildSearchParams(options); const mergeRequests = await gitlabGet(endpoint, params); return z.array(GitLabMergeRequestSchema).parse(mergeRequests); } export async function createMergeRequest(projectId, options) { if (!projectId?.trim()) { throw new Error("Project ID is required"); } if (!options?.title?.trim()) { throw new Error("Merge request title is required"); } if (!options?.source_branch?.trim()) { throw new Error("Source branch is required"); } if (!options?.target_branch?.trim()) { throw new Error("Target branch is required"); } const endpoint = `/projects/${encodeProjectId(projectId)}/merge_requests`; const mergeRequest = await gitlabPost(endpoint, { title: options.title, description: options.description, source_branch: options.source_branch, target_branch: options.target_branch, allow_collaboration: options.allow_collaboration, draft: options.draft }); return GitLabMergeRequestSchema.parse(mergeRequest); } export async function updateMergeRequest(projectId, mergeRequestIid, options) { if (!projectId?.trim()) { throw new Error("Project ID is required"); } if (!mergeRequestIid || mergeRequestIid < 1) { throw new Error("Valid merge request IID is required"); } const endpoint = `/projects/${encodeProjectId(projectId)}/merge_requests/${mergeRequestIid}`; const mergeRequest = await gitlabPut(endpoint, { ...options, labels: options.labels?.join(",") }); return GitLabMergeRequestSchema.parse(mergeRequest); } export async function mergeMergeRequest(projectId, mergeRequestIid, options = {}) { if (!projectId?.trim()) { throw new Error("Project ID is required"); } if (!mergeRequestIid || mergeRequestIid < 1) { throw new Error("Valid merge request IID is required"); } const endpoint = `/projects/${encodeProjectId(projectId)}/merge_requests/${mergeRequestIid}/merge`; const mergeRequest = await gitlabPut(endpoint, options); return GitLabMergeRequestSchema.parse(mergeRequest); } export async function addMergeRequestComment(projectId, mergeRequestIid, body) { if (!projectId?.trim()) { throw new Error("Project ID is required"); } if (!mergeRequestIid || mergeRequestIid < 1) { throw new Error("Valid merge request IID is required"); } if (!body?.trim()) { throw new Error("Comment body is required"); } const endpoint = `/projects/${encodeProjectId(projectId)}/merge_requests/${mergeRequestIid}/notes`; const comment = await gitlabPost(endpoint, { body }); return GitLabCommentSchema.parse(comment); }