#53 removing logging, remove extraneous comments
This commit is contained in:
+3
-41
@@ -11,8 +11,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// parse errors
|
// parse errors
|
||||||
@@ -21,10 +19,10 @@ var (
|
|||||||
ErrParsingPayload = errors.New("error parsing payload")
|
ErrParsingPayload = errors.New("error parsing payload")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Event defines a GitHub hook event type
|
// Event defines a Docker hook event type
|
||||||
type Event string
|
type Event string
|
||||||
|
|
||||||
// GitHub hook types
|
// Docker hook types (only one for now)
|
||||||
const (
|
const (
|
||||||
BuildEvent Event = "build"
|
BuildEvent Event = "build"
|
||||||
)
|
)
|
||||||
@@ -58,40 +56,14 @@ type BuildPayload struct {
|
|||||||
} `json:"repository"`
|
} `json:"repository"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// there are no options for docker webhooks
|
|
||||||
// however I'm leaving this here for now in anticipation of future support for Docker Trusted Registry
|
|
||||||
|
|
||||||
// // Option is a configuration option for the webhook
|
|
||||||
// type Option func(*Webhook) error
|
|
||||||
|
|
||||||
// // Options is a namespace var for configuration options
|
|
||||||
// var Options = WebhookOptions{}
|
|
||||||
|
|
||||||
// // WebhookOptions is a namespace for configuration option methods
|
|
||||||
// type WebhookOptions struct{}
|
|
||||||
|
|
||||||
// // Secret registers the GitHub secret
|
|
||||||
// func (WebhookOptions) Secret(secret string) Option {
|
|
||||||
// return func(hook *Webhook) error {
|
|
||||||
// hook.secret = secret
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Webhook instance contains all methods needed to process events
|
// Webhook instance contains all methods needed to process events
|
||||||
type Webhook struct {
|
type Webhook struct {
|
||||||
secret string
|
secret string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates and returns a WebHook instance denoted by the Provider type
|
// New creates and returns a WebHook instance
|
||||||
func New() (*Webhook, error) {
|
func New() (*Webhook, error) {
|
||||||
// func New(options ...Option) (*Webhook, error) {
|
|
||||||
hook := new(Webhook)
|
hook := new(Webhook)
|
||||||
// for _, opt := range options {
|
|
||||||
// if err := opt(hook); err != nil {
|
|
||||||
// return nil, errors.New("Error applying Option")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
return hook, nil
|
return hook, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,24 +78,14 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
|
|||||||
return nil, ErrInvalidHTTPMethod
|
return nil, ErrInvalidHTTPMethod
|
||||||
}
|
}
|
||||||
|
|
||||||
// event := r.Header.Get("X-GitHub-Event")
|
|
||||||
// if event == "" {
|
|
||||||
// return nil, ErrMissingGithubEventHeader
|
|
||||||
// }
|
|
||||||
// gitHubEvent := Event(event)
|
|
||||||
|
|
||||||
payload, err := ioutil.ReadAll(r.Body)
|
payload, err := ioutil.ReadAll(r.Body)
|
||||||
if err != nil || len(payload) == 0 {
|
if err != nil || len(payload) == 0 {
|
||||||
log.Error(ErrParsingPayload)
|
|
||||||
log.Error(err)
|
|
||||||
return nil, ErrParsingPayload
|
return nil, ErrParsingPayload
|
||||||
}
|
}
|
||||||
|
|
||||||
var pl BuildPayload
|
var pl BuildPayload
|
||||||
err = json.Unmarshal([]byte(payload), &pl)
|
err = json.Unmarshal([]byte(payload), &pl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(ErrParsingPayload)
|
|
||||||
log.Error(err)
|
|
||||||
return nil, ErrParsingPayload
|
return nil, ErrParsingPayload
|
||||||
}
|
}
|
||||||
return pl, err
|
return pl, err
|
||||||
|
|||||||
@@ -61,9 +61,6 @@ func TestWebhooks(t *testing.T) {
|
|||||||
event: BuildEvent,
|
event: BuildEvent,
|
||||||
typ: BuildPayload{},
|
typ: BuildPayload{},
|
||||||
filename: "../testdata/docker/docker_hub_build_notice.json",
|
filename: "../testdata/docker/docker_hub_build_notice.json",
|
||||||
headers: http.Header{
|
|
||||||
"X-Github-Event": []string{"commit_comment"},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +83,6 @@ func TestWebhooks(t *testing.T) {
|
|||||||
defer server.Close()
|
defer server.Close()
|
||||||
req, err := http.NewRequest(http.MethodPost, server.URL+path, payload)
|
req, err := http.NewRequest(http.MethodPost, server.URL+path, payload)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
req.Header = tc.headers
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
|||||||
Reference in New Issue
Block a user