-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge master into prod, release: v1.1.29
- Loading branch information
Showing
10 changed files
with
353 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,8 @@ import ( | |
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/bitrise-io/bitrise-webhooks/bitriseapi" | ||
"github.com/stretchr/testify/require" | ||
"io/ioutil" | ||
"strings" | ||
) | ||
|
@@ -14,7 +14,7 @@ func Test_detectContentType(t *testing.T) { | |
t.Log("Push event - should handle") | ||
{ | ||
header := http.Header{ | ||
"Content-Type": {"application/json"}, | ||
"Content-Type": {"application/json"}, | ||
} | ||
contentType, err := detectContentType(header) | ||
require.NoError(t, err) | ||
|
@@ -27,20 +27,20 @@ func Test_transformPushEvent(t *testing.T) { | |
{ | ||
pushEvent := PushEventModel{ | ||
SpaceEventModel: SpaceEventModel{ | ||
Space: "Space name", | ||
Space: "Space name", | ||
Action: "committed", | ||
Object: "Changeset", | ||
}, | ||
MessageEventModel: MessageEventModel{ | ||
Title: "1 commits [branchname]", | ||
Body: "ErikPoort pushed 1 commits [branchname]\n", | ||
Title: "1 commits [branchname]", | ||
Body: "ErikPoort pushed 1 commits [branchname]\n", | ||
Author: "ErikPoort", | ||
}, | ||
GitEventModel: GitEventModel{ | ||
RepositorySuffix: "origin", | ||
RepositoryURL: "[email protected]:username/project.git", | ||
Branch: "branchname", | ||
CommitID: "sha1chars11", | ||
RepositoryURL: "[email protected]:username/project.git", | ||
Branch: "branchname", | ||
CommitID: "sha1chars11", | ||
}, | ||
} | ||
|
||
|
@@ -71,20 +71,20 @@ func Test_incorrectPostOptions(t *testing.T) { | |
{ | ||
pushEvent := PushEventModel{ | ||
SpaceEventModel: SpaceEventModel{ | ||
Space: "Space name", | ||
Space: "Space name", | ||
Action: "committed", | ||
Object: "Changeset", | ||
}, | ||
MessageEventModel: MessageEventModel{ | ||
Title: "1 commits [branchname]", | ||
Body: "ErikPoort pushed 1 commits [branchname]\n", | ||
Title: "1 commits [branchname]", | ||
Body: "ErikPoort pushed 1 commits [branchname]\n", | ||
Author: "ErikPoort", | ||
}, | ||
GitEventModel: GitEventModel{ | ||
RepositorySuffix: "---", | ||
RepositoryURL: "---", | ||
Branch: "---", | ||
CommitID: "---", | ||
RepositoryURL: "---", | ||
Branch: "---", | ||
CommitID: "---", | ||
}, | ||
} | ||
|
||
|
@@ -101,20 +101,20 @@ func Test_emptyGitEventOptions(t *testing.T) { | |
{ | ||
pushEvent := PushEventModel{ | ||
SpaceEventModel: SpaceEventModel{ | ||
Space: "Space name", | ||
Space: "Space name", | ||
Action: "committed", | ||
Object: "Changeset", | ||
}, | ||
MessageEventModel: MessageEventModel{ | ||
Title: "1 commits [branchname]", | ||
Body: "ErikPoort pushed 1 commits [branchname]\n", | ||
Title: "1 commits [branchname]", | ||
Body: "ErikPoort pushed 1 commits [branchname]\n", | ||
Author: "ErikPoort", | ||
}, | ||
GitEventModel: GitEventModel{ | ||
RepositorySuffix: "", | ||
RepositoryURL: "", | ||
Branch: "", | ||
CommitID: "", | ||
RepositoryURL: "", | ||
Branch: "", | ||
CommitID: "", | ||
}, | ||
} | ||
|
||
|
@@ -172,7 +172,7 @@ func Test_HookProvider_TransformRequest(t *testing.T) { | |
{ | ||
request := http.Request{ | ||
Header: http.Header{ | ||
"Content-Type": {"not/supported"}, | ||
"Content-Type": {"not/supported"}, | ||
}, | ||
} | ||
hookTransformResult := provider.TransformRequest(&request) | ||
|
@@ -184,7 +184,7 @@ func Test_HookProvider_TransformRequest(t *testing.T) { | |
{ | ||
request := http.Request{ | ||
Header: http.Header{ | ||
"Content-Type": {"application/json"}, | ||
"Content-Type": {"application/json"}, | ||
}, | ||
} | ||
hookTransformResult := provider.TransformRequest(&request) | ||
|
@@ -196,7 +196,7 @@ func Test_HookProvider_TransformRequest(t *testing.T) { | |
{ | ||
request := http.Request{ | ||
Header: http.Header{ | ||
"Content-Type": {"application/json"}, | ||
"Content-Type": {"application/json"}, | ||
}, | ||
Body: ioutil.NopCloser(strings.NewReader(sampleCodePushData)), | ||
} | ||
|
@@ -224,11 +224,11 @@ func Test_IncorrectJSONData(t *testing.T) { | |
{ | ||
request := http.Request{ | ||
Header: http.Header{ | ||
"Content-Type": {"application/json"}, | ||
"Content-Type": {"application/json"}, | ||
}, | ||
Body: ioutil.NopCloser(strings.NewReader(sampleIncorrectJSONData)), | ||
} | ||
hookTransformResult := provider.TransformRequest(&request) | ||
require.Error(t, hookTransformResult.Error) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package passthrough | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
|
||
"github.com/bitrise-io/bitrise-webhooks/bitriseapi" | ||
hookCommon "github.com/bitrise-io/bitrise-webhooks/service/hook/common" | ||
) | ||
|
||
const ( | ||
envKeyHeaders = `BITRISE_WEBHOOK_PASSTHROUGH_HEADERS` | ||
maxHeaderSizeBytes = 10 * 1024 | ||
envKeyBody = `BITRISE_WEBHOOK_PASSTHROUGH_BODY` | ||
maxBodySizeBytes = 10 * 1024 | ||
) | ||
|
||
// HookProvider ... | ||
type HookProvider struct{} | ||
|
||
// TransformRequest ... | ||
func (hp HookProvider) TransformRequest(r *http.Request) hookCommon.TransformResultModel { | ||
headerAsJSON := []byte{} | ||
if r.Header != nil { | ||
b, err := json.Marshal(r.Header) | ||
if err != nil { | ||
return hookCommon.TransformResultModel{Error: fmt.Errorf("Failed to JSON serialize request headers: %s", err)} | ||
} | ||
headerAsJSON = b | ||
} | ||
if len(headerAsJSON) > maxHeaderSizeBytes { | ||
return hookCommon.TransformResultModel{Error: fmt.Errorf("Headers too large, larger than %d bytes", maxHeaderSizeBytes)} | ||
} | ||
|
||
bodyBytes := []byte{} | ||
if r.Body != nil { | ||
b, err := ioutil.ReadAll(r.Body) | ||
if err != nil { | ||
return hookCommon.TransformResultModel{Error: fmt.Errorf("Failed to get request body: %s", err)} | ||
} | ||
bodyBytes = b | ||
} | ||
if len(bodyBytes) > maxBodySizeBytes { | ||
return hookCommon.TransformResultModel{Error: fmt.Errorf("Body too large, larger than %d bytes", maxBodySizeBytes)} | ||
} | ||
|
||
environments := []bitriseapi.EnvironmentItem{ | ||
bitriseapi.EnvironmentItem{Name: envKeyHeaders, Value: string(headerAsJSON), IsExpand: false}, | ||
bitriseapi.EnvironmentItem{Name: envKeyBody, Value: string(bodyBytes), IsExpand: false}, | ||
} | ||
|
||
return hookCommon.TransformResultModel{ | ||
TriggerAPIParams: []bitriseapi.TriggerAPIParamsModel{ | ||
{ | ||
BuildParams: bitriseapi.BuildParamsModel{ | ||
Branch: "master", | ||
Environments: environments, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.