-
-
Notifications
You must be signed in to change notification settings - Fork 456
/
Copy pathProjects.php
1283 lines (1112 loc) · 53.1 KB
/
Projects.php
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
<?php
declare(strict_types=1);
/*
* This file is part of the Gitlab API library.
*
* (c) Matt Humphrey <matth@windsor-telecom.co.uk>
* (c) Graham Campbell <hello@gjcampbell.co.uk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Gitlab\Api;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class Projects extends AbstractApi
{
/**
* @param array $parameters {
*
* @var bool $archived limit by archived status
* @var string $visibility limit by visibility public, internal, or private
* @var string $order_by Return projects ordered by id, name, path, created_at, updated_at,
* last_activity_at, repository_size, storage_size, packages_size or
* wiki_size fields (default is created_at)
* @var string $sort Return projects sorted in asc or desc order (default is desc)
* @var string $search return list of projects matching the search criteria
* @var bool $search_namespaces Include ancestor namespaces when matching search criteria
* @var bool $simple return only the ID, URL, name, and path of each project
* @var bool $owned limit by projects owned by the current user
* @var bool $membership limit by projects that the current user is a member of
* @var bool $starred limit by projects starred by the current user
* @var bool $statistics include project statistics
* @var bool $with_issues_enabled limit by enabled issues feature
* @var bool $with_merge_requests_enabled limit by enabled merge requests feature
* @var int $min_access_level Limit by current user minimal access level
* @var int $id_after Limit by project id's greater than the specified id
* @var int $id_before Limit by project id's less than the specified id
* @var \DateTimeInterface $last_activity_after Limit by last_activity after specified time
* @var \DateTimeInterface $last_activity_before Limit by last_activity before specified time
* @var bool $repository_checksum_failed Limit by failed repository checksum calculation
* @var string $repository_storage Limit by repository storage type
* @var bool $wiki_checksum_failed Limit by failed wiki checksum calculation
* @var bool $with_custom_attributes Include custom attributes in response
* @var string $with_programming_language Limit by programming language
* @var string $topic Limit by topic
* }
*
* @throws UndefinedOptionsException If an option name is undefined
* @throws InvalidOptionsException If an option doesn't fulfill the specified validation rules
*/
public function all(array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$booleanNormalizer = function (Options $resolver, $value): string {
return $value ? 'true' : 'false';
};
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string {
return $value->format('c');
};
$resolver->setDefined('archived')
->setAllowedTypes('archived', 'bool')
->setNormalizer('archived', $booleanNormalizer)
;
$resolver->setDefined('visibility')
->setAllowedValues('visibility', ['public', 'internal', 'private'])
;
$orderBy = [
'id', 'name', 'path', 'created_at', 'updated_at', 'last_activity_at',
'repository_size', 'storage_size', 'packages_size', 'wiki_size',
];
$resolver->setDefined('order_by')
->setAllowedValues('order_by', $orderBy)
;
$resolver->setDefined('sort')
->setAllowedValues('sort', ['asc', 'desc'])
;
$resolver->setDefined('search');
$resolver->setDefined('search_namespaces')
->setAllowedTypes('search_namespaces', 'bool')
->setNormalizer('search_namespaces', $booleanNormalizer)
;
$resolver->setDefined('simple')
->setAllowedTypes('simple', 'bool')
->setNormalizer('simple', $booleanNormalizer)
;
$resolver->setDefined('owned')
->setAllowedTypes('owned', 'bool')
->setNormalizer('owned', $booleanNormalizer)
;
$resolver->setDefined('membership')
->setAllowedTypes('membership', 'bool')
->setNormalizer('membership', $booleanNormalizer)
;
$resolver->setDefined('starred')
->setAllowedTypes('starred', 'bool')
->setNormalizer('starred', $booleanNormalizer)
;
$resolver->setDefined('statistics')
->setAllowedTypes('statistics', 'bool')
->setNormalizer('statistics', $booleanNormalizer)
;
$resolver->setDefined('with_issues_enabled')
->setAllowedTypes('with_issues_enabled', 'bool')
->setNormalizer('with_issues_enabled', $booleanNormalizer)
;
$resolver->setDefined('with_merge_requests_enabled')
->setAllowedTypes('with_merge_requests_enabled', 'bool')
->setNormalizer('with_merge_requests_enabled', $booleanNormalizer)
;
$resolver->setDefined('min_access_level')
->setAllowedValues('min_access_level', [null, 10, 20, 30, 40, 50])
;
$resolver->setDefined('id_after')
->setAllowedTypes('id_after', 'integer')
;
$resolver->setDefined('id_before')
->setAllowedTypes('id_before', 'integer')
;
$resolver->setDefined('last_activity_after')
->setAllowedTypes('last_activity_after', \DateTimeInterface::class)
->setNormalizer('last_activity_after', $datetimeNormalizer)
;
$resolver->setDefined('last_activity_before')
->setAllowedTypes('last_activity_before', \DateTimeInterface::class)
->setNormalizer('last_activity_before', $datetimeNormalizer)
;
$resolver->setDefined('repository_checksum_failed')
->setAllowedTypes('repository_checksum_failed', 'bool')
->setNormalizer('repository_checksum_failed', $booleanNormalizer)
;
$resolver->setDefined('repository_storage');
$resolver->setDefined('wiki_checksum_failed')
->setAllowedTypes('wiki_checksum_failed', 'bool')
->setNormalizer('wiki_checksum_failed', $booleanNormalizer)
;
$resolver->setDefined('with_custom_attributes')
->setAllowedTypes('with_custom_attributes', 'bool')
->setNormalizer('with_custom_attributes', $booleanNormalizer)
;
$resolver->setDefined('with_programming_language');
$resolver->setDefined('topic');
return $this->get('projects', $resolver->resolve($parameters));
}
/**
* @param array $parameters {
*
* @var bool $statistics include project statistics
* @var bool $with_custom_attributes Include project custom attributes.
* }
*/
public function show(int|string $project_id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$booleanNormalizer = function (Options $resolver, $value): bool {
return (bool) $value;
};
$resolver->setDefined('statistics')
->setAllowedTypes('statistics', 'bool')
->setNormalizer('statistics', $booleanNormalizer)
;
$resolver->setDefined('with_custom_attributes')
->setAllowedTypes('with_custom_attributes', 'bool')
->setNormalizer('with_custom_attributes', $booleanNormalizer)
;
return $this->get('projects/'.self::encodePath($project_id), $resolver->resolve($parameters));
}
public function create(string $name, array $parameters = []): mixed
{
$parameters['name'] = $name;
return $this->post('projects', $parameters);
}
public function createForUser(int $user_id, string $name, array $parameters = []): mixed
{
$parameters['name'] = $name;
return $this->post('projects/user/'.self::encodePath($user_id), $parameters);
}
public function update(int|string $project_id, array $parameters): mixed
{
return $this->put('projects/'.self::encodePath($project_id), $parameters);
}
public function remove(int|string $project_id): mixed
{
return $this->delete('projects/'.self::encodePath($project_id));
}
public function archive(int|string $project_id): mixed
{
return $this->post('projects/'.self::encodePath($project_id).'/archive');
}
public function unarchive(int|string $project_id): mixed
{
return $this->post('projects/'.self::encodePath($project_id).'/unarchive');
}
public function triggers(int|string $project_id): mixed
{
return $this->get('projects/'.self::encodePath($project_id).'/triggers');
}
public function trigger(int|string $project_id, int $trigger_id): mixed
{
return $this->get($this->getProjectPath($project_id, 'triggers/'.self::encodePath($trigger_id)));
}
public function createTrigger(int|string $project_id, string $description): mixed
{
return $this->post($this->getProjectPath($project_id, 'triggers'), [
'description' => $description,
]);
}
public function removeTrigger(int|string $project_id, int $trigger_id): mixed
{
return $this->delete($this->getProjectPath($project_id, 'triggers/'.self::encodePath($trigger_id)));
}
public function triggerPipeline(int|string $project_id, string $ref, string $token, array $variables = []): mixed
{
return $this->post($this->getProjectPath($project_id, 'trigger/pipeline'), [
'ref' => $ref,
'token' => $token,
'variables' => $variables,
]);
}
public function disableRunner(int $project_id, int $runner_id): mixed
{
return $this->delete('projects/'.self::encodePath($project_id).'/runners/'.self::encodePath($runner_id));
}
public function enableRunner(int $project_id, int $runner_id): mixed
{
$parameters = [
'runner_id' => $runner_id,
];
return $this->post('projects/'.self::encodePath($project_id).'/runners', $parameters);
}
/**
* @param array $parameters {
*
* @var string $scope the scope of pipelines, one of: running, pending, finished, branches, tags
* @var string $status the status of pipelines, one of: running, pending, success, failed, canceled, skipped
* @var string $ref the ref of pipelines
* @var string $sha the sha of pipelines
* @var bool $yaml_errors returns pipelines with invalid configurations
* @var string $name the name of the user who triggered pipelines
* @var string $username the username of the user who triggered pipelines
* @var string $order_by order pipelines by id, status, ref, updated_at, or user_id (default: id)
* @var string $order sort pipelines in asc or desc order (default: desc)
* @var string $source the source of the pipeline
* }
*/
public function pipelines(int|string $project_id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$booleanNormalizer = function (Options $resolver, $value): string {
return $value ? 'true' : 'false';
};
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string {
return $value->format('Y-m-d');
};
$resolver->setDefined('scope')
->setAllowedValues('scope', ['running', 'pending', 'finished', 'branches', 'tags'])
;
$resolver->setDefined('status')
->setAllowedValues('status', ['running', 'pending', 'success', 'failed', 'canceled', 'skipped'])
;
$resolver->setDefined('ref');
$resolver->setDefined('sha');
$resolver->setDefined('yaml_errors')
->setAllowedTypes('yaml_errors', 'bool')
->setNormalizer('yaml_errors', $booleanNormalizer)
;
$resolver->setDefined('name');
$resolver->setDefined('username');
$resolver->setDefined('updated_after')
->setAllowedTypes('updated_after', \DateTimeInterface::class)
->setNormalizer('updated_after', $datetimeNormalizer)
;
$resolver->setDefined('updated_before')
->setAllowedTypes('updated_before', \DateTimeInterface::class)
->setNormalizer('updated_before', $datetimeNormalizer)
;
$resolver->setDefined('order_by')
->setAllowedValues('order_by', ['id', 'status', 'ref', 'updated_at', 'user_id'])
;
$resolver->setDefined('sort')
->setAllowedValues('sort', ['asc', 'desc'])
;
$resolver->setDefined('source')
->setAllowedValues('source', ['push', 'web', 'trigger', 'schedule', 'api', 'external', 'pipeline', 'chat', 'webide', 'merge_request_event', 'external_pull_request_event', 'parent_pipeline', 'ondemand_dast_scan', 'ondemand_dast_validation'])
;
return $this->get($this->getProjectPath($project_id, 'pipelines'), $resolver->resolve($parameters));
}
public function pipeline(int|string $project_id, int $pipeline_id): mixed
{
return $this->get($this->getProjectPath($project_id, 'pipelines/'.self::encodePath($pipeline_id)));
}
public function pipelineJobs(int|string $project_id, int $pipeline_id): mixed
{
return $this->get($this->getProjectPath($project_id, 'pipelines/'.self::encodePath($pipeline_id).'/jobs'));
}
public function pipelineVariables(int|string $project_id, int $pipeline_id): mixed
{
return $this->get($this->getProjectPath($project_id, 'pipelines/'.self::encodePath($pipeline_id).'/variables'));
}
public function pipelineTestReport(int|string $project_id, int $pipeline_id): mixed
{
return $this->get($this->getProjectPath($project_id, 'pipelines/'.self::encodePath($pipeline_id).'/test_report'));
}
public function pipelineTestReportSummary(int|string $project_id, int $pipeline_id): mixed
{
return $this->get($this->getProjectPath($project_id, 'pipelines/'.self::encodePath($pipeline_id).'/test_report_summary'));
}
/**
* @param array|null $variables {
*
* @var string $key The name of the variable
* @var mixed $value The value of the variable
* @var string $variable_type env_var (default) or file
* }
*/
public function createPipeline(int|string $project_id, string $commit_ref, ?array $variables = null): mixed
{
$parameters = [];
if (null !== $variables) {
$parameters['variables'] = $variables;
}
return $this->post($this->getProjectPath($project_id, 'pipeline'), $parameters, [], [], [
'ref' => $commit_ref,
]);
}
public function retryPipeline(int|string $project_id, int $pipeline_id): mixed
{
return $this->post($this->getProjectPath($project_id, 'pipelines/'.self::encodePath($pipeline_id)).'/retry');
}
public function cancelPipeline(int|string $project_id, int $pipeline_id): mixed
{
return $this->post($this->getProjectPath($project_id, 'pipelines/'.self::encodePath($pipeline_id)).'/cancel');
}
public function deletePipeline(int|string $project_id, int $pipeline_id): mixed
{
return $this->delete($this->getProjectPath($project_id, 'pipelines/'.self::encodePath($pipeline_id)));
}
public function allMembers(int|string $project_id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$resolver->setDefined('query');
$resolver->setDefined('user_ids')
->setAllowedTypes('user_ids', 'array')
->setAllowedValues('user_ids', function (array $value) {
return \count($value) === \count(\array_filter($value, 'is_int'));
})
;
return $this->get('projects/'.self::encodePath($project_id).'/members/all', $resolver->resolve($parameters));
}
/**
* @param array $parameters {
*
* @var string $query The query you want to search members for.
* }
*/
public function members(int|string $project_id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$resolver->setDefined('query')
->setAllowedTypes('query', 'string')
;
$resolver->setDefined('user_ids')
->setAllowedTypes('user_ids', 'array')
->setAllowedValues('user_ids', function (array $value) {
return \count($value) === \count(\array_filter($value, 'is_int'));
})
;
return $this->get($this->getProjectPath($project_id, 'members'), $resolver->resolve($parameters));
}
public function member(int|string $project_id, int $user_id): mixed
{
return $this->get($this->getProjectPath($project_id, 'members/'.self::encodePath($user_id)));
}
public function allMember(int|string $project_id, int $user_id): mixed
{
return $this->get($this->getProjectPath($project_id, 'members/all/'.self::encodePath($user_id)));
}
public function addMember(int|string $project_id, int $user_id, int $access_level, ?string $expires_at = null): mixed
{
$params = [
'user_id' => $user_id,
'access_level' => $access_level,
];
if (null !== $expires_at) {
$params['expires_at'] = $expires_at;
}
return $this->post($this->getProjectPath($project_id, 'members'), $params);
}
public function saveMember(int|string $project_id, int $user_id, int $access_level, ?string $expires_at = null): mixed
{
$params = [
'access_level' => $access_level,
];
if (null !== $expires_at) {
$params['expires_at'] = $expires_at;
}
return $this->put($this->getProjectPath($project_id, 'members/'.self::encodePath($user_id)), $params);
}
public function removeMember(int|string $project_id, int $user_id): mixed
{
return $this->delete($this->getProjectPath($project_id, 'members/'.self::encodePath($user_id)));
}
public function hooks(int|string $project_id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
return $this->get($this->getProjectPath($project_id, 'hooks'), $resolver->resolve($parameters));
}
public function hook(int|string $project_id, int $hook_id): mixed
{
return $this->get($this->getProjectPath($project_id, 'hooks/'.self::encodePath($hook_id)));
}
/**
* Get project users.
*
* See https://docs.gitlab.com/ee/api/projects.html#get-project-users for more info.
*/
public function users(int|string $project_id, array $parameters = []): mixed
{
return $this->get($this->getProjectPath($project_id, 'users'), $parameters);
}
/**
* Get project issues.
*
* See https://docs.gitlab.com/ee/api/issues.html#list-project-issues for more info.
*/
public function issues(int|string $project_id, array $parameters = []): mixed
{
return $this->get($this->getProjectPath($project_id, 'issues'), $parameters);
}
/**
* Get projects board list.
*
* See https://docs.gitlab.com/ee/api/boards.html for more info.
*/
public function boards(int|string $project_id): mixed
{
return $this->get($this->getProjectPath($project_id, 'boards'));
}
/**
* @param array $parameters {
*
* @var string $state Return opened, upcoming, current (previously started), closed, or all iterations.
* Filtering by started state is deprecated starting with 14.1, please use current instead.
* @var string $search return only iterations with a title matching the provided string
* @var bool $include_ancestors Include iterations from parent group and its ancestors. Defaults to true.
* }
*/
public function iterations(int|string $project_id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$booleanNormalizer = function (Options $resolver, $value): string {
return $value ? 'true' : 'false';
};
$resolver->setDefined('state')
->setAllowedValues('state', ['opened', 'upcoming', 'current', 'current (previously started)', 'closed', 'all'])
;
$resolver->setDefined('include_ancestors')
->setAllowedTypes('include_ancestors', 'bool')
->setNormalizer('include_ancestors', $booleanNormalizer)
->setDefault('include_ancestors', true)
;
return $this->get('projects/'.self::encodePath($project_id).'/iterations', $resolver->resolve($parameters));
}
/**
* Gets a list of all discussion items for a single commit.
*
* Example:
* - https://gitlab.com/gitlab-org/gitlab/-/commit/695c29abcf7dc2eabde8d59869abcea0923ce8fa#note_334686748
* - https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab/repository/commits/695c29abcf7dc2eabde8d59869abcea0923ce8fa/discussions
*
* @see https://docs.gitlab.com/ee/api/discussions.html#list-project-commit-discussion-items
*/
public function getRepositoryCommitDiscussions(int|string $project_id, string $commit_id): mixed
{
return $this->get($this->getProjectPath($project_id, 'repository/commits/'.self::encodePath($commit_id)).'/discussions');
}
public function addHook(int|string $project_id, string $url, array $parameters = []): mixed
{
if (0 === \count($parameters)) {
$parameters = ['push_events' => true];
}
$parameters['url'] = $url;
return $this->post($this->getProjectPath($project_id, 'hooks'), $parameters);
}
public function updateHook(int|string $project_id, int $hook_id, array $parameters): mixed
{
return $this->put($this->getProjectPath($project_id, 'hooks/'.self::encodePath($hook_id)), $parameters);
}
public function removeHook(int|string $project_id, int $hook_id): mixed
{
return $this->delete($this->getProjectPath($project_id, 'hooks/'.self::encodePath($hook_id)));
}
public function transfer(int|string $project_id, mixed $namespace): mixed
{
return $this->put($this->getProjectPath($project_id, 'transfer'), ['namespace' => $namespace]);
}
public function deployKeys(int|string $project_id): mixed
{
return $this->get($this->getProjectPath($project_id, 'deploy_keys'));
}
public function deployKey(int|string $project_id, int $key_id): mixed
{
return $this->get($this->getProjectPath($project_id, 'deploy_keys/'.self::encodePath($key_id)));
}
public function addDeployKey(int|string $project_id, string $title, string $key, bool $canPush = false): mixed
{
return $this->post($this->getProjectPath($project_id, 'deploy_keys'), [
'title' => $title,
'key' => $key,
'can_push' => $canPush,
]);
}
public function deleteDeployKey(int|string $project_id, int $key_id): mixed
{
return $this->delete($this->getProjectPath($project_id, 'deploy_keys/'.self::encodePath($key_id)));
}
public function enableDeployKey(int|string $project_id, int $key_id): mixed
{
return $this->post($this->getProjectPath($project_id, 'deploy_keys/'.self::encodePath($key_id).'/enable'));
}
public function deployTokens(int|string $project_id, ?bool $active = null): mixed
{
return $this->get($this->getProjectPath($project_id, 'deploy_tokens'), (null !== $active) ? ['active' => $active] : []);
}
/**
* @param array $parameters {
*
* @var string $name the name of the deploy token
* @var \DateTimeInterface $expires_at expiration date for the deploy token, does not expire if no value is provided
* @var string $username the username for the deploy token
* @var array $scopes the scopes, one or many of: read_repository, read_registry, write_registry, read_package_registry, write_package_registry
* }
*/
public function createDeployToken(int|string $project_id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string {
return $value->format('c');
};
$resolver->define('name')
->required()
;
$resolver->define('scopes')
->required()
->allowedTypes('array')
->allowedValues(function ($scopes) {
$allowed = ['read_repository', 'read_registry', 'write_registry', 'read_package_registry', 'write_package_registry'];
foreach ($scopes as $scope) {
if (!\in_array($scope, $allowed, true)) {
return false;
}
}
return true;
})
;
$resolver->setDefined('username')
->setAllowedTypes('username', 'string')
;
$resolver->setDefined('expires_at')
->setAllowedTypes('expires_at', \DateTimeInterface::class)
->setNormalizer('expires_at', $datetimeNormalizer)
;
return $this->post($this->getProjectPath($project_id, 'deploy_tokens'), $resolver->resolve($parameters));
}
public function deleteDeployToken(int|string $project_id, int $token_id): mixed
{
return $this->delete($this->getProjectPath($project_id, 'deploy_tokens/'.self::encodePath($token_id)));
}
/**
* @param array $parameters {
*
* @var string $action include only events of a particular action type
* @var string $target_type include only events of a particular target type
* @var \DateTimeInterface $before include only events created before a particular date
* @var \DateTimeInterface $after include only events created after a particular date
* @var string $sort Sort events in asc or desc order by created_at (default is desc)
* }
*/
public function events(int|string $project_id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string {
return $value->format('Y-m-d');
};
$resolver->setDefined('action')
->setAllowedValues('action', ['created', 'updated', 'closed', 'reopened', 'pushed', 'commented', 'merged', 'joined', 'left', 'destroyed', 'expired', 'approved'])
;
$resolver->setDefined('target_type')
->setAllowedValues('target_type', ['issue', 'milestone', 'merge_request', 'note', 'project', 'snippet', 'user'])
;
$resolver->setDefined('before')
->setAllowedTypes('before', \DateTimeInterface::class)
->setNormalizer('before', $datetimeNormalizer);
$resolver->setDefined('after')
->setAllowedTypes('after', \DateTimeInterface::class)
->setNormalizer('after', $datetimeNormalizer)
;
$resolver->setDefined('sort')
->setAllowedValues('sort', ['asc', 'desc'])
;
return $this->get($this->getProjectPath($project_id, 'events'), $resolver->resolve($parameters));
}
/**
* @param array $parameters {
*
* @var bool $with_counts Whether or not to include issue and merge request counts. Defaults to false.
* @var bool $include_ancestor_groups Include ancestor groups. Defaults to true.
* @var string $search Keyword to filter labels by.
* }
*/
public function labels(int|string $project_id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$resolver->setDefined('with_counts')
->setAllowedTypes('with_counts', 'bool');
$resolver->setDefined('include_ancestor_groups')
->setAllowedTypes('include_ancestor_groups', 'bool');
$resolver->setDefined('search')
->setAllowedTypes('search', 'string');
return $this->get($this->getProjectPath($project_id, 'labels'), $resolver->resolve($parameters));
}
public function addLabel(int|string $project_id, array $parameters): mixed
{
return $this->post($this->getProjectPath($project_id, 'labels'), $parameters);
}
public function updateLabel(int|string $project_id, int $label_id, array $parameters): mixed
{
return $this->put($this->getProjectPath($project_id, 'labels/'.self::encodePath($label_id)), $parameters);
}
public function removeLabel(int|string $project_id, int $label_id): mixed
{
return $this->delete($this->getProjectPath($project_id, 'labels/'.self::encodePath($label_id)));
}
/**
* Get languages used in a project with percentage value.
*/
public function languages(int|string $project_id): mixed
{
return $this->get($this->getProjectPath($project_id, 'languages'));
}
/**
* @param array $parameters {
*
* @var bool $archived Limit by archived status
* @var string $visibility Limit by visibility public, internal, or private
* @var string $order_by Return projects ordered by id, name, path, created_at, updated_at,
* last_activity_at, repository_size, storage_size, packages_size or
* wiki_size fields (default is created_at)
* @var string $sort Return projects sorted in asc or desc order (default is desc)
* @var string $search Return list of projects matching the search criteria
* @var bool $simple Return only the ID, URL, name, and path of each project
* @var bool $owned Limit by projects owned by the current user
* @var bool $membership Limit by projects that the current user is a member of
* @var bool $starred Limit by projects starred by the current user
* @var bool $statistics Include project statistics
* @var bool $with_issues_enabled Limit by enabled issues feature
* @var bool $with_merge_requests_enabled Limit by enabled merge requests feature
* @var int $min_access_level Limit by current user minimal access level
* @var \DateTimeInterface $updated_before limit results to projects last updated before the specified time
* @var \DateTimeInterface $updated_after limit results to projects last updated after the specified time
* @var bool $with_custom_attributes Include custom attributes in response
* }
*/
public function forks(int|string $project_id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$booleanNormalizer = function (Options $resolver, $value): string {
return $value ? 'true' : 'false';
};
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string {
return $value->format('c');
};
$resolver->setDefined('archived')
->setAllowedTypes('archived', 'bool')
->setNormalizer('archived', $booleanNormalizer)
;
$resolver->setDefined('visibility')
->setAllowedValues('visibility', ['public', 'internal', 'private'])
;
$orderBy = [
'id', 'name', 'path', 'created_at', 'updated_at', 'last_activity_at',
'repository_size', 'storage_size', 'packages_size', 'wiki_size',
];
$resolver->setDefined('order_by')
->setAllowedValues('order_by', $orderBy)
;
$resolver->setDefined('sort')
->setAllowedValues('sort', ['asc', 'desc'])
;
$resolver->setDefined('search');
$resolver->setDefined('simple')
->setAllowedTypes('simple', 'bool')
->setNormalizer('simple', $booleanNormalizer)
;
$resolver->setDefined('owned')
->setAllowedTypes('owned', 'bool')
->setNormalizer('owned', $booleanNormalizer)
;
$resolver->setDefined('membership')
->setAllowedTypes('membership', 'bool')
->setNormalizer('membership', $booleanNormalizer)
;
$resolver->setDefined('starred')
->setAllowedTypes('starred', 'bool')
->setNormalizer('starred', $booleanNormalizer)
;
$resolver->setDefined('statistics')
->setAllowedTypes('statistics', 'bool')
->setNormalizer('statistics', $booleanNormalizer)
;
$resolver->setDefined('with_issues_enabled')
->setAllowedTypes('with_issues_enabled', 'bool')
->setNormalizer('with_issues_enabled', $booleanNormalizer)
;
$resolver->setDefined('with_merge_requests_enabled')
->setAllowedTypes('with_merge_requests_enabled', 'bool')
->setNormalizer('with_merge_requests_enabled', $booleanNormalizer)
;
$resolver->setDefined('min_access_level')
->setAllowedValues('min_access_level', [null, 10, 20, 30, 40, 50])
;
$resolver->setDefined('updated_before')
->setAllowedTypes('updated_before', \DateTimeInterface::class)
->setNormalizer('updated_before', $datetimeNormalizer)
;
$resolver->setDefined('updated_after')
->setAllowedTypes('updated_after', \DateTimeInterface::class)
->setNormalizer('updated_after', $datetimeNormalizer)
;
$resolver->setDefined('with_custom_attributes')
->setAllowedTypes('with_custom_attributes', 'bool')
->setNormalizer('with_custom_attributes', $booleanNormalizer)
;
return $this->get($this->getProjectPath($project_id, 'forks'), $resolver->resolve($parameters));
}
/**
* @param array $parameters {
*
* @var string $namespace The ID or path of the namespace that the project will be forked to
* @var string $path The path of the forked project (optional)
* @var string $name The name of the forked project (optional)
* }
*/
public function fork(int|string $project_id, array $parameters = []): mixed
{
$resolver = new OptionsResolver();
$resolver->setDefined(['namespace', 'path', 'name']);
$resolved = $resolver->resolve($parameters);
return $this->post($this->getProjectPath($project_id, 'fork'), $resolved);
}
public function createForkRelation(int|string $project_id, int|string $forked_project_id): mixed
{
return $this->post($this->getProjectPath($project_id, 'fork/'.self::encodePath($forked_project_id)));
}
public function removeForkRelation(int|string $project_id): mixed
{
return $this->delete($this->getProjectPath($project_id, 'fork'));
}
public function setService(int|string $project_id, string $service_name, array $parameters = []): mixed
{
return $this->put($this->getProjectPath($project_id, 'services/'.self::encodePath($service_name)), $parameters);
}
public function removeService(int|string $project_id, string $service_name): mixed
{
return $this->delete($this->getProjectPath($project_id, 'services/'.self::encodePath($service_name)));
}
public function variables(int|string $project_id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
return $this->get($this->getProjectPath($project_id, 'variables'), $resolver->resolve($parameters));
}
public function variable(int|string $project_id, string $key, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$resolver->setDefined('filter')
->setAllowedTypes('filter', 'array');
return $this->get($this->getProjectPath($project_id, 'variables/'.self::encodePath($key)), $resolver->resolve($parameters));
}
/**
* @param array<string,mixed> $parameters {
*
* @var string $variable_type env_var (default) or file
* }
*/
public function addVariable(int|string $project_id, string $key, string $value, ?bool $protected = null, ?string $environment_scope = null, array $parameters = []): mixed
{
$payload = [
'key' => $key,
'value' => $value,
];
if ($protected) {
$payload['protected'] = $protected;
}
if ($environment_scope) {
$payload['environment_scope'] = $environment_scope;
}
$payload = \array_merge($parameters, $payload);
return $this->post($this->getProjectPath($project_id, 'variables'), $payload);
}
/**
* @param array<string,mixed> $parameters {
*
* @var string $variable_type env_var (default) or file
*}
*/
public function updateVariable(int|string $project_id, string $key, string $value, ?bool $protected = null, ?string $environment_scope = null, array $parameters = []): mixed
{
$payload = [
'value' => $value,
];
if ($protected) {
$payload['protected'] = $protected;
}
if ($environment_scope) {
$payload['environment_scope'] = $environment_scope;
}
$payload = \array_merge($parameters, $payload);
return $this->put($this->getProjectPath($project_id, 'variables/'.self::encodePath($key)), $payload);
}
/**
* @param array<string, mixed> $parameters {
*
* @var array $filter {
* @var string $environment_scope Use filter[environment_scope] to select the variable with the matching environment_scope attribute.
* }
* }
*/
public function removeVariable(int|string $project_id, string $key, array $parameters = []): mixed
{
$resolver = new OptionsResolver();
$resolver->setDefined('filter')
->setAllowedTypes('filter', 'array');
return $this->delete($this->getProjectPath($project_id, 'variables/'.self::encodePath($key)), $resolver->resolve($parameters));
}
public function uploadFile(int|string $project_id, string $file): mixed
{
return $this->post($this->getProjectPath($project_id, 'uploads'), [], [], ['file' => $file]);
}
public function uploadAvatar(int|string $project_id, string $file): mixed
{
return $this->put('projects/'.self::encodePath($project_id), [], [], ['avatar' => $file]);
}
/**
* @see https://docs.gitlab.com/ee/api/deployments.html#list-project-deployments
*/
public function deployments(int|string $project_id, array $parameters = []): mixed
{
$resolver = $this->createOptionsResolver();
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string {
return $value->format('c');
};
$resolver->setDefined('order_by')
->setAllowedTypes('order_by', 'string')
->setAllowedValues('order_by', ['id', 'iid', 'created_at', 'updated_at', 'finished_at', 'ref'])
;
$resolver->setDefined('sort')
->setAllowedTypes('sort', 'string')
->setAllowedValues('sort', ['asc', 'desc'])
;
$resolver->setDefined('updated_after')
->setAllowedTypes('updated_after', \DateTimeInterface::class)
->setNormalizer('updated_after', $datetimeNormalizer)
;
$resolver->setDefined('updated_before')
->setAllowedTypes('updated_before', \DateTimeInterface::class)
->setNormalizer('updated_before', $datetimeNormalizer)
;
$resolver->setDefined('finished_after')
->setAllowedTypes('finished_after', \DateTimeInterface::class)
->setNormalizer('finished_after', $datetimeNormalizer)
;
$resolver->setDefined('finished_before')
->setAllowedTypes('finished_before', \DateTimeInterface::class)