temp checkin
This commit is contained in:
+4
-9
@@ -16,8 +16,6 @@ before_install:
|
|||||||
- go get -u github.com/go-playground/overalls
|
- go get -u github.com/go-playground/overalls
|
||||||
- go get -u github.com/mattn/goveralls
|
- go get -u github.com/mattn/goveralls
|
||||||
- go get -u golang.org/x/tools/cmd/cover
|
- go get -u golang.org/x/tools/cmd/cover
|
||||||
- go get -u github.com/golang/lint/golint
|
|
||||||
- go get -u github.com/gordonklaus/ineffassign
|
|
||||||
- mkdir -p $GOPATH/src/gopkg.in
|
- mkdir -p $GOPATH/src/gopkg.in
|
||||||
- ln -s $GOPATH/src/github.com/$TRAVIS_REPO_SLUG $GOPATH/src/gopkg.in/webhooks.v2
|
- ln -s $GOPATH/src/github.com/$TRAVIS_REPO_SLUG $GOPATH/src/gopkg.in/webhooks.v2
|
||||||
- ln -s $GOPATH/src/github.com/$TRAVIS_REPO_SLUG $GOPATH/src/gopkg.in/webhooks.v3
|
- ln -s $GOPATH/src/github.com/$TRAVIS_REPO_SLUG $GOPATH/src/gopkg.in/webhooks.v3
|
||||||
@@ -25,16 +23,13 @@ before_install:
|
|||||||
- ln -s $GOPATH/src/github.com/$TRAVIS_REPO_SLUG $GOPATH/src/gopkg.in/webhooks.v5
|
- ln -s $GOPATH/src/github.com/$TRAVIS_REPO_SLUG $GOPATH/src/gopkg.in/webhooks.v5
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- go vet ./...
|
- go get -t ./...
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- gofmt -d -s .
|
- make lint
|
||||||
- golint ./...
|
- make test
|
||||||
- ineffassign ./
|
|
||||||
- go test -v ./...
|
|
||||||
- go test -race
|
|
||||||
|
|
||||||
after_success: |
|
after_success: |
|
||||||
[ $TRAVIS_GO_VERSION = 1.10.3 ] &&
|
[ $TRAVIS_GO_VERSION = 1.10.3 ] &&
|
||||||
overalls -project="github.com/go-playground/webhooks" -covermode=count -ignore=.git,examples -debug &&
|
overalls -project="github.com/go-playground/webhooks" -covermode=count -ignore=.git,_examples,testdata -debug &&
|
||||||
goveralls -coverprofile=overalls.coverprofile -service travis-ci -repotoken $COVERALLS_TOKEN
|
goveralls -coverprofile=overalls.coverprofile -service travis-ci -repotoken $COVERALLS_TOKEN
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
GOCMD=go
|
||||||
|
|
||||||
|
linters-install:
|
||||||
|
@gometalinter --version >/dev/null 2>&1 || { \
|
||||||
|
echo "installing linting tools..."; \
|
||||||
|
$(GOCMD) get github.com/alecthomas/gometalinter; \
|
||||||
|
gometalinter --install; \
|
||||||
|
}
|
||||||
|
|
||||||
|
lint: linters-install
|
||||||
|
@gofmt -l . >gofmt.test 2>&1 && if [ -s gofmt.test ]; then echo "Fix formatting using 'gofmt -s -w .' for:"; cat gofmt.test; exit 1; fi && rm gofmt.test
|
||||||
|
gometalinter --vendor --disable-all --enable=vet --enable=vetshadow --enable=golint --enable=maligned --enable=megacheck --enable=ineffassign --enable=misspell --enable=errcheck --enable=goconst ./...
|
||||||
|
|
||||||
|
test:
|
||||||
|
$(GOCMD) test -cover -race ./...
|
||||||
|
|
||||||
|
.PHONY: test lint linters-install
|
||||||
+11
-10
@@ -9,14 +9,14 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// parse errros
|
// parse errors
|
||||||
var (
|
var (
|
||||||
ErrEventNotSpecifiedToParse = errors.New("No Event specified to parse")
|
ErrEventNotSpecifiedToParse = errors.New("no Event specified to parse")
|
||||||
ErrInvalidHTTPMethod = errors.New("Invalid HTTP Method")
|
ErrInvalidHTTPMethod = errors.New("invalid HTTP Method")
|
||||||
ErrMissingHookUUIDHeader = errors.New("Missing X-Hook-UUID Header")
|
ErrMissingHookUUIDHeader = errors.New("missing X-Hook-UUID Header")
|
||||||
ErrMissingEventKeyHeader = errors.New("Missing X-Event-Key Header")
|
ErrMissingEventKeyHeader = errors.New("missing X-Event-Key Header")
|
||||||
ErrEventNotFound = errors.New("Event not defined to be parsed")
|
ErrEventNotFound = errors.New("event not defined to be parsed")
|
||||||
ErrParsingPayload = errors.New("Error parsing payload")
|
ErrParsingPayload = errors.New("error parsing payload")
|
||||||
ErrUUIDVerificationFailed = errors.New("UUID verification failed")
|
ErrUUIDVerificationFailed = errors.New("UUID verification failed")
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -96,15 +96,16 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
|
|||||||
if uuid == "" {
|
if uuid == "" {
|
||||||
return nil, ErrMissingHookUUIDHeader
|
return nil, ErrMissingHookUUIDHeader
|
||||||
}
|
}
|
||||||
if len(hook.uuid) > 0 && uuid != hook.uuid {
|
|
||||||
return nil, ErrUUIDVerificationFailed
|
|
||||||
}
|
|
||||||
|
|
||||||
event := r.Header.Get("X-Event-Key")
|
event := r.Header.Get("X-Event-Key")
|
||||||
if event == "" {
|
if event == "" {
|
||||||
return nil, ErrMissingEventKeyHeader
|
return nil, ErrMissingEventKeyHeader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(hook.uuid) > 0 && uuid != hook.uuid {
|
||||||
|
return nil, ErrUUIDVerificationFailed
|
||||||
|
}
|
||||||
|
|
||||||
bitbucketEvent := Event(event)
|
bitbucketEvent := Event(event)
|
||||||
|
|
||||||
var found bool
|
var found bool
|
||||||
|
|||||||
+2733
-2721
File diff suppressed because it is too large
Load Diff
+7
-7
@@ -12,14 +12,14 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// parse errros
|
// parse errors
|
||||||
var (
|
var (
|
||||||
ErrEventNotSpecifiedToParse = errors.New("No Event specified to parse")
|
ErrEventNotSpecifiedToParse = errors.New("no Event specified to parse")
|
||||||
ErrInvalidHTTPMethod = errors.New("Invalid HTTP Method")
|
ErrInvalidHTTPMethod = errors.New("invalid HTTP Method")
|
||||||
ErrMissingGithubEventHeader = errors.New("Missing X-GitHub-Event Header")
|
ErrMissingGithubEventHeader = errors.New("missing X-GitHub-Event Header")
|
||||||
ErrMissingHubSignatureHeader = errors.New("Missing X-Hub-Signature Header")
|
ErrMissingHubSignatureHeader = errors.New("missing X-Hub-Signature Header")
|
||||||
ErrEventNotFound = errors.New("Event not defined to be parsed")
|
ErrEventNotFound = errors.New("event not defined to be parsed")
|
||||||
ErrParsingPayload = errors.New("Error parsing payload")
|
ErrParsingPayload = errors.New("error parsing payload")
|
||||||
ErrHMACVerificationFailed = errors.New("HMAC verification failed")
|
ErrHMACVerificationFailed = errors.New("HMAC verification failed")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1574,7 +1574,7 @@ func TestIssueCommentEvent(t *testing.T) {
|
|||||||
"created_at": "2015-05-05T23:40:28Z",
|
"created_at": "2015-05-05T23:40:28Z",
|
||||||
"updated_at": "2015-05-05T23:40:28Z",
|
"updated_at": "2015-05-05T23:40:28Z",
|
||||||
"closed_at": null,
|
"closed_at": null,
|
||||||
"body": "It looks like you accidently spelled 'commit' with two 't's."
|
"body": "It looks like you accidentally spelled 'commit' with two 't's."
|
||||||
},
|
},
|
||||||
"comment": {
|
"comment": {
|
||||||
"url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/comments/99262140",
|
"url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/comments/99262140",
|
||||||
|
|||||||
+11
-11
@@ -9,6 +9,17 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// parse errors
|
||||||
|
var (
|
||||||
|
ErrEventNotSpecifiedToParse = errors.New("no Event specified to parse")
|
||||||
|
ErrInvalidHTTPMethod = errors.New("invalid HTTP Method")
|
||||||
|
ErrMissingGitLabEventHeader = errors.New("missing X-Gitlab-Event Header")
|
||||||
|
ErrMissingGitLabTokenHeader = errors.New("missing X-Gitlab-Token Header")
|
||||||
|
ErrEventNotFound = errors.New("event not defined to be parsed")
|
||||||
|
ErrParsingPayload = errors.New("error parsing payload")
|
||||||
|
// ErrHMACVerificationFailed = errors.New("HMAC verification failed")
|
||||||
|
)
|
||||||
|
|
||||||
// GitLab hook types
|
// GitLab hook types
|
||||||
const (
|
const (
|
||||||
PushEvents Event = "Push Hook"
|
PushEvents Event = "Push Hook"
|
||||||
@@ -58,17 +69,6 @@ func New(options ...Option) (*Webhook, error) {
|
|||||||
return hook, nil
|
return hook, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse errros
|
|
||||||
var (
|
|
||||||
ErrEventNotSpecifiedToParse = errors.New("No Event specified to parse")
|
|
||||||
ErrInvalidHTTPMethod = errors.New("Invalid HTTP Method")
|
|
||||||
ErrMissingGitLabEventHeader = errors.New("Missing X-Gitlab-Event Header")
|
|
||||||
ErrMissingGitLabTokenHeader = errors.New("Missing X-Gitlab-Token Header")
|
|
||||||
ErrEventNotFound = errors.New("Event not defined to be parsed")
|
|
||||||
ErrParsingPayload = errors.New("Error parsing payload")
|
|
||||||
// ErrHMACVerificationFailed = errors.New("HMAC verification failed")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Parse verifies and parses the events specified and returns the payload object or an error
|
// Parse verifies and parses the events specified and returns the payload object or an error
|
||||||
func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error) {
|
func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|||||||
+11
-20
@@ -2,11 +2,11 @@ package gitlab
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
. "gopkg.in/go-playground/assert.v1"
|
. "gopkg.in/go-playground/assert.v1"
|
||||||
"gopkg.in/go-playground/webhooks.v5"
|
"gopkg.in/go-playground/webhooks.v5"
|
||||||
@@ -24,7 +24,6 @@ import (
|
|||||||
//
|
//
|
||||||
|
|
||||||
const (
|
const (
|
||||||
port = 3011
|
|
||||||
path = "/webhooks"
|
path = "/webhooks"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,28 +37,20 @@ var hook *Webhook
|
|||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
|
||||||
// setup
|
// setup
|
||||||
hook = New(&Config{Secret: "sampleToken!"})
|
var err error
|
||||||
hook.RegisterEvents(HandlePayload,
|
hook, err = New(Options.Secret("sampleToken!!"))
|
||||||
PushEvents,
|
if err != nil {
|
||||||
TagEvents,
|
log.Fatal(err)
|
||||||
IssuesEvents,
|
}
|
||||||
ConfidentialIssuesEvents,
|
|
||||||
CommentEvents,
|
|
||||||
MergeRequestEvents,
|
|
||||||
WikiPageEvents,
|
|
||||||
PipelineEvents,
|
|
||||||
BuildEvents,
|
|
||||||
)
|
|
||||||
go webhooks.Run(hook, "127.0.0.1:"+strconv.Itoa(port), path)
|
|
||||||
time.Sleep(time.Millisecond * 500)
|
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|
||||||
// teardown
|
// teardown
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProvider(t *testing.T) {
|
func newServer(handler http.HandlerFunc) *httptest.Server {
|
||||||
Equal(t, hook.Provider(), webhooks.GitLab)
|
mux := http.NewServeMux()
|
||||||
|
mux.HandleFunc(path, handler)
|
||||||
|
return httptest.NewServer(mux)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBadNoEventHeader(t *testing.T) {
|
func TestBadNoEventHeader(t *testing.T) {
|
||||||
|
|||||||
+11
-11
@@ -15,6 +15,17 @@ import (
|
|||||||
client "github.com/gogits/go-gogs-client"
|
client "github.com/gogits/go-gogs-client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// parse errors
|
||||||
|
var (
|
||||||
|
ErrEventNotSpecifiedToParse = errors.New("no Event specified to parse")
|
||||||
|
ErrInvalidHTTPMethod = errors.New("invalid HTTP Method")
|
||||||
|
ErrMissingGogsEventHeader = errors.New("missing X-Gogs-Event Header")
|
||||||
|
ErrMissingGogsSignatureHeader = errors.New("missing X-Gogs-Signature Header")
|
||||||
|
ErrEventNotFound = errors.New("event not defined to be parsed")
|
||||||
|
ErrParsingPayload = errors.New("error parsing payload")
|
||||||
|
ErrHMACVerificationFailed = errors.New("HMAC verification failed")
|
||||||
|
)
|
||||||
|
|
||||||
// Option is a configuration option for the webhook
|
// Option is a configuration option for the webhook
|
||||||
type Option func(*Webhook) error
|
type Option func(*Webhook) error
|
||||||
|
|
||||||
@@ -63,17 +74,6 @@ func New(options ...Option) (*Webhook, error) {
|
|||||||
return hook, nil
|
return hook, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse errros
|
|
||||||
var (
|
|
||||||
ErrEventNotSpecifiedToParse = errors.New("No Event specified to parse")
|
|
||||||
ErrInvalidHTTPMethod = errors.New("Invalid HTTP Method")
|
|
||||||
ErrMissingGogsEventHeader = errors.New("Missing X-Gogs-Event Header")
|
|
||||||
ErrMissingGogsSignatureHeader = errors.New("Missing X-Gogs-Signature Header")
|
|
||||||
ErrEventNotFound = errors.New("Event not defined to be parsed")
|
|
||||||
ErrParsingPayload = errors.New("Error parsing payload")
|
|
||||||
ErrHMACVerificationFailed = errors.New("HMAC verification failed")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Parse verifies and parses the events specified and returns the payload object or an error
|
// Parse verifies and parses the events specified and returns the payload object or an error
|
||||||
func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error) {
|
func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
package webhooks
|
|
||||||
|
|
||||||
import "log"
|
|
||||||
|
|
||||||
// DefaultLog contains the default logger for webhooks, and prints only info and error messages by default
|
|
||||||
// for debugs override DefaultLog or see NewLogger for creating one without debugs.
|
|
||||||
var DefaultLog Logger = new(logger)
|
|
||||||
|
|
||||||
// Logger allows for customizable logging
|
|
||||||
type Logger interface {
|
|
||||||
// Info prints basic information.
|
|
||||||
Info(...interface{})
|
|
||||||
// Error prints error information.
|
|
||||||
Error(...interface{})
|
|
||||||
// Debug prints information usefull for debugging.
|
|
||||||
Debug(...interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewLogger returns a new logger for use.
|
|
||||||
func NewLogger(debug bool) Logger {
|
|
||||||
return &logger{PrintDebugs: debug}
|
|
||||||
}
|
|
||||||
|
|
||||||
type logger struct {
|
|
||||||
PrintDebugs bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info prints basic information.
|
|
||||||
func (l *logger) Info(msg ...interface{}) {
|
|
||||||
log.Println("INFO:", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// v prints error information.
|
|
||||||
func (l *logger) Error(msg ...interface{}) {
|
|
||||||
log.Println("ERROR:", msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug prints information usefull for debugging.
|
|
||||||
func (l *logger) Debug(msg ...interface{}) {
|
|
||||||
if !l.PrintDebugs {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Println("DEBUG:", msg)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user