Skip to content

Commit c36c31e

Browse files
committed
FEATURE: add API service to integrate with prunner via a PHP api
1 parent ba5cf6e commit c36c31e

10 files changed

Lines changed: 578 additions & 0 deletions

File tree

Classes/Dto/Job.php

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
4+
namespace Flowpack\Prunner\Dto;
5+
6+
use Neos\Flow\Annotations as Flow;
7+
8+
/**
9+
* @Flow\Proxy(false)
10+
*/
11+
class Job
12+
{
13+
private string $id;
14+
/**
15+
* @var string Pipeline name
16+
*/
17+
private string $pipeline;
18+
private TaskResults $taskResults;
19+
private bool $completed;
20+
private bool $canceled;
21+
private bool $errored;
22+
private \DateTimeImmutable $created;
23+
private ?\DateTimeImmutable $start;
24+
private ?\DateTimeImmutable $end;
25+
private ?string $lastError;
26+
private array $variables;
27+
private string $user;
28+
29+
public static function fromJsonArray(array $in): self
30+
{
31+
$job = new static();
32+
$job->id = $in['id'];
33+
$job->pipeline = $in['pipeline'];
34+
$job->taskResults = TaskResults::fromJsonArray($in['tasks']);;
35+
$job->completed = $in['completed'];
36+
$job->canceled = $in['canceled'];
37+
$job->errored = $in['errored'];
38+
$job->created = \DateTimeImmutable::createFromFormat(\DateTimeInterface::W3C, $in['created']);
39+
$job->start = isset($in['start']) ? \DateTimeImmutable::createFromFormat(\DateTimeInterface::W3C, $in['start']) : null;
40+
$job->end = isset($in['end']) ? \DateTimeImmutable::createFromFormat(\DateTimeInterface::W3C, $in['end']) : null;
41+
$job->lastError = $in['lastError'];
42+
$job->variables = $in['variables'] ?? [];
43+
$job->user = $in['user'];
44+
45+
return $job;
46+
}
47+
48+
/**
49+
* @return string
50+
*/
51+
public function getId(): string
52+
{
53+
return $this->id;
54+
}
55+
56+
public function getPipeline(): string
57+
{
58+
return $this->pipeline;
59+
}
60+
61+
public function getTaskResults(): TaskResults
62+
{
63+
return $this->taskResults;
64+
}
65+
66+
public function isCompleted(): bool
67+
{
68+
return $this->completed;
69+
}
70+
71+
public function isCanceled(): bool
72+
{
73+
return $this->canceled;
74+
}
75+
76+
public function isErrored(): bool
77+
{
78+
return $this->errored;
79+
}
80+
81+
public function getCreated(): \DateTimeImmutable
82+
{
83+
return $this->created;
84+
}
85+
86+
public function getStart(): ?\DateTimeImmutable
87+
{
88+
return $this->start;
89+
}
90+
91+
public function getEnd(): ?\DateTimeImmutable
92+
{
93+
return $this->end;
94+
}
95+
96+
public function getLastError(): ?string
97+
{
98+
return $this->lastError;
99+
}
100+
101+
public function getVariables(): array
102+
{
103+
return $this->variables;
104+
}
105+
106+
public function getUser(): string
107+
{
108+
return $this->user;
109+
}
110+
}

Classes/Dto/Jobs.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Flowpack\Prunner\Dto;
4+
5+
use Neos\Flow\Annotations as Flow;
6+
7+
/**
8+
* @Flow\Proxy(false)
9+
*/
10+
class Jobs implements \IteratorAggregate
11+
{
12+
/**
13+
* @var Job[]
14+
*/
15+
protected array $jobs;
16+
17+
private function __construct(array $jobs)
18+
{
19+
$this->jobs = $jobs;
20+
}
21+
22+
23+
public function fromJsonArray(array $in): self
24+
{
25+
$converted = [];
26+
foreach ($in as $el) {
27+
$converted[] = Job::fromJsonArray($el);
28+
}
29+
return new self($converted);
30+
}
31+
32+
public function forPipeline(string $pipeline): Jobs
33+
{
34+
$filteredJobs = [];
35+
foreach ($this->jobs as $job) {
36+
if ($job->getPipeline() === $pipeline) {
37+
$filteredJobs[] = $job;
38+
}
39+
}
40+
41+
return new self($filteredJobs);
42+
}
43+
44+
/**
45+
* @return \Iterator<Job>
46+
*/
47+
public function getIterator()
48+
{
49+
return new \ArrayIterator($this->jobs);
50+
}
51+
}

Classes/Dto/Pipeline.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
4+
namespace Flowpack\Prunner\Dto;
5+
6+
use Neos\Flow\Annotations as Flow;
7+
8+
/**
9+
* @Flow\Proxy(false)
10+
*/
11+
class Pipeline
12+
{
13+
private string $pipeline;
14+
private bool $schedulable;
15+
private bool $running;
16+
17+
public static function fromJsonArray(array $in): self
18+
{
19+
$pipeline = new static();
20+
$pipeline->pipeline = $in['pipeline'];
21+
$pipeline->schedulable = $in['schedulable'];
22+
$pipeline->running = $in['running'];
23+
24+
return $pipeline;
25+
}
26+
27+
public function getPipeline(): string
28+
{
29+
return $this->pipeline;
30+
}
31+
32+
public function isSchedulable(): bool
33+
{
34+
return $this->schedulable;
35+
}
36+
37+
public function isRunning(): bool
38+
{
39+
return $this->running;
40+
}
41+
42+
}

Classes/Dto/Pipelines.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
4+
namespace Flowpack\Prunner\Dto;
5+
6+
use Neos\Flow\Annotations as Flow;
7+
8+
/**
9+
* @Flow\Proxy(false)
10+
*/
11+
class Pipelines implements \IteratorAggregate
12+
{
13+
protected array $pipelines;
14+
15+
public function fromJsonArray(array $in): self
16+
{
17+
$converted = [];
18+
foreach ($in as $el) {
19+
$converted[] = Pipeline::fromJsonArray($el);
20+
}
21+
22+
$pipelines = new self();
23+
$pipelines->pipelines = $converted;
24+
return $pipelines;
25+
}
26+
27+
28+
/**
29+
* @return \Iterator<Pipeline>
30+
*/
31+
public function getIterator()
32+
{
33+
return new \ArrayIterator($this->pipelines);
34+
}
35+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Flowpack\Prunner\Dto;
4+
5+
use Neos\Flow\Annotations as Flow;
6+
7+
/**
8+
* @Flow\Proxy(false)
9+
*/
10+
class PipelinesAndJobsResponse
11+
{
12+
13+
protected Pipelines $pipelines;
14+
protected Jobs $jobs;
15+
16+
protected function __construct(Pipelines $pipelines, Jobs $jobs)
17+
{
18+
$this->pipelines = $pipelines;
19+
$this->jobs = $jobs;
20+
}
21+
22+
public function fromJsonArray(array $in): self
23+
{
24+
$pipelines = Pipelines::fromJsonArray($in['pipelines']);
25+
$jobs = Jobs::fromJsonArray($in['jobs']);
26+
27+
return new self($pipelines, $jobs);
28+
}
29+
30+
/**
31+
* @return Pipelines
32+
*/
33+
public function getPipelines(): Pipelines
34+
{
35+
return $this->pipelines;
36+
}
37+
38+
/**
39+
* @return Jobs
40+
*/
41+
public function getJobs(): Jobs
42+
{
43+
return $this->jobs;
44+
}
45+
}

Classes/Dto/TaskResult.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace Flowpack\Prunner\Dto;
4+
5+
use Neos\Flow\Annotations as Flow;
6+
7+
/**
8+
* @Flow\Proxy(false)
9+
*/
10+
class TaskResult
11+
{
12+
13+
private string $name;
14+
private string $status;
15+
private ?\DateTimeImmutable $start;
16+
private ?\DateTimeImmutable $end;
17+
private bool $skipped;
18+
private int $exitCode;
19+
private bool $errored;
20+
private ?string $error;
21+
22+
public static function fromJsonArray(array $in): self
23+
{
24+
$taskResult = new static();
25+
$taskResult->name = $in['name'];
26+
$taskResult->status = $in['status'];
27+
$taskResult->start = isset($in['start']) ? \DateTimeImmutable::createFromFormat(\DateTimeInterface::RFC3339, $in['start']) : null;
28+
$taskResult->end = isset($in['end']) ? \DateTimeImmutable::createFromFormat(\DateTimeInterface::RFC3339, $in['end']) : null;
29+
$taskResult->skipped = $in['skipped'];
30+
$taskResult->exitCode = $in['exitCode'];
31+
$taskResult->errored = $in['errored'];
32+
$taskResult->error = $in['error'];
33+
34+
return $taskResult;
35+
}
36+
37+
/**
38+
* @return string
39+
*/
40+
public function getName(): string
41+
{
42+
return $this->name;
43+
}
44+
45+
/**
46+
* @return string
47+
*/
48+
public function getStatus(): string
49+
{
50+
return $this->status;
51+
}
52+
53+
/**
54+
* @return \DateTimeImmutable
55+
*/
56+
public function getStart(): ?\DateTimeImmutable
57+
{
58+
return $this->start;
59+
}
60+
61+
/**
62+
* @return \DateTimeImmutable
63+
*/
64+
public function getEnd(): ?\DateTimeImmutable
65+
{
66+
return $this->end;
67+
}
68+
69+
/**
70+
* @return bool
71+
*/
72+
public function isSkipped(): bool
73+
{
74+
return $this->skipped;
75+
}
76+
77+
/**
78+
* @return int
79+
*/
80+
public function getExitCode(): int
81+
{
82+
return $this->exitCode;
83+
}
84+
85+
/**
86+
* @return bool
87+
*/
88+
public function isErrored(): bool
89+
{
90+
return $this->errored;
91+
}
92+
93+
/**
94+
* @return string
95+
*/
96+
public function getError(): ?string
97+
{
98+
return $this->error;
99+
}
100+
101+
}

0 commit comments

Comments
 (0)