Skip to content

Commit

Permalink
webhook: name dumped files after value of X-GitHub-Delivery header
Browse files Browse the repository at this point in the history
  • Loading branch information
rjeczalik committed Mar 22, 2015
1 parent e85ab37 commit 0fbb3e6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions webhook/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,18 @@ func (d *Dumper) ServeHTTP(w http.ResponseWriter, req *http.Request) {
req.Body = ioutil.NopCloser(io.TeeReader(req.Body, buf))
d.Handler.ServeHTTP(rec, req)
if rec.status == 200 {
go d.dump(req.Header.Get("X-GitHub-Event"), buf)
go d.dump(req.Header.Get("X-GitHub-Event"), req.Header.Get("X-GitHub-Delivery"), buf)
}
}

func (d *Dumper) dump(event string, buf *bytes.Buffer) {
func (d *Dumper) dump(event, delivery string, buf *bytes.Buffer) {
var name string
if event != "" {
switch {
case event != "" && delivery != "":
name = filepath.Join(d.Dir, fmt.Sprintf("%s-%s.json", event, delivery))
case event != "":
name = filepath.Join(d.Dir, fmt.Sprintf("%s-%s.json", event, now()))
} else {
default:
name = filepath.Join(d.Dir, now())
}
var err error
Expand Down

0 comments on commit 0fbb3e6

Please sign in to comment.