diff options
| author | Gauvain Pocentek <gauvain@pocentek.net> | 2016-08-11 10:58:40 +0200 |
|---|---|---|
| committer | Gauvain Pocentek <gauvain@pocentek.net> | 2016-08-11 10:58:40 +0200 |
| commit | 131739f492946ba1cd58852be1caf000af451384 (patch) | |
| tree | e0fc7e848fc93f90e6fcad8685a5eff18547dd29 /gitlab | |
| parent | 3e026d2ee62eba3ad92ff2cdd53db19f5e0e9f6a (diff) | |
| download | gitlab-131739f492946ba1cd58852be1caf000af451384.tar.gz | |
implement the todo API
Diffstat (limited to 'gitlab')
| -rw-r--r-- | gitlab/__init__.py | 2 | ||||
| -rw-r--r-- | gitlab/exceptions.py | 4 | ||||
| -rw-r--r-- | gitlab/objects.py | 51 |
3 files changed, 56 insertions, 1 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py index fce2569..d70cea0 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -124,6 +124,7 @@ class Gitlab(object): team_members (TeamMemberManager): Manager for GitLab teams members team_projects (TeamProjectManager): Manager for GitLab teams projects teams (TeamManager): Manager for GitLab teams + todos (TodoManager): Manager for user todos """ def __init__(self, url, private_token=None, email=None, password=None, @@ -191,6 +192,7 @@ class Gitlab(object): self.team_members = TeamMemberManager(self) self.team_projects = TeamProjectManager(self) self.teams = TeamManager(self) + self.todos = TodoManager(self) @staticmethod def from_config(gitlab_id=None, config_files=None): diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py index 41dad98..e07f0cc 100644 --- a/gitlab/exceptions.py +++ b/gitlab/exceptions.py @@ -111,6 +111,10 @@ class GitlabMROnBuildSuccessError(GitlabOperationError): pass +class GitlabTodoError(GitlabOperationError): + pass + + def raise_error_from_response(response, error, expected_code=200): """Tries to parse gitlab error message from response and raises error. diff --git a/gitlab/objects.py b/gitlab/objects.py index 4db6354..0e9c75f 100644 --- a/gitlab/objects.py +++ b/gitlab/objects.py @@ -1237,6 +1237,17 @@ class ProjectIssue(GitlabObject): raise_error_from_response(r, GitlabUpdateError, 201) self._set_from_dict(r.json()) + def todo(self, **kwargs): + """Create a todo for the issue. + + Raises: + GitlabConnectionError: If the server cannot be reached. + """ + url = ('/projects/%(project_id)s/issues/%(issue_id)s/todo' % + {'project_id': self.project_id, 'issue_id': self.id}) + r = self.gitlab._raw_post(url, **kwargs) + raise_error_from_response(r, GitlabTodoError, [201, 304]) + class ProjectIssueManager(BaseManager): obj_cls = ProjectIssue @@ -1498,6 +1509,17 @@ class ProjectMergeRequest(GitlabObject): raise_error_from_response(r, errors) self._set_from_dict(r.json()) + def todo(self, **kwargs): + """Create a todo for the merge request. + + Raises: + GitlabConnectionError: If the server cannot be reached. + """ + url = ('/projects/%(project_id)s/merge_requests/%(mr_id)s/todo' % + {'project_id': self.project_id, 'mr_id': self.id}) + r = self.gitlab._raw_post(url, **kwargs) + raise_error_from_response(r, GitlabTodoError, [201, 304]) + class ProjectMergeRequestManager(BaseManager): obj_cls = ProjectMergeRequest @@ -2154,7 +2176,7 @@ class RunnerManager(BaseManager): Raises: GitlabConnectionError: If the server cannot be reached. - GitlabListError; If the resource cannot be found + GitlabListError: If the resource cannot be found """ url = '/runners/all' if scope is not None: @@ -2170,6 +2192,33 @@ class TeamMember(GitlabObject): shortPrintAttr = 'username' +class Todo(GitlabObject): + _url = '/todos' + canGet = 'from_list' + canUpdate = False + canCreate = False + optionalListAttrs = ['action', 'author_id', 'project_id', 'state', 'type'] + + +class TodoManager(BaseManager): + obj_cls = Todo + + def delete_all(self, **kwargs): + """Mark all the todos as done. + + Raises: + GitlabConnectionError: If the server cannot be reached. + GitlabDeleteError: If the resource cannot be found + + Returns: + The number of todos maked done. + """ + url = '/todos' + r = self.gitlab._raw_delete(url, **kwargs) + raise_error_from_response(r, GitlabDeleteError) + return int(r.text) + + class UserProject(GitlabObject): _url = '/projects/user/%(user_id)s' _constructorTypes = {'owner': 'User', 'namespace': 'Group'} |
