38 lines
817 B
Go
38 lines
817 B
Go
// Package git_hook...
|
|
//
|
|
// Description : git_hook...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 2021-11-11 6:39 下午
|
|
package git_hook
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// RegisterGitHookRouter 注册 git hook 回调的路由
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 6:40 下午 2021/11/11
|
|
func RegisterGitHookRouter(router *gin.Engine, handler IGitHookEventHandler) error {
|
|
if nil == handler {
|
|
return errors.New("handler is nil")
|
|
}
|
|
router.POST("/git/hook/notice", func(ctx *gin.Context) {
|
|
var (
|
|
hookData HookData
|
|
err error
|
|
)
|
|
if err = ctx.ShouldBindJSON(&hookData); nil != err {
|
|
ctx.JSON(http.StatusBadRequest, gin.H{"code": -1, "message": err.Error()})
|
|
}
|
|
handler(ctx, &hookData)
|
|
})
|
|
return nil
|
|
}
|