Skip to content

Commit

Permalink
up: update some for get job and build params info
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 18, 2022
1 parent c0abb17 commit d2d7c62
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
15 changes: 10 additions & 5 deletions src/Jenkins.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,21 +344,26 @@ public function getJob(string $jobName): Job
* @param string $jobName
* @param string $tree
*
* @return Job
* @return DataObject
*/
public function getJobParams(string $jobName, string $tree = ''): Job
public function getJobParams(string $jobName, string $tree = ''): DataObject
{
$tree = $tree ?: 'property[parameterDefinitions[description,name,type,choices]]';
$tree = $tree ?: 'property[parameterDefinitions[description,name,type,choices,defaultParameterValue]]';
$url = $this->buildUrl('/job/%s/api/json?tree=%s', $jobName, $tree);
$cli = $this->getHttpClient()->get($url);

if (!$cli->isSuccess()) {
throw new RuntimeException(sprintf('Error on get information for job %s', $jobName));
}

$infos = $cli->getDataObject();
$data = $cli->getArrayData();

return new Jenkins\Job($infos, $this);
$params = [];
if (isset($data['property'])) {
$params = Job::fmtBuildParams($data['property']);
}

return DataObject::new($params);
}

/**
Expand Down
18 changes: 14 additions & 4 deletions src/Jenkins/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class Job
*/
public function __construct(DataObject $job, Jenkins $jenkins)
{
$this->job = $job;
$this->jenkins = $jenkins;
$this->job = $job;
$this->jenkins = $jenkins;
}

/**
Expand Down Expand Up @@ -76,17 +76,27 @@ public function getName(): string
* @return array
*/
public function getParametersDefinitions(): array
{
return self::fmtBuildParams($this->job->property);
}

/**
* @param array $jobProperty
*
* @return array
*/
public static function fmtBuildParams(array $jobProperty): array
{
$parameters = [];

foreach ($this->job->property as $action) {
foreach ($jobProperty as $action) {
if (!isset($action['parameterDefinitions'])) {
continue;
}

foreach ($action['parameterDefinitions'] as $paramDefinition) {
$description = $paramDefinition['description'] ?? null;
$paramType = $paramDefinition['type'] ?? null;
$paramType = $paramDefinition['type'] ?? null;

$default = $paramDefinition['defaultParameterValue']['value'] ?? null;
$choices = $paramDefinition['choices'] ?? null;
Expand Down

0 comments on commit d2d7c62

Please sign in to comment.