@@ -11,8 +11,6 @@ import (
11
11
"io"
12
12
"io/ioutil"
13
13
"net/http"
14
-
15
- log "github.com/Sirupsen/logrus"
16
14
)
17
15
18
16
// parse errors
@@ -21,10 +19,10 @@ var (
21
19
ErrParsingPayload = errors .New ("error parsing payload" )
22
20
)
23
21
24
- // Event defines a GitHub hook event type
22
+ // Event defines a Docker hook event type
25
23
type Event string
26
24
27
- // GitHub hook types
25
+ // Docker hook types (only one for now)
28
26
const (
29
27
BuildEvent Event = "build"
30
28
)
@@ -58,40 +56,14 @@ type BuildPayload struct {
58
56
} `json:"repository"`
59
57
}
60
58
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
-
81
59
// Webhook instance contains all methods needed to process events
82
60
type Webhook struct {
83
61
secret string
84
62
}
85
63
86
- // New creates and returns a WebHook instance denoted by the Provider type
64
+ // New creates and returns a WebHook instance
87
65
func New () (* Webhook , error ) {
88
- // func New(options ...Option) (*Webhook, error) {
89
66
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
- // }
95
67
return hook , nil
96
68
}
97
69
@@ -106,24 +78,14 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
106
78
return nil , ErrInvalidHTTPMethod
107
79
}
108
80
109
- // event := r.Header.Get("X-GitHub-Event")
110
- // if event == "" {
111
- // return nil, ErrMissingGithubEventHeader
112
- // }
113
- // gitHubEvent := Event(event)
114
-
115
81
payload , err := ioutil .ReadAll (r .Body )
116
82
if err != nil || len (payload ) == 0 {
117
- log .Error (ErrParsingPayload )
118
- log .Error (err )
119
83
return nil , ErrParsingPayload
120
84
}
121
85
122
86
var pl BuildPayload
123
87
err = json .Unmarshal ([]byte (payload ), & pl )
124
88
if err != nil {
125
- log .Error (ErrParsingPayload )
126
- log .Error (err )
127
89
return nil , ErrParsingPayload
128
90
}
129
91
return pl , err
0 commit comments