Skip to content

Commit

Permalink
render out methods for debugging purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
djeebus committed Dec 21, 2023
1 parent a1cd9f6 commit 87e4a3e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
9 changes: 4 additions & 5 deletions pkg/server/hook_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"context"
"fmt"
"net/http"
"strings"

Expand All @@ -24,10 +25,9 @@ type VCSHookHandler struct {
cfg *config.ServerConfig
// labelFilter is a string specifying the required label name to filter merge events by; if empty, all merge events will pass the filter.
labelFilter string
hooksPrefix string
}

var ProjectHookPath string

func NewVCSHookHandler(cfg *config.ServerConfig) *VCSHookHandler {
labelFilter := viper.GetString("label-filter")

Expand All @@ -38,9 +38,8 @@ func NewVCSHookHandler(cfg *config.ServerConfig) *VCSHookHandler {
}
}
func (h *VCSHookHandler) AttachHandlers(grp *echo.Group) {
log.Info().Str("path", GetServer().hooksPrefix()).Msg("setting up hook handler")
grp.POST(ProjectHookPath, h.groupHandler)
log.Info().Str("path", GetServer().hooksPrefix()).Str("projectPath", ProjectHookPath).Msg("hook handler setup complete")
projectHookPath := fmt.Sprintf("/%s/project", h.cfg.VcsClient.GetName())
grp.POST(projectHookPath, h.groupHandler)
}

func (h *VCSHookHandler) groupHandler(c echo.Context) error {
Expand Down
15 changes: 7 additions & 8 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"context"
"fmt"
"net/url"
"strings"

Expand All @@ -20,19 +21,12 @@ import (

const KubeChecksHooksPathPrefix = "/hooks"

var singleton *Server

type Server struct {
cfg *config.ServerConfig
}

func NewServer(cfg *config.ServerConfig) *Server {
singleton = &Server{cfg: cfg}
return singleton
}

func GetServer() *Server {
return singleton
return &Server{cfg: cfg}
}

func (s *Server) Start(ctx context.Context) {
Expand Down Expand Up @@ -64,6 +58,11 @@ func (s *Server) Start(ctx context.Context) {
ghHooks := NewVCSHookHandler(s.cfg)
ghHooks.AttachHandlers(hooksGroup)

fmt.Println("Method\tPath")
for _, r := range e.Routes() {
fmt.Printf("%s\t%s\n", r.Method, r.Path)
}

if err := e.Start(":8080"); err != nil {
log.Fatal().Err(err).Msg("could not start hooks server")
}
Expand Down

0 comments on commit 87e4a3e

Please sign in to comment.