1
1
<?php namespace Gitlab \Api ;
2
2
3
3
use Psr \Http \Message \StreamInterface ;
4
+ use Symfony \Component \OptionsResolver \OptionsResolver ;
4
5
5
6
class Jobs extends AbstractApi
6
7
{
@@ -15,27 +16,40 @@ class Jobs extends AbstractApi
15
16
16
17
/**
17
18
* @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
+ *
19
25
* @return mixed
20
26
*/
21
- public function all ($ project_id , array $ scope = [])
27
+ public function all ($ project_id , array $ parameters = [])
22
28
{
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 ));
26
32
}
27
33
28
34
/**
29
35
* @param int|string $project_id
30
36
* @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
+ *
32
43
* @return mixed
33
44
*/
34
- public function pipelineJobs ($ project_id , $ pipeline_id , array $ scope = [])
45
+ public function pipelineJobs ($ project_id , $ pipeline_id , array $ parameters = [])
35
46
{
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
+ );
39
53
}
40
54
41
55
/**
@@ -130,4 +144,35 @@ public function play($project_id, $job_id)
130
144
{
131
145
return $ this ->post ("projects/ " .$ this ->encodePath ($ project_id )."/jobs/ " .$ this ->encodePath ($ job_id )."/play " );
132
146
}
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
+ }
133
178
}
0 commit comments