diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2016-10-23 12:18:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-23 12:18:44 +0200 |
commit | 20fdbe870f161ad7c47c7d57ebb2b6952acba8be (patch) | |
tree | f7c75c8a2a4cf87eee28d50f2bf5abae23db1d0d /gitlab/objects.py | |
parent | 9da5d69002c59317ef215bfaf70db2ab5b38b490 (diff) | |
parent | 23b5b6e583c257821bea077096378df2fc20fde6 (diff) | |
download | gitlab-20fdbe870f161ad7c47c7d57ebb2b6952acba8be.tar.gz |
Merge pull request #169 from hakkeroid/allow-iid-parameter-to-request-distinct-objects
Convert response list to single data source for iid requests
Diffstat (limited to 'gitlab/objects.py')
-rw-r--r-- | gitlab/objects.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/gitlab/objects.py b/gitlab/objects.py index 8247a93..9ab1dc0 100644 --- a/gitlab/objects.py +++ b/gitlab/objects.py @@ -378,6 +378,22 @@ class GitlabObject(object): data = self.gitlab.get(self.__class__, data, **kwargs) self._from_api = True + # the API returned a list because custom kwargs where used + # instead of the id to request an object. Usually parameters + # other than an id return ambiguous results. However in the + # gitlab universe iids together with a project_id are + # unambiguous for merge requests and issues, too. + # So if there is only one element we can use it as our data + # source. + if 'iid' in kwargs and isinstance(data, list): + if len(data) < 1: + raise GitlabGetError('Not found') + elif len(data) == 1: + data = data[0] + else: + raise GitlabGetError('Impossible! You found multiple' + ' elements with the same iid.') + self._set_from_dict(data, **kwargs) if kwargs: |