Skip to content

Commit 98a31a5

Browse files
GrahamCampbellivancliStyleCIBot
authored
[12.1] Add pipeline inputs support (#891)
* Add pipeline inputs support Co-authored-by: Ivan Li <14046763+ivancli@users.noreply.github.com> * Apply fixes from StyleCI --------- Co-authored-by: Ivan Li <14046763+ivancli@users.noreply.github.com> Co-authored-by: StyleCI Bot <bot@styleci.io>
1 parent 7d36c88 commit 98a31a5

3 files changed

Lines changed: 60 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
* Add support for project integrations endpoints
1515
* Add support for group hook endpoints
1616
* Add support for `job_inputs` and `job_variables_attributes` in `Jobs::play`
17+
* Add support for `inputs` in `Projects::createPipeline`
1718
* Add support for filters in `Projects::projectAccessTokens`
1819
* Add support for `Projects::rotateProjectAccessToken`
1920
* Add support for listing merge requests associated with a commit

‎src/Api/Projects.php‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,20 @@ public function pipelineTestReportSummary(int|string $project_id, int $pipeline_
368368
* @var mixed $value The value of the variable
369369
* @var string $variable_type env_var (default) or file
370370
* }
371+
*
372+
* @param array $parameters {
373+
*
374+
* @var array $inputs Inputs to use when creating the pipeline.
375+
* }
371376
*/
372-
public function createPipeline(int|string $project_id, string $commit_ref, ?array $variables = null): mixed
377+
public function createPipeline(int|string $project_id, string $commit_ref, ?array $variables = null, array $parameters = []): mixed
373378
{
374-
$parameters = [];
379+
$resolver = new OptionsResolver();
380+
$resolver->setDefined('inputs')
381+
->setAllowedTypes('inputs', 'array')
382+
;
383+
384+
$parameters = $resolver->resolve($parameters);
375385

376386
if (null !== $variables) {
377387
$parameters['variables'] = $variables;

‎tests/Api/ProjectsTest.php‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,53 @@ public function shouldCreatePipelineWithVariables(): void
939939
$this->assertEquals($expectedArray, $api->createPipeline(1, 'test-pipeline', $variables));
940940
}
941941

942+
#[Test]
943+
public function shouldCreatePipelineWithInputs(): void
944+
{
945+
$expectedArray = [
946+
['id' => 4, 'status' => 'created', 'ref' => 'test-pipeline'],
947+
];
948+
$inputs = [
949+
'environment' => 'production',
950+
'scan_security' => false,
951+
'level' => 3,
952+
];
953+
954+
$api = $this->getApiMock();
955+
$api->expects($this->once())
956+
->method('post')
957+
->with('projects/1/pipeline', ['inputs' => $inputs], [], [], ['ref' => 'test-pipeline'])
958+
->willReturn($expectedArray);
959+
960+
$this->assertEquals($expectedArray, $api->createPipeline(1, 'test-pipeline', null, ['inputs' => $inputs]));
961+
}
962+
963+
#[Test]
964+
public function shouldCreatePipelineWithVariablesAndInputs(): void
965+
{
966+
$expectedArray = [
967+
['id' => 4, 'status' => 'created', 'ref' => 'test-pipeline'],
968+
];
969+
$variables = [
970+
[
971+
'key' => 'test_var_1',
972+
'value' => 'test_value_1',
973+
],
974+
];
975+
$inputs = [
976+
'environment' => 'production',
977+
'scan_security' => false,
978+
];
979+
980+
$api = $this->getApiMock();
981+
$api->expects($this->once())
982+
->method('post')
983+
->with('projects/1/pipeline', ['inputs' => $inputs, 'variables' => $variables], [], [], ['ref' => 'test-pipeline'])
984+
->willReturn($expectedArray);
985+
986+
$this->assertEquals($expectedArray, $api->createPipeline(1, 'test-pipeline', $variables, ['inputs' => $inputs]));
987+
}
988+
942989
#[Test]
943990
public function shouldRetryPipeline(): void
944991
{

0 commit comments

Comments
 (0)