Skip to content

GitbookIO/go-github-webhook

Repository files navigation

go-github-webhook

A GitHub webhook handler written in Go. It simplifies payload validation, etc ...

Sample app

package main

import (
    "fmt"
    "net/http"

    "github.com/GitbookIO/go-github-webhook"
)

func main() {
    // Your GitHub secret (this could also be dynamic), if you're secret is empty it will skip validation
    secret := ""

    if err := http.ListenAndServe(":8000", WebhookLog(secret)); err != nil {
        fmt.Errorf("Error: %s", err)
    }
}

func WebhookLog(secret string) http.Handler {
    return github.Handler(secret, func(event string, payload *github.GitHubPayload, req *http.Request) error {
        // Log webhook
        fmt.Println("Received", event, "for ", payload.Repository.Name)

        // You'll probably want to do some real processing
        fmt.Println("Can clone repo at:", payload.Repository.CloneURL)

        // All is good (return an error to fail)
        return nil
    })
}

About

A GitHub webhook handler written in Go

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages