|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ApiClients\Client\Github\OpenAPI\ApiGitHubCom\Operation\Actions; |
| 4 | + |
| 5 | +final class AddCustomLabelsToSelfHostedRunnerForRepo |
| 6 | +{ |
| 7 | + private const OPERATION_ID = 'actions/add-custom-labels-to-self-hosted-runner-for-repo'; |
| 8 | + public const OPERATION_MATCH = 'POST /repos/{owner}/{repo}/actions/runners/{runner_id}/labels'; |
| 9 | + private readonly \League\OpenAPIValidation\Schema\SchemaValidator $requestSchemaValidator; |
| 10 | + private readonly \League\OpenAPIValidation\Schema\SchemaValidator $responseSchemaValidator; |
| 11 | + /**The account owner of the repository. The name is not case sensitive.**/ |
| 12 | + private readonly string $owner; |
| 13 | + /**The name of the repository. The name is not case sensitive.**/ |
| 14 | + private readonly string $repo; |
| 15 | + /**Unique identifier of the self-hosted runner.**/ |
| 16 | + private readonly int $runner_id; |
| 17 | + public function operationId() : string |
| 18 | + { |
| 19 | + return self::OPERATION_ID; |
| 20 | + } |
| 21 | + public function __construct(\League\OpenAPIValidation\Schema\SchemaValidator $requestSchemaValidator, \League\OpenAPIValidation\Schema\SchemaValidator $responseSchemaValidator, string $owner, string $repo, int $runner_id) |
| 22 | + { |
| 23 | + $this->requestSchemaValidator = $requestSchemaValidator; |
| 24 | + $this->responseSchemaValidator = $responseSchemaValidator; |
| 25 | + $this->owner = $owner; |
| 26 | + $this->repo = $repo; |
| 27 | + $this->runner_id = $runner_id; |
| 28 | + } |
| 29 | + function createRequest(array $data = array()) : \Psr\Http\Message\RequestInterface |
| 30 | + { |
| 31 | + $this->requestSchemaValidator->validate($data, \cebe\openapi\Reader::readFromJson(\ApiClients\Client\Github\OpenAPI\ApiGitHubCom\Schema\Unknown\CCd5D02C54E256C1F61Acea463E527414::SCHEMA_JSON, '\\cebe\\openapi\\spec\\Schema')); |
| 32 | + return new \RingCentral\Psr7\Request('post', \str_replace(array('{owner}', '{repo}', '{runner_id}'), array($this->owner, $this->repo, $this->runner_id), '/repos/{owner}/{repo}/actions/runners/{runner_id}/labels'), array('Content-Type' => 'application/json'), json_encode($data)); |
| 33 | + } |
| 34 | + function createResponse(\Psr\Http\Message\ResponseInterface $response) : \ApiClients\Client\Github\OpenAPI\ApiGitHubCom\Schema\Unknown\C465Ffe2283692C35B7E35Cd3F31B8C6B|\ApiClients\Client\Github\OpenAPI\ApiGitHubCom\Schema\BasicError|\ApiClients\Client\Github\OpenAPI\ApiGitHubCom\Schema\ValidationErrorSimple |
| 35 | + { |
| 36 | + $contentType = $response->getHeaderLine('Content-Type'); |
| 37 | + $body = json_decode($response->getBody()->getContents(), true); |
| 38 | + $hydrator = new \WyriHaximus\Hydrator\Hydrator(); |
| 39 | + switch ($response->getStatusCode()) { |
| 40 | + /**Response**/ |
| 41 | + case 200: |
| 42 | + switch ($contentType) { |
| 43 | + case 'application/json': |
| 44 | + $this->responseSchemaValidator->validate($body, \cebe\openapi\Reader::readFromJson(\ApiClients\Client\Github\OpenAPI\ApiGitHubCom\Schema\Unknown\C465Ffe2283692C35B7E35Cd3F31B8C6B::SCHEMA_JSON, '\\cebe\\openapi\\spec\\Schema')); |
| 45 | + return $hydrator->hydrate('\\ApiClients\\Client\\Github\\OpenAPI\\ApiGitHubCom\\Schema\\Unknown\\C465Ffe2283692C35B7E35Cd3F31B8C6B', $body); |
| 46 | + } |
| 47 | + break; |
| 48 | + /**Resource not found**/ |
| 49 | + case 404: |
| 50 | + switch ($contentType) { |
| 51 | + case 'application/json': |
| 52 | + $this->responseSchemaValidator->validate($body, \cebe\openapi\Reader::readFromJson(\ApiClients\Client\Github\OpenAPI\ApiGitHubCom\Schema\BasicError::SCHEMA_JSON, '\\cebe\\openapi\\spec\\Schema')); |
| 53 | + return $hydrator->hydrate('\\ApiClients\\Client\\Github\\OpenAPI\\ApiGitHubCom\\Schema\\BasicError', $body); |
| 54 | + } |
| 55 | + break; |
| 56 | + /**Validation failed, or the endpoint has been spammed.**/ |
| 57 | + case 422: |
| 58 | + switch ($contentType) { |
| 59 | + case 'application/json': |
| 60 | + $this->responseSchemaValidator->validate($body, \cebe\openapi\Reader::readFromJson(\ApiClients\Client\Github\OpenAPI\ApiGitHubCom\Schema\ValidationErrorSimple::SCHEMA_JSON, '\\cebe\\openapi\\spec\\Schema')); |
| 61 | + return $hydrator->hydrate('\\ApiClients\\Client\\Github\\OpenAPI\\ApiGitHubCom\\Schema\\ValidationErrorSimple', $body); |
| 62 | + } |
| 63 | + break; |
| 64 | + } |
| 65 | + throw new \RuntimeException('Unable to find matching reponse code and content type'); |
| 66 | + } |
| 67 | +} |
0 commit comments