Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
```
Expand All @@ -77,15 +77,14 @@ $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');
```

### Interacting with Buildkite's GraphQL API
```php
use bbaga\BuildkiteApi\Api\GraphQLApi;
use bbaga\BuildkiteApi\Api\GuzzleClient;

$query = '
query example($slug: ID!, $first: Int){
Expand All @@ -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));
Expand All @@ -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 */
Expand Down Expand Up @@ -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');

/**
Expand All @@ -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']);
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
}
47 changes: 47 additions & 0 deletions test
Original file line number Diff line number Diff line change
@@ -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}"
4 changes: 2 additions & 2 deletions tests/Integration/Api/Rest/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Api/Rest/Fluent/BuildRelatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down