feat(github): add github support
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-08-09 15:44:31 +02:00
parent 65fba21285
commit 89c1c72d87
11 changed files with 452 additions and 24 deletions

View File

@@ -50,16 +50,23 @@ func serverCmd() *cobra.Command {
var (
url string
token string
githubAppID int64
githubInstallationID int64
githubPrivateKeyPath string
)
giteaClient := providers.NewGiteaClient(&url, &token)
githubClient := providers.NewGitHubClient(&githubAppID, &githubInstallationID, &githubPrivateKeyPath)
renovateClient := renovate.NewRenovateClient("")
queue := queue.NewGoQueue()
botHandler := bot.NewBotHandler(giteaClient)
botHandler := bot.NewBotHandler(giteaClient, githubClient)
giteaWebhook := features.NewGiteaWebhook(botHandler, queue)
githubWebhook := features.NewGitHubWebhook(botHandler, queue)
features.RegisterGiteaQueues(queue, renovateClient, giteaClient)
features.RegisterGitHubQueues(queue, renovateClient, githubClient)
cmd := &cobra.Command{
Use: "server",
@@ -68,7 +75,11 @@ func serverCmd() *cobra.Command {
cmd.PersistentFlags().StringVar(&url, "url", "", "the api url of the server")
cmd.PersistentFlags().StringVar(&token, "token", "", "the token to authenticate with")
cmd.AddCommand(serverServeCmd(&url, &token, giteaWebhook))
cmd.PersistentFlags().Int64Var(&githubAppID, "github-app-id", 0, "github app id to authenticate with")
cmd.PersistentFlags().Int64Var(&githubInstallationID, "github-installation-id", 0, "github installation id to authenticate with")
cmd.PersistentFlags().StringVar(&githubPrivateKeyPath, "github-private-key-path", "", "path to the github app private key")
cmd.AddCommand(serverServeCmd(&url, &token, giteaWebhook, githubWebhook))
return cmd
}
@@ -77,16 +88,34 @@ func serverServeCmd(
url *string,
token *string,
giteaWebhook *features.GiteaWebhook,
githubWebhook *features.GitHubWebhook,
) *cobra.Command {
cmd := &cobra.Command{
Use: "serve",
Run: func(cmd *cobra.Command, args []string) {
engine := gin.Default()
github := engine.Group("/github")
{
github.POST("/webhook", func(ctx *gin.Context) {
var request features.GitHubWebhookRequest
if err := ctx.BindJSON(&request); err != nil {
ctx.AbortWithError(500, err)
return
}
if err := githubWebhook.HandleGitHubWebhook(ctx.Request.Context(), &request); err != nil {
ctx.AbortWithError(500, err)
return
}
ctx.Status(204)
})
}
gitea := engine.Group("/gitea")
{
gitea.POST("/webhook", func(ctx *gin.Context) {
var request features.GiteaWebhookRequest
if err := ctx.BindJSON(&request); err != nil {
ctx.AbortWithError(500, err)
@@ -102,7 +131,7 @@ func serverServeCmd(
})
}
engine.Run("0.0.0.0:8080")
engine.Run("0.0.0.0:9111")
},
}