From a63b070956211236136c3c9f4adfcd5e8e9663ad Mon Sep 17 00:00:00 2001 From: Admin Date: Tue, 18 Mar 2025 02:50:41 -0700 Subject: [PATCH] Fix Issue Links API schema to properly handle GitLab response formats --- index.ts | 8 +++++--- schemas.ts | 14 ++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/index.ts b/index.ts index e107803..02196e1 100644 --- a/index.ts +++ b/index.ts @@ -49,6 +49,7 @@ import { UpdateIssueSchema, DeleteIssueSchema, GitLabIssueLinkSchema, + GitLabIssueWithLinkDetailsSchema, ListIssueLinksSchema, GetIssueLinkSchema, CreateIssueLinkSchema, @@ -72,6 +73,7 @@ import { type FileOperation, type GitLabMergeRequestDiff, type GitLabIssueLink, + type GitLabIssueWithLinkDetails, type GitLabNamespace, type GitLabNamespaceExistsResponse, type GitLabProject, @@ -480,12 +482,12 @@ async function deleteIssue( * * @param {string} projectId - The ID or URL-encoded path of the project * @param {number} issueIid - The internal ID of the project issue - * @returns {Promise} List of issue links + * @returns {Promise} List of issues with link details */ async function listIssueLinks( projectId: string, issueIid: number -): Promise { +): Promise { const url = new URL( `${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}/issues/${issueIid}/links` ); @@ -496,7 +498,7 @@ async function listIssueLinks( await handleGitLabError(response); const data = await response.json(); - return z.array(GitLabIssueLinkSchema).parse(data); + return z.array(GitLabIssueWithLinkDetailsSchema).parse(data); } /** diff --git a/schemas.ts b/schemas.ts index 3d68f38..a3fd19c 100644 --- a/schemas.ts +++ b/schemas.ts @@ -280,6 +280,14 @@ export const GitLabIssueSchema = z.object({ weight: z.number().nullable().optional(), }); +// NEW SCHEMA: For issue with link details (used in listing issue links) +export const GitLabIssueWithLinkDetailsSchema = GitLabIssueSchema.extend({ + issue_link_id: z.number(), + link_type: z.enum(['relates_to', 'blocks', 'is_blocked_by']), + link_created_at: z.string(), + link_updated_at: z.string(), +}); + // Fork related schemas export const GitLabForkParentSchema = z.object({ name: z.string(), @@ -544,12 +552,9 @@ export const DeleteIssueSchema = z.object({ // Issue links related schemas export const GitLabIssueLinkSchema = z.object({ - id: z.number(), - link_type: z.enum(['relates_to', 'blocks', 'is_blocked_by']), source_issue: GitLabIssueSchema, target_issue: GitLabIssueSchema, - link_created_at: z.string().optional(), - link_updated_at: z.string().optional(), + link_type: z.enum(['relates_to', 'blocks', 'is_blocked_by']), }); export const ListIssueLinksSchema = z.object({ @@ -618,6 +623,7 @@ export const ListProjectsSchema = z.object({ export type GitLabAuthor = z.infer; export type GitLabFork = z.infer; export type GitLabIssue = z.infer; +export type GitLabIssueWithLinkDetails = z.infer; export type GitLabMergeRequest = z.infer; export type GitLabRepository = z.infer; export type GitLabFileContent = z.infer;