Skip to content

Commit

Permalink
#53 removing logging, remove extraneous comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bnfinet committed Nov 28, 2018
1 parent a92dd93 commit f1f5db7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 45 deletions.
44 changes: 3 additions & 41 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"io"
"io/ioutil"
"net/http"

log "github.com/Sirupsen/logrus"
)

// parse errors
Expand All @@ -21,10 +19,10 @@ var (
ErrParsingPayload = errors.New("error parsing payload")
)

// Event defines a GitHub hook event type
// Event defines a Docker hook event type
type Event string

// GitHub hook types
// Docker hook types (only one for now)
const (
BuildEvent Event = "build"
)
Expand Down Expand Up @@ -58,40 +56,14 @@ type BuildPayload struct {
} `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
type Webhook struct {
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(options ...Option) (*Webhook, error) {
hook := new(Webhook)
// for _, opt := range options {
// if err := opt(hook); err != nil {
// return nil, errors.New("Error applying Option")
// }
// }
return hook, nil
}

Expand All @@ -106,24 +78,14 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
return nil, ErrInvalidHTTPMethod
}

// event := r.Header.Get("X-GitHub-Event")
// if event == "" {
// return nil, ErrMissingGithubEventHeader
// }
// gitHubEvent := Event(event)

payload, err := ioutil.ReadAll(r.Body)
if err != nil || len(payload) == 0 {
log.Error(ErrParsingPayload)
log.Error(err)
return nil, ErrParsingPayload
}

var pl BuildPayload
err = json.Unmarshal([]byte(payload), &pl)
if err != nil {
log.Error(ErrParsingPayload)
log.Error(err)
return nil, ErrParsingPayload
}
return pl, err
Expand Down
4 changes: 0 additions & 4 deletions docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ func TestWebhooks(t *testing.T) {
event: BuildEvent,
typ: BuildPayload{},
filename: "../testdata/docker/docker_hub_build_notice.json",
headers: http.Header{
"X-Github-Event": []string{"commit_comment"},
},
},
}

Expand All @@ -86,7 +83,6 @@ func TestWebhooks(t *testing.T) {
defer server.Close()
req, err := http.NewRequest(http.MethodPost, server.URL+path, payload)
assert.NoError(err)
req.Header = tc.headers
req.Header.Set("Content-Type", "application/json")

resp, err := client.Do(req)
Expand Down

0 comments on commit f1f5db7

Please sign in to comment.