Skip to content

Latest commit

 

History

History
72 lines (54 loc) · 1.75 KB

README.md

File metadata and controls

72 lines (54 loc) · 1.75 KB

Library webhooks

GitHub go.mod Go version (subdirectory of monorepo) GitHub commit activity GitHub Go Report Card Goproxy.cn

Library webhooks allows for easy receiving and parsing of Gitea, GitHub and GitLab Webhook Events

Installation

go get -u github.com/ergoapi/webhooks

import package into your code

import "github.com/ergoapi/webhooks"

Usage

package main

import (
 "fmt"

 "net/http"

 "github.com/ergoapi/webhooks/gitea"
)

const (
 path = "/webhooks"
)

func main() {
 hook, _ := gitea.New(gitea.Options.Secret("MyGiteaSuperSecretSecrect...?"))
 http.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
  payload, err := hook.Parse(r, github.ReleaseEvent, gitea.PullRequestEvent)
  if err != nil {
   if err == gitea.ErrEventNotFound {
    // ok event wasn;t one of the ones asked to be parsed
   }
  }
  switch payload.(type) {

  case gitea.ReleasePayload:
   release := payload.(gitea.ReleasePayload)
   // Do whatever you want from here...
   fmt.Printf("%+v", release)

  case gitea.PullRequestPayload:
   pullRequest := payload.(gitea.PullRequestPayload)
   // Do whatever you want from here...
   fmt.Printf("%+v", pullRequest)
  }
 })
 http.ListenAndServe(":3000", nil)
}

Support

  • gitea 1.18.5
  • gogs
  • github
  • gitlab