8000 Add support for boards API · rowhit/python-gitlab@f332907 · GitHub
[go: up one dir, main page]

Skip to content

Commit f332907

Browse files
author
Gauvain Pocentek
committed
Add support for boards API
This is not fully usable because the gitlab API has some limitations: - not possible to create boards programmatically - not possible to get labels ID (https://gitlab.com/gitlab-org/gitlab-ce/issues/23448)
1 parent 20fdbe8 commit f332907

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-0
lines changed

docs/gl_objects/projects.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,39 @@
405405
# pipeline cancel
406406
pipeline.cancel()
407407
# end pipeline cancel
408+
409+
# boards list
410+
boards = gl.project_boards.list(project_id=1)
411+
# or
412+
boards = project.boards.list()
413+
# end boards list
414+
415+
# boards get
416+
board = gl.project_boards.get(board_id, project_id=1)
417+
# or
418+
board = project.boards.get(board_id)
419+
# end boards get
420+
421+
# board lists list
422+
b_lists = board.lists.list()
423+
# end board lists list
424+
425+
# board lists get
426+
b_list = board.lists.get(list_id)
427+
# end board lists get
428+
429+
# board lists create
430+
# First get a ProjectLabel
431+
label = get_or_create_label()
432+
# Then use its ID to create the new board list
433+
b_list = board.lists.create({'label_id': label.id})
434+
# end board lists create
435+
436+
# board lists update
437+
b_list.position = 2
438+
b_list.save()
439+
# end board lists update
440+
441+
# board lists delete
442+
b_list.delete()
443+
# end boards lists delete

docs/gl_objects/projects.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,57 @@ Disable a service:
468468
.. literalinclude:: projects.py
469469
:start-after: # service delete
470470
:end-before: # end service delete
471+
472+
Boards
473+
------
474+
475+
Boards are a visual representation of existing issues for a project. Issues can
476+
be moved from one list to the other to track progress and help with
477+
priorities.
478+
479+
Get the list of existing boards for a project:
480+
481+
.. literalinclude:: projects.py
482+
:start-after: # boards list
483+
:end-before: # end boards list
484+
485+
Get a single board for a project:
486+
487+
.. literalinclude:: projects.py
488+
:start-after: # boards get
489+
:end-before: # end boards get
490+
491+
Boards have lists of issues. Each list is defined by a
492+
:class:`~gitlab.objects.ProjectLabel` and a position in the board.
493+
494+
List the issue lists for a board:
495+
496+
.. literalinclude:: projects.py
497+
:start-after: # board lists list
498+
:end-before: # end board lists list
499+
500+
Get a single list:
501+
502+
.. literalinclude:: projects.py
503+
:start-after: # board lists get
504+
:end-before: # end board lists get
505+
506+
Create a new list. Note that getting the label ID is broken at the moment (see
507+
https://gitlab.com/gitlab-org/gitlab-ce/issues/23448):
508+
509+
.. literalinclude:: projects.py
510+
:start-after: # board lists create
511+
:end-before: # end board lists create
512+
513+
Change a list position. The first list is at position 0. Moving a list will
514+
insert it at the given position and move the following lists up a position:
515+
516+
.. literalinclude:: projects.py
517+
:start-after: # board lists update
518+
:end-before: # end board lists update
519+
520+
Delete a list:
521+
522+
.. literalinclude:: projects.py
523+
:start-after: # board lists delete
524+
:end-before: # end board lists delete

gitlab/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ class Gitlab(object):
8282
namespaces (NamespaceManager): Manager for namespaces
8383
project_accessrequests (ProjectAccessRequestManager): Manager for
8484
GitLab projects access requests
85+
project_boards (ProjectBoardManager): Manager for GitLab projects
86+
boards
87+
project_board_lists (ProjectBoardListManager): Manager for GitLab
88+
project board lists
8589
project_branches (ProjectBranchManager): Manager for GitLab projects
8690
branches
8791
project_builds (ProjectBuildManager): Manager for GitLab projects
@@ -175,6 +179,8 @@ def __init__(self, url, private_token=None, email=None, password=None,
175179
self.licenses = LicenseManager(self)
176180
self.namespaces = NamespaceManager(self)
177181
self.project_accessrequests = ProjectAccessRequestManager(self)
182+
self.project_boards = ProjectBoardManager(self)
183+
self.project_board_listss = ProjectBoardListManager(self)
178184
self.project_branches = ProjectBranchManager(self)
179185
self.project_builds = ProjectBuildManager(self)
180186
self.project_commits = ProjectCommitManager(self)

gitlab/objects.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,34 @@ class NamespaceManager(BaseManager):
925925
obj_cls = Namespace
926926

927927

928+
class ProjectBoardList(GitlabObject):
929+
_url = '/projects/%(project_id)s/boards/%(board_id)s/lists'
930+
requiredUrlAttrs = ['project_id', 'board_id']
931+
_constructorTypes = {'label': 'ProjectLabel'}
932+
requiredCreateAttrs = ['label_id']
933+
requiredUpdateAttrs = ['position']
934+
935+
936+
class ProjectBoardListManager(BaseManager):
937+
obj_cls = ProjectBoardList
938+
939+
940+
class ProjectBoard(GitlabObject):
941+
_url = '/projects/%(project_id)s/boards'
942+
requiredUrlAttrs = ['project_id']
943+
_constructorTypes = {'labels': 'ProjectBoardList'}
944+
canGet = 'from_list'
945+
canUpdate = False
946+
canCreate = False
947+
canDelete = False
948+
managers = [('lists', ProjectBoardListManager,
949+
[('project_id', 'project_id'), ('board_id', 'id')])]
950+
951+
952+
class ProjectBoardManager(BaseManager):
953+
obj_cls = ProjectBoard
954+
955+
928956
class ProjectBranch(GitlabObject):
929957
_url = '/projects/%(project_id)s/repository/branches'
930958
_constructorTypes = {'author': 'User', "committer": "User"}
@@ -1925,6 +1953,8 @@ class Project(GitlabObject):
19251953
managers = [
19261954
('accessrequests', ProjectAccessRequestManager,
19271955
[('project_id', 'id')]),
1956+
('boards', ProjectBoardManager, [('project_id', 'id')]),
1957+
('board_lists', ProjectBoardListManager, [('project_id', 'id')]),
19281958
('branches', ProjectBranchManager, [('project_id', 'id')]),
19291959
('builds', ProjectBuildManager, [('project_id', 'id')]),
19301960
('commits', ProjectCommitManager, [('project_id', 'id')]),

tools/python_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,19 @@
253253
admin_project = admin_project.unstar()
254254
assert(admin_project.star_count == 0)
255255

256+
# project boards
257+
#boards = admin_project.boards.list()
258+
#assert(len(boards))
259+
#board = boards[0]
260+
#lists = board.lists.list()
261+
#begin_size = len(lists)
262+
#last_list = lists[-1]
263+
#last_list.position = 0
264+
#last_list.save()
265+
#last_list.delete()
266+
#lists = board.lists.list()
267+
#assert(len(lists) == begin_size - 1)
268+
256269
# namespaces
257270
ns = gl.namespaces.list()
258271
assert(len(ns) != 0)

0 commit comments

Comments
 (0)
0