Skip to content

Commit

Permalink
feat: drop gh hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Dec 17, 2024
1 parent 36a3fe5 commit d574f55
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 682 deletions.
99 changes: 44 additions & 55 deletions cmd/bot/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"github.com/gotd/bot/internal/dispatch"
"github.com/gotd/bot/internal/docs"
"github.com/gotd/bot/internal/entdb"
"github.com/gotd/bot/internal/gh"
"github.com/gotd/bot/internal/oas"
"github.com/gotd/bot/internal/storage"
"github.com/gotd/bot/internal/tgmanager"
Expand Down Expand Up @@ -223,66 +222,56 @@ func (b *App) Run(ctx context.Context) error {
return b.manager.Run(ctx)
})

if secret, ok := os.LookupEnv("GITHUB_SECRET"); ok {
logger := b.logger.Named("webhook")
httpAddr := os.Getenv("HTTP_ADDR")
if httpAddr == "" {
httpAddr = "localhost:8080"
}

httpAddr := os.Getenv("HTTP_ADDR")
if httpAddr == "" {
httpAddr = "localhost:8080"
}
logger := b.logger.Named("http")
e := echo.New()
e.Use(
middleware.Recover(),
middleware.RequestID(),
echozap.ZapLogger(logger.Named("requests")),
)

webhook := gh.NewWebhook(b.storage, b.sender, secret).
WithLogger(logger)
if notifyGroup, ok := os.LookupEnv("TG_NOTIFY_GROUP"); ok {
webhook = webhook.WithNotifyGroup(notifyGroup)
}
e.GET("/probe/startup", func(c echo.Context) error {
return c.String(http.StatusOK, "ok")
})
e.GET("/probe/ready", func(c echo.Context) error {
return c.String(http.StatusOK, "ok")
})

e := echo.New()
e.Use(
middleware.Recover(),
middleware.RequestID(),
echozap.ZapLogger(logger.Named("requests")),
)
e.GET("/status", func(c echo.Context) error {
return c.String(http.StatusOK, "ok")
})

e.GET("/probe/startup", func(c echo.Context) error {
return c.String(http.StatusOK, "ok")
})
e.GET("/probe/ready", func(c echo.Context) error {
return c.String(http.StatusOK, "ok")
})
mux := http.NewServeMux()
mux.Handle("/", e)
mux.Handle("/api/", b.srv)

e.GET("/status", func(c echo.Context) error {
return c.String(http.StatusOK, "ok")
})
webhook.RegisterRoutes(e)

mux := http.NewServeMux()
mux.Handle("/", e)
mux.Handle("/api/", b.srv)

server := http.Server{
Addr: httpAddr,
Handler: mux,
BaseContext: func(listener net.Listener) context.Context {
return zctx.Base(ctx, b.logger)
},
}
group.Go(func() error {
logger.Info("ListenAndServe", zap.String("addr", server.Addr))
return server.ListenAndServe()
})
group.Go(func() error {
<-ctx.Done()
shutCtx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

logger.Info("Shutdown", zap.String("addr", server.Addr))
if err := server.Shutdown(shutCtx); err != nil {
return multierr.Append(err, server.Close())
}
return nil
})
server := http.Server{
Addr: httpAddr,
Handler: mux,
BaseContext: func(listener net.Listener) context.Context {
return zctx.Base(ctx, b.logger)
},
}
group.Go(func() error {
logger.Info("ListenAndServe", zap.String("addr", server.Addr))
return server.ListenAndServe()
})
group.Go(func() error {
<-ctx.Done()
shutCtx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

logger.Info("Shutdown", zap.String("addr", server.Addr))
if err := server.Shutdown(shutCtx); err != nil {
return multierr.Append(err, server.Close())
}
return nil
})

group.Go(func() error {
return b.client.Run(ctx, func(ctx context.Context) error {
Expand Down
2 changes: 0 additions & 2 deletions internal/gh/doc.go

This file was deleted.

63 changes: 0 additions & 63 deletions internal/gh/handle_discussion.go

This file was deleted.

94 changes: 0 additions & 94 deletions internal/gh/handle_issue.go

This file was deleted.

Loading

0 comments on commit d574f55

Please sign in to comment.