Skip to content

Commit

Permalink
Add support for boards API
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Gauvain Pocentek committed Oct 23, 2016
1 parent 20fdbe8 commit f332907
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docs/gl_objects/projects.py
Expand Up @@ -405,3 +405,39 @@
# pipeline cancel
pipeline.cancel()
# end pipeline cancel

# boards list
boards = gl.project_boards.list(project_id=1)
# or
boards = project.boards.list()
# end boards list

# boards get
board = gl.project_boards.get(board_id, project_id=1)
# or
board = project.boards.get(board_id)
# end boards get

# board lists list
b_lists = board.lists.list()
# end board lists list

# board lists get
b_list = board.lists.get(list_id)
# end board lists get

# board lists create
# First get a ProjectLabel
label = get_or_create_label()
# Then use its ID to create the new board list
b_list = board.lists.create({'label_id': label.id})
# end board lists create

# board lists update
b_list.position = 2
b_list.save()
# end board lists update

# board lists delete
b_list.delete()
# end boards lists delete
54 changes: 54 additions & 0 deletions docs/gl_objects/projects.rst
Expand Up @@ -468,3 +468,57 @@ Disable a service:
.. literalinclude:: projects.py
:start-after: # service delete
:end-before: # end service delete

Boards
------

Boards are a visual representation of existing issues for a project. Issues can
be moved from one list to the other to track progress and help with
priorities.

Get the list of existing boards for a project:

.. literalinclude:: projects.py
:start-after: # boards list
:end-before: # end boards list

Get a single board for a project:

.. literalinclude:: projects.py
:start-after: # boards get
:end-before: # end boards get

Boards have lists of issues. Each list is defined by a
:class:`~gitlab.objects.ProjectLabel` and a position in the board.

List the issue lists for a board:

.. literalinclude:: projects.py
:start-after: # board lists list
:end-before: # end board lists list

Get a single list:

.. literalinclude:: projects.py
:start-after: # board lists get
:end-before: # end board lists get

Create a new list. Note that getting the label ID is broken at the moment (see
https://gitlab.com/gitlab-org/gitlab-ce/issues/23448):

.. literalinclude:: projects.py
:start-after: # board lists create
:end-before: # end board lists create

Change a list position. The first list is at position 0. Moving a list will
insert it at the given position and move the following lists up a position:

.. literalinclude:: projects.py
:start-after: # board lists update
:end-before: # end board lists update

Delete a list:

.. literalinclude:: projects.py
:start-after: # board lists delete
:end-before: # end board lists delete
6 changes: 6 additions & 0 deletions gitlab/__init__.py
Expand Up @@ -82,6 +82,10 @@ class Gitlab(object):
namespaces (NamespaceManager): Manager for namespaces
project_accessrequests (ProjectAccessRequestManager): Manager for
GitLab projects access requests
project_boards (ProjectBoardManager): Manager for GitLab projects
boards
project_board_lists (ProjectBoardListManager): Manager for GitLab
project board lists
project_branches (ProjectBranchManager): Manager for GitLab projects
branches
project_builds (ProjectBuildManager): Manager for GitLab projects
Expand Down Expand Up @@ -175,6 +179,8 @@ def __init__(self, url, private_token=None, email=None, password=None,
self.licenses = LicenseManager(self)
self.namespaces = NamespaceManager(self)
self.project_accessrequests = ProjectAccessRequestManager(self)
self.project_boards = ProjectBoardManager(self)
self.project_board_listss = ProjectBoardListManager(self)
self.project_branches = ProjectBranchManager(self)
self.project_builds = ProjectBuildManager(self)
self.project_commits = ProjectCommitManager(self)
Expand Down
30 changes: 30 additions & 0 deletions gitlab/objects.py
Expand Up @@ -925,6 +925,34 @@ class NamespaceManager(BaseManager):
obj_cls = Namespace


class ProjectBoardList(GitlabObject):
_url = '/projects/%(project_id)s/boards/%(board_id)s/lists'
requiredUrlAttrs = ['project_id', 'board_id']
_constructorTypes = {'label': 'ProjectLabel'}
requiredCreateAttrs = ['label_id']
requiredUpdateAttrs = ['position']


class ProjectBoardListManager(BaseManager):
obj_cls = ProjectBoardList


class ProjectBoard(GitlabObject):
_url = '/projects/%(project_id)s/boards'
requiredUrlAttrs = ['project_id']
_constructorTypes = {'labels': 'ProjectBoardList'}
canGet = 'from_list'
canUpdate = False
canCreate = False
canDelete = False
managers = [('lists', ProjectBoardListManager,
[('project_id', 'project_id'), ('board_id', 'id')])]


class ProjectBoardManager(BaseManager):
obj_cls = ProjectBoard


class ProjectBranch(GitlabObject):
_url = '/projects/%(project_id)s/repository/branches'
_constructorTypes = {'author': 'User', "committer": "User"}
Expand Down Expand Up @@ -1925,6 +1953,8 @@ class Project(GitlabObject):
managers = [
('accessrequests', ProjectAccessRequestManager,
[('project_id', 'id')]),
('boards', ProjectBoardManager, [('project_id', 'id')]),
('board_lists', ProjectBoardListManager, [('project_id', 'id')]),
('branches', ProjectBranchManager, [('project_id', 'id')]),
('builds', ProjectBuildManager, [('project_id', 'id')]),
('commits', ProjectCommitManager, [('project_id', 'id')]),
Expand Down
13 changes: 13 additions & 0 deletions tools/python_test.py
Expand Up @@ -253,6 +253,19 @@
admin_project = admin_project.unstar()
assert(admin_project.star_count == 0)

# project boards
#boards = admin_project.boards.list()
#assert(len(boards))
#board = boards[0]
#lists = board.lists.list()
#begin_size = len(lists)
#last_list = lists[-1]
#last_list.position = 0
#last_list.save()
#last_list.delete()
#lists = board.lists.list()
#assert(len(lists) == begin_size - 1)

# namespaces
ns = gl.namespaces.list()
assert(len(ns) != 0)
Expand Down

0 comments on commit f332907

Please sign in to comment.