-
Notifications
You must be signed in to change notification settings - Fork 323
Expand file tree
/
Copy pathschemas.ts
More file actions
4833 lines (4498 loc) · 182 KB
/
Copy pathschemas.ts
File metadata and controls
4833 lines (4498 loc) · 182 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { z } from "zod";
import { omitIncompleteMergeRequestPosition } from "./utils/merge-request-position.js";
// Helper: coerce a JSON-stringified array to an actual array.
// LLMs sometimes send '["a", "b"]' (string) instead of ["a", "b"] (array).
const coerceStringArray = z.preprocess(val => {
if (typeof val === "string") {
try {
const parsed = JSON.parse(val);
if (Array.isArray(parsed)) return parsed;
} catch {
/* not JSON, fall through */
}
}
return val;
}, z.array(z.string()));
const coerceBooleanString = z.preprocess(val => {
if (typeof val === "string") {
const normalized = val.trim().toLowerCase();
if (normalized === "true") return true;
if (normalized === "false") return false;
}
return val;
}, z.boolean());
// Base schemas for common types
export const GitLabAuthorSchema = z.object({
name: z.string(),
email: z.string(),
date: z.string(),
});
// Pipeline related schemas
export const GitLabPipelineSchema = z.object({
id: z.coerce.string(),
project_id: z.coerce.string(),
sha: z.string(),
ref: z.string(),
status: z.string(),
source: z.string().optional(),
created_at: z.string(),
updated_at: z.string(),
web_url: z.string(),
duration: z.coerce.number().nullable().optional(),
started_at: z.string().nullable().optional(),
finished_at: z.string().nullable().optional(),
coverage: z.coerce.number().nullable().optional(),
user: z
.object({
id: z.coerce.string(),
name: z.string(),
username: z.string(),
avatar_url: z.string().nullable().optional(),
})
.optional(),
detailed_status: z
.object({
icon: z.string().optional(),
text: z.string().optional(),
label: z.string().optional(),
group: z.string().optional(),
tooltip: z.string().optional(),
has_details: z.coerce.boolean().optional(),
details_path: z.string().optional(),
illustration: z
.object({
image: z.string().optional(),
size: z.string().optional(),
title: z.string().optional(),
})
.nullable()
.optional(),
favicon: z.string().optional(),
})
.optional(),
});
// Pipeline job related schemas
export const GitLabPipelineJobSchema = z.object({
id: z.coerce.string(),
status: z.string(),
stage: z.string(),
name: z.string(),
ref: z.string(),
tag: z.coerce.boolean(),
coverage: z.coerce.number().nullable().optional(),
created_at: z.string(),
started_at: z.string().nullable().optional(),
finished_at: z.string().nullable().optional(),
duration: z.coerce.number().nullable().optional(),
queued_duration: z.coerce.number().nullable().optional(),
failure_reason: z.string().nullable().optional(),
user: z
.object({
id: z.coerce.string(),
name: z.string(),
username: z.string(),
avatar_url: z.string().nullable().optional(),
})
.optional(),
commit: z
.object({
id: z.string(),
short_id: z.string(),
title: z.string(),
author_name: z.string(),
author_email: z.string(),
})
.optional(),
pipeline: z
.object({
id: z.coerce.string(),
project_id: z.coerce.string(),
status: z.string(),
ref: z.string(),
sha: z.string(),
})
.optional(),
web_url: z.string().optional(),
allow_failure: z.coerce.boolean().optional(),
retried: z.coerce.boolean().optional(),
tag_list: z.array(z.string()).optional(),
runner: z
.object({
id: z.coerce.string().optional(),
description: z.string().nullable().optional(),
active: z.coerce.boolean().optional(),
is_shared: z.coerce.boolean().optional(),
runner_type: z.string().optional(),
})
.nullable()
.optional(),
});
// Pipeline trigger job (bridge) schema
export const GitLabPipelineTriggerJobSchema = z.object({
id: z.coerce.string(),
status: z.string(),
stage: z.string(),
name: z.string(),
ref: z.string(),
tag: z.coerce.boolean(),
coverage: z.coerce.number().nullable().optional(),
created_at: z.string(),
started_at: z.string().nullable().optional(),
finished_at: z.string().nullable().optional(),
duration: z.coerce.number().nullable().optional(),
queued_duration: z.coerce.number().nullable().optional(),
user: z
.object({
id: z.coerce.string(),
name: z.string(),
username: z.string(),
avatar_url: z.string().nullable().optional(),
})
.optional(),
commit: z
.object({
id: z.string(),
short_id: z.string(),
title: z.string(),
author_name: z.string(),
author_email: z.string(),
})
.optional(),
pipeline: z
.object({
id: z.coerce.string(),
project_id: z.coerce.string(),
status: z.string(),
ref: z.string(),
sha: z.string(),
created_at: z.string().optional(),
updated_at: z.string().optional(),
web_url: z.string().optional(),
})
.optional(),
web_url: z.string().optional(),
allow_failure: z.coerce.boolean().optional(),
archived: z.coerce.boolean().optional(),
source: z.string().optional(),
erased_at: z.string().nullable().optional(),
project: z
.object({
ci_job_token_scope_enabled: z.coerce.boolean().optional(),
})
.optional(),
downstream_pipeline: z
.object({
id: z.coerce.string(),
sha: z.string(),
ref: z.string(),
status: z.string(),
created_at: z.string(),
updated_at: z.string(),
web_url: z.string(),
})
.nullable()
.optional(),
});
// Shared base schema for various pagination options
// See https://docs.gitlab.com/api/rest/#pagination
export const PaginationOptionsSchema = z.object({
page: z.coerce.number().optional().describe("Page number for pagination (default: 1)"),
per_page: z.coerce
.number()
.optional()
.describe("Number of items per page (max: 100, default: 20)"),
});
// Schema for listing pipelines
export const ListPipelinesSchema = z
.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
scope: z
.enum(["running", "pending", "finished", "branches", "tags"])
.optional()
.describe("The scope of pipelines"),
status: z
.enum([
"created",
"waiting_for_resource",
"preparing",
"pending",
"running",
"success",
"failed",
"canceled",
"skipped",
"manual",
"scheduled",
])
.optional()
.describe("The status of pipelines"),
ref: z.string().optional().describe("The ref of pipelines"),
sha: z.string().optional().describe("The SHA of pipelines"),
yaml_errors: z.coerce
.boolean()
.optional()
.describe("Returns pipelines with invalid configurations"),
username: z.string().optional().describe("The username of the user who triggered pipelines"),
updated_after: z
.string()
.optional()
.describe("Return pipelines updated after the specified date"),
updated_before: z
.string()
.optional()
.describe("Return pipelines updated before the specified date"),
order_by: z
.enum(["id", "status", "ref", "updated_at", "user_id"])
.optional()
.describe("Order pipelines by"),
sort: z.enum(["asc", "desc"]).optional().describe("Sort pipelines"),
})
.merge(PaginationOptionsSchema);
// Schema for getting a specific pipeline
export const GetPipelineSchema = z.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
pipeline_id: z.coerce.string().describe("The ID of the pipeline"),
});
export const GitLabMergeRequestPipelineSchema = z.object({
id: z.coerce.string(),
sha: z.string(),
ref: z.string(),
status: z.string(),
project_id: z.coerce.string().optional(),
source: z.string().optional(),
created_at: z.string().optional(),
updated_at: z.string().optional(),
web_url: z.string().optional(),
});
// Schema for listing jobs in a pipeline
export const ListPipelineJobsSchema = z
.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
pipeline_id: z.coerce.string().describe("The ID of the pipeline"),
scope: z
.enum(["created", "pending", "running", "failed", "success", "canceled", "skipped", "manual"])
.optional()
.describe("The scope of jobs to show"),
include_retried: z.coerce.boolean().optional().describe("Whether to include retried jobs"),
})
.merge(PaginationOptionsSchema);
// Schema for listing trigger jobs (bridges) in a pipeline
export const ListPipelineTriggerJobsSchema = z
.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
pipeline_id: z.coerce.string().describe("The ID of the pipeline"),
scope: z
// https://docs.gitlab.com/api/jobs/#job-status-values
.enum([
"canceled",
"canceling",
"created",
"failed",
"manual",
"pending",
"preparing",
"running",
"scheduled",
"skipped",
"success",
"waiting_for_resource",
])
.optional()
.describe("The scope of trigger jobs to show"),
})
.merge(PaginationOptionsSchema);
export const GitLabCiLintResultSchema = z.object({
valid: z.coerce.boolean(),
errors: z.array(z.string()),
warnings: z.array(z.string()).optional(),
merged_yaml: z.string().optional(),
includes: z.array(z.unknown()).optional(),
jobs: z.array(z.unknown()).optional(),
});
export const ValidateCiLintSchema = z.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
content: z.string().describe("GitLab CI/CD YAML content to validate"),
dry_run: z.coerce.boolean().optional().describe("Run pipeline creation simulation"),
include_jobs: z.coerce.boolean().optional().describe("Include jobs in the lint response"),
ref: z.string().optional().describe("Branch or tag context for dry_run validation"),
});
export const ValidateProjectCiLintSchema = z.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
content_ref: z
.string()
.optional()
.describe("Commit SHA, branch, or tag to read the existing CI config from"),
dry_run: z.coerce.boolean().optional().describe("Run pipeline creation simulation"),
dry_run_ref: z.string().optional().describe("Branch or tag context for dry_run validation"),
include_jobs: z.coerce.boolean().optional().describe("Include jobs in the lint response"),
});
const CiCatalogResourceSortSchema = z.enum([
"CREATED_ASC",
"CREATED_DESC",
"LATEST_RELEASED_AT_ASC",
"LATEST_RELEASED_AT_DESC",
"NAME_ASC",
"NAME_DESC",
"STAR_COUNT_ASC",
"STAR_COUNT_DESC",
"USAGE_COUNT_ASC",
"USAGE_COUNT_DESC",
]);
const CiCatalogResourceVerificationLevelSchema = z.enum([
"GITLAB_MAINTAINED",
"GITLAB_PARTNER_MAINTAINED",
"UNVERIFIED",
"VERIFIED_CREATOR_MAINTAINED",
"VERIFIED_CREATOR_SELF_MANAGED",
]);
export const ListCiCatalogResourcesSchema = z.object({
search: z.string().optional().describe("Search catalog resources by name or description"),
first: z.coerce.number().int().min(1).max(100).optional().describe("Number of resources to return (default: 20, max: 100)"),
after: z.string().optional().describe("GraphQL cursor for the next page"),
group_ids: z.array(z.string()).optional().describe("Filter to catalog resources in these group IDs"),
scope: z.enum(["ALL", "NAMESPACES"]).optional().describe("Catalog resource scope"),
sort: CiCatalogResourceSortSchema.optional().describe("Sort order"),
topics: z.array(z.string()).optional().describe("Filter by project topic names"),
verification_level: CiCatalogResourceVerificationLevelSchema.optional().describe("Filter by verification level"),
});
const GetCiCatalogResourceOptionsSchema = z.object({
version_limit: z.coerce.number().int().min(1).max(20).optional().describe("Number of versions to include (default: 5, max: 20)"),
component_limit: z.coerce.number().int().min(1).max(50).optional().describe("Number of components per version to include (default: 20, max: 50)"),
component_name: z.string().optional().describe("Filter returned components by component name"),
include_readme: z.coerce.boolean().optional().describe("Include version README content"),
});
export const GetCiCatalogResourceSchema = z.union([
GetCiCatalogResourceOptionsSchema.extend({
id: z.string().min(1).describe("CI/CD Catalog resource global ID. Required when full_path is omitted."),
full_path: z.string().min(1).optional().describe("CI/CD Catalog resource full project path. Required when id is omitted."),
}),
GetCiCatalogResourceOptionsSchema.extend({
id: z.string().min(1).optional().describe("CI/CD Catalog resource global ID. Required when full_path is omitted."),
full_path: z.string().min(1).describe("CI/CD Catalog resource full project path. Required when id is omitted."),
}),
]).refine(args => Boolean(args.id) !== Boolean(args.full_path), {
message: "Provide exactly one of id or full_path",
});
// Deployment related schemas
export const GitLabDeploymentSchema = z.object({
id: z.coerce.string(),
iid: z.coerce.string().optional(),
status: z.string(),
ref: z.string().optional(),
sha: z.string(),
created_at: z.string(),
updated_at: z.string().optional(),
finished_at: z.string().nullable().optional(),
environment: z
.object({
id: z.coerce.string().optional(),
name: z.string(),
slug: z.string().optional(),
external_url: z.string().nullable().optional(),
state: z.string().optional(),
tier: z.string().optional(),
})
.optional(),
deployable: z
.object({
id: z.coerce.string().optional(),
name: z.string().optional(),
status: z.string().optional(),
stage: z.string().optional(),
web_url: z.string().optional(),
pipeline: z
.object({
id: z.coerce.string().optional(),
status: z.string().optional(),
ref: z.string().optional(),
sha: z.string().optional(),
web_url: z.string().optional(),
})
.optional(),
})
.nullable()
.optional(),
user: z
.object({
id: z.coerce.string().optional(),
username: z.string().optional(),
name: z.string().optional(),
avatar_url: z.string().nullable().optional(),
})
.optional(),
web_url: z.string().optional(),
});
export const ListDeploymentsSchema = z
.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
environment: z.string().optional().describe("Filter by environment name"),
ref: z.string().optional().describe("Filter by ref"),
sha: z
.string()
.optional()
.describe("Filter by commit SHA (if supported by your GitLab version)"),
status: z.string().optional().describe("Filter by deployment status"),
updated_after: z
.string()
.optional()
.describe("Return deployments updated after the specified date"),
updated_before: z
.string()
.optional()
.describe("Return deployments updated before the specified date"),
order_by: z
.enum(["id", "iid", "created_at", "updated_at", "ref", "status", "environment"])
.optional()
.describe("Order deployments by"),
sort: z.enum(["asc", "desc"]).optional().describe("Sort deployments"),
})
.merge(PaginationOptionsSchema);
export const GetDeploymentSchema = z.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
deployment_id: z.coerce.string().describe("The ID of the deployment"),
});
// Environment related schemas
const GitLabEnvironmentLastDeploymentSchema = z.object({
id: z.coerce.string().optional(),
iid: z.coerce.string().optional(),
status: z.string().optional(),
ref: z.string().optional(),
sha: z.string().optional(),
created_at: z.string().optional(),
updated_at: z.string().optional(),
web_url: z.string().optional(),
});
export const GitLabEnvironmentSchema = z.object({
id: z.coerce.string(),
name: z.string(),
slug: z.string().optional(),
external_url: z.string().nullable().optional(),
state: z.string().optional(),
tier: z.string().optional(),
environment_type: z.string().optional(),
created_at: z.string().optional(),
updated_at: z.string().optional(),
auto_stop_at: z.string().nullable().optional(),
enable_advanced_logs_querying: z.coerce.boolean().optional(),
logs_api_path: z.string().optional(),
web_url: z.string().optional(),
last_deployment: GitLabEnvironmentLastDeploymentSchema.nullable().optional(),
});
export const ListEnvironmentsSchema = z
.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
name: z.string().optional().describe("Return environments with this exact name"),
search: z.string().optional().describe("Search environments by name"),
states: z.enum(["available", "stopped"]).optional().describe("Filter environments by state"),
})
.merge(PaginationOptionsSchema);
export const GetEnvironmentSchema = z.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
environment_id: z.coerce.string().describe("The ID of the environment"),
});
// Schema for creating a new pipeline
export const CreatePipelineSchema = z.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
ref: z.string().describe("The branch or tag to run the pipeline on"),
variables: z
.array(
z.object({
key: z.string().describe("The key of the variable"),
value: z.string().describe("The value of the variable"),
})
)
.optional()
.describe("An array of variables to use for the pipeline"),
inputs: z
.record(z.string(), z.string())
.optional()
.describe("Input parameters for the pipeline (key-value pairs for spec:inputs)"),
});
// Schema for retrying a pipeline
export const RetryPipelineSchema = z.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
pipeline_id: z.coerce.string().describe("The ID of the pipeline to retry"),
});
// Schema for canceling a pipeline
export const CancelPipelineSchema = z.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
pipeline_id: z.coerce.string().describe("The ID of the pipeline to cancel"),
});
// Schema for the input parameters for pipeline job operations
export const GetPipelineJobOutputSchema = z.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
job_id: z.coerce.string().describe("The ID of the job"),
limit: z
.number()
.optional()
.describe("Maximum number of lines to return from the end of the log (default/max: 1000)"),
offset: z
.number()
.optional()
.describe("Number of lines to skip from the end of the log (default: 0)"),
});
// Schema for pipeline job control operations
export const PipelineJobControlSchema = z.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
job_id: z.coerce.string().describe("The ID of the job"),
});
// Schema for running a manual job
export const PlayPipelineJobSchema = z.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
job_id: z.coerce.string().describe("The ID of the job"),
job_variables_attributes: z
.array(
z.object({
key: z.string().describe("Variable key"),
value: z.string().describe("Variable value"),
})
)
.optional()
.describe("Custom job variables to use when running the job"),
});
// Schema for retrying a job
export const RetryPipelineJobSchema = PipelineJobControlSchema;
// Schema for canceling a job
export const CancelPipelineJobSchema = z.object({
project_id: z.coerce.string().describe("Project ID or URL-encoded path"),
job_id: z.coerce.string().describe("The ID of the job"),
force: z.coerce.boolean().optional().describe("Force cancellation of the job"),
});
// User schemas
export const GitLabUserSchema = z.object({
username: z.string().optional(), // Changed from login to match GitLab API
id: z.coerce.string(),
name: z.string().optional(),
avatar_url: z.string().nullable().optional(),
web_url: z.string().optional(), // Changed from html_url to match GitLab API
});
export const GetUsersSchema = z.object({
usernames: z.array(z.string()).describe("Array of usernames to search for"),
});
export const GitLabUsersResponseSchema = z.record(
z.string(),
z
.object({
id: z.coerce.string(),
username: z.string(),
name: z.string(),
avatar_url: z.string().nullable(),
web_url: z.string(),
})
.nullable()
);
export const GetUserSchema = z.object({
user_id: z.coerce.string().describe("The ID of the user"),
});
export const GitLabUserFullSchema = z
.object({
id: z.coerce.string(),
username: z.string(),
name: z.string(),
state: z.string(),
avatar_url: z.string().nullable(),
web_url: z.string(),
created_at: z.string(),
bio: z.string().nullable(),
location: z.string().nullable(),
public_email: z.string().nullable(),
website_url: z.string().nullable(),
organization: z.string().nullable(),
job_title: z.string().nullable(),
pronouns: z.string().nullable(),
bot: z.boolean().optional(),
work_information: z.string().nullable(),
followers: z.number().optional(),
following: z.number().optional(),
is_followed: z.boolean().optional(),
local_time: z.string().nullable().optional(),
last_sign_in_at: z.string().nullable().optional(),
confirmed_at: z.string().nullable().optional(),
last_activity_on: z.string().nullable().optional(),
email: z.string().nullable().optional(),
theme_id: z.number().nullable().optional(),
color_scheme_id: z.number().nullable().optional(),
projects_limit: z.number().nullable().optional(),
current_sign_in_at: z.string().nullable().optional(),
identities: z
.array(
z.object({
provider: z.string(),
extern_uid: z.string(),
})
)
.optional(),
can_create_group: z.boolean().nullable().optional(),
can_create_project: z.boolean().nullable().optional(),
two_factor_enabled: z.boolean().nullable().optional(),
external: z.boolean().nullable().optional(),
private_profile: z.boolean().nullable().optional(),
is_admin: z.boolean().nullable().optional(),
})
.passthrough();
export const WhoAmISchema = z.object({});
export const GitLabCurrentUserSchema = z
.object({
id: z.coerce.string(),
username: z.string(),
name: z.string(),
state: z.string(),
avatar_url: z.string().nullable(),
web_url: z.string(),
created_at: z.string(),
bio: z.string().nullable(),
location: z.string().nullable(),
public_email: z.string().nullable(),
website_url: z.string().nullable(),
organization: z.string().nullable(),
job_title: z.string().nullable(),
email: z.string().nullable(),
last_sign_in_at: z.string().nullable(),
confirmed_at: z.string().nullable(),
last_activity_on: z.string().nullable(),
is_admin: z.boolean().optional(),
can_create_group: z.boolean().optional(),
can_create_project: z.boolean().optional(),
identities: z
.array(
z.object({
provider: z.string(),
extern_uid: z.string(),
})
)
.optional(),
})
.passthrough();
// Group related schemas
export const CreateGroupSchema = z.object({
name: z.string().describe("The name of the group"),
path: z.string().describe("The path of the group"),
description: z.string().optional().describe("The group's description"),
visibility: z
.enum(["private", "internal", "public"])
.optional()
.describe("The group's visibility level"),
parent_id: z.coerce.number().optional().describe("The parent group ID for creating a subgroup"),
});
export const GitLabGroupSchema = z.object({
id: z.coerce.string(),
name: z.string(),
path: z.string(),
description: z.string().nullable(),
visibility: z.string().optional(),
share_with_group_lock: z.boolean().optional(),
require_two_factor_authentication: z.boolean().optional(),
two_factor_grace_period: z.number().optional(),
project_creation_level: z.string().optional(),
auto_devops_enabled: z.boolean().nullable().optional(),
subgroup_creation_level: z.string().optional(),
emails_disabled: z.boolean().nullable().optional(),
mentions_disabled: z.boolean().nullable().optional(),
lfs_enabled: z.boolean().nullable().optional(),
avatar_url: z.string().nullable().optional(),
web_url: z.string(),
request_access_enabled: z.boolean().nullable().optional(),
full_name: z.string(),
full_path: z.string(),
file_template_project_id: z.number().nullable().optional(),
parent_id: z.coerce.string().nullable().optional(),
created_at: z.string().optional(),
statistics: z.any().optional(),
});
// Namespace related schemas
// Base schema for project-related operations
const ProjectParamsSchema = z.object({
project_id: z.coerce.string().describe("Project ID or complete URL-encoded path to project"), // Changed from owner/repo to match GitLab API
});
export const GitLabNamespaceSchema = z.object({
id: z.coerce.string(),
name: z.string(),
path: z.string(),
kind: z.enum(["user", "group"]),
full_path: z.string(),
parent_id: z.coerce.string().nullable(),
avatar_url: z.string().nullable(),
web_url: z.string(),
members_count_with_descendants: z.coerce.number().optional(),
billable_members_count: z.coerce.number().optional(),
max_seats_used: z.coerce.number().optional(),
seats_in_use: z.coerce.number().optional(),
plan: z.string().optional(),
end_date: z.string().nullable().optional(),
trial_ends_on: z.string().nullable().optional(),
trial: z.coerce.boolean().optional(),
root_repository_size: z.coerce.number().optional(),
projects_count: z.coerce.number().optional(),
});
export const GitLabNamespaceExistsResponseSchema = z.object({
exists: z.coerce.boolean(),
suggests: z.array(z.string()).optional(),
});
// Repository related schemas
export const GitLabOwnerSchema = z.object({
username: z.string(), // Changed from login to match GitLab API
id: z.coerce.string(),
avatar_url: z.string().nullable(),
web_url: z.string(), // Changed from html_url to match GitLab API
name: z.string(), // Added as GitLab includes full name
state: z.string(), // Added as GitLab includes user state
});
export const GitLabRepositorySchema = z.object({
id: z.coerce.string(),
name: z.string(),
path_with_namespace: z.string(),
visibility: z.string().optional(),
owner: GitLabOwnerSchema.optional(),
web_url: z.string().optional(),
description: z.string().nullable(),
fork: z.coerce.boolean().optional(),
ssh_url_to_repo: z.string().optional(),
http_url_to_repo: z.string().optional(),
created_at: z.string().optional(),
last_activity_at: z.string().optional(),
default_branch: z.string().nullable().optional(),
namespace: z
.object({
id: z.coerce.string(),
name: z.string(),
path: z.string(),
kind: z.string(),
full_path: z.string(),
avatar_url: z.string().nullable().optional(),
web_url: z.string().optional(),
})
.optional(),
readme_url: z.string().optional().nullable(),
topics: z.array(z.string()).optional(),
tag_list: z.array(z.string()).optional(), // deprecated but still present
open_issues_count: z.coerce.number().optional(),
archived: z.coerce.boolean().optional(),
forks_count: z.coerce.number().optional(),
star_count: z.coerce.number().optional(),
permissions: z
.object({
project_access: z
.object({
access_level: z.coerce.number(),
notification_level: z.coerce.number().nullable().optional(),
})
.optional()
.nullable(),
group_access: z
.object({
access_level: z.coerce.number(),
notification_level: z.coerce.number().nullable().optional(),
})
.optional()
.nullable(),
})
.optional(),
container_registry_enabled: z.coerce.boolean().optional(),
container_registry_access_level: z.string().optional(),
issues_enabled: z.coerce.boolean().optional(),
merge_requests_enabled: z.coerce.boolean().optional(),
merge_requests_template: z.string().nullable().optional(),
wiki_enabled: z.coerce.boolean().optional(),
jobs_enabled: z.coerce.boolean().optional(),
snippets_enabled: z.coerce.boolean().optional(),
can_create_merge_request_in: z.coerce.boolean().optional(),
resolve_outdated_diff_discussions: z.coerce.boolean().nullable().optional(),
shared_runners_enabled: z.coerce.boolean().optional(),
shared_with_groups: z
.array(
z.object({
group_id: z.coerce.string(),
group_name: z.string(),
group_full_path: z.string(),
group_access_level: z.coerce.number(),
})
)
.optional(),
});
// Project schema (extended from repository schema)
export const GitLabProjectSchema = GitLabRepositorySchema;
// File content schemas
export const GitLabFileContentSchema = z.object({
file_name: z.string().optional(),
file_path: z.string(),
size: z.coerce.number().optional(),
encoding: z.string(),
content: z.string(),
content_sha256: z.string().optional(),
ref: z.string().optional(),
blob_id: z.string().optional(),
commit_id: z.string().optional(),
last_commit_id: z.string().optional(),
execute_filemode: z.coerce.boolean().optional(),
});
export const GitLabDirectoryContentSchema = z.object({
name: z.string(),
path: z.string(),
type: z.string(),
mode: z.string(),
id: z.string(), // Changed from sha to match GitLab API
web_url: z.string(), // Changed from html_url to match GitLab API
});
export const GitLabContentSchema = z.union([
GitLabFileContentSchema,
z.array(GitLabDirectoryContentSchema),
]);
// Operation schemas
export const FileOperationSchema = z.object({
path: z.string(),
content: z.string(),
});
// Tree and commit schemas
export const GitLabTreeItemSchema = z.object({
id: z.string(),
name: z.string(),
type: z.enum(["tree", "blob", "commit"]),
path: z.string(),
mode: z.string(),
});
export const GetRepositoryTreeSchema = z.object({
project_id: z.coerce.string().describe("The ID or URL-encoded path of the project"),
path: z.string().optional().describe("The path inside the repository"),
ref: z
.string()
.optional()
.describe("The name of a repository branch or tag. Defaults to the default branch."),
recursive: z.coerce.boolean().optional().describe("Boolean value to get a recursive tree"),
per_page: z.coerce.number().optional().describe("Number of results to show per page"),
page_token: z
.string()
.optional()
.describe(
"Token for keyset pagination. Use the next_page_token value returned in the previous response to retrieve the next page."
),
pagination: z
.string()
.optional()
.describe(
"Pagination method. Use 'keyset' for keyset-based pagination (required for repositories with many files). Non-keyset calls keep the legacy array response for backward compatibility; that legacy response shape is deprecated and may be removed in a future major release. Keyset calls return a structured response with items and next_page_token when more pages are available."
),
});
export const GitLabTreeSchema = z.object({
id: z.string(), // Changed from sha to match GitLab API
tree: z.array(GitLabTreeItemSchema),
});
export const GitLabCommitSchema = z.object({
id: z.string(), // Changed from sha to match GitLab API
short_id: z.string(), // Added to match GitLab API
title: z.string(), // Changed from message to match GitLab API
author_name: z.string(),
author_email: z.string(),
authored_date: z.string(),
committer_name: z.string(),
committer_email: z.string(),
committed_date: z.string(),
created_at: z.string().optional(), // Add created_at field
message: z.string().optional(), // Add full message field
web_url: z.string(), // Changed from html_url to match GitLab API
parent_ids: z.array(z.string()), // Changed from parents to match GitLab API
stats: z
.object({
additions: z.coerce.number().optional().nullable(),
deletions: z.coerce.number().optional().nullable(),
total: z.coerce.number().optional().nullable(),
})
.optional(), // Only present when with_stats=true
trailers: z.record(z.string()).optional().default({}), // Git trailers, may be empty object
extended_trailers: z.record(z.array(z.string())).optional().default({}), // Extended trailers, may be empty object
});
export const GitLabCommitStatusSchema = z
.object({
id: z.coerce.number().optional(),
sha: z.string(),
ref: z.string().nullable().optional(),
status: z.string(),
name: z.string().optional(),
context: z.string().optional(),
target_url: z.string().nullable().optional(),
description: z.string().nullable().optional(),
coverage: z.coerce.number().nullable().optional(),
allow_failure: z.coerce.boolean().optional(),
created_at: z.string().optional(),
started_at: z.string().nullable().optional(),
finished_at: z.string().nullable().optional(),
author: z
.object({
id: z.coerce.number().optional(),
name: z.string().optional(),
username: z.string().optional(),
state: z.string().optional(),
avatar_url: z.string().nullable().optional(),
web_url: z.string().optional(),
})
.passthrough()
.nullable()
.optional(),
})
.passthrough();
// Reference schema
export const GitLabReferenceSchema = z.object({
name: z.string(), // Changed from ref to match GitLab API
commit: z.object({
id: z.string(), // Changed from sha to match GitLab API
web_url: z.string(), // Changed from url to match GitLab API
}),
});