-
Notifications
You must be signed in to change notification settings - Fork 643
/
objects.py
1658 lines (1271 loc) · 56.5 KB
/
objects.py
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
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013-2017 Gauvain Pocentek <gauvain@pocentek.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
from __future__ import absolute_import
import base64
import json
import six
from gitlab.base import * # noqa
from gitlab.exceptions import * # noqa
from gitlab.mixins import * # noqa
from gitlab import utils
VISIBILITY_PRIVATE = 'private'
VISIBILITY_INTERNAL = 'internal'
VISIBILITY_PUBLIC = 'public'
ACCESS_GUEST = 10
ACCESS_REPORTER = 20
ACCESS_DEVELOPER = 30
ACCESS_MASTER = 40
ACCESS_OWNER = 50
class SidekiqManager(RESTManager):
"""Manager for the Sidekiq methods.
This manager doesn't actually manage objects but provides helper fonction
for the sidekiq metrics API.
"""
def queue_metrics(self, **kwargs):
"""Returns the registred queues information."""
return self.gitlab.http_get('/sidekiq/queue_metrics', **kwargs)
def process_metrics(self, **kwargs):
"""Returns the registred sidekiq workers."""
return self.gitlab.http_get('/sidekiq/process_metrics', **kwargs)
def job_stats(self, **kwargs):
"""Returns statistics about the jobs performed."""
return self.gitlab.http_get('/sidekiq/job_stats', **kwargs)
def compound_metrics(self, **kwargs):
"""Returns all available metrics and statistics."""
return self.gitlab.http_get('/sidekiq/compound_metrics', **kwargs)
class UserEmail(ObjectDeleteMixin, RESTObject):
_short_print_attr = 'email'
class UserEmailManager(RetrieveMixin, CreateMixin, DeleteMixin, RESTManager):
_path = '/users/%(user_id)s/emails'
_obj_cls = UserEmail
_from_parent_attrs = {'user_id': 'id'}
_create_attrs = (('email', ), tuple())
class UserKey(ObjectDeleteMixin, RESTObject):
pass
class UserKeyManager(GetFromListMixin, CreateMixin, DeleteMixin, RESTManager):
_path = '/users/%(user_id)s/emails'
_obj_cls = UserKey
_from_parent_attrs = {'user_id': 'id'}
_create_attrs = (('title', 'key'), tuple())
class UserProject(RESTObject):
_constructor_types = {'owner': 'User', 'namespace': 'Group'}
class UserProjectManager(CreateMixin, RESTManager):
_path = '/projects/user/%(user_id)s'
_obj_cls = UserProject
_from_parent_attrs = {'user_id': 'id'}
_create_attrs = (
('name', ),
('default_branch', 'issues_enabled', 'wall_enabled',
'merge_requests_enabled', 'wiki_enabled', 'snippets_enabled',
'public', 'visibility', 'description', 'builds_enabled',
'public_builds', 'import_url', 'only_allow_merge_if_build_succeeds')
)
class User(SaveMixin, ObjectDeleteMixin, RESTObject):
_short_print_attr = 'username'
_managers = (
('emails', 'UserEmailManager'),
('keys', 'UserKeyManager'),
('projects', 'UserProjectManager'),
)
def block(self, **kwargs):
"""Blocks the user.
Returns:
bool: whether the user status has been changed.
"""
path = '/users/%s/block' % self.id
server_data = self.manager.gitlab.http_post(path, **kwargs)
if server_data is True:
self._attrs['state'] = 'blocked'
return server_data
def unblock(self, **kwargs):
"""Unblocks the user.
Returns:
bool: whether the user status has been changed.
"""
path = '/users/%s/unblock' % self.id
server_data = self.manager.gitlab.http_post(path, **kwargs)
if server_data is True:
self._attrs['state'] = 'active'
return server_data
class UserManager(CRUDMixin, RESTManager):
_path = '/users'
_obj_cls = User
_list_filters = ('active', 'blocked', 'username', 'extern_uid', 'provider',
'external')
_create_attrs = (
('email', 'username', 'name'),
('password', 'reset_password', 'skype', 'linkedin', 'twitter',
'projects_limit', 'extern_uid', 'provider', 'bio', 'admin',
'can_create_group', 'website_url', 'skip_confirmation', 'external',
'organization', 'location')
)
_update_attrs = (
('email', 'username', 'name'),
('password', 'skype', 'linkedin', 'twitter', 'projects_limit',
'extern_uid', 'provider', 'bio', 'admin', 'can_create_group',
'website_url', 'skip_confirmation', 'external', 'organization',
'location')
)
def _sanitize_data(self, data, action):
new_data = data.copy()
if 'confirm' in data:
new_data['confirm'] = str(new_data['confirm']).lower()
return new_data
class CurrentUserEmail(ObjectDeleteMixin, RESTObject):
_short_print_attr = 'email'
class CurrentUserEmailManager(RetrieveMixin, CreateMixin, DeleteMixin,
RESTManager):
_path = '/user/emails'
_obj_cls = CurrentUserEmail
_create_attrs = (('email', ), tuple())
class CurrentUserKey(ObjectDeleteMixin, RESTObject):
_short_print_attr = 'title'
class CurrentUserKeyManager(RetrieveMixin, CreateMixin, DeleteMixin,
RESTManager):
_path = '/user/keys'
_obj_cls = CurrentUserKey
_create_attrs = (('title', 'key'), tuple())
class CurrentUser(RESTObject):
_id_attr = None
_short_print_attr = 'username'
_managers = (
('emails', 'CurrentUserEmailManager'),
('keys', 'CurrentUserKeyManager'),
)
class CurrentUserManager(GetWithoutIdMixin, RESTManager):
_path = '/user'
_obj_cls = CurrentUser
def credentials_auth(self, email, password):
data = {'email': email, 'password': password}
server_data = self.gitlab.http_post('/session', post_data=data)
return CurrentUser(self, server_data)
class ApplicationSettings(SaveMixin, RESTObject):
_id_attr = None
class ApplicationSettingsManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
_path = '/application/settings'
_obj_cls = ApplicationSettings
_update_attrs = (
tuple(),
('after_sign_out_path', 'container_registry_token_expire_delay',
'default_branch_protection', 'default_project_visibility',
'default_projects_limit', 'default_snippet_visibility',
'domain_blacklist', 'domain_blacklist_enabled', 'domain_whitelist',
'enabled_git_access_protocol', 'gravatar_enabled', 'home_page_url',
'max_attachment_size', 'repository_storage',
'restricted_signup_domains', 'restricted_visibility_levels',
'session_expire_delay', 'sign_in_text', 'signin_enabled',
'signup_enabled', 'twitter_sharing_enabled',
'user_oauth_applications')
)
def _sanitize_data(self, data, action):
new_data = data.copy()
if 'domain_whitelist' in data and data['domain_whitelist'] is None:
new_data.pop('domain_whitelist')
return new_data
class BroadcastMessage(SaveMixin, ObjectDeleteMixin, RESTObject):
pass
class BroadcastMessageManager(CRUDMixin, RESTManager):
_path = '/broadcast_messages'
_obj_cls = BroadcastMessage
_create_attrs = (('message', ), ('starts_at', 'ends_at', 'color', 'font'))
_update_attrs = (tuple(), ('message', 'starts_at', 'ends_at', 'color',
'font'))
class DeployKey(RESTObject):
pass
class DeployKeyManager(GetFromListMixin, RESTManager):
_path = '/deploy_keys'
_obj_cls = DeployKey
class NotificationSettings(SaveMixin, RESTObject):
_id_attr = None
class NotificationSettingsManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
_path = '/notification_settings'
_obj_cls = NotificationSettings
_update_attrs = (
tuple(),
('level', 'notification_email', 'new_note', 'new_issue',
'reopen_issue', 'close_issue', 'reassign_issue', 'new_merge_request',
'reopen_merge_request', 'close_merge_request',
'reassign_merge_request', 'merge_merge_request')
)
class Dockerfile(RESTObject):
_id_attr = 'name'
class DockerfileManager(RetrieveMixin, RESTManager):
_path = '/templates/dockerfiles'
_obj_cls = Dockerfile
class Gitignore(RESTObject):
_id_attr = 'name'
class GitignoreManager(RetrieveMixin, RESTManager):
_path = '/templates/gitignores'
_obj_cls = Gitignore
class Gitlabciyml(RESTObject):
_id_attr = 'name'
class GitlabciymlManager(RetrieveMixin, RESTManager):
_path = '/templates/gitlab_ci_ymls'
_obj_cls = Gitlabciyml
class GroupIssue(RESTObject):
pass
class GroupIssueManager(GetFromListMixin, RESTManager):
_path = '/groups/%(group_id)s/issues'
_obj_cls = GroupIssue
_from_parent_attrs = {'group_id': 'id'}
_list_filters = ('state', 'labels', 'milestone', 'order_by', 'sort')
class GroupMember(SaveMixin, ObjectDeleteMixin, RESTObject):
_short_print_attr = 'username'
class GroupMemberManager(GetFromListMixin, CreateMixin, UpdateMixin,
DeleteMixin, RESTManager):
_path = '/groups/%(group_id)s/members'
_obj_cls = GroupMember
_from_parent_attrs = {'group_id': 'id'}
_create_attrs = (('access_level', 'user_id'), ('expires_at', ))
_update_attrs = (('access_level', ), ('expires_at', ))
class GroupNotificationSettings(NotificationSettings):
pass
class GroupNotificationSettingsManager(NotificationSettingsManager):
_path = '/groups/%(group_id)s/notification_settings'
_obj_cls = GroupNotificationSettings
_from_parent_attrs = {'group_id': 'id'}
class GroupAccessRequest(AccessRequestMixin, ObjectDeleteMixin, RESTObject):
pass
class GroupAccessRequestManager(GetFromListMixin, CreateMixin, DeleteMixin,
RESTManager):
_path = '/groups/%(group_id)s/access_requests'
_obj_cls = GroupAccessRequest
_from_parent_attrs = {'group_id': 'id'}
class Hook(ObjectDeleteMixin, RESTObject):
_url = '/hooks'
_short_print_attr = 'url'
class HookManager(NoUpdateMixin, RESTManager):
_path = '/hooks'
_obj_cls = Hook
_create_attrs = (('url', ), tuple())
class Issue(RESTObject):
_url = '/issues'
_constructor_types = {'author': 'User',
'assignee': 'User',
'milestone': 'ProjectMilestone'}
_short_print_attr = 'title'
class IssueManager(GetFromListMixin, RESTManager):
_path = '/issues'
_obj_cls = Issue
_list_filters = ('state', 'labels', 'order_by', 'sort')
class License(RESTObject):
_id_attr = 'key'
class LicenseManager(RetrieveMixin, RESTManager):
_path = '/templates/licenses'
_obj_cls = License
_list_filters = ('popular', )
_optional_get_attrs = ('project', 'fullname')
class Snippet(SaveMixin, ObjectDeleteMixin, RESTObject):
_constructor_types = {'author': 'User'}
_short_print_attr = 'title'
def content(self, streamed=False, action=None, chunk_size=1024, **kwargs):
"""Return the content of a snippet.
Args:
streamed (bool): If True the data will be processed by chunks of
`chunk_size` and each chunk is passed to `action` for
treatment.
action (callable): Callable responsible of dealing with chunk of
data.
chunk_size (int): Size of each chunk.
Returns:
str: The snippet content.
"""
path = '/snippets/%s/raw' % self.get_id()
result = self.manager.gitlab.http_get(path, streamed=streamed,
**kwargs)
return utils.response_content(result, streamed, action, chunk_size)
class SnippetManager(CRUDMixin, RESTManager):
_path = '/snippets'
_obj_cls = Snippet
_create_attrs = (('title', 'file_name', 'content'),
('lifetime', 'visibility'))
_update_attrs = (tuple(),
('title', 'file_name', 'content', 'visibility'))
def public(self, **kwargs):
"""List all the public snippets.
Args:
all (bool): If True, return all the items, without pagination
**kwargs: Additional arguments to send to GitLab.
Returns:
list(gitlab.Gitlab.Snippet): The list of snippets.
"""
return self.list(path='/snippets/public', **kwargs)
class Namespace(RESTObject):
pass
class NamespaceManager(GetFromListMixin, RESTManager):
_path = '/namespaces'
_obj_cls = Namespace
_list_filters = ('search', )
class ProjectBoardList(SaveMixin, ObjectDeleteMixin, RESTObject):
_constructor_types = {'label': 'ProjectLabel'}
class ProjectBoardListManager(CRUDMixin, RESTManager):
_path = '/projects/%(project_id)s/boards/%(board_id)s/lists'
_obj_cls = ProjectBoardList
_from_parent_attrs = {'project_id': 'project_id',
'board_id': 'id'}
_create_attrs = (('label_id', ), tuple())
_update_attrs = (('position', ), tuple())
class ProjectBoard(RESTObject):
_constructor_types = {'labels': 'ProjectBoardList'}
_managers = (('lists', 'ProjectBoardListManager'), )
class ProjectBoardManager(GetFromListMixin, RESTManager):
_path = '/projects/%(project_id)s/boards'
_obj_cls = ProjectBoard
_from_parent_attrs = {'project_id': 'id'}
class ProjectBranch(ObjectDeleteMixin, RESTObject):
_constructor_types = {'author': 'User', "committer": "User"}
_id_attr = 'name'
def protect(self, developers_can_push=False, developers_can_merge=False,
**kwargs):
"""Protects the branch.
Args:
developers_can_push (bool): Set to True if developers are allowed
to push to the branch
developers_can_merge (bool): Set to True if developers are allowed
to merge to the branch
"""
path = '%s/%s/protect' % (self.manager.path, self.get_id())
post_data = {'developers_can_push': developers_can_push,
'developers_can_merge': developers_can_merge}
self.manager.gitlab.http_put(path, post_data=post_data, **kwargs)
self._attrs['protected'] = True
def unprotect(self, **kwargs):
"""Unprotects the branch."""
path = '%s/%s/protect' % (self.manager.path, self.get_id())
self.manager.gitlab.http_put(path, **kwargs)
self._attrs['protected'] = False
class ProjectBranchManager(NoUpdateMixin, RESTManager):
_path = '/projects/%(project_id)s/repository/branches'
_obj_cls = ProjectBranch
_from_parent_attrs = {'project_id': 'id'}
_create_attrs = (('branch', 'ref'), tuple())
class ProjectJob(RESTObject):
_constructor_types = {'user': 'User',
'commit': 'ProjectCommit',
'runner': 'Runner'}
def cancel(self, **kwargs):
"""Cancel the job."""
path = '%s/%s/cancel' % (self.manager.path, self.get_id())
self.manager.gitlab.http_post(path)
def retry(self, **kwargs):
"""Retry the job."""
path = '%s/%s/retry' % (self.manager.path, self.get_id())
self.manager.gitlab.http_post(path)
def play(self, **kwargs):
"""Trigger a job explicitly."""
path = '%s/%s/play' % (self.manager.path, self.get_id())
self.manager.gitlab.http_post(path)
def erase(self, **kwargs):
"""Erase the job (remove job artifacts and trace)."""
path = '%s/%s/erase' % (self.manager.path, self.get_id())
self.manager.gitlab.http_post(path)
def keep_artifacts(self, **kwargs):
"""Prevent artifacts from being delete when expiration is set."""
path = '%s/%s/artifacts/keep' % (self.manager.path, self.get_id())
self.manager.gitlab.http_post(path)
def artifacts(self, streamed=False, action=None, chunk_size=1024,
**kwargs):
"""Get the job artifacts.
Args:
streamed (bool): If True the data will be processed by chunks of
`chunk_size` and each chunk is passed to `action` for
treatment.
action (callable): Callable responsible of dealing with chunk of
data.
chunk_size (int): Size of each chunk.
Returns:
str: The artifacts if `streamed` is False, None otherwise.
"""
path = '%s/%s/artifacts' % (self.manager.path, self.get_id())
result = self.manager.gitlab.get_http(path, streamed=streamed,
**kwargs)
return utils.response_content(result, streamed, action, chunk_size)
def trace(self, streamed=False, action=None, chunk_size=1024, **kwargs):
"""Get the job trace.
Args:
streamed (bool): If True the data will be processed by chunks of
`chunk_size` and each chunk is passed to `action` for
treatment.
action (callable): Callable responsible of dealing with chunk of
data.
chunk_size (int): Size of each chunk.
Returns:
str: The trace.
"""
path = '%s/%s/trace' % (self.manager.path, self.get_id())
result = self.manager.gitlab.get_http(path, streamed=streamed,
**kwargs)
return utils.response_content(result, streamed, action, chunk_size)
class ProjectJobManager(RetrieveMixin, RESTManager):
_path = '/projects/%(project_id)s/jobs'
_obj_cls = ProjectJob
_from_parent_attrs = {'project_id': 'id'}
class ProjectCommitStatus(RESTObject):
pass
class ProjectCommitStatusManager(RetrieveMixin, CreateMixin, RESTManager):
_path = ('/projects/%(project_id)s/repository/commits/%(commit_id)s'
'/statuses')
_obj_cls = ProjectCommitStatus
_from_parent_attrs = {'project_id': 'project_id', 'commit_id': 'id'}
_create_attrs = (('state', ),
('description', 'name', 'context', 'ref', 'target_url'))
def create(self, data, **kwargs):
"""Creates a new object.
Args:
data (dict): parameters to send to the server to create the
resource
**kwargs: Extra data to send to the Gitlab server (e.g. sudo or
'ref_name', 'stage', 'name', 'all'.
Returns:
RESTObject: a new instance of the manage object class build with
the data sent by the server
"""
path = '/projects/%(project_id)s/statuses/%(commit_id)s'
computed_path = self._compute_path(path)
return CreateMixin.create(self, data, path=computed_path, **kwargs)
class ProjectCommitComment(RESTObject):
pass
class ProjectCommitCommentManager(ListMixin, CreateMixin, RESTManager):
_path = ('/projects/%(project_id)s/repository/commits/%(commit_id)s'
'/comments')
_obj_cls = ProjectCommitComment
_from_parent_attrs = {'project_id': 'project_id', 'commit_id': 'id'}
_create_attrs = (('note', ), ('path', 'line', 'line_type'))
class ProjectCommit(RESTObject):
_short_print_attr = 'title'
_managers = (
('comments', 'ProjectCommitCommentManager'),
('statuses', 'ProjectCommitStatusManager'),
)
def diff(self, **kwargs):
"""Generate the commit diff."""
path = '%s/%s/diff' % (self.manager.path, self.get_id())
return self.manager.gitlab.http_get(path, **kwargs)
def cherry_pick(self, branch, **kwargs):
"""Cherry-pick a commit into a branch.
Args:
branch (str): Name of target branch.
"""
path = '%s/%s/cherry_pick' % (self.manager.path, self.get_id())
post_data = {'branch': branch}
self.manager.gitlab.http_post(path, post_data=post_data, **kwargs)
class ProjectCommitManager(RetrieveMixin, CreateMixin, RESTManager):
_path = '/projects/%(project_id)s/repository/commits'
_obj_cls = ProjectCommit
_from_parent_attrs = {'project_id': 'id'}
_create_attrs = (('branch', 'commit_message', 'actions'),
('author_email', 'author_name'))
class ProjectEnvironment(SaveMixin, ObjectDeleteMixin, RESTObject):
pass
class ProjectEnvironmentManager(GetFromListMixin, CreateMixin, UpdateMixin,
DeleteMixin, RESTManager):
_path = '/projects/%(project_id)s/environments'
_obj_cls = ProjectEnvironment
_from_parent_attrs = {'project_id': 'id'}
_create_attrs = (('name', ), ('external_url', ))
_update_attrs = (tuple(), ('name', 'external_url'))
class ProjectKey(ObjectDeleteMixin, RESTObject):
pass
class ProjectKeyManager(NoUpdateMixin, RESTManager):
_path = '/projects/%(project_id)s/deploy_keys'
_obj_cls = ProjectKey
_from_parent_attrs = {'project_id': 'id'}
_create_attrs = (('title', 'key'), tuple())
def enable(self, key_id, **kwargs):
"""Enable a deploy key for a project.
Args:
key_id (int): The ID of the key to enable
"""
path = '%s/%s/enable' % (self.manager.path, key_id)
self.manager.gitlab.http_post(path, **kwargs)
class ProjectEvent(RESTObject):
_short_print_attr = 'target_title'
class ProjectEventManager(GetFromListMixin, RESTManager):
_path = '/projects/%(project_id)s/events'
_obj_cls = ProjectEvent
_from_parent_attrs = {'project_id': 'id'}
class ProjectFork(RESTObject):
pass
class ProjectForkManager(CreateMixin, RESTManager):
_path = '/projects/%(project_id)s/fork'
_obj_cls = ProjectFork
_from_parent_attrs = {'project_id': 'id'}
_create_attrs = (tuple(), ('namespace', ))
class ProjectHook(SaveMixin, ObjectDeleteMixin, RESTObject):
_short_print_attr = 'url'
class ProjectHookManager(CRUDMixin, RESTManager):
_path = '/projects/%(project_id)s/hooks'
_obj_cls = ProjectHook
_from_parent_attrs = {'project_id': 'id'}
_create_attrs = (
('url', ),
('push_events', 'issues_events', 'note_events',
'merge_requests_events', 'tag_push_events', 'build_events',
'enable_ssl_verification', 'token', 'pipeline_events')
)
_update_attrs = (
('url', ),
('push_events', 'issues_events', 'note_events',
'merge_requests_events', 'tag_push_events', 'build_events',
'enable_ssl_verification', 'token', 'pipeline_events')
)
class ProjectIssueNote(SaveMixin, ObjectDeleteMixin, RESTObject):
_constructor_types = {'author': 'User'}
class ProjectIssueNoteManager(CRUDMixin, RESTManager):
_path = '/projects/%(project_id)s/issues/%(issue_iid)s/notes'
_obj_cls = ProjectIssueNote
_from_parent_attrs = {'project_id': 'project_id', 'issue_iid': 'iid'}
_create_attrs = (('body', ), ('created_at'))
_update_attrs = (('body', ), tuple())
class ProjectIssue(SubscribableMixin, TodoMixin, TimeTrackingMixin, SaveMixin,
ObjectDeleteMixin, RESTObject):
_constructor_types = {'author': 'User', 'assignee': 'User', 'milestone':
'ProjectMilestone'}
_short_print_attr = 'title'
_id_attr = 'iid'
_managers = (('notes', 'ProjectIssueNoteManager'), )
def move(self, to_project_id, **kwargs):
"""Move the issue to another project."""
path = '%s/%s/move' % (self.manager.path, self.get_id())
data = {'to_project_id': to_project_id}
server_data = self.manager.gitlab.http_post(path, post_data=data,
**kwargs)
self._update_attrs(server_data)
class ProjectIssueManager(CRUDMixin, RESTManager):
_path = '/projects/%(project_id)s/issues/'
_obj_cls = ProjectIssue
_from_parent_attrs = {'project_id': 'id'}
_list_filters = ('state', 'labels', 'milestone', 'order_by', 'sort')
_create_attrs = (('title', ),
('description', 'assignee_id', 'milestone_id', 'labels',
'created_at', 'due_date'))
_update_attrs = (tuple(), ('title', 'description', 'assignee_id',
'milestone_id', 'labels', 'created_at',
'updated_at', 'state_event', 'due_date'))
class ProjectMember(SaveMixin, ObjectDeleteMixin, RESTObject):
_short_print_attr = 'username'
class ProjectMemberManager(CRUDMixin, RESTManager):
_path = '/projects/%(project_id)s/members'
_obj_cls = ProjectMember
_from_parent_attrs = {'project_id': 'id'}
_create_attrs = (('access_level', 'user_id'), ('expires_at', ))
_update_attrs = (('access_level', ), ('expires_at', ))
class ProjectNote(RESTObject):
_constructor_types = {'author': 'User'}
class ProjectNoteManager(RetrieveMixin, RESTManager):
_path = '/projects/%(project_id)s/notes'
_obj_cls = ProjectNote
_from_parent_attrs = {'project_id': 'id'}
_create_attrs = (('body', ), tuple())
class ProjectNotificationSettings(NotificationSettings):
pass
class ProjectNotificationSettingsManager(NotificationSettingsManager):
_path = '/projects/%(project_id)s/notification_settings'
_obj_cls = ProjectNotificationSettings
_from_parent_attrs = {'project_id': 'id'}
class ProjectTag(ObjectDeleteMixin, RESTObject):
_constructor_types = {'release': 'ProjectTagRelease',
'commit': 'ProjectCommit'}
_id_attr = 'name'
_short_print_attr = 'name'
def set_release_description(self, description, **kwargs):
"""Set the release notes on the tag.
If the release doesn't exist yet, it will be created. If it already
exists, its description will be updated.
Args:
description (str): Description of the release.
"""
path = '%s/%s/release' % (self.manager.path, self.get_id())
data = {'description': description}
if self.release is None:
result = self.manager.gitlab.http_post(path, post_data=data,
**kwargs)
else:
result = self.manager.gitlab.http_put(path, post_data=data,
**kwargs)
self.release = result.json()
class ProjectTagManager(GetFromListMixin, CreateMixin, DeleteMixin,
RESTManager):
_path = '/projects/%(project_id)s/repository/tags'
_obj_cls = ProjectTag
_from_parent_attrs = {'project_id': 'id'}
_create_attrs = (('tag_name', 'ref'), ('message',))
class ProjectMergeRequestDiff(RESTObject):
pass
class ProjectMergeRequestDiffManager(RetrieveMixin, RESTManager):
_path = '/projects/%(project_id)s/merge_requests/%(mr_iid)s/versions'
_obj_cls = ProjectMergeRequestDiff
_from_parent_attrs = {'project_id': 'project_id', 'mr_iid': 'iid'}
class ProjectMergeRequestNote(SaveMixin, ObjectDeleteMixin, RESTObject):
_constructor_types = {'author': 'User'}
class ProjectMergeRequestNoteManager(CRUDMixin, RESTManager):
_path = '/projects/%(project_id)s/merge_requests/%(mr_iid)s/notes'
_obj_cls = ProjectMergeRequestNote
_from_parent_attrs = {'project_id': 'project_id', 'mr_iid': 'iid'}
_create_attrs = (('body', ), tuple())
_update_attrs = (('body', ), tuple())
class ProjectMergeRequest(SubscribableMixin, TodoMixin, TimeTrackingMixin,
SaveMixin, ObjectDeleteMixin, RESTObject):
_constructor_types = {'author': 'User', 'assignee': 'User'}
_id_attr = 'iid'
_managers = (
('notes', 'ProjectMergeRequestNoteManager'),
('diffs', 'ProjectMergeRequestDiffManager')
)
def cancel_merge_when_pipeline_succeeds(self, **kwargs):
"""Cancel merge when build succeeds."""
path = ('%s/%s/cancel_merge_when_pipeline_succeeds' %
(self.manager.path, self.get_id()))
server_data = self.manager.gitlab.http_put(path, **kwargs)
self._update_attrs(server_data)
def closes_issues(self, **kwargs):
"""List issues that will close on merge."
Returns:
list (ProjectIssue): List of issues
"""
path = '%s/%s/closes_issues' % (self.manager.path, self.get_id())
data_list = self.manager.gitlab.http_list(path, **kwargs)
manager = ProjectIssueManager(self.manager.gitlab,
parent=self.manager._parent)
return RESTObjectList(manager, ProjectIssue, data_list)
def commits(self, **kwargs):
"""List the merge request commits.
Returns:
list (ProjectCommit): List of commits
"""
path = '%s/%s/commits' % (self.manager.path, self.get_id())
data_list = self.manager.gitlab.http_list(path, **kwargs)
manager = ProjectCommitManager(self.manager.gitlab,
parent=self.manager._parent)
return RESTObjectList(manager, ProjectCommit, data_list)
def changes(self, **kwargs):
"""List the merge request changes.
Returns:
list (dict): List of changes
"""
path = '%s/%s/changes' % (self.manager.path, self.get_id())
return self.manager.gitlab.http_get(path, **kwargs)
def merge(self, merge_commit_message=None,
should_remove_source_branch=False,
merge_when_pipeline_succeeds=False,
**kwargs):
"""Accept the merge request.
Args:
merge_commit_message (bool): Commit message
should_remove_source_branch (bool): If True, removes the source
branch
merge_when_pipeline_succeeds (bool): Wait for the build to succeed,
then merge
"""
path = '%s/%s/merge' % (self.manager.path, self.get_id())
data = {}
if merge_commit_message:
data['merge_commit_message'] = merge_commit_message
if should_remove_source_branch:
data['should_remove_source_branch'] = True
if merge_when_pipeline_succeeds:
data['merge_when_pipeline_succeeds'] = True
server_data = self.manager.gitlab.http_put(path, post_data=data,
**kwargs)
self._update_attrs(server_data)
class ProjectMergeRequestManager(CRUDMixin, RESTManager):
_path = '/projects/%(project_id)s/merge_requests'
_obj_cls = ProjectMergeRequest
_from_parent_attrs = {'project_id': 'id'}
_create_attrs = (
('source_branch', 'target_branch', 'title'),
('assignee_id', 'description', 'target_project_id', 'labels',
'milestone_id', 'remove_source_branch')
)
_update_attrs = (tuple(), ('target_branch', 'assignee_id', 'title',
'description', 'state_event', 'labels',
'milestone_id'))
_list_filters = ('iids', 'state', 'order_by', 'sort')
class ProjectMilestone(SaveMixin, ObjectDeleteMixin, RESTObject):
_short_print_attr = 'title'
def issues(self, **kwargs):
"""List issues related to this milestone
Returns:
list (ProjectIssue): The list of issues
"""
path = '%s/%s/issues' % (self.manager.path, self.get_id())
data_list = self.manager.gitlab.http_list(path, **kwargs)
manager = ProjectCommitManager(self.manager.gitlab,
parent=self.manager._parent)
# FIXME(gpocentek): the computed manager path is not correct
return RESTObjectList(manager, ProjectIssue, data_list)
def merge_requests(self, **kwargs):
"""List the merge requests related to this milestone
Returns:
list (ProjectMergeRequest): List of merge requests
"""
path = '%s/%s/merge_requests' % (self.manager.path, self.get_id())
data_list = self.manager.gitlab.http_list(path, **kwargs)
manager = ProjectCommitManager(self.manager.gitlab,
parent=self.manager._parent)
# FIXME(gpocentek): the computed manager path is not correct
return RESTObjectList(manager, ProjectMergeRequest, data_list)
class ProjectMilestoneManager(RetrieveMixin, CreateMixin, DeleteMixin,
RESTManager):
_path = '/projects/%(project_id)s/milestones'
_obj_cls = ProjectMilestone
_from_parent_attrs = {'project_id': 'id'}
_create_attrs = (('title', ), ('description', 'due_date', 'start_date',
'state_event'))
_update_attrs = (tuple(), ('title', 'description', 'due_date',
'start_date', 'state_event'))
_list_filters = ('iids', 'state')
class ProjectLabel(SubscribableMixin, SaveMixin, ObjectDeleteMixin,
RESTObject):
_id_attr = 'name'
class ProjectLabelManager(GetFromListMixin, CreateMixin, UpdateMixin,
DeleteMixin, RESTManager):
_path = '/projects/%(project_id)s/labels'
_obj_cls = ProjectLabel
_from_parent_attrs = {'project_id': 'id'}
_create_attrs = (('name', 'color'), ('description', 'priority'))
_update_attrs = (('name', ),
('new_name', 'color', 'description', 'priority'))
# Delete without ID.