mirror of
https://github.com/zoriya/cish.git
synced 2025-12-06 07:16:16 +00:00
33 lines
779 B
Go
33 lines
779 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/ren3gadem4rm0t/github-hook-types-go/webhook"
|
|
"github.com/zoriya/cish/api/github"
|
|
)
|
|
|
|
func main() {
|
|
e := echo.New()
|
|
|
|
secret := os.Getenv("GITHUB_WEBHOOK_SECRET")
|
|
|
|
// Create a new webhook handler
|
|
handler := webhook.NewHandler(secret)
|
|
|
|
e.POST("/hooks/github", func(c echo.Context) error {
|
|
event, err := handler.ProcessWebhook(c.Request())
|
|
if err != nil {
|
|
return c.String(http.StatusBadRequest, "Webhook payload parsing failed")
|
|
}
|
|
if err := github.HandleEvent(event); err != nil {
|
|
return c.String(http.StatusInternalServerError, "Webhook event handler failed")
|
|
}
|
|
return c.String(http.StatusOK, "Webhook handled succesfully")
|
|
})
|
|
|
|
e.Logger.Fatal(e.Server.ListenAndServe())
|
|
}
|