Skip to content

Decouple from Buzz #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2017
Merged

Decouple from Buzz #191

merged 1 commit into from
Jul 7, 2017

Conversation

fbourigault
Copy link
Contributor

@fbourigault fbourigault commented Jun 2, 2017

As discussed in #171 this replace the buzz client by httplug.

I tried to implement this as it was done by @Nyholm for https://github.com/KnpLabs/php-github-api. This remove all the HttpClient stuff which was built on the top of Buzz. Instead it use Httplug standard plugins with a few custom ones for error handling and authentication.

I set PHP required version to 5.6+ as discussed in #171.

This IS a breaking change.

To do

Copy link

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work. I really like it. I only had one small comment.

You may also want to consider creating a factory function like: https://github.com/FriendsOfApi/boilerplate/blob/master/src/ApiClient.php#L78-L83

@@ -1,6 +1,11 @@
<?php namespace Gitlab\Api;

use Gitlab\Client;
use Gitlab\HttpClient\Message\ResponseMediator;
use function GuzzleHttp\Psr7\stream_for;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to remove this line. It will couple us to Guzzle. You should use the StreamFactoryDiscovery instead.

@m1guelpf m1guelpf mentioned this pull request Jun 5, 2017
@fbourigault fbourigault added this to the v4 milestone Jun 6, 2017
@fbourigault
Copy link
Contributor Author

@Nyholm I fixed the StreamFactory related issue. About the factory function, as there is many authentication methods, I don't know which one I should promote over the others.

I also added tests on some new classes, improved the Gitlab\Client code to limit the amount of breaking changes. I re-introduced the user-agent with a getter and a setter instead of the options array.

ResultPager is now fixed, but still waiting for unit tests.

@fbourigault fbourigault mentioned this pull request Jun 6, 2017
Copy link

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. I like it 👍

'user_agent' => 'php-gitlab-api (http://github.com/m4tthumphrey/php-gitlab-api)',
'timeout' => 60
);
private $userAgent = 'php-gitlab-api (http://github.com/m4tthumphrey/php-gitlab-api)';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this in a property? We never read from it (as I can see)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users where able to read it through getOption('user_agent'). I added it to limit the breaking changes surface.

@fbourigault
Copy link
Contributor Author

I removed useless methods kept to limit breaking changes.
I documented the breaking changes in UPGRADE.md and also updated README.md.

@fbourigault
Copy link
Contributor Author

ResultPager is currently broken. Waiting for php-http/client-common#74 and a release.

@fbourigault fbourigault changed the title [WIP] Decouple for Buzz [WIP] Decouple from Buzz Jun 10, 2017
@fbourigault
Copy link
Contributor Author

I no longer require php-http/client-common#74. I ended with a ApiVersion plugin which add the /api/v3/ part when required.

This PR is definitively ready for review.

@fbourigault fbourigault changed the title [WIP] Decouple from Buzz Decouple from Buzz Jun 12, 2017
@m1guelpf
Copy link
Member

ping @m4tthumphrey

Copy link

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. I approve this. I just added some small comments and suggestions.

README.md Outdated

3. Include Composer's autoloader:
```bash
composer require m4tthumphrey/php-gitlab-api php-http/guzzle6-adapter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add php-http/message here. We could also add a link to http://docs.php-http.org/en/latest/httplug/users.html

Copy link
Contributor Author

@fbourigault fbourigault Jun 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using php-http/guzzle6-adapter, there is no need for php-http/message, right?

EDIT: php-http/message is a php-http/client-common dependency.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, okey.

*
* @return Client
*/
public static function createWithHttpClient(HttpClient $httpClient)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I know I asked before. Maybe create a factory function for URL?

Client::create($url)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks interesting as many companies/users run their own GitLab instance.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, exactly.

$client = new \Gitlab\Client();
$client->setUrl('http://git.yourdomain.com');

// Could be the same as
$client = Gitlab\Client::create('http://git.yourdomain.com');

*/
public function getOption($name)
public function __get($api)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, mailgun/mailgun-php#192 (comment)

We decided to remove it in Mailgun api

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humm. This should not be in the diff. I will give it a look. Moreover, I also prefer writing methods and remove the magic method and huge comment in the top of the file. It's the same amount of work!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this will be part of an other PR.

{
$uri = $request->getUri();

if (substr($uri->getPath(), 0, 8) !== '/api/v3/') {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, But what if there get new endpoints with /api/v4/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no plans to support multiple versions in a single release. V3 api will be discontinued in august, so the plan is to replace this by v4.

@fbourigault
Copy link
Contributor Author

What about removing Client::setUserAgent and documenting how to customize it like https://github.com/KnpLabs/php-github-api/blob/master/doc/customize.md#configure-the-http-client?

@Nyholm
Copy link

Nyholm commented Jun 13, 2017

👍

@fbourigault
Copy link
Contributor Author

As we are breaking, I cleaned a bit more the Gitlab\Client public API. I will update UPGRADE.md and add a doc/customize.md to document how to set the client timeout, how to customize the user-agent and how to add custom headers.

@fbourigault
Copy link
Contributor Author

Documentation is now up-to-date.

@m1guelpf
Copy link
Member

@fbourigault Is this ready now?

@fbourigault
Copy link
Contributor Author

Yes! I will change things only if a reviewer can convince me to do so!

Copy link

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good.
I've made some comments. I am really picky now. This PR is good to merge without them.

UPGRADE.md Outdated

## `Gitlab\Client` changes

* The constructor no longer allow to specify base url. Use `setUrl` instead.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use setUrl or Client::create instead.


$this->httpClientBuilder->addPlugin(new GitlabExceptionThrower());
$this->httpClientBuilder->addPlugin(new HistoryPlugin($this->responseHistory));
$this->httpClientBuilder->addPlugin(new RedirectPlugin());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this?

namespace Gitlab\HttpClient\Message;

use Psr\Http\Message\ResponseInterface;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a class comment?

@fbourigault
Copy link
Contributor Author

@m4tthumphrey, do you agree with these changes?

@moufmouf moufmouf mentioned this pull request Jun 19, 2017
@fbourigault
Copy link
Contributor Author

Is it ok if I move forward with next release and merge this PR by the end of this week? ping @m4tthumphrey @jubianchi @radutopala

@fbourigault
Copy link
Contributor Author

@fbourigault fbourigault merged commit 0a46ae1 into GitLabPHP:master Jul 7, 2017
@fbourigault fbourigault deleted the httplug branch July 7, 2017 08:52
@m1guelpf
Copy link
Member

m1guelpf commented Jul 7, 2017

@fbourigault Did you tag a new release?

@fbourigault
Copy link
Contributor Author

Not yet, we have to make the library v4 only.

@m1guelpf
Copy link
Member

m1guelpf commented Jul 7, 2017

@fbourigault Do you have a task list/milestone?

@fbourigault
Copy link
Contributor Author

I will post a task list today with some "instructions" to be efficient.

@m1guelpf
Copy link
Member

m1guelpf commented Jul 7, 2017

@fbourigault Please ping me then 😄

@m4tthumphrey
Copy link
Contributor

Amazing @fbourigault! Top work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants