diff --git a/README.md b/README.md index 5ee36d1..2bf8af4 100644 --- a/README.md +++ b/README.md @@ -60,14 +60,14 @@ composer require bbaga/buildkite-php ### Setting up the API objects -`\Psr\Http\Client\ClientInterface` implementation is available in the [`bbaga/buildkite-php-guzzle-client`](https://github.com/bbaga/buildkite-php-guzzle-client) package. +`\GuzzleHttp\Client()` is available in the `guzzlehttp/guzzle` package #### Rest API ```php use bbaga\BuildkiteApi\Api\RestApi; /** @var \Psr\Http\Client\ClientInterface $client */ -$client = new MyHttpClient(); +$client = new \GuzzleHttp\Client(); $api = new RestApi($client, 'MY_BUILDKITE_API_TOKEN'); ``` @@ -77,7 +77,7 @@ $api = new RestApi($client, 'MY_BUILDKITE_API_TOKEN'); use bbaga\BuildkiteApi\Api\GraphQLApi; /** @var \Psr\Http\Client\ClientInterface $client */ -$client = new MyHttpClient(); +$client = new \GuzzleHttp\Client(); $api = new GraphQLApi($client, 'MY_BUILDKITE_API_TOKEN'); ``` @@ -85,7 +85,6 @@ $api = new GraphQLApi($client, 'MY_BUILDKITE_API_TOKEN'); ### Interacting with Buildkite's GraphQL API ```php use bbaga\BuildkiteApi\Api\GraphQLApi; -use bbaga\BuildkiteApi\Api\GuzzleClient; $query = ' query example($slug: ID!, $first: Int){ @@ -105,7 +104,7 @@ $query = ' $variables = json_encode(['slug' => 'my-org', 'first' => 5]); -$client = new GuzzleClient(); +$client = new \GuzzleHttp\Client(); $api = new GraphQLApi($client, 'MY_BUILDKITE_API_TOKEN'); $api->getResponseBody($api->post($query, $variables)); @@ -115,11 +114,10 @@ $api->getResponseBody($api->post($query, $variables)); #### Example of traversing through resources ```php -use bbaga\BuildkiteApi\Api\GuzzleClient; use bbaga\BuildkiteApi\Api\Rest\Fluent; use bbaga\BuildkiteApi\Api\RestApi; -$client = new GuzzleClient(); +$client = new \GuzzleHttp\Client(); $api = new RestApi($client, 'MY_BUILDKITE_API_TOKEN'); /** Getting all the organizations that are visible with the TOKEN */ @@ -156,11 +154,10 @@ $agents = $organizations[0]->getAgents(); Fetching data for a specific build without traversing through the hierarchy. ```php -use bbaga\BuildkiteApi\Api\GuzzleClient; use bbaga\BuildkiteApi\Api\Rest\Fluent; use bbaga\BuildkiteApi\Api\RestApi; -$client = new GuzzleClient(); +$client = new \GuzzleHttp\Client(); $api = new RestApi($client, 'MY_BUILDKITE_API_TOKEN'); /** @@ -180,11 +177,10 @@ $build->fetch()->getJobs(); #### Creating a new pipeline ```php -use bbaga\BuildkiteApi\Api\GuzzleClient; use bbaga\BuildkiteApi\Api\Rest\Fluent; use bbaga\BuildkiteApi\Api\RestApi; -$client = new GuzzleClient(); +$client = new \GuzzleHttp\Client(); $api = new RestApi($client, 'MY_BUILDKITE_API_TOKEN'); $organization = new Fluent\Organization($api, ['slug' => 'my-org']); diff --git a/composer.json b/composer.json index 598e608..8cd4b01 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "vimeo/psalm": "^3.11", "psalm/plugin-phpunit": "^0.10.0", "symplify/easy-coding-standard": "^7.2", - "bbaga/buildkite-php-guzzle-client": "^2.0" + "guzzlehttp/guzzle": "^7.1" }, "scripts": { "ecs-fix": { @@ -54,6 +54,6 @@ } }, "suggest": { - "bbaga/buildkite-php-guzzle-client": "Provides basic, off the shelf http client implementation" + "guzzlehttp/guzzle": "Provides PSR-18 HTTP Client implementation" } } diff --git a/test b/test new file mode 100755 index 0000000..5200f93 --- /dev/null +++ b/test @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +RESULT=$(curl -X POST "https://api.buildkite.com/v2/organizations/${ORG_SLUG}/pipelines" \ + -H "Authorization: Bearer ${TOKEN}" \ + -d '{ + "name": "My Pipeline", + "repository": "git@github.com:acme-inc/my-pipeline.git", + "steps": [ + { + "type": "script", + "name": "Test :package:", + "command": "script/Test.sh" + }, + { + "type": "waiter" + }, + { + "type": "script", + "name": "Test :package:", + "command": "script/Test.sh" + } + ] + }') + +PIPELINE_SLUG=$(echo $RESULT | jq '.slug' -r) + +curl -X POST "https://api.buildkite.com/v2/organizations/${ORG_SLUG}/pipelines/${PIPELINE_SLUG}/builds" \ + -H "Authorization: Bearer ${TOKEN}" \ + -d '{ + "commit": "abcd0b72a1e580e90712cdd9eb26d3fb41cd09c8", + "branch": "master", + "message": "Testing all the things :rocket:", + "author": { + "name": "Keith Pitt", + "email": "me@keithpitt.com" + }, + "env": { + "MY_ENV_VAR": "some_value" + }, + "meta_data": { + "some build data": "value", + "other build data": true + } + }' + +curl -X DELETE "https://api.buildkite.com/v2/organizations/${ORG_SLUG}/pipelines/${PIPELINE_SLUG}" \ + -H "Authorization: Bearer ${TOKEN}" diff --git a/tests/Integration/Api/Rest/AbstractTestCase.php b/tests/Integration/Api/Rest/AbstractTestCase.php index 983cfc0..91a2824 100644 --- a/tests/Integration/Api/Rest/AbstractTestCase.php +++ b/tests/Integration/Api/Rest/AbstractTestCase.php @@ -4,8 +4,8 @@ namespace bbaga\BuildkiteApi\Tests\Integration\Api\Rest; -use bbaga\BuildkiteApi\Api\GuzzleClient; use bbaga\BuildkiteApi\Api\RestApi; +use GuzzleHttp\Client; use PHPUnit\Framework\TestCase; abstract class AbstractTestCase extends TestCase @@ -32,7 +32,7 @@ public function setUp(): void $token = (string) getenv('BK_TEST_TOKEN'); $this->prefix = (string) getenv('BK_TEST_PREFIX'); $this->organizationSlug = (string) getenv('BK_TEST_ORG'); - $this->api = new RestApi(new GuzzleClient(), $token); + $this->api = new RestApi(new Client(), $token); } protected function slugify(string $name): string diff --git a/tests/Integration/Api/Rest/Fluent/BuildRelatedTest.php b/tests/Integration/Api/Rest/Fluent/BuildRelatedTest.php index e815617..9263538 100644 --- a/tests/Integration/Api/Rest/Fluent/BuildRelatedTest.php +++ b/tests/Integration/Api/Rest/Fluent/BuildRelatedTest.php @@ -98,7 +98,7 @@ public function testBuildRelatedFunctions(): void $timeoutCounter = 0; do { - if (++$timeoutCounter > 120) { + if ($timeoutCounter++ > 120) { throw new \RuntimeException('Build did not finish in time'); }