Skip to content

ergoapi/webhooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published