diff --git a/README.md b/README.md index 47ff1282522..c715a8dc5f2 100644 --- a/README.md +++ b/README.md @@ -109,5 +109,6 @@ This library is maintained by the following people (alphabetically sorted) : - Thanks to [Nicolas Pastorino](http://github.com/jeanvoye) for his contribution on the Pull Request API. - Thanks to [Edoardo Rivello](http://github.com/erivello) for his contribution on the Gists API. - Thanks to [Miguel Piedrafita](https://github.com/m1guelpf) for his contribution to the v4 & Apps API. +- Thanks to [Emre DEGER](https://github.com/lexor) for his contribution to the Actions API. Thanks to GitHub for the high quality API and documentation. diff --git a/doc/organization/actions/secrets.md b/doc/organization/actions/secrets.md new file mode 100644 index 00000000000..113a37997ac --- /dev/null +++ b/doc/organization/actions/secrets.md @@ -0,0 +1,85 @@ +## Organization / Secrets API +[Back to the "Organization API"](../organization.md) | [Back to the navigation](../README.md) + +### List organization secrets + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-organization-secrets + +```php +$secrets = $client->organization()->secrets()->all('KnpLabs'); +``` + +### Get an organization secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-organization-secret + +```php +$secret = $client->organization()->secrets()->show('KnpLabs', $secretName); +``` + +### Create an organization secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-an-organization-secret + +```php +$client->organization()->secrets()->create('KnpLabs', $secretName, [ + 'encrypted_value' => $encryptedValue, + 'visibility' => $visibility, + 'selected_repository_ids' => $selectedRepositoryIds, +]); +``` + +### Update an organization secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-an-organization-secret + +```php +$client->organization()->secrets()->update('KnpLabs', $secretName, [ + 'key_id' => 'keyId', + 'encrypted_value' => 'encryptedValue', + 'visibility' => 'private', +]); +``` + +### Delete an organization secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-an-organization-secret + +```php +$client->organization()->secrets()->remove('KnpLabs', $secretName); +``` + +### List selected repositories for organization secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-selected-repositories-for-an-organization-secret + +```php +$client->organization()->secrets()->selectedRepositories('KnpLabs', $secretName); +``` + +### Set selected repositories for an organization secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#set-selected-repositories-for-an-organization-secret + +```php +$client->organization()->secrets()->setSelectedRepositories('KnpLabs', 'secretName', [ + 'selected_repository_ids' => [1, 2, 3], +]); +``` + +### Remove selected repository from an organization secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#remove-selected-repository-from-an-organization-secret + +```php +$client->organization()->secrets()->addSecret('KnpLabs', $repositoryId, $secretName); +``` + +### Get an organization public key + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-organization-public-key + +```php +$client->organization()->secrets()->publicKey('KnpLabs'); +``` + diff --git a/doc/repo/actions/artifacts.md b/doc/repo/actions/artifacts.md new file mode 100644 index 00000000000..b457f12c806 --- /dev/null +++ b/doc/repo/actions/artifacts.md @@ -0,0 +1,44 @@ +## Repo / Artifacts API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### List artifacts for a repository + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-artifacts-for-a-repository + +```php +$artifacts = $client->api('repo')->artifacts()->all('KnpLabs'); +``` + +### List workflow run artifacts + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-run-artifacts + +```php +$runArtifacts = $client->api('repo')->artifacts()->runArtifacts('KnpLabs', 'php-github-api', $runId); +``` + +### Get an artifact + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-artifact + +```php +$artifact = $client->api('repo')->artifacts()->show('KnpLabs', 'php-github-api', $artifactId); +``` + +### Delete an artifact + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-an-artifact + +```php +$client->api('repo')->artifacts()->delete('KnpLabs', 'php-github-api', $artifactId); +``` + + +### Download an artifact + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-an-artifact + +```php +$artifactFile = $client->api('repo')->artifacts()->download('KnpLabs', 'php-github-api', $artifactId, $format = 'zip'); +file_put_contents($artifactId.'.'.$format, $artifactFile); +``` diff --git a/doc/repo/actions/secrets.md b/doc/repo/actions/secrets.md new file mode 100644 index 00000000000..037409fd53e --- /dev/null +++ b/doc/repo/actions/secrets.md @@ -0,0 +1,54 @@ +## Repo / Secrets API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### List repository secrets + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-repository-secrets + +```php +$secrets = $client->api('repo')->secrets()->all('KnpLabs', 'php-github-api'); +``` + +### Get a repository secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-repository-secret + +```php +$secret = $client->api('repo')->secrets()->show('KnpLabs', 'php-github-api', $secretName); +``` + +### Create a repository secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-a-repository-secret + +```php +$client->api('repo')->secrets()->create('KnpLabs', 'php-github-api', $secretName, [ + 'encrypted_value' => $encryptedValue, +]); $client->api('repo')->secrets()->all(); +``` + +### Update a repository secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-a-repository-secret + +```php +$client->api('repo')->secrets()->update('KnpLabs', 'php-github-api', $secretName, [ + 'key_id' => $keyId, 'encrypted_value' => $encryptedValue, +]); +``` + +### Delete a repository secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-repository-secret + +```php +$client->api('repo')->secrets()->remove('KnpLabs', 'php-github-api', $secretName); +``` + +### Get a repository public key + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-repository-public-key + +```php +$publicKey = $client->api('repo')->secrets()->publicKey('KnpLabs', 'php-github-api'); +``` diff --git a/doc/repo/actions/self_hosted_runners.md b/doc/repo/actions/self_hosted_runners.md new file mode 100644 index 00000000000..1c09767d6cd --- /dev/null +++ b/doc/repo/actions/self_hosted_runners.md @@ -0,0 +1,35 @@ +## Repo / Self Hosted Runners API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +# List self-hosted runners for a repository + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-self-hosted-runners-for-a-repository + +```php +$runners = $client->api('repo')->selfHostedRunners()->all('KnpLabs', 'php-github-api'); +``` + +# Get a self-hosted runner for a repository + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-self-hosted-runner-for-a-repository + +```php +$runner = $client->api('repo')->selfHostedRunners()->show('KnpLabs', 'php-github-api', $runnerId); +``` + +# Delete a self-hosted runner from a repository + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-self-hosted-runner-from-a-repository + +```php +$client->api('repo')->selfHostedRunners()->remove('KnpLabs', 'php-github-api', $runnerId); +``` + +# List runner applications for a repository + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-runner-applications-for-a-repository + +```php +$applications = $client->api('repo')->selfHostedRunners()->applications('KnpLabs', 'php-github-api'); +``` + diff --git a/doc/repo/actions/workflow_jobs.md b/doc/repo/actions/workflow_jobs.md new file mode 100644 index 00000000000..151c59c5e95 --- /dev/null +++ b/doc/repo/actions/workflow_jobs.md @@ -0,0 +1,27 @@ +## Repo / Workflow Jobs API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### List jobs for a workflow run + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-jobs-for-a-workflow-run + +```php +$client->api('repo')->workflowJobs()->all('KnpLabs', 'php-github-api', $runId); +``` + +### Get a job for a workflow run + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-job-for-a-workflow-run + +```php +$job = $client->api('repo')->workflowJobs()->all('KnpLabs', 'php-github-api', $jobId); +``` + +### Download job logs for a workflow run + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-job-logs-for-a-workflow-run + +```php +$jobLogs = $client->api('repo')->workflowJobs()->downloadLogs('KnpLabs', 'php-github-api', $jobId); +file_put_contents('jobLogs.zip', $jobLogs); +``` diff --git a/doc/repo/actions/workflow_runs.md b/doc/repo/actions/workflow_runs.md new file mode 100644 index 00000000000..88c6da7c621 --- /dev/null +++ b/doc/repo/actions/workflow_runs.md @@ -0,0 +1,76 @@ +## Repo / Workflow Runs API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### List workflow runs for a repository + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs-for-a-repository + +```php +$workflowRuns = $client->api('repo')->workflowRuns()->all('KnpLabs', 'php-github-api'); +``` + +### List workflow runs + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs + +```php +$runs = $client->api('repo')->workflowRuns()->listRuns('KnpLabs', 'php-github-api', $workflowId); +``` + +### Get a workflow run + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-workflow-run + +```php +$workflowRun = $client->api('repo')->workflowRuns()->show('KnpLabs', 'php-github-api', $runId); +``` + +### Delete a workflow run + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-workflow-run + +```php +$client->api('repo')->workflowRuns()->remove('KnpLabs', 'php-github-api', $runId); +``` + +### Re-run a workflow + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#re-run-a-workflow + +```php +$client->api('repo')->workflowRuns()->rerun('KnpLabs', 'php-github-api', $runId); +``` + +### Cancel a workflow run + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#cancel-a-workflow-run + +```php +$client->api('repo')->workflowRuns()->cancel('KnpLabs', 'php-github-api', $runId); +``` + +### Get workflow run usage + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-workflow-run-usage + +```php +$workflowUsage = $client->api('repo')->workflowRuns()->usage('KnpLabs', 'php-github-api', $runId); +``` + +### Download workflow run logs + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-workflow-run-logs + +```php +$logs = $client->api('repo')->workflowRuns()->downloadLogs('KnpLabs', 'php-github-api', $runId); + +file_put_contents('logs.zip', $logs); +``` + +### Delete workflow run logs + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-workflow-run-logs + +```php +$client->api('repo')->workflowRuns()->deleteLogs('KnpLabs', 'php-github-api', $runId); +``` diff --git a/doc/repo/actions/workflows.md b/doc/repo/actions/workflows.md new file mode 100644 index 00000000000..d6689d90aa2 --- /dev/null +++ b/doc/repo/actions/workflows.md @@ -0,0 +1,26 @@ +## Repo / Workflows API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### List repository workflows + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-repository-workflows + +```php +$workflows = $client->api('repo')->workflows()->all('KnpLabs', 'php-github-api'); +``` + +### Get a workflow + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-workflow + +```php +$workflow = $client->api('repo')->workflows()->show('KnpLabs', 'php-github-api', $workflowId); +``` + +### Get workflow usage + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-workflow-usage + +```php +$usage = $client->api('repo')->workflows()->usage('KnpLabs', 'php-github-api', $workflowId); +``` diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 46dd975ca0a..be4df40ac25 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -2,6 +2,7 @@ namespace Github\Api; +use Github\Api\Organization\Actions\Secrets; use Github\Api\Organization\Hooks; use Github\Api\Organization\Members; use Github\Api\Organization\OutsideCollaborators; @@ -101,6 +102,14 @@ public function teams() return new Teams($this->client); } + /** + * @return Secrets + */ + public function secrets(): Secrets + { + return new Secrets($this->client); + } + /** * @return OutsideCollaborators */ diff --git a/lib/Github/Api/Organization/Actions/Secrets.php b/lib/Github/Api/Organization/Actions/Secrets.php new file mode 100644 index 00000000000..7a08212907f --- /dev/null +++ b/lib/Github/Api/Organization/Actions/Secrets.php @@ -0,0 +1,144 @@ +get('/orgs/'.rawurlencode($organization).'/actions/secrets'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-organization-secret + * + * @param string $organization + * @param string $secretName + * + * @return array|string + */ + public function show(string $organization, string $secretName) + { + return $this->get('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName)); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-an-organization-secret + * + * @param string $organization + * @param string $secretName + * @param array $parameters + * + * @return array|string + */ + public function create(string $organization, string $secretName, array $parameters = []) + { + return $this->put('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName), $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-an-organization-secret + * + * @param string $organization + * @param string $secretName + * @param array $parameters + * + * @return array|string + */ + public function update(string $organization, string $secretName, array $parameters = []) + { + return $this->put('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName), $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-an-organization-secret + * + * @param string $organization + * @param string $secretName + * + * @return array|string + */ + public function remove(string $organization, string $secretName) + { + return $this->delete('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName)); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-selected-repositories-for-an-organization-secret + * + * @param string $organization + * @param string $secretName + * + * @return array|string + */ + public function selectedRepositories(string $organization, string $secretName) + { + return $this->get('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName).'/repositories'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#set-selected-repositories-for-an-organization-secret + * + * @param string $organization + * @param string $secretName + * @param array $parameters + * + * @return array|string + */ + public function setSelectedRepositories(string $organization, string $secretName, array $parameters = []) + { + return $this->put('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName).'/repositories', $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#add-selected-repository-to-an-organization-secret + * + * @param string $organization + * @param string $repositoryId + * @param string $secretName + * + * @return array|string + */ + public function addSecret(string $organization, string $repositoryId, string $secretName) + { + return $this->put('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName).'/repositories/'.$repositoryId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#remove-selected-repository-from-an-organization-secret + * + * @param string $organization + * @param string $repositoryId + * @param string $secretName + * + * @return array|string + */ + public function removeSecret(string $organization, string $repositoryId, string $secretName) + { + return $this->delete('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName).'/repositories/'.$repositoryId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-organization-public-key + * + * @param string $organization + * + * @return array|string + */ + public function publicKey(string $organization) + { + return $this->get('/orgs/'.rawurlencode($organization).'/actions/secrets/secret-key'); + } +} diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 76bb1baa1c1..b9b02ea0b30 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -2,6 +2,12 @@ namespace Github\Api; +use Github\Api\Repository\Actions\Artifacts; +use Github\Api\Repository\Actions\Secrets; +use Github\Api\Repository\Actions\SelfHostedRunners; +use Github\Api\Repository\Actions\WorkflowJobs; +use Github\Api\Repository\Actions\WorkflowRuns; +use Github\Api\Repository\Actions\Workflows; use Github\Api\Repository\Checks; use Github\Api\Repository\Checks\CheckRuns; use Github\Api\Repository\Checks\CheckSuites; @@ -364,6 +370,54 @@ public function checkSuites(): CheckSuites return new CheckSuites($this->client); } + /** + * @link https://developer.github.com/v3/actions/artifacts/#artifacts + */ + public function artifacts(): Artifacts + { + return new Artifacts($this->client); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#workflows + */ + public function workflows(): Workflows + { + return new Workflows($this->client); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#workflow-runs + */ + public function workflowRuns(): WorkflowRuns + { + return new WorkflowRuns($this->client); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#workflow-jobs + */ + public function workflowJobs(): WorkflowJobs + { + return new WorkflowJobs($this->client); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#self-hosted-runners + */ + public function selfHostedRunners(): SelfHostedRunners + { + return new SelfHostedRunners($this->client); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#secrets + */ + public function secrets(): Secrets + { + return new Secrets($this->client); + } + /** * Manage the content of a repository. * diff --git a/lib/Github/Api/Repository/Actions/Artifacts.php b/lib/Github/Api/Repository/Actions/Artifacts.php new file mode 100644 index 00000000000..b81d560b00d --- /dev/null +++ b/lib/Github/Api/Repository/Actions/Artifacts.php @@ -0,0 +1,82 @@ +get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/artifacts', $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-run-artifacts + * + * @param string $username + * @param string $repository + * @param int $runId + * + * @return array + */ + public function runArtifacts(string $username, string $repository, int $runId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/artifacts'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-artifact + * + * @param string $username + * @param string $repository + * @param int $artifactId + * + * @return array + */ + public function show(string $username, string $repository, int $artifactId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/artifacts/'.$artifactId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-an-artifact + * + * @param string $username + * @param string $repository + * @param int $artifactId + * + * @return array + */ + public function remove(string $username, string $repository, int $artifactId) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/artifacts/'.$artifactId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-an-artifact + * + * @param string $username + * @param string $repository + * @param int $artifactId + * @param string $format + * + * @return array + */ + public function download(string $username, string $repository, int $artifactId, string $format = 'zip') + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/artifacts/'.$artifactId.'/'.$format); + } +} diff --git a/lib/Github/Api/Repository/Actions/Secrets.php b/lib/Github/Api/Repository/Actions/Secrets.php new file mode 100644 index 00000000000..4c38de203dc --- /dev/null +++ b/lib/Github/Api/Repository/Actions/Secrets.php @@ -0,0 +1,95 @@ +get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/secrets'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-repository-secret + * + * @param string $username + * @param string $repository + * @param string $secretName + * + * @return array|string + */ + public function show(string $username, string $repository, string $secretName) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/secrets/'.rawurlencode($secretName)); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-a-repository-secret + * + * @param string $username + * @param string $repository + * @param string $secretName + * @param array $parameters + * + * @return array|string + */ + public function create(string $username, string $repository, string $secretName, array $parameters = []) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/secrets/'.rawurlencode($secretName), $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-a-repository-secret + * + * @param string $username + * @param string $repository + * @param string $secretName + * @param array $parameters + * + * @return array|string + */ + public function update(string $username, string $repository, string $secretName, array $parameters = []) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/secrets/'.rawurlencode($secretName), $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-repository-secret + * + * @param string $username + * @param string $repository + * @param string $secretName + * + * @return array|string + */ + public function remove(string $username, string $repository, string $secretName) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/secrets/'.rawurlencode($secretName)); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-repository-public-key + * + * @param string $username + * @param string $repository + * + * @return array|string + */ + public function publicKey(string $username, string $repository) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/secrets/secret-key'); + } +} diff --git a/lib/Github/Api/Repository/Actions/SelfHostedRunners.php b/lib/Github/Api/Repository/Actions/SelfHostedRunners.php new file mode 100644 index 00000000000..4a20b1169bf --- /dev/null +++ b/lib/Github/Api/Repository/Actions/SelfHostedRunners.php @@ -0,0 +1,65 @@ +get('/repos/'.rawurlencode($username).'/'.rawurldecode($repository).'/actions/runners'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-self-hosted-runner-for-a-repository + * + * @param string $username + * @param string $repository + * @param int $runnerId + * + * @return array|string + */ + public function show(string $username, string $repository, int $runnerId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurldecode($repository).'/actions/runners/'.$runnerId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-self-hosted-runner-from-a-repository + * + * @param string $username + * @param string $repository + * @param int $runnerId + * + * @return array|string + */ + public function remove(string $username, string $repository, int $runnerId) + { + return $this->delete('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/actions/runners/'.$runnerId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-runner-applications-for-a-repository + * + * @param string $username + * @param string $repository + * + * @return array|string + */ + public function applications(string $username, string $repository) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runners/downloads'); + } +} diff --git a/lib/Github/Api/Repository/Actions/WorkflowJobs.php b/lib/Github/Api/Repository/Actions/WorkflowJobs.php new file mode 100644 index 00000000000..edcb806ee6c --- /dev/null +++ b/lib/Github/Api/Repository/Actions/WorkflowJobs.php @@ -0,0 +1,54 @@ +get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/jobs', $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-job-for-a-workflow-run + * + * @param string $username + * @param string $repository + * @param int $jobId + * + * @return array + */ + public function show(string $username, string $repository, int $jobId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/jobs/'.$jobId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-job-logs-for-a-workflow-run + * + * @param string $username + * @param string $repository + * @param int $jobId + * + * @return array + */ + public function downloadLogs(string $username, string $repository, int $jobId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/jobs/'.$jobId.'/logs'); + } +} diff --git a/lib/Github/Api/Repository/Actions/WorkflowRuns.php b/lib/Github/Api/Repository/Actions/WorkflowRuns.php new file mode 100644 index 00000000000..27213826207 --- /dev/null +++ b/lib/Github/Api/Repository/Actions/WorkflowRuns.php @@ -0,0 +1,139 @@ +get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs', $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs + * + * @param string $username + * @param string $repository + * @param string $workflowId + * @param array $parameters + * + * @return array + */ + public function listRuns(string $username, string $repository, string $workflowId, array $parameters = []) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/workflows/'.$workflowId.'/runs', $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-workflow-run + * + * @param string $username + * @param string $repository + * @param int $runId + * @param array $parameters + * + * @return array + */ + public function show(string $username, string $repository, int $runId, array $parameters = []) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId, $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-workflow-run + * + * @param string $username + * @param string $repository + * @param int $runId + * + * @return array|string + */ + public function remove(string $username, string $repository, int $runId) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#re-run-a-workflow + * + * @param string $username + * @param string $repository + * @param int $runId + * + * @return array + */ + public function rerun(string $username, string $repository, int $runId) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/rerun'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#cancel-a-workflow-run + * + * @param string $username + * @param string $repository + * @param int $runId + * + * @return array + */ + public function cancel(string $username, string $repository, int $runId) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/cancel'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-workflow-run-usage + * + * @param string $username + * @param string $repository + * @param int $runId + * + * @return array + */ + public function usage(string $username, string $repository, int $runId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/timing'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-workflow-run-logs + * + * @param string $username + * @param string $repository + * @param int $runId + * + * @return array|string + */ + public function downloadLogs(string $username, string $repository, int $runId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/logs'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-workflow-run-logs + * + * @param string $username + * @param string $repository + * @param int $runId + * + * @return array|string + */ + public function deleteLogs(string $username, string $repository, int $runId) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/logs'); + } +} diff --git a/lib/Github/Api/Repository/Actions/Workflows.php b/lib/Github/Api/Repository/Actions/Workflows.php new file mode 100644 index 00000000000..3843c59a0ba --- /dev/null +++ b/lib/Github/Api/Repository/Actions/Workflows.php @@ -0,0 +1,53 @@ +get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/workflows', $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-workflow + * + * @param string $username + * @param string $repository + * @param int $workflowId + * + * @return array + */ + public function show(string $username, string $repository, int $workflowId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/workflows/'.$workflowId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-workflow-usage + * + * @param string $username + * @param string $repository + * @param int $workflowId + * + * @return array|string + */ + public function usage(string $username, string $repository, int $workflowId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/workflows/'.$workflowId.'/timing'); + } +} diff --git a/test/Github/Tests/Api/Organization/Actions/SecretsTest.php b/test/Github/Tests/Api/Organization/Actions/SecretsTest.php new file mode 100644 index 00000000000..cf10c066c99 --- /dev/null +++ b/test/Github/Tests/Api/Organization/Actions/SecretsTest.php @@ -0,0 +1,219 @@ + 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at', 'visibility' => 'all'], + ['name' => 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at', 'visibility' => 'private'], + ['name' => 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at', 'visibility' => 'selected'], + ]; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/secrets') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs')); + } + + /** + * @test + */ + public function shouldGetOrganizationSecret() + { + $expectedArray = []; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/secrets/secretName') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 'secretName')); + } + + /** + * @test + */ + public function shouldCreateOrganizationSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/orgs/KnpLabs/actions/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'secretName', [ + 'encrypted_value' => 'foo', 'visibility' => 'all', 'selected_repository_ids' => [1, 2, 3], + ])); + } + + /** + * @test + */ + public function shouldUpdateOrganizationSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/orgs/KnpLabs/actions/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update('KnpLabs', 'secretName', [ + 'key_id' => 'keyId', + 'encrypted_value' => 'encryptedValue', + 'visibility' => 'private', + ])); + } + + /** + * @test + */ + public function shouldRemoveOrganizationSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/orgs/KnpLabs/actions/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'secretName')); + } + + /** + * @test + */ + public function shouldGetSelectedRepositories() + { + $expectedArray = [1, 2, 3]; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/secrets/secretName/repositories') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->selectedRepositories('KnpLabs', 'secretName')); + } + + /** + * @test + */ + public function shouldSetSelectedRepositories() + { + $expectedArray = [ + 'selected_repository_ids' => [1, 2, 3], + ]; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/orgs/KnpLabs/actions/secrets/secretName/repositories') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->setSelectedRepositories('KnpLabs', 'secretName', [ + 'selected_repository_ids' => [1, 2, 3], + ])); + } + + /** + * @test + */ + public function shouldAddSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/orgs/KnpLabs/actions/secrets/secretName/repositories/1') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->addSecret('KnpLabs', '1', 'secretName')); + } + + /** + * @test + */ + public function shouldRemoveSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/orgs/KnpLabs/actions/secrets/secretName/repositories/1') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removeSecret('KnpLabs', '1', 'secretName')); + } + + /** + * @test + */ + public function shouldGetPublicKey() + { + $expectedArray = ['key_id' => 'key_id', 'key' => 'foo']; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/secrets/secret-key') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->publicKey('KnpLabs')); + } + + protected function getApiClass() + { + return Secrets::class; + } +} diff --git a/test/Github/Tests/Api/Repository/Actions/ArtifactsTest.php b/test/Github/Tests/Api/Repository/Actions/ArtifactsTest.php new file mode 100644 index 00000000000..90ace988bab --- /dev/null +++ b/test/Github/Tests/Api/Repository/Actions/ArtifactsTest.php @@ -0,0 +1,96 @@ + 'id', + 'node_id' => 'node_id', + 'name' => 'name', + 'size_in_bytes' => 453, + 'url' => 'foo', + 'archive_download_url' => 'foo', + 'expired' => false, + 'created_at' => '2020-01-10T14:59:22Z', + 'expires_at' => '2020-01-21T14:59:22Z', + ], + ]; + + /** @var Artifacts|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/artifacts') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetRunArtifacts() + { + $expectedArray = [ + [ + 'id' => 'id', + 'node_id' => 'node_id', + 'name' => 'name', + 'size_in_bytes' => 453, + 'url' => 'foo', + 'archive_download_url' => 'foo', + 'expired' => false, + 'created_at' => '2020-01-10T14:59:22Z', + 'expires_at' => '2020-01-21T14:59:22Z', + ], + ]; + + /** @var Artifacts|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runs/1/artifacts') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->runArtifacts('KnpLabs', 'php-github-api', 1)); + } + + /** + * @test + */ + public function shouldRemoveArtifact() + { + $expectedValue = 'response'; + + /** @var Artifacts|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/actions/artifacts/1') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 1)); + } + + protected function getApiClass() + { + return Artifacts::class; + } +} diff --git a/test/Github/Tests/Api/Repository/Actions/SecretsTest.php b/test/Github/Tests/Api/Repository/Actions/SecretsTest.php new file mode 100644 index 00000000000..670e623b688 --- /dev/null +++ b/test/Github/Tests/Api/Repository/Actions/SecretsTest.php @@ -0,0 +1,136 @@ + 'GH_TOKEN', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ['name' => 'GIST_ID', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ]; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/secrets') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetSecret() + { + $expectedArray = ['name' => 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at']; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/secrets/secretName') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api', 'secretName')); + } + + /** + * @test + */ + public function shouldCreateSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/actions/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', 'secretName', [ + 'encrypted_value' => 'encryptedValue', + ])); + } + + /** + * @test + */ + public function shouldUpdateSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/actions/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 'secretName', [ + 'key_id' => 'keyId', 'encrypted_value' => 'encryptedValue', + ])); + } + + /** + * @test + */ + public function shouldRemoveSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/actions/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'secretName')); + } + + /** + * @test + */ + public function shouldGetPublicKey() + { + $expectedArray = ['key_id' => 'key_id', 'key' => 'foo']; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/secrets/secret-key') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->publicKey('KnpLabs', 'php-github-api')); + } + + protected function getApiClass() + { + return Secrets::class; + } +} diff --git a/test/Github/Tests/Api/Repository/Actions/SelfHostedRunnersTest.php b/test/Github/Tests/Api/Repository/Actions/SelfHostedRunnersTest.php new file mode 100644 index 00000000000..67c8eade4bd --- /dev/null +++ b/test/Github/Tests/Api/Repository/Actions/SelfHostedRunnersTest.php @@ -0,0 +1,115 @@ + 1, + 'name' => 'MBP', + 'os' => 'macos', + 'status' => 'online', + ], + [ + 'id' => 2, + 'name' => 'iMac', + 'os' => 'macos', + 'status' => 'offline', + ], + ]; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runners') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetSelfHostedRunner() + { + $expectedArray = [ + 'id' => 1, + 'name' => 'MBP', + 'os' => 'macos', + 'status' => 'online', + ]; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runners/1') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api', 1)); + } + + /** + * @test + */ + public function shouldRemoveSelfHostedRunner() + { + $expectedValue = 'response'; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/actions/runners/1') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 1)); + } + + /** + * @test + */ + public function shouldGetSelfHostedRunnerApps() + { + $expectedArray = [ + ['os' => 'osx', 'architecture' => 'x64', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'linux', 'architecture' => 'x64', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'linux', 'architecture' => 'arm', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'win', 'architecture' => 'x64', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'linux', 'architecture' => 'arm64', 'download_url' => 'download_url', 'filename' => 'filename'], + ]; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runners/downloads') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->applications('KnpLabs', 'php-github-api')); + } + + protected function getApiClass() + { + return SelfHostedRunners::class; + } +} diff --git a/test/Github/Tests/Api/Repository/Actions/WorkflowJobsTest.php b/test/Github/Tests/Api/Repository/Actions/WorkflowJobsTest.php new file mode 100644 index 00000000000..4af8b52ebc9 --- /dev/null +++ b/test/Github/Tests/Api/Repository/Actions/WorkflowJobsTest.php @@ -0,0 +1,57 @@ + 'id', 'run_id' => 'run_id', 'status' => 'completed', 'conclusion' => 'success'], + ]; + + /** @var WorkflowJobs|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runs/1/jobs') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs', 'php-github-api', 1)); + } + + /** + * @test + */ + public function shouldShowWorkflowJob() + { + $expectedArray = [ + 'id' => 'id', 'run_id' => 'run_id', 'status' => 'completed', 'conclusion' => 'success', + ]; + + /** @var WorkflowJobs|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/jobs/1') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api', 1)); + } + + protected function getApiClass() + { + return WorkflowJobs::class; + } +} diff --git a/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php b/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php new file mode 100644 index 00000000000..27155148ce0 --- /dev/null +++ b/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php @@ -0,0 +1,205 @@ + 'id', + 'event' => 'push', + 'status' => 'queued', + ], + ]; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runs') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetWorkflowRuns() + { + $expectedArray = [ + [ + 'id' => 'id', + 'name' => 'CI', + 'event' => 'push', + 'status' => 'completed', + 'conclusion' => 'success', + 'workflow_id' => 3441570, + ], + ]; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/workflows/3441570/runs') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->listRuns('KnpLabs', 'php-github-api', 3441570)); + } + + /** + * @test + */ + public function shouldShowWorkflowRun() + { + $expectedArray = ['id' => 'id', 'name' => 'CI']; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api', 374473304)); + } + + /** + * @test + */ + public function shouldDeleteWorkflowRun() + { + $expectedValue = 'response'; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 374473304)); + } + + /** + * @test + */ + public function shouldGetWorkflowRunUsage() + { + $expectedArray = [ + 'billable' => [ + 'UBUNTU' => ['total_ms' => 180000, 'jobs' => 1], + 'MACOS' => ['total_ms' => 240000, 'jobs' => 1], + 'WINDOWS' => ['total_ms' => 300000, 'jobs' => 1], + ], + 'run_duration_ms' => 500000, + ]; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304/timing') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->usage('KnpLabs', 'php-github-api', 374473304)); + } + + /** + * @test + */ + public function shouldRerunWorkflowRun() + { + $expectedValue = 'response'; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304/rerun') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->rerun('KnpLabs', 'php-github-api', 374473304)); + } + + /** + * @test + */ + public function shouldCancelWorkflowRun() + { + $expectedValue = 'response'; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304/cancel') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->cancel('KnpLabs', 'php-github-api', 374473304)); + } + + /** + * @test + */ + public function shouldDownloadWorkflowRunLogs() + { + $expectedValue = 'response'; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304/logs') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->downloadLogs('KnpLabs', 'php-github-api', 374473304)); + } + + /** + * @test + */ + public function shouldDeleteWorkflowRunLogs() + { + $expectedValue = 'response'; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304/logs') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->deleteLogs('KnpLabs', 'php-github-api', 374473304)); + } + + protected function getApiClass() + { + return WorkflowRuns::class; + } +} diff --git a/test/Github/Tests/Api/Repository/Actions/WorkflowsTest.php b/test/Github/Tests/Api/Repository/Actions/WorkflowsTest.php new file mode 100644 index 00000000000..a018f396531 --- /dev/null +++ b/test/Github/Tests/Api/Repository/Actions/WorkflowsTest.php @@ -0,0 +1,96 @@ + 'id', + 'node_id' => 'node_id', + 'name' => 'CI', + 'path' => '.github/workflows/ci.yml', + 'state' => 'active', + 'created_at' => '2020-11-07T15:09:45.000Z', + 'updated_at' => '2020-11-07T15:09:45.000Z', + ], + ]; + + /** @var Workflows|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/workflows') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldShowWorkflow() + { + $expectedArray = [ + 'id' => 'id', + 'node_id' => 'node_id', + 'name' => 'CI', + 'path' => '.github/workflows/ci.yml', + 'state' => 'active', + 'created_at' => '2020-11-07T15:09:45.000Z', + 'updated_at' => '2020-11-07T15:09:45.000Z', + ]; + + /** @var Workflows|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/workflows/1') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api', 1)); + } + + /** + * @test + */ + public function shouldGetWorkflowUsage() + { + $expectedArray = [ + 'billable' => [ + 'UBUNTU' => ['total_ms' => 180000, 'jobs' => 1], + 'MACOS' => ['total_ms' => 240000, 'jobs' => 1], + 'WINDOWS' => ['total_ms' => 300000, 'jobs' => 1], + ], + ]; + + /** @var Workflows|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/workflows/1/timing') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->usage('KnpLabs', 'php-github-api', 1)); + } + + protected function getApiClass() + { + return Workflows::class; + } +}