11<?php namespace Gitlab \Api ;
22
33use Psr \Http \Message \StreamInterface ;
4+ use Symfony \Component \OptionsResolver \OptionsResolver ;
45
56class Jobs extends AbstractApi
67{
@@ -15,27 +16,40 @@ class Jobs extends AbstractApi
1516
1617 /**
1718 * @param int|string $project_id
18- * @param array $scope
19+ * @param array $parameters (
20+ *
21+ * @var string|string[] $scope The scope of jobs to show, one or array of: created, pending, running, failed,
22+ * success, canceled, skipped, manual; showing all jobs if none provided.
23+ * )
24+ *
1925 * @return mixed
2026 */
21- public function all ($ project_id , array $ scope = [])
27+ public function all ($ project_id , array $ parameters = [])
2228 {
23- return $ this ->get ( " projects/ " . $ this -> encodePath ( $ project_id ). " /jobs " , array (
24- ' scope ' => $ scope
25- ));
29+ $ resolver = $ this ->createOptionsResolver ();
30+
31+ return $ this -> get ( " projects/ " . $ this -> encodePath ( $ project_id ). " /jobs " , $ resolver -> resolve ( $ parameters ));
2632 }
2733
2834 /**
2935 * @param int|string $project_id
3036 * @param int $pipeline_id
31- * @param array $scope
37+ * @param array $parameters (
38+ *
39+ * @var string|string[] $scope The scope of jobs to show, one or array of: created, pending, running, failed,
40+ * success, canceled, skipped, manual; showing all jobs if none provided.
41+ * )
42+ *
3243 * @return mixed
3344 */
34- public function pipelineJobs ($ project_id , $ pipeline_id , array $ scope = [])
45+ public function pipelineJobs ($ project_id , $ pipeline_id , array $ parameters = [])
3546 {
36- return $ this ->get ("projects/ " .$ this ->encodePath ($ project_id )."/pipelines/ " .$ this ->encodePath ($ pipeline_id )."/jobs " , array (
37- 'scope ' => $ scope
38- ));
47+ $ resolver = $ this ->createOptionsResolver ();
48+
49+ return $ this ->get (
50+ $ this ->getProjectPath ($ project_id , 'pipelines/ ' ).$ this ->encodePath ($ pipeline_id )."/jobs " ,
51+ $ resolver ->resolve ($ parameters )
52+ );
3953 }
4054
4155 /**
@@ -130,4 +144,35 @@ public function play($project_id, $job_id)
130144 {
131145 return $ this ->post ("projects/ " .$ this ->encodePath ($ project_id )."/jobs/ " .$ this ->encodePath ($ job_id )."/play " );
132146 }
147+
148+ /**
149+ * {@inheritdoc}
150+ */
151+ protected function createOptionsResolver ()
152+ {
153+ $ allowedScopeValues = [
154+ self ::SCOPE_CANCELED ,
155+ self ::SCOPE_CREATED ,
156+ self ::SCOPE_FAILED ,
157+ self ::SCOPE_MANUAL ,
158+ self ::SCOPE_PENDING ,
159+ self ::SCOPE_RUNNING ,
160+ self ::SCOPE_SKIPPED ,
161+ self ::SCOPE_SUCCESS ,
162+ ];
163+
164+ $ resolver = parent ::createOptionsResolver ();
165+ $ resolver ->setDefined ('scope ' )
166+ ->setAllowedTypes ('scope ' , ['string ' , 'array ' ])
167+ ->setAllowedValues ('scope ' , $ allowedScopeValues )
168+ ->addAllowedValues ('scope ' , function ($ value ) use ($ allowedScopeValues ) {
169+ return is_array ($ value ) && empty (array_diff ($ value , $ allowedScopeValues ));
170+ })
171+ ->setNormalizer ('scope ' , function (OptionsResolver $ resolver , $ value ) {
172+ return (array ) $ value ;
173+ })
174+ ;
175+
176+ return $ resolver ;
177+ }
133178}
0 commit comments