Skip to content

Commit

Permalink
Merge master into prod, release: v1.1.36
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorbenei committed Nov 17, 2017
2 parents c3bba98 + 085c1b2 commit d03255a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,16 @@ response provider will be used.
and `"failed_responses": []` JSON arrays
* And all the errors (where the response was not available / call timed out, etc.)
as a `"errors": []` JSON array (if any)
* If at least one call fails or the response is an error response
the HTTP status code will be `400`
* If at least one call fails:
* In case the error is not an internal error, nor an authorization or any other system error,
just the build could not be started (e.g. Trigger Map doesn't have any mapping for the trigger),
then the response code with be `200`. This is to prevent services to "disable" the Webhook,
as most of the git hosting services auto-disable webhooks if too many / too frequent non `2xx`
responses received.
* On the other hand, if it's a system error (e.g. an internal error or an authentication error)
then of course the webhook server will not return a `2xx` (success) code,
but instead it'll return a `400` error with as much details in the response about the
error as the server can determine.
* If all trigger calls succeed the status code will be `201`
* If the provider declares that it does not want to wait for the Trigger API response,
then a response will be returned immediately after triggering a build (calling the Trigger API),
Expand Down
4 changes: 4 additions & 0 deletions bitriseapi/bitriseapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ func TriggerBuild(url *url.URL, apiToken string, params TriggerAPIParamsModel, i
return TriggerAPIResponseModel{}, false, errors.Wrapf(err, "TriggerBuild: request sent, but failed to parse response (http-code:%d)", resp.StatusCode)
}

if respModel.Status == "" && respModel.Message == "" {
respModel.Message = string(body)
}

if 200 <= resp.StatusCode && resp.StatusCode <= 202 {
return respModel, true, nil
}
Expand Down
19 changes: 18 additions & 1 deletion service/hook/common/default_response_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,18 @@ func (hp DefaultResponseProvider) TransformResponse(input TransformResponseInput
httpStatusCode = 200
}

if len(input.Errors) > 0 || len(input.FailedTriggerResponses) > 0 {
if len(input.Errors) > 0 {
httpStatusCode = 400
}

if len(input.FailedTriggerResponses) > 0 {
if hp.knownError(input) {
httpStatusCode = 200
} else {
httpStatusCode = 400
}
}

return TransformResponseModel{
Data: DefaultTransformResponseModel{
Errors: input.Errors,
Expand Down Expand Up @@ -70,3 +78,12 @@ func (hp DefaultResponseProvider) TransformSuccessMessageResponse(msg string) Tr
HTTPStatusCode: 200,
}
}

func (hp DefaultResponseProvider) knownError(input TransformResponseInputModel) bool {
for _, response := range input.FailedTriggerResponses {
if response.Status != "error" {
return false
}
}
return true
}
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package version

// VERSION ...
const VERSION = "1.1.35"
const VERSION = "1.1.36"

0 comments on commit d03255a

Please sign in to comment.