8000 Add project push rules configuration · python-gitlab/python-gitlab@5cae00c · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 5cae00c

Browse files
committed
Add project push rules configuration
1 parent 92ca5c4 commit 5cae00c

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

docs/gl_objects/projects.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,3 +618,29 @@ markdown to reference the uploaded file::
618618
issue.notes.create({
619619
"body": "See the [attached file]({})".format(uploaded_file["url"])
620620
})
621+
622+
Project push rules
623+
==================
624+
625+
Reference
626+
---------
627+
628+
* v4 API:
629+
630+
+ :class:`gitlab.v4.objects.ProjectPushRules`
631+
+ :class:`gitlab.v4.objects.ProjectPushRulesManager`
632+
+ :attr:`gitlab.v4.objects.Project.pushrules`
633+
634+
* GitLab API: https://docs.gitlab.com/ee/api/projects.html#push-rules
635+
636+
Examples
637+
---------
638+
639+
Get project push rules::
640+
641+
pr = project.pushrules.get()
642+
643+
Edit project push rules::
644+
645+
pr.branch_name_regex = '^(master|develop|support-\d+|release-\d+\..+|hotfix-.+|feature-.+)$'
646+
pr.save()

gitlab/v4/objects.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,26 @@ class ProjectPipelineScheduleManager(CRUDMixin, RESTManager):
23642364
('description', 'ref', 'cron', 'cron_timezone', 'active'))
23652365

23662366

2367+
class ProjectPushRules(SaveMixin, ObjectDeleteMixin, RESTObject):
2368+
_id_attr = None
2369+
2370+
2371+
class ProjectPushRulesManager(GetWithoutIdMixin, CRUDMixin, RESTManager):
2372+
_path = '/projects/%(project_id)s/push_rule'
2373+
_obj_cls = ProjectPushRules
2374+
_from_parent_attrs = {'project_id': 'id'}
2375+
_create_attrs = (tuple(),
2376+
('deny_delete_tag', 'member_check',
2377+
'prevent_secrets', 'commit_message_regex',
2378+
'branch_name_regex', 'author_email_regex',
2379+
'file_name_regex', 'max_file_size'))
2380+
_update_attrs = (tuple(),
2381+
('deny_delete_tag', 'member_check',
2382+
'prevent_secrets', 'commit_message_regex',
2383+
'branch_name_regex', 'author_email_regex',
2384+
'file_name_regex', 'max_file_size'))
2385+
2386+
23672387
class ProjectSnippetNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
23682388
pass
23692389

@@ -2755,6 +2775,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject):
27552775
('pipelines', 'ProjectPipelineManager'),
27562776
('protectedbranches', 'ProjectProtectedBranchManager'),
27572777
('pipelineschedules', 'ProjectPipelineScheduleManager'),
2778+
('pushrules', 'ProjectPushRulesManager'),
27582779
('runners', 'ProjectRunnerManager'),
27592780
('services', 'ProjectServiceManager'),
27602781
('snippets', 'ProjectSnippetManager'),

0 commit comments

Comments
 (0)
0