diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2016-10-23 16:16:54 +0200 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2016-10-23 16:16:54 +0200 |
commit | f332907457c897ad0483a0bffce3d01503445d0b (patch) | |
tree | d871082cc6b0fec206ea5c7a135fe4573039b1a2 | |
parent | 20fdbe870f161ad7c47c7d57ebb2b6952acba8be (diff) | |
download | gitlab-f332907457c897ad0483a0bffce3d01503445d0b.tar.gz |
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)
-rw-r--r-- | docs/gl_objects/projects.py | 36 | ||||
-rw-r--r-- | docs/gl_objects/projects.rst | 54 | ||||
-rw-r--r-- | gitlab/__init__.py | 6 | ||||
-rw-r--r-- | gitlab/objects.py | 30 | ||||
-rw-r--r-- | tools/python_test.py | 13 |
5 files changed, 139 insertions, 0 deletions
diff --git a/docs/gl_objects/projects.py b/docs/gl_objects/projects.py index 7623c15..c2bc5aa 100644 --- a/docs/gl_objects/projects.py +++ b/docs/gl_objects/projects.py @@ -405,3 +405,39 @@ pipeline.retry() # 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 diff --git a/docs/gl_objects/projects.rst b/docs/gl_objects/projects.rst index afc0d3a..bdbf140 100644 --- a/docs/gl_objects/projects.rst +++ b/docs/gl_objects/projects.rst @@ -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 diff --git a/gitlab/__init__.py b/gitlab/__init__.py index 2699328..56a53c9 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -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 @@ -175,6 +179,8 @@ class Gitlab(object): 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) diff --git a/gitlab/objects.py b/gitlab/objects.py index 9ab1dc0..ad57d2f 100644 --- a/gitlab/objects.py +++ b/gitlab/objects.py @@ -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"} @@ -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')]), diff --git a/tools/python_test.py b/tools/python_test.py index f9f5bb8..888d553 100644 --- a/tools/python_test.py +++ b/tools/python_test.py @@ -253,6 +253,19 @@ assert(admin_project.star_count == 1) 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) |