Description
Description of the problem, including code/CLI snippet
Last year, I've proposed the #398 PR in order to implement the support for pipeline schedules. The implementation has been updated and merged upstream, thank you for that.
However, this year I am trying to use the latest upstream release and have trouble to list the variables of a pipeline schedule. When I access the variables
member of a project.pipelineschedule
, I access the ProjectPipelineScheduleVariableManager
which is neither iterable nor has a list()
method implemented.
Therefore, I don't know how to access the actual list of variables. Maybe I am just assuming something wrong. Further, depending on how the list of pipeline schedules of a project has been retrieved, the pipeline schedule object contains the actual value of the variables or not.
Can someone point me out what the correct way would be?
Thank you
Expected Behavior
I expected the ProjectPipelineScheduleVariableManager
to be either iterable or to implement a list()
method.
Actual Behavior
Not supported (?)
Solution
As a solution, I just implemented a list()
method that also takes care of the case where the actual variables have not been retrieved for the schedule. This is probably not the correct way to do it, but I do not know better.
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index 1d771ae..6886962 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -2649,6 +2649,12 @@ class ProjectPipelineScheduleVariableManager(CreateMixin, UpdateMixin,
_create_attrs = (('key', 'value'), tuple())
_update_attrs = (('key', 'value'), tuple())
+ def list(self, **kwargs):
+ if 'variables' in self._parent._attrs:
+ return [self._obj_cls(self, x) for x in self._parent._attrs['variables']]
+ else:
+ return [self._obj_cls(self, x) for x in self._parent.manager.get(self._parent.id)._attrs['variables']]
+
class ProjectPipelineSchedule(SaveMixin, ObjectDeleteMixin, RESTObject):
_managers = (('variables', 'ProjectPipelineScheduleVariableManager'),)
Specifications
- python-gitlab version: 1.6.0
- API version you are using (v3/v4): v4
- Gitlab server version (or gitlab.com): GitLab Community Edition 11.3.0 17bd59a