@@ -11,8 +11,6 @@ import (
1111 "io"
1212 "io/ioutil"
1313 "net/http"
14-
15- log "github.com/Sirupsen/logrus"
1614)
1715
1816// parse errors
@@ -21,10 +19,10 @@ var (
2119 ErrParsingPayload = errors .New ("error parsing payload" )
2220)
2321
24- // Event defines a GitHub hook event type
22+ // Event defines a Docker hook event type
2523type Event string
2624
27- // GitHub hook types
25+ // Docker hook types (only one for now)
2826const (
2927 BuildEvent Event = "build"
3028)
@@ -58,40 +56,14 @@ type BuildPayload struct {
5856 } `json:"repository"`
5957}
6058
61- // there are no options for docker webhooks
62- // however I'm leaving this here for now in anticipation of future support for Docker Trusted Registry
63-
64- // // Option is a configuration option for the webhook
65- // type Option func(*Webhook) error
66-
67- // // Options is a namespace var for configuration options
68- // var Options = WebhookOptions{}
69-
70- // // WebhookOptions is a namespace for configuration option methods
71- // type WebhookOptions struct{}
72-
73- // // Secret registers the GitHub secret
74- // func (WebhookOptions) Secret(secret string) Option {
75- // return func(hook *Webhook) error {
76- // hook.secret = secret
77- // return nil
78- // }
79- // }
80-
8159// Webhook instance contains all methods needed to process events
8260type Webhook struct {
8361 secret string
8462}
8563
86- // New creates and returns a WebHook instance denoted by the Provider type
64+ // New creates and returns a WebHook instance
8765func New () (* Webhook , error ) {
88- // func New(options ...Option) (*Webhook, error) {
8966 hook := new (Webhook )
90- // for _, opt := range options {
91- // if err := opt(hook); err != nil {
92- // return nil, errors.New("Error applying Option")
93- // }
94- // }
9567 return hook , nil
9668}
9769
@@ -106,24 +78,14 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
10678 return nil , ErrInvalidHTTPMethod
10779 }
10880
109- // event := r.Header.Get("X-GitHub-Event")
110- // if event == "" {
111- // return nil, ErrMissingGithubEventHeader
112- // }
113- // gitHubEvent := Event(event)
114-
11581 payload , err := ioutil .ReadAll (r .Body )
11682 if err != nil || len (payload ) == 0 {
117- log .Error (ErrParsingPayload )
118- log .Error (err )
11983 return nil , ErrParsingPayload
12084 }
12185
12286 var pl BuildPayload
12387 err = json .Unmarshal ([]byte (payload ), & pl )
12488 if err != nil {
125- log .Error (ErrParsingPayload )
126- log .Error (err )
12789 return nil , ErrParsingPayload
12890 }
12991 return pl , err
0 commit comments