Skip to content

Remove boilerplate for receiving webhooks #466

@apelisse

Description

@apelisse

I have two goals:

  • Remove the amount of boilerplate you have to write if you want to create a small app listening to webhooks,
  • Hide the event interface{} cast to actual type from the user.

I'm proposing something like this:

whl := NewWebHookListener("my-github-secret")

// Mimic http.Handler
type MyCommitCommentEventHandler struct{}
func (MyCommitCommentEventHandler) ProcessHook(w http.ResponseWriter, event CommitCommentEvent) {
    fmt.Println("Received CommitCommentEvent:", event)
    w.Write([]byte("OK"))
}

// The following two functions mimic net/http Handle() and HandleFunc()
whl.CommitCommentEventHandle(MyCommitCommentEventHandler{})
whl.CommitCommentEventHandleFunc(func(w http.ResponseWriter, event CommitCommentEvent) {
    fmt.Println("Received CommitCommentEvent:", event)
    w.Write([]byte("OK"))
})

// Add *Handle and *HandleFunc for each type of events.

log.Fatal(whl.ListenAndProcess(":8080"))

Is that something you would be interested in merging in your tree?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions