Skip to content
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

Updates deploy to build API #454

Merged
merged 15 commits into from
Jan 18, 2018
Merged

Updates deploy to build API #454

merged 15 commits into from
Jan 18, 2018

Conversation

Cawllec
Copy link
Contributor

@Cawllec Cawllec commented Jan 10, 2018

Updates to the new Bugsnag build API.

  • Adds build method to client to send build information off to bugsnag
  • Points clients deploy method to build method
  • Maintains old deploy method in HTTP client unchanged
  • Adds new sendBuildReport to HTTP client to handle new API calls.
  • Adds setBuildEndpoint and getBuildEndpoint to configuration, with a default.

@Cawllec Cawllec requested a review from kattrali January 10, 2018 15:56
src/Client.php Outdated
@@ -309,7 +309,7 @@ public function notify(Report $report, callable $callback = null)
}

/**
* Notify Bugsnag of a deployment.
* Notify Bugsnag of a deployment. This function is being deprecated in favour of `build`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Add the @deprecated annotation at the beginning of this line. Then it will also be picked up by API documentation/linting.

@@ -71,6 +71,7 @@ public function queue(Report $report)

/**
* Notify Bugsnag of a deployment.
* This method should no longer be used in favour of sendBuildReport.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, add @deprecated

$this->client->build('baz', 'foo', 'github', 'me');
}

public function testBuildAutoDetectsProvider()
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be tests for the other providers as well

$sourceControl['provider'] = $buildInfo['provider'];
} elseif (isset($buildInfo['repository'])) {
$url = $buildInfo['repository'];
if (strpos($url, 'github.com') != false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You dont need to do this. Provider is optional

Copy link
Contributor

Choose a reason for hiding this comment

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

Every field is optional though. Are we using this field for something?

Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldnt automatically set this in any of our sdks. This logic of guessing the provider is on the server (and therefore is easier to update).

The user needs to be able to set it for when they are using an on-premise installation of github and the repository URL isnt the github.com one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It gives us the extra data they may not set otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, ok, didn't see this.

}

if (isset($buildInfo['buildTool'])) {
$data['buildTool'] = $buildInfo['buildTool'];
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldnt be able to externally set this

Copy link
Contributor

Choose a reason for hiding this comment

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

Its settable for laravel to override

Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think we care about php/laravel distinction at an analytics level. We just care that this lib is being used for deploys.

}

if (isset($buildInfo['builder'])) {
$data['builderName'] = $buildInfo['builder'];
Copy link
Contributor

Choose a reason for hiding this comment

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

This should default to whoami or a php cross platform equivalent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we want to add shell calls in the base notifier, it's much safer to use wrapped commands in higher level libs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not? If this isnt automated very few people will set it.

Copy link
Contributor

Choose a reason for hiding this comment

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

You probably want:

get_current_user();

instead of shell executing whoami. That function will give you the owner of the file, which is maybe better than nothing.

Something you could do if the user has installed and not disabled the functions from posix extension, is:

posix_getpwuid(posix_geteuid())['name'];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoami works across all windows post server-2003 & unix-like systems. I'll add a check on the response to see if it returned correctly and fallback to get_current_user if not.

if (isset($buildInfo['builder'])) {
$data['builderName'] = $buildInfo['builder'];
} else {
$data['builderName'] = exec('whoami');
Copy link
Contributor

Choose a reason for hiding this comment

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

You should check if this function has been disabled, otherwise it'll crash. Many web hosts disable this by default for security.

}

if (isset($buildInfo['builder'])) {
$data['builderName'] = $buildInfo['builder'];
Copy link
Contributor

Choose a reason for hiding this comment

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

You probably want:

get_current_user();

instead of shell executing whoami. That function will give you the owner of the file, which is maybe better than nothing.

Something you could do if the user has installed and not disabled the functions from posix extension, is:

posix_getpwuid(posix_geteuid())['name'];

@jbrooksuk
Copy link

I was just looking for this and was about to contribute it. Is there any chance we can see this get merged and released soon?

@Cawllec
Copy link
Contributor Author

Cawllec commented Jan 16, 2018

Yeah, i'll get this released this afternoon if possible.

@jbrooksuk
Copy link

Awesome, thanks @Cawllec!

@kattrali kattrali dismissed GrahamCampbell’s stale review January 18, 2018 22:34

adjustments made to fallback to get_file_owner

@kattrali kattrali merged commit 4c66b9a into master Jan 18, 2018
@kattrali kattrali deleted the cawllec/update-build-api branch January 18, 2018 22:35
@imjoehaines imjoehaines mentioned this pull request Jun 4, 2020
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants