temp checkin

This commit is contained in:
Dean Karn
2018-07-26 08:54:32 -07:00
parent e452811cf1
commit 1d0289a3ae
13 changed files with 2806 additions and 2834 deletions
+4 -9
View File
@@ -16,8 +16,6 @@ before_install:
- go get -u github.com/go-playground/overalls
- go get -u github.com/mattn/goveralls
- 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
- 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
@@ -25,16 +23,13 @@ before_install:
- ln -s $GOPATH/src/github.com/$TRAVIS_REPO_SLUG $GOPATH/src/gopkg.in/webhooks.v5
before_script:
- go vet ./...
- go get -t ./...
script:
- gofmt -d -s .
- golint ./...
- ineffassign ./
- go test -v ./...
- go test -race
- make lint
- make test
after_success: |
[ $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
+17
View File
@@ -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
View File
@@ -9,14 +9,14 @@ import (
"net/http"
)
// parse errros
// parse errors
var (
ErrEventNotSpecifiedToParse = errors.New("No Event specified to parse")
ErrInvalidHTTPMethod = errors.New("Invalid HTTP Method")
ErrMissingHookUUIDHeader = errors.New("Missing X-Hook-UUID Header")
ErrMissingEventKeyHeader = errors.New("Missing X-Event-Key Header")
ErrEventNotFound = errors.New("Event not defined to be parsed")
ErrParsingPayload = errors.New("Error parsing payload")
ErrEventNotSpecifiedToParse = errors.New("no Event specified to parse")
ErrInvalidHTTPMethod = errors.New("invalid HTTP Method")
ErrMissingHookUUIDHeader = errors.New("missing X-Hook-UUID Header")
ErrMissingEventKeyHeader = errors.New("missing X-Event-Key Header")
ErrEventNotFound = errors.New("event not defined to be parsed")
ErrParsingPayload = errors.New("error parsing payload")
ErrUUIDVerificationFailed = errors.New("UUID verification failed")
)
@@ -96,15 +96,16 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
if uuid == "" {
return nil, ErrMissingHookUUIDHeader
}
if len(hook.uuid) > 0 && uuid != hook.uuid {
return nil, ErrUUIDVerificationFailed
}
event := r.Header.Get("X-Event-Key")
if event == "" {
return nil, ErrMissingEventKeyHeader
}
if len(hook.uuid) > 0 && uuid != hook.uuid {
return nil, ErrUUIDVerificationFailed
}
bitbucketEvent := Event(event)
var found bool
+2735 -2723
View File
File diff suppressed because it is too large Load Diff
+7 -7
View File
@@ -12,14 +12,14 @@ import (
"net/http"
)
// parse errros
// parse errors
var (
ErrEventNotSpecifiedToParse = errors.New("No Event specified to parse")
ErrInvalidHTTPMethod = errors.New("Invalid HTTP Method")
ErrMissingGithubEventHeader = errors.New("Missing X-GitHub-Event Header")
ErrMissingHubSignatureHeader = errors.New("Missing X-Hub-Signature Header")
ErrEventNotFound = errors.New("Event not defined to be parsed")
ErrParsingPayload = errors.New("Error parsing payload")
ErrEventNotSpecifiedToParse = errors.New("no Event specified to parse")
ErrInvalidHTTPMethod = errors.New("invalid HTTP Method")
ErrMissingGithubEventHeader = errors.New("missing X-GitHub-Event Header")
ErrMissingHubSignatureHeader = errors.New("missing X-Hub-Signature Header")
ErrEventNotFound = errors.New("event not defined to be parsed")
ErrParsingPayload = errors.New("error parsing payload")
ErrHMACVerificationFailed = errors.New("HMAC verification failed")
)
+1 -1
View File
@@ -1574,7 +1574,7 @@ func TestIssueCommentEvent(t *testing.T) {
"created_at": "2015-05-05T23:40:28Z",
"updated_at": "2015-05-05T23:40:28Z",
"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": {
"url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/comments/99262140",
+11 -11
View File
@@ -9,6 +9,17 @@ import (
"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
const (
PushEvents Event = "Push Hook"
@@ -58,17 +69,6 @@ func New(options ...Option) (*Webhook, error) {
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
func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error) {
defer func() {
+11 -20
View File
@@ -2,11 +2,11 @@ package gitlab
import (
"bytes"
"log"
"net/http"
"net/http/httptest"
"os"
"strconv"
"testing"
"time"
. "gopkg.in/go-playground/assert.v1"
"gopkg.in/go-playground/webhooks.v5"
@@ -24,7 +24,6 @@ import (
//
const (
port = 3011
path = "/webhooks"
)
@@ -38,28 +37,20 @@ var hook *Webhook
func TestMain(m *testing.M) {
// setup
hook = New(&Config{Secret: "sampleToken!"})
hook.RegisterEvents(HandlePayload,
PushEvents,
TagEvents,
IssuesEvents,
ConfidentialIssuesEvents,
CommentEvents,
MergeRequestEvents,
WikiPageEvents,
PipelineEvents,
BuildEvents,
)
go webhooks.Run(hook, "127.0.0.1:"+strconv.Itoa(port), path)
time.Sleep(time.Millisecond * 500)
var err error
hook, err = New(Options.Secret("sampleToken!!"))
if err != nil {
log.Fatal(err)
}
os.Exit(m.Run())
// teardown
}
func TestProvider(t *testing.T) {
Equal(t, hook.Provider(), webhooks.GitLab)
func newServer(handler http.HandlerFunc) *httptest.Server {
mux := http.NewServeMux()
mux.HandleFunc(path, handler)
return httptest.NewServer(mux)
}
func TestBadNoEventHeader(t *testing.T) {
+11 -11
View File
@@ -15,6 +15,17 @@ import (
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
type Option func(*Webhook) error
@@ -63,17 +74,6 @@ func New(options ...Option) (*Webhook, error) {
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
func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error) {
defer func() {
-44
View File
@@ -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)
}